From: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
To: lkp@intel.com
Cc: clang-built-linux@googlegroups.com, kbuild-all@lists.01.org,
linux-kernel@vger.kernel.org, phillip@squashfs.org.uk,
snovitoll@gmail.com,
syzbot+2ccea6339d368360800d@syzkaller.appspotmail.com
Subject: [PATCH v2] fs/squashfs: restrict length of xattr_ids in read_xattr_id_table
Date: Wed, 3 Feb 2021 19:45:16 +0600 [thread overview]
Message-ID: <20210203134516.1697931-1-snovitoll@gmail.com> (raw)
In-Reply-To: <202102032044.wrsk1CfP-lkp@intel.com>
In PATCH v2 fixed return -ENOMEM as error pointer.
>syzbot found WARNING in squashfs_read_table [1] when length of xattr_ids
>exceeds KMALLOC_MAX_SIZE in squashfs_read_table() for kmalloc().
>
>For other squashfs tables, currently such as boundary is checked with
>another table's boundaries. Xattr table is the last one, so there is
>no defined limit. But to avoid order >= MAX_ORDER warning condition,
>we should restrict SQUASHFS_XATTR_BLOCK_BYTES(*xattr_ids) to
>KMALLOC_MAX_SIZE, and it gives 1024 pages in squashfs_read_table via
>(length + PAGE_SIZE - 1) >> PAGE_SHIFT.
>
>[1]
>Call Trace:
> alloc_pages_current+0x18c/0x2a0 mm/mempolicy.c:2267
> alloc_pages include/linux/gfp.h:547 [inline]
> kmalloc_order+0x2e/0xb0 mm/slab_common.c:916
> kmalloc_order_trace+0x14/0x120 mm/slab_common.c:932
> kmalloc include/linux/slab.h:559 [inline]
> squashfs_read_table+0x43/0x1e0 fs/squashfs/cache.c:413
> squashfs_read_xattr_id_table+0x191/0x220 fs/squashfs/xattr_id.c:81
Reported-by: syzbot+2ccea6339d368360800d@syzkaller.appspotmail.com
Reported-by: kernel test robot <lkp@intel.com>
Signed-off-by: Sabyrzhan Tasbolatov <snovitoll@gmail.com>
---
fs/squashfs/xattr_id.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/fs/squashfs/xattr_id.c b/fs/squashfs/xattr_id.c
index d99e08464554..2462876c66c4 100644
--- a/fs/squashfs/xattr_id.c
+++ b/fs/squashfs/xattr_id.c
@@ -78,5 +78,8 @@ __le64 *squashfs_read_xattr_id_table(struct super_block *sb, u64 start,
TRACE("In read_xattr_index_table, length %d\n", len);
+ if (len > KMALLOC_MAX_SIZE)
+ return ERR_PTR(-ENOMEM);
+
return squashfs_read_table(sb, start + sizeof(*id_table), len);
}
--
2.25.1
next prev parent reply other threads:[~2021-02-03 13:46 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-02-03 10:35 [PATCH] fs/squashfs: restrict length of xattr_ids in read_xattr_id_table Sabyrzhan Tasbolatov
2021-02-03 12:56 ` kernel test robot
2021-02-03 13:45 ` Sabyrzhan Tasbolatov [this message]
2021-02-03 14:11 ` kernel test robot
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=20210203134516.1697931-1-snovitoll@gmail.com \
--to=snovitoll@gmail.com \
--cc=clang-built-linux@googlegroups.com \
--cc=kbuild-all@lists.01.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lkp@intel.com \
--cc=phillip@squashfs.org.uk \
--cc=syzbot+2ccea6339d368360800d@syzkaller.appspotmail.com \
/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).