Commit a0e3c3e0 authored by Randall Huang's avatar Randall Huang Committed by Kelsey Skunberg

f2fs: fix to avoid memory leakage in f2fs_listxattr

In f2fs_listxattr, there is no boundary check before
memcpy e_name to buffer.
If the e_name_len is corrupted,
unexpected memory contents may be returned to the buffer.
Signed-off-by: default avatarRandall Huang <huangrandall@google.com>
Reviewed-by: default avatarChao Yu <yuchao0@huawei.com>
Signed-off-by: default avatarJaegeuk Kim <jaegeuk@kernel.org>

CVE-2020-0067
(backported from commit 688078e7)
[ ben_r: modified error code to older value ]
Signed-off-by: default avatarBenjamin M Romer <benjamin.romer@canonical.com>
Acked-by: default avatarKamal Mostafa <kamal@canonical.com>
Acked-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
Signed-off-by: default avatarKelsey Skunberg <kelsey.skunberg@canonical.com>
parent 5b45a77d
......@@ -451,8 +451,9 @@ int f2fs_getxattr(struct inode *inode, int index, const char *name,
ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
{
struct inode *inode = d_inode(dentry);
nid_t xnid = F2FS_I(inode)->i_xattr_nid;
struct f2fs_xattr_entry *entry;
void *base_addr;
void *base_addr, *last_base_addr;
int error = 0;
size_t rest = buffer_size;
......@@ -460,11 +461,23 @@ ssize_t f2fs_listxattr(struct dentry *dentry, char *buffer, size_t buffer_size)
if (!base_addr)
return -ENOMEM;
last_base_addr = (void *)base_addr + XATTR_SIZE(xnid, inode);
list_for_each_xattr(entry, base_addr) {
const struct xattr_handler *handler =
f2fs_xattr_handler(entry->e_name_index);
size_t size;
if ((void *)(entry) + sizeof(__u32) > last_base_addr ||
(void *)XATTR_NEXT_ENTRY(entry) > last_base_addr) {
f2fs_msg(F2FS_I_SB(inode)->sb, KERN_ERR,
"inode (%lu) has corrupted xattr",
inode->i_ino);
set_sbi_flag(F2FS_I_SB(inode), SBI_NEED_FSCK);
error = -EUCLEAN;
goto cleanup;
}
if (!handler)
continue;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment