Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

block: Fix memory leak in rw_copy_check_uvector() handling

Fix a memory leak in the error handling path of function sg_io()
that is used during the processing of scsi ioctl. Memory already
allocated by rw_copy_check_uvector() needs to be freed correctly.
Detected by Coverity: CID 1128953.

Signed-off-by: Christian Engelmayer <cengelma@gmx.at>
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christian Engelmayer and committed by
Jens Axboe
17a05cca 5837c80e

+4 -2
+4 -2
block/scsi_ioctl.c
··· 323 323 324 324 if (hdr->iovec_count) { 325 325 size_t iov_data_len; 326 - struct iovec *iov; 326 + struct iovec *iov = NULL; 327 327 328 328 ret = rw_copy_check_uvector(-1, hdr->dxferp, hdr->iovec_count, 329 329 0, NULL, &iov); 330 - if (ret < 0) 330 + if (ret < 0) { 331 + kfree(iov); 331 332 goto out; 333 + } 332 334 333 335 iov_data_len = ret; 334 336 ret = 0;