cifsd: check return value of ksmbd_vfs_getcasexattr() correctly
authorYang Yingliang <yangyingliang@huawei.com>
Mon, 31 May 2021 08:25:05 +0000 (17:25 +0900)
committerNamjae Jeon <namjae.jeon@samsung.com>
Tue, 1 Jun 2021 00:26:20 +0000 (09:26 +0900)
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>
fs/cifsd/vfs.c

index 8587241..56b1091 100644 (file)
@@ -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,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);
@@ -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;
        }