cifsd: fix memleak in ksmbd_vfs_stream_write()
Subsystems (2)
PATCH 1/3 cifsd: fix memleak in ksmbd_vfs_stream_write()
Before assigning wbuf to stream_buf, memory allocate in ksmbd_vfs_getcasexattr() need be freed.
--- fs/cifsd/vfs.c | 1 + 1 file changed, 1 insertion(+)
fs/cifsd/vfs.c +1 -0
@@ -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; }
Signature · 1 line
2.25.1
PATCH 2/3 cifsd: fix memleak in ksmbd_vfs_stream_read()
Before ksmbd_vfs_stream_read() return, memory allocate in ksmbd_vfs_getcasexattr() need be freed.
--- fs/cifsd/vfs.c | 1 + 1 file changed, 1 insertion(+)
fs/cifsd/vfs.c +1 -0
@@ -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; }
Signature · 1 line
2.25.1
RE: [PATCH -next 2/3] cifsd: fix memleak in ksmbd_vfs_stream_read()
Quoted 5 lines
Before
ksmbd_vfs_stream_read()return, memory allocate inksmbd_vfs_getcasexattr()need be freed.Fixes f44158485826 ("cifsd: add file operations")Signed-off-by Yang Yingliang <[email protected]>
I will apply, Thanks for your patch!
PATCH 3/3 cifsd: check return value of ksmbd_vfs_getcasexattr() correctly
In reply to Yang YingliangIf 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.
--- fs/cifsd/vfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)
fs/cifsd/vfs.c +4 -6
@@ -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; }
Signature · 1 line
2.25.1
Re: [PATCH -next 3/3] cifsd: check return value of ksmbd_vfs_getcasexattr() correctly
Hi Yang,
2021년 5월 29일 (토) 오후 5:16, Yang Yingliang <[email protected]>님이 작성:
Quoted 25 lines
If
ksmbd_vfs_getcasexattr()returns-ENOMEM,stream_bufis NULL, it will cause null-ptr-deref when using it to copy memory. So we need check the return value ofksmbd_vfs_getcasexattr()by comparing with 0.Fixes f44158485826 ("cifsd: add file operations")Signed-off-by Yang Yingliang <[email protected]>--- fs/cifsd/vfs.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-)fs/cifsd/vfs.c +0
-1@@ -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);
fs/cifsd/vfs.c static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos, · line 285
Quoted 5 lines
fs/cifsd/vfs.c +1
-1@@ -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
Quoted 22 lines
fs/cifsd/vfs.c +3
-5ksmbd_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
Quoted 5 lines
Before assigning wbuf to
stream_buf, memory allocate inksmbd_vfs_getcasexattr()need be freed.Fixes f44158485826 ("cifsd: add file operations")Signed-off-by Yang Yingliang <[email protected]>
I will apply, Thanks for your patch!