From: Eric Biggers <ebiggers@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Subject: [f2fs-dev] [PATCH 2/3] f2fs: fix copying too many bytes in FS_IOC_SETFSLABEL
Date: Thu, 15 Aug 2019 22:55:38 -0700 [thread overview]
Message-ID: <20190816055539.30420-3-ebiggers@kernel.org> (raw)
In-Reply-To: <20190816055539.30420-1-ebiggers@kernel.org>
From: Eric Biggers <ebiggers@google.com>
Userspace provides a null-terminated string, so don't assume that the
full FSLABEL_MAX bytes can always be copied.
Fixes: 61a3da4d5ef8 ("f2fs: support FS_IOC_{GET,SET}FSLABEL")
Signed-off-by: Eric Biggers <ebiggers@google.com>
---
fs/f2fs/file.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/fs/f2fs/file.c b/fs/f2fs/file.c
index d521a582d94d..315127251bc1 100644
--- a/fs/f2fs/file.c
+++ b/fs/f2fs/file.c
@@ -3111,23 +3111,11 @@ static int f2fs_set_volume_name(struct file *filp, unsigned long arg)
struct inode *inode = file_inode(filp);
struct f2fs_sb_info *sbi = F2FS_I_SB(inode);
char *vbuf;
- int len;
int err = 0;
- vbuf = f2fs_kzalloc(sbi, MAX_VOLUME_NAME, GFP_KERNEL);
- if (!vbuf)
- return -ENOMEM;
-
- if (copy_from_user(vbuf, (char __user *)arg, FSLABEL_MAX)) {
- err = -EFAULT;
- goto out;
- }
-
- len = strnlen(vbuf, FSLABEL_MAX);
- if (len > FSLABEL_MAX - 1) {
- err = -EINVAL;
- goto out;
- }
+ vbuf = strndup_user((const char __user *)arg, FSLABEL_MAX);
+ if (IS_ERR(vbuf))
+ return PTR_ERR(vbuf);
err = mnt_want_write_file(filp);
if (err)
@@ -3137,7 +3125,7 @@ static int f2fs_set_volume_name(struct file *filp, unsigned long arg)
memset(sbi->raw_super->volume_name, 0,
sizeof(sbi->raw_super->volume_name));
- utf8s_to_utf16s(vbuf, MAX_VOLUME_NAME, UTF16_LITTLE_ENDIAN,
+ utf8s_to_utf16s(vbuf, strlen(vbuf), UTF16_LITTLE_ENDIAN,
sbi->raw_super->volume_name,
ARRAY_SIZE(sbi->raw_super->volume_name));
@@ -3147,7 +3135,7 @@ static int f2fs_set_volume_name(struct file *filp, unsigned long arg)
mnt_drop_write_file(filp);
out:
- kvfree(vbuf);
+ kfree(vbuf);
return err;
}
--
2.22.0
_______________________________________________
Linux-f2fs-devel mailing list
Linux-f2fs-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel
next prev parent reply other threads:[~2019-08-16 5:56 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-08-16 5:55 [f2fs-dev] [PATCH 0/3] f2fs: fixes for FS_IOC_{GET,SET}FSLABEL Eric Biggers
2019-08-16 5:55 ` [f2fs-dev] [PATCH 1/3] f2fs: fix buffer overruns in FS_IOC_{GET, SET}FSLABEL Eric Biggers
2019-08-16 6:50 ` Chao Yu
2019-08-16 5:55 ` Eric Biggers [this message]
2019-08-16 6:59 ` [f2fs-dev] [PATCH 2/3] f2fs: fix copying too many bytes in FS_IOC_SETFSLABEL Chao Yu
2019-08-18 15:41 ` Eric Biggers
2019-08-19 1:33 ` Chao Yu
2019-08-19 1:58 ` Chao Yu
2019-08-19 2:55 ` Eric Biggers
2019-08-19 3:24 ` Chao Yu
2019-08-16 5:55 ` [f2fs-dev] [PATCH 3/3] f2fs: add missing authorization check " Eric Biggers
2019-08-16 7:00 ` Chao Yu
2019-08-16 6:49 ` [f2fs-dev] [PATCH 0/3] f2fs: fixes for FS_IOC_{GET,SET}FSLABEL Chao Yu
2019-08-18 13:03 ` Chao Yu
2019-08-18 15:42 ` Eric Biggers
2019-08-19 3:03 ` Jaegeuk Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190816055539.30420-3-ebiggers@kernel.org \
--to=ebiggers@kernel.org \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).