From: Richard Weinberger <richard@nod.at>
To: u-boot@lists.denx.de
Cc: upstream+uboot@sigma-star.at, trini@konsulko.com,
miquel.raynal@bootlin.com, thomas.petazzoni@bootlin.com,
jmcosta944@gmail.com, Richard Weinberger <richard@nod.at>
Subject: [PATCH v2 2/4] squashfs: Fix integer overflow in sqfs_inode_size()
Date: Fri, 2 Aug 2024 18:36:45 +0200 [thread overview]
Message-ID: <20240802163647.26674-2-richard@nod.at> (raw)
In-Reply-To: <20240802163647.26674-1-richard@nod.at>
A carefully crafted squashfs filesystem can exhibit an extremly large
inode size and overflow the calculation in sqfs_inode_size().
As a consequence, the squashfs driver will read from wrong locations.
Fix by using __builtin_add_overflow() to detect the overflow.
Signed-off-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Miquel Raynal <miquel.raynal@bootlin.com>
---
fs/squashfs/sqfs_inode.c | 9 +++++++--
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/fs/squashfs/sqfs_inode.c b/fs/squashfs/sqfs_inode.c
index d25cfb53e7..bb3ccd37e3 100644
--- a/fs/squashfs/sqfs_inode.c
+++ b/fs/squashfs/sqfs_inode.c
@@ -78,11 +78,16 @@ int sqfs_inode_size(struct squashfs_base_inode *inode, u32 blk_size)
case SQFS_SYMLINK_TYPE:
case SQFS_LSYMLINK_TYPE: {
+ int size;
+
struct squashfs_symlink_inode *symlink =
(struct squashfs_symlink_inode *)inode;
- return sizeof(*symlink) +
- get_unaligned_le32(&symlink->symlink_size);
+ if (__builtin_add_overflow(sizeof(*symlink),
+ get_unaligned_le32(&symlink->symlink_size), &size))
+ return -EINVAL;
+
+ return size;
}
case SQFS_BLKDEV_TYPE:
--
2.35.3
next prev parent reply other threads:[~2024-08-02 16:37 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 16:36 [PATCH v2 1/4] squashfs: Fix integer overflow in sqfs_resolve_symlink() Richard Weinberger
2024-08-02 16:36 ` Richard Weinberger [this message]
2024-08-02 16:36 ` [PATCH v2 3/4] squashfs: Check sqfs_find_inode() return value Richard Weinberger
2024-08-02 16:36 ` [PATCH v2 4/4] squashfs: Fix stack overflow while symlink resolving Richard Weinberger
2024-08-12 7:51 ` Miquel Raynal
2024-08-16 3:47 ` [PATCH v2 1/4] squashfs: Fix integer overflow in sqfs_resolve_symlink() Tom Rini
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=20240802163647.26674-2-richard@nod.at \
--to=richard@nod.at \
--cc=jmcosta944@gmail.com \
--cc=miquel.raynal@bootlin.com \
--cc=thomas.petazzoni@bootlin.com \
--cc=trini@konsulko.com \
--cc=u-boot@lists.denx.de \
--cc=upstream+uboot@sigma-star.at \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.