All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org, torvalds@osdl.org
Cc: Justin Forbes <jmforbes@linuxtx.org>,
	Zwane Mwaikambo <zwane@arm.linux.org.uk>,
	"Theodore Ts'o" <tytso@mit.edu>,
	Randy Dunlap <rdunlap@xenotime.net>,
	Dave Jones <davej@redhat.com>,
	Chuck Wolber <chuckw@quantumlinux.com>,
	Chris Wedgwood <reviews@ml.cw.f00f.org>,
	akpm@osdl.org, alan@lxorguk.ukuu.org.uk, jack@suse.cz,
	esandeen@redhat.com, neilb@suse.de,
	Marcel Holtmann <marcel@holtmann.org>,
	"Stephen C. Tweedie" <sct@redhat.com>,
	Greg Kroah-Hartman <gregkh@suse.de>
Subject: [patch 16/23] ext3: avoid triggering ext3_error on bad NFS file handle
Date: Thu, 3 Aug 2006 22:40:10 -0700	[thread overview]
Message-ID: <20060804054010.GQ769@kroah.com> (raw)
In-Reply-To: <20060804053807.GA769@kroah.com>

[-- Attachment #1: ext3-avoid-triggering-ext3_error-on-bad-nfs-file-handle.patch --]
[-- Type: text/plain, Size: 3529 bytes --]

-stable review patch.  If anyone has any objections, please let us know.

------------------
From: Neil Brown <neilb@suse.de>

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 an error, then bad filehandles can have unpleasant
effect - ext3_error() will usually cause a forced read-only remount, or a
panic if `errors=panic' was used.

So remove the call to ext3_error there and put a matching check in
ext3/namei.c where inode numbers are read off storage.

[akpm@osdl.org: fix off-by-one error]
Signed-off-by: Neil Brown <neilb@suse.de>
Signed-off-by: Jan Kara <jack@suse.cz>
Cc: Marcel Holtmann <marcel@holtmann.org>
Cc: "Stephen C. Tweedie" <sct@redhat.com>
Cc: Eric Sandeen <esandeen@redhat.com>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>

---
 fs/ext3/inode.c         |   13 +++++++------
 fs/ext3/namei.c         |   15 +++++++++++++--
 include/linux/ext3_fs.h |    9 +++++++++
 3 files changed, 29 insertions(+), 8 deletions(-)

--- linux-2.6.17.7.orig/fs/ext3/inode.c
+++ linux-2.6.17.7/fs/ext3/inode.c
@@ -2402,14 +2402,15 @@ static unsigned long ext3_get_inode_bloc
 	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 is already checked for in namei.c unless we are
+		 * looking at an NFS filehandle, in which case no error
+		 * report 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");
--- linux-2.6.17.7.orig/fs/ext3/namei.c
+++ linux-2.6.17.7/fs/ext3/namei.c
@@ -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);
--- linux-2.6.17.7.orig/include/linux/ext3_fs.h
+++ linux-2.6.17.7/include/linux/ext3_fs.h
@@ -495,6 +495,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

--

  parent reply	other threads:[~2006-08-04  5:48 UTC|newest]

Thread overview: 49+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20060804053258.391158155@quad.kroah.org>
2006-08-04  5:38 ` [patch 00/23] -stable review Greg KH
2006-08-04  5:38   ` [patch 01/23] PCI: fix issues with extended conf space when MMCONFIG disabled because of e820 Greg KH
2006-08-04  5:38   ` [patch 02/23] Dont allow chmod() on the /proc/<pid>/ files Greg KH
2006-08-04  5:38   ` [patch 03/23] : H.323 helper: fix possible NULL-ptr dereference Greg KH
2006-08-04  5:38   ` [patch 04/23] scx200_acb: Fix the state machine Greg KH
2006-08-04  5:38   ` [patch 05/23] scx200_acb: Fix the block transactions Greg KH
2006-08-04  5:38   ` [patch 06/23] i2c: Fix ignore module parameter handling in i2c-core Greg KH
2006-08-04  5:39   ` [patch 07/23] sky2: NAPI bug Greg KH
2006-08-04  5:39   ` [patch 08/23] UHCI: Fix handling of short last packet Greg KH
2006-08-04  5:39   ` [patch 09/23] : Update frag_list in pskb_trim Greg KH
2006-08-04  5:39   ` [patch 10/23] VLAN state handling fix Greg KH
2006-08-04  5:39   ` [patch 11/23] Sparc64 quad-float emulation fix Greg KH
2006-08-04  5:39   ` [patch 12/23] invalidate_bdev() speedup Greg KH
2006-08-04  8:50     ` Christoph Hellwig
2006-08-04  9:04       ` Andrew Morton
2006-08-04 13:08         ` Arjan van de Ven
2006-08-04 13:25           ` Jes Sorensen
2006-08-04 15:18           ` Andrew Morton
2006-08-04  5:39   ` [patch 13/23] ieee1394: sbp2: enable auto spin-up for Maxtor disks Greg KH
2006-08-04  5:39   ` [patch 14/23] Fix race related problem when adding items to and svcrpc auth cache Greg KH
2006-08-04  5:39     ` Greg KH
2006-08-04  5:40   ` [patch 15/23] ext3 -nobh option causes oops Greg KH
2006-11-16 22:51     ` Adrian Bunk
2006-11-16 23:07       ` Badari Pulavarty
2006-11-17 16:47         ` Adrian Bunk
2006-08-04  5:40   ` Greg KH [this message]
2006-08-04 14:45     ` [patch 16/23] ext3: avoid triggering ext3_error on bad NFS file handle Eric Sandeen
2006-08-04 14:52       ` Christoph Hellwig
2006-08-04 15:35         ` Eric Sandeen
2006-08-05  1:28           ` Theodore Tso
2006-08-10  5:38           ` [stable] " Greg KH
2006-08-04  5:40   ` [patch 17/23] e1000: add forgotten PCI ID for supported device Greg KH
2006-08-04  5:40   ` [patch 18/23] cond_resched() fix Greg KH
2006-08-04  5:40   ` [patch 19/23] Fix budget-av compile failure Greg KH
2006-08-04  5:40   ` [patch 20/23] S390: fix futex_atomic_cmpxchg_inatomic Greg KH
2006-08-07  8:39     ` Martin Schwidefsky
2006-08-04  5:40   ` [patch 21/23] tty serialize flush_to_ldisc Greg KH
2006-08-04  5:40   ` [patch 22/23] Add stable branch to maintainers file Greg KH
2006-08-04  5:41   ` [patch 23/23] Have ext2 reject file handles with bad inode numbers early Greg KH
2006-08-04  7:18   ` [patch 00/23] -stable review Grant Coady
2006-08-04  7:20     ` Greg KH
2006-08-04  9:04   ` Jesper Juhl
2006-08-04  9:10     ` Patrick McHardy
2006-08-04  9:19       ` Jesper Juhl
2006-08-04  9:24         ` Patrick McHardy
2006-08-04  9:31           ` Jesper Juhl
2006-08-04  9:19     ` Andrew Morton
2006-08-04  9:22       ` Jesper Juhl
2006-08-04 13:50         ` Auke Kok

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=20060804054010.GQ769@kroah.com \
    --to=gregkh@suse.de \
    --cc=akpm@osdl.org \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=chuckw@quantumlinux.com \
    --cc=davej@redhat.com \
    --cc=esandeen@redhat.com \
    --cc=jack@suse.cz \
    --cc=jmforbes@linuxtx.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=marcel@holtmann.org \
    --cc=neilb@suse.de \
    --cc=rdunlap@xenotime.net \
    --cc=reviews@ml.cw.f00f.org \
    --cc=sct@redhat.com \
    --cc=stable@kernel.org \
    --cc=torvalds@osdl.org \
    --cc=tytso@mit.edu \
    --cc=zwane@arm.linux.org.uk \
    /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.