cifsd: check return value of ksmbd_vfs_getcasexattr() correctly
Subsystems (2)
PATCH v2 1/1 cifsd: check return value of ksmbd_vfs_getcasexattr() correctly
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.
---
v2:
Handle the case ksmbd_vfs_getcasexattr() returns 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 v_len ==0 ? -ENOENT : (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 = v_len ==0 ? -ENOENT : (int )v_len; goto out; }
Signature · 1 line
2.25.1
2021년 5월 31일 (월) 오후 12:01, Yang Yingliang <[email protected]>님이 작성:
Quoted 28 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]>---
v2:
Handle the caseksmbd_vfs_getcasexattr()returns 0.--- 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 287
Quoted 9 lines
fs/cifsd/vfs.c +2
-3@@ -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 v_len ==0 ? -ENOENT : (int )v_len;
How about making ksmbd_vfs_getcasexattr return -ENONENT instead of returning 0 to
remove duplicate error handling code?
Thanks,
Hyunchul
Quoted 18 lines
fs/cifsd/vfs.c +2
-3}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 = v_len ==0 ? -ENOENT : (int )v_len; goto out; } --2.25.1
Quoted 25 lines · Hyunchul Lee
2021년 5월 31일 (월) 오후 12:01, Yang Yingliang <[email protected]>님이 작성:
Quoted 24 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]>---
v2:
Handle the caseksmbd_vfs_getcasexattr()returns 0.--- 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;
Quoted 15 lines
fs/cifsd/vfs.c static int ksmbd_vfs_stream_read(struct ksmbd_file *fp, char *buf, loff_t *pos, · line 287
Quoted 12 lines
fs/cifsd/vfs.c +2
-3ksmbd_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 v_len ==0 ? -ENOENT : (int )v_len;How about making
ksmbd_vfs_getcasexattrreturn-ENONENTinstead of returning 0 to
remove duplicate error handling code?
Yes, I think it's ok, I will send a v3 later.
Thanks,
Yang
Quoted 23 lines
Thanks,
HyunchulQuoted 16 lines
fs/cifsd/vfs.c +2
-3}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 = v_len ==0 ? -ENOENT : (int )v_len; goto out; } --Quoted 2 lines
2.25.1
.