From: Tobias Stoeckmann <tobias@stoeckmann.org>
To: util-linux@vger.kernel.org
Subject: [PATCH] fsck.minix: Verify more fields in super-block.
Date: Sun, 29 May 2016 18:56:58 +0200 [thread overview]
Message-ID: <20160529165658.GA7092@localhost> (raw)
The field s_ninodes in super-block is used for memory allocation and
division without verifications. The memory allocation increments the
unchecked value by 1, making it vulnerable to an integer overflow
on 32 bit systems with minix 3 file systems. I did not find a (good)
way to exploit this by crafting a malicious file system, so I consider
it as a reliability issue. If it's 0, a division by zero occurs when
"-v" has been used. A filesystem without any inodes is definitely
wrong, because it means that there's not even the root inode, which is
accessed unchecked later on.
The field s_firstdatazone has to be checked against s_(n)zones. If it
is larger than the highest allowed index, the file system is definitely
corrupted -- hard to say which value is wrong though, therefore I
decided to simply call die(). A maliciously created file system could
do more harm in this way: single bits inside the memory area could be
flipped because range checks would fail. Hard to consider it as a
security issue though, because these addresses are not arbitrarily
accessible without very careful crafting (if at all possible).
---
disk-utils/fsck.minix.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/disk-utils/fsck.minix.c b/disk-utils/fsck.minix.c
index aa64569..931658f 100644
--- a/disk-utils/fsck.minix.c
+++ b/disk-utils/fsck.minix.c
@@ -573,8 +573,12 @@ read_superblock(void) {
die(_("bad magic number in super-block"));
if (get_zone_size() != 0 || MINIX_BLOCK_SIZE != 1024)
die(_("Only 1k blocks/zones supported"));
+ if (get_ninodes() == 0 || get_ninodes() == UINT32_MAX)
+ die(_("bad s_ninodes field in super-block"));
if (get_nimaps() * MINIX_BLOCK_SIZE * 8 < get_ninodes() + 1)
die(_("bad s_imap_blocks field in super-block"));
+ if (get_first_zone() > get_nzones())
+ die(_("bad s_firstdatazone field in super-block"));
if (get_nzmaps() * MINIX_BLOCK_SIZE * 8 <
get_nzones() - get_first_zone() + 1)
die(_("bad s_zmap_blocks field in super-block"));
--
2.8.3
next reply other threads:[~2016-05-29 16:56 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-29 16:56 Tobias Stoeckmann [this message]
2016-05-31 11:21 ` [PATCH] fsck.minix: Verify more fields in super-block Karel Zak
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=20160529165658.GA7092@localhost \
--to=tobias@stoeckmann.org \
--cc=util-linux@vger.kernel.org \
/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.