* [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() @ 2021-05-29 8:20 ` Yang Yingliang 2021-05-29 8:20 ` [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read() Yang Yingliang ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Yang Yingliang @ 2021-05-29 8:20 UTC (permalink / raw) To: linux-kernel, linux-cifsd-devel, linux-cifs Cc: namjae.jeon, sergey.senozhatsky, sfrench, hyc.lee Before assigning wbuf to stream_buf, memory allocate in ksmbd_vfs_getcasexattr() need be freed. Fixes: f44158485826 ("cifsd: add file operations") Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- fs/cifsd/vfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/cifsd/vfs.c b/fs/cifsd/vfs.c index 291953eff5fa..9057b30278b9 100644 --- a/fs/cifsd/vfs.c +++ b/fs/cifsd/vfs.c @@ -429,6 +429,7 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos, if (v_len > 0) memcpy(wbuf, stream_buf, v_len); + kfree(stream_buf); stream_buf = wbuf; } -- 2.25.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read() 2021-05-29 8:20 ` [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() Yang Yingliang @ 2021-05-29 8:20 ` Yang Yingliang 2021-05-31 1:09 ` Namjae Jeon 2021-05-29 8:20 ` [PATCH -next 3/3] cifsd: check return value of ksmbd_vfs_getcasexattr() correctly Yang Yingliang 2021-05-31 1:09 ` [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() Namjae Jeon 2 siblings, 1 reply; 6+ messages in thread From: Yang Yingliang @ 2021-05-29 8:20 UTC (permalink / raw) To: linux-kernel, linux-cifsd-devel, linux-cifs Cc: namjae.jeon, sergey.senozhatsky, sfrench, hyc.lee Before ksmbd_vfs_stream_read() return, memory allocate in ksmbd_vfs_getcasexattr() need be freed. Fixes: f44158485826 ("cifsd: add file operations") Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- fs/cifsd/vfs.c | 1 + 1 file changed, 1 insertion(+) diff --git a/fs/cifsd/vfs.c b/fs/cifsd/vfs.c index 9057b30278b9..97d5584ec870 100644 --- a/fs/cifsd/vfs.c +++ b/fs/cifsd/vfs.c @@ -290,6 +290,7 @@ static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos, } memcpy(buf, &stream_buf[*pos], count); + kfree(stream_buf); return v_len > count ? count : v_len; } -- 2.25.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* RE: [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read() 2021-05-29 8:20 ` [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read() Yang Yingliang @ 2021-05-31 1:09 ` Namjae Jeon 0 siblings, 0 replies; 6+ messages in thread From: Namjae Jeon @ 2021-05-31 1:09 UTC (permalink / raw) To: 'Yang Yingliang' Cc: sergey.senozhatsky, sfrench, hyc.lee, linux-kernel, linux-cifsd-devel, linux-cifs > Before ksmbd_vfs_stream_read() return, memory allocate in > ksmbd_vfs_getcasexattr() need be freed. > > Fixes: f44158485826 ("cifsd: add file operations") > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> I will apply, Thanks for your patch! ^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH -next 3/3] cifsd: check return value of ksmbd_vfs_getcasexattr() correctly 2021-05-29 8:20 ` [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() Yang Yingliang 2021-05-29 8:20 ` [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read() Yang Yingliang @ 2021-05-29 8:20 ` Yang Yingliang 2021-05-29 14:13 ` Hyunchul Lee 2021-05-31 1:09 ` [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() Namjae Jeon 2 siblings, 1 reply; 6+ messages in thread From: Yang Yingliang @ 2021-05-29 8:20 UTC (permalink / raw) To: linux-kernel, linux-cifsd-devel, linux-cifs Cc: namjae.jeon, sergey.senozhatsky, sfrench, hyc.lee If ksmbd_vfs_getcasexattr() returns -ENOMEM, stream_buf is NULL, it will cause null-ptr-deref when using it to copy memory. So we need check the return value of ksmbd_vfs_getcasexattr() by comparing with 0. Fixes: f44158485826 ("cifsd: add file operations") Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> --- fs/cifsd/vfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/fs/cifsd/vfs.c b/fs/cifsd/vfs.c index 97d5584ec870..45ba30f1f2d2 100644 --- a/fs/cifsd/vfs.c +++ b/fs/cifsd/vfs.c @@ -274,7 +274,6 @@ static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos, { ssize_t v_len; char *stream_buf = NULL; - int err; ksmbd_debug(VFS, "read stream data pos : %llu, count : %zd\n", *pos, count); @@ -283,10 +282,9 @@ static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos, fp->stream.name, fp->stream.size, &stream_buf); - if (v_len == -ENOENT) { + if ((int)v_len < 0) { ksmbd_err("not found stream in xattr : %zd\n", v_len); - err = -ENOENT; - return err; + return (int)v_len; } memcpy(buf, &stream_buf[*pos], count); @@ -415,9 +413,9 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos, fp->stream.name, fp->stream.size, &stream_buf); - if (v_len == -ENOENT) { + if ((int)v_len < 0) { ksmbd_err("not found stream in xattr : %zd\n", v_len); - err = -ENOENT; + err = (int)v_len; goto out; } -- 2.25.1 ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH -next 3/3] cifsd: check return value of ksmbd_vfs_getcasexattr() correctly 2021-05-29 8:20 ` [PATCH -next 3/3] cifsd: check return value of ksmbd_vfs_getcasexattr() correctly Yang Yingliang @ 2021-05-29 14:13 ` Hyunchul Lee 0 siblings, 0 replies; 6+ messages in thread From: Hyunchul Lee @ 2021-05-29 14:13 UTC (permalink / raw) To: Yang Yingliang Cc: LKML, linux-cifsd-devel, linux-cifs, Namjae Jeon, Sergey Senozhatsky, Steve French Hi Yang, 2021년 5월 29일 (토) 오후 5:16, Yang Yingliang <yangyingliang@huawei.com>님이 작성: > > If ksmbd_vfs_getcasexattr() returns -ENOMEM, stream_buf is NULL, > it will cause null-ptr-deref when using it to copy memory. So we > need check the return value of ksmbd_vfs_getcasexattr() by comparing > with 0. > > Fixes: f44158485826 ("cifsd: add file operations") > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> > --- > fs/cifsd/vfs.c | 10 ++++------ > 1 file changed, 4 insertions(+), 6 deletions(-) > > diff --git a/fs/cifsd/vfs.c b/fs/cifsd/vfs.c > index 97d5584ec870..45ba30f1f2d2 100644 > --- a/fs/cifsd/vfs.c > +++ b/fs/cifsd/vfs.c > @@ -274,7 +274,6 @@ static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos, > { > ssize_t v_len; > char *stream_buf = NULL; > - int err; > > ksmbd_debug(VFS, "read stream data pos : %llu, count : %zd\n", > *pos, count); > @@ -283,10 +282,9 @@ static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos, > fp->stream.name, > fp->stream.size, > &stream_buf); > - if (v_len == -ENOENT) { > + if ((int)v_len < 0) { because ksmbd_vfs_getcasexattr can return 0, 0 has to be handled. Thanks, Hyunchul > ksmbd_err("not found stream in xattr : %zd\n", v_len); > - err = -ENOENT; > - return err; > + return (int)v_len; > } > > memcpy(buf, &stream_buf[*pos], count); > @@ -415,9 +413,9 @@ static int ksmbd_vfs_stream_write(struct ksmbd_file *fp, char *buf, loff_t *pos, > fp->stream.name, > fp->stream.size, > &stream_buf); > - if (v_len == -ENOENT) { > + if ((int)v_len < 0) { > ksmbd_err("not found stream in xattr : %zd\n", v_len); > - err = -ENOENT; > + err = (int)v_len; > goto out; > } > > -- > 2.25.1 > ^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() 2021-05-29 8:20 ` [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() Yang Yingliang 2021-05-29 8:20 ` [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read() Yang Yingliang 2021-05-29 8:20 ` [PATCH -next 3/3] cifsd: check return value of ksmbd_vfs_getcasexattr() correctly Yang Yingliang @ 2021-05-31 1:09 ` Namjae Jeon 2 siblings, 0 replies; 6+ messages in thread From: Namjae Jeon @ 2021-05-31 1:09 UTC (permalink / raw) To: 'Yang Yingliang' Cc: sergey.senozhatsky, sfrench, hyc.lee, linux-kernel, linux-cifsd-devel, linux-cifs > Before assigning wbuf to stream_buf, memory allocate in > ksmbd_vfs_getcasexattr() need be freed. > > Fixes: f44158485826 ("cifsd: add file operations") > Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> I will apply, Thanks for your patch! ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2021-05-31 1:09 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- [not found] <CGME20210529081635epcas1p130adfff1e044c7749f059e413ad4e8b8@epcas1p1.samsung.com> 2021-05-29 8:20 ` [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() Yang Yingliang 2021-05-29 8:20 ` [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read() Yang Yingliang 2021-05-31 1:09 ` Namjae Jeon 2021-05-29 8:20 ` [PATCH -next 3/3] cifsd: check return value of ksmbd_vfs_getcasexattr() correctly Yang Yingliang 2021-05-29 14:13 ` Hyunchul Lee 2021-05-31 1:09 ` [PATCH -next 1/3] cifsd: fix memleak in ksmbd_vfs_stream_write() Namjae Jeon
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).