Skip to content

Commit

Permalink
lib/iov_iter: fix import_iovec_ubuf iovec management
Browse files Browse the repository at this point in the history
import_iovec() says that it should always be fine to kfree the iovec
returned in @iovp regardless of the error code.  __import_iovec_ubuf()
never reallocates it and thus should clear the pointer even in cases when
copy_iovec_*() fail.

Link: https://lkml.kernel.org/r/378ae26923ffc20fd5e41b4360d673bf47b1775b.1738332461.git.asml.silence@gmail.com
Fixes: 3b2deb0 ("iov_iter: import single vector iovecs as ITER_UBUF")
Signed-off-by: Pavel Begunkov <[email protected]>
Reviewed-by: Jens Axboe <[email protected]>
Cc: Al Viro <[email protected]>
Cc: Christian Brauner <[email protected]>
Cc: <[email protected]>
Signed-off-by: Andrew Morton <[email protected]>
  • Loading branch information
isilence authored and akpm00 committed Feb 18, 2025
1 parent c8a3e63 commit f4b7826
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/iov_iter.c
Original file line number Diff line number Diff line change
Expand Up @@ -1428,6 +1428,8 @@ static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec,
struct iovec *iov = *iovp;
ssize_t ret;

*iovp = NULL;

if (compat)
ret = copy_compat_iovec_from_user(iov, uvec, 1);
else
Expand All @@ -1438,7 +1440,6 @@ static ssize_t __import_iovec_ubuf(int type, const struct iovec __user *uvec,
ret = import_ubuf(type, iov->iov_base, iov->iov_len, i);
if (unlikely(ret))
return ret;
*iovp = NULL;
return i->count;
}

Expand Down

0 comments on commit f4b7826

Please sign in to comment.