Skip to content

Commit

Permalink
cifsd: check return value of ksmbd_vfs_getcasexattr() correctly
Browse files Browse the repository at this point in the history
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.

Signed-off-by: Yang Yingliang <yangyingliang@huawei.com>
Signed-off-by: Namjae Jeon <namjae.jeon@samsung.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
  • Loading branch information
Yang Yingliang authored and namjaejeon committed Jun 1, 2021
1 parent 673b9ba commit fd6de09
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions fs/cifsd/vfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -283,11 +282,8 @@ 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) {
ksmbd_err("not found stream in xattr : %zd\n", v_len);
err = -ENOENT;
return err;
}
if ((int)v_len <= 0)
return (int)v_len;

memcpy(buf, &stream_buf[*pos], count);
kvfree(stream_buf);
Expand Down Expand Up @@ -415,9 +411,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;
}

Expand Down

0 comments on commit fd6de09

Please sign in to comment.