lib/iov_iter: fix import_iovec_ubuf iovec management
Subsystems (2)
PATCH 1/1 lib/iov_iter: fix import_iovec_ubuf iovec management
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.
--- lib/iov_iter.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
lib/iov_iter.c +2 -1
@@ -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
@@ -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; }
Signature · 1 line
2.47.1
Quoted 4 lines · Pavel Begunkov
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.
Looks good to me:
Signature · 1 line
Jens Axboe
Quoted 4 lines · Pavel Begunkov
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.
To be fair, all callers I checked don't look at the returned iovec if import_iovec*() fails, but I didn't track down all of them.
Signature · 1 line
Pavel Begunkov
Quoted 8 lines · Pavel Begunkov
Quoted 4 lines · Pavel Begunkov
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.To be fair, all callers I checked don't look at the returned iovec if import_iovec*() fails, but I didn't track down all of them.
Yep I also checked too and didn't spot any issues from this, but it's still prudent to clean it up.
Signature · 1 line
Jens Axboe