From: Jan Kara <jack@suse.cz>
To: Neil Brown <neilb@suse.de>
Cc: James <20@madingley.org>, Marcel Holtmann <marcel@holtmann.org>,
linux-kernel@vger.kernel.org, akpm@osdl.org, sct@redhat.com
Subject: Re: Bad ext3/nfs DoS bug
Date: Fri, 21 Jul 2006 16:24:15 +0200 [thread overview]
Message-ID: <20060721142415.GC2020@atrey.karlin.mff.cuni.cz> (raw)
In-Reply-To: <17600.30372.397971.955987@cse.unsw.edu.au>
> On Thursday July 20, jack@suse.cz wrote:
> > Yes, that looks fine too. I did not realize that we get the inode
> > number only in a few places. Maybe we could wrap the checks in a
> > function (possibly inline) so that the checks are just in one place?
>
> Like this?
Yes.
> NeilBrown
>
>
> Avoid triggering ext3_error on bad NFS file handle
>
> The inode number out of an NFS file handle gets passed
> eventually to ext3_get_inode_block without any checking.
> If ext3_get_inode_block allows it to trigger a error,
> then bad filehandles can have unpleasant effect.
>
> So remove the call to ext3_error there and put a matching
> check in ext3/namei.c where inode numbers are read of storage.
>
> Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Jan Kara <jack@suse.cz>
Honza
> ### Diffstat output
> ./fs/ext3/inode.c | 13 ++++++-------
> ./fs/ext3/namei.c | 15 +++++++++++++--
> ./include/linux/ext3_fs.h | 9 +++++++++
> 3 files changed, 28 insertions(+), 9 deletions(-)
>
> diff .prev/fs/ext3/inode.c ./fs/ext3/inode.c
> --- .prev/fs/ext3/inode.c 2006-07-20 14:41:07.000000000 +1000
> +++ ./fs/ext3/inode.c 2006-07-21 16:36:32.000000000 +1000
> @@ -2402,14 +2402,13 @@ static ext3_fsblk_t ext3_get_inode_block
> struct buffer_head *bh;
> struct ext3_group_desc * gdp;
>
> -
> - if ((ino != EXT3_ROOT_INO && ino != EXT3_JOURNAL_INO &&
> - ino != EXT3_RESIZE_INO && ino < EXT3_FIRST_INO(sb)) ||
> - ino > le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count)) {
> - ext3_error(sb, "ext3_get_inode_block",
> - "bad inode number: %lu", ino);
> + if (!ext3_valid_inum(sb, ino))
> + /* This error already checked for in namei.c unless we
> + * are looking at an NFS filehandle, in which case,
> + * no error reported is needed
> + */
> return 0;
> - }
> +
> block_group = (ino - 1) / EXT3_INODES_PER_GROUP(sb);
> if (block_group >= EXT3_SB(sb)->s_groups_count) {
> ext3_error(sb,"ext3_get_inode_block","group >= groups count");
>
> diff .prev/fs/ext3/namei.c ./fs/ext3/namei.c
> --- .prev/fs/ext3/namei.c 2006-07-20 14:39:51.000000000 +1000
> +++ ./fs/ext3/namei.c 2006-07-21 16:36:09.000000000 +1000
> @@ -1000,7 +1000,12 @@ static struct dentry *ext3_lookup(struct
> if (bh) {
> unsigned long ino = le32_to_cpu(de->inode);
> brelse (bh);
> - inode = iget(dir->i_sb, ino);
> + if (!ext3_valid_inum(dir->i_sb, ino)) {
> + ext3_error(dir->i_sb, "ext3_lookup",
> + "bad inode number: %lu", ino);
> + inode = NULL;
> + } else
> + inode = iget(dir->i_sb, ino);
>
> if (!inode)
> return ERR_PTR(-EACCES);
> @@ -1028,7 +1033,13 @@ struct dentry *ext3_get_parent(struct de
> return ERR_PTR(-ENOENT);
> ino = le32_to_cpu(de->inode);
> brelse(bh);
> - inode = iget(child->d_inode->i_sb, ino);
> +
> + if (!ext3_valid_inum(child->d_inode->i_sb, ino)) {
> + ext3_error(child->d_inode->i_sb, "ext3_get_parent",
> + "bad inode number: %lu", ino);
> + inode = NULL;
> + } else
> + inode = iget(child->d_inode->i_sb, ino);
>
> if (!inode)
> return ERR_PTR(-EACCES);
>
> diff .prev/include/linux/ext3_fs.h ./include/linux/ext3_fs.h
> --- .prev/include/linux/ext3_fs.h 2006-07-21 16:34:01.000000000 +1000
> +++ ./include/linux/ext3_fs.h 2006-07-21 16:35:55.000000000 +1000
> @@ -492,6 +492,15 @@ static inline struct ext3_inode_info *EX
> {
> return container_of(inode, struct ext3_inode_info, vfs_inode);
> }
> +
> +static inline int ext3_valid_inum(struct super_block *sb, unsigned long ino)
> +{
> + return ino == EXT3_ROOT_INO ||
> + ino == EXT3_JOURNAL_INO ||
> + ino == EXT3_RESIZE_INO ||
> + (ino > EXT3_FIRST_INO(sb) &&
> + ino <= le32_to_cpu(EXT3_SB(sb)->s_es->s_inodes_count));
> +}
> #else
> /* Assume that user mode programs are passing in an ext3fs superblock, not
> * a kernel struct super_block. This will allow us to call the feature-test
--
Jan Kara <jack@suse.cz>
SuSE CR Labs
next prev parent reply other threads:[~2006-07-21 14:24 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-07-17 13:01 James
2006-07-17 13:06 ` Marcel Holtmann
2006-07-17 18:43 ` Marcel Holtmann
2006-07-18 7:55 ` Marcel Holtmann
2006-07-18 14:56 ` James
2006-07-18 15:22 ` Marcel Holtmann
2006-07-18 15:23 ` James
2006-07-18 20:18 ` Marcel Holtmann
2006-07-19 9:28 ` James
2006-07-19 15:55 ` Jan Kara
2006-07-20 4:46 ` Neil Brown
2006-07-20 16:06 ` Jan Kara
2006-07-20 20:11 ` James
2006-07-21 6:44 ` Neil Brown
2006-07-21 6:39 ` Neil Brown
2006-07-21 14:24 ` Jan Kara [this message]
2006-07-22 0:06 ` Andrew Morton
2006-07-22 13:17 ` Theodore Tso
2006-07-25 1:56 ` Andrew Morton
2006-07-25 2:21 ` Neil Brown
2006-07-26 17:12 ` Eric Sandeen
2006-07-26 23:53 ` Neil Brown
2006-07-27 18:32 ` Eric Sandeen
2006-07-27 19:12 ` Christoph Hellwig
2006-07-28 0:34 ` Neil Brown
2006-07-28 13:27 ` Peter Staubach
2006-07-28 13:30 ` Christoph Hellwig
2006-07-25 2:36 ` Neil Brown
2006-07-25 18:27 ` Eric Sandeen
2006-07-21 0:42 ` Marcel Holtmann
2006-07-21 12:29 ` Andrew Morton
2006-07-22 3:38 linux
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=20060721142415.GC2020@atrey.karlin.mff.cuni.cz \
--to=jack@suse.cz \
--cc=20@madingley.org \
--cc=akpm@osdl.org \
--cc=linux-kernel@vger.kernel.org \
--cc=marcel@holtmann.org \
--cc=neilb@suse.de \
--cc=sct@redhat.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
all inboxes | Powered by JetHome®