From: Steven Whitehouse <swhiteho@redhat.com>
To: cluster-devel.redhat.com
Subject: [Cluster-devel] [GFS2] Patch to detect corrupt number of dir entries in leaf and/or inode blocks [25/34]
Date: Tue, 01 May 2007 11:19:26 +0100 [thread overview]
Message-ID: <1178014766.5462.180.camel@quoit.chygwyn.com> (raw)
In-Reply-To: <1178013376.5462.127.camel@quoit.chygwyn.com>
From bdd19a22f85a7039e01accd8717eaec4addd9dfd Mon Sep 17 00:00:00 2001
From: Steven Whitehouse <swhiteho@redhat.com>
Date: Wed, 18 Apr 2007 09:38:42 +0100
Subject: [PATCH] [GFS2] Patch to detect corrupt number of dir entries in leaf and/or inode blocks
This patch detects when the number of entries in a leaf block or inode
block (in the case of stuffed directories) is corrupt and informs the
user. It prevents us from running off the end of the array thats been
allocated for the sorting in this case,
Signed-off-by: Steven Whitehouse <swhiteho@redhat.com>
diff --git a/fs/gfs2/dir.c b/fs/gfs2/dir.c
index 82a1ac7..6c3ed76 100644
--- a/fs/gfs2/dir.c
+++ b/fs/gfs2/dir.c
@@ -1262,9 +1262,10 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
u64 leaf_no)
{
struct gfs2_inode *ip = GFS2_I(inode);
+ struct gfs2_sbd *sdp = GFS2_SB(inode);
struct buffer_head *bh;
struct gfs2_leaf *lf;
- unsigned entries = 0;
+ unsigned entries = 0, entries2 = 0;
unsigned leaves = 0;
const struct gfs2_dirent **darr, *dent;
struct dirent_gather g;
@@ -1290,7 +1291,13 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
return 0;
error = -ENOMEM;
- larr = vmalloc((leaves + entries) * sizeof(void *));
+ /*
+ * The extra 99 entries are not normally used, but are a buffer
+ * zone in case the number of entries in the leaf is corrupt.
+ * 99 is the maximum number of entries that can fit in a single
+ * leaf block.
+ */
+ larr = vmalloc((leaves + entries + 99) * sizeof(void *));
if (!larr)
goto out;
darr = (const struct gfs2_dirent **)(larr + leaves);
@@ -1305,10 +1312,18 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
lf = (struct gfs2_leaf *)bh->b_data;
lfn = be64_to_cpu(lf->lf_next);
if (lf->lf_entries) {
+ entries2 += be16_to_cpu(lf->lf_entries);
dent = gfs2_dirent_scan(inode, bh->b_data, bh->b_size,
gfs2_dirent_gather, NULL, &g);
error = PTR_ERR(dent);
- if (IS_ERR(dent)) {
+ if (IS_ERR(dent))
+ goto out_kfree;
+ if (entries2 != g.offset) {
+ fs_warn(sdp, "Number of entries corrupt in dir leaf %llu, "
+ "entries2 (%u) != g.offset (%u)\n",
+ (u64)bh->b_blocknr, entries2, g.offset);
+
+ error = -EIO;
goto out_kfree;
}
error = 0;
@@ -1318,6 +1333,7 @@ static int gfs2_dir_read_leaf(struct inode *inode, u64 *offset, void *opaque,
}
} while(lfn);
+ BUG_ON(entries2 != entries);
error = do_filldir_main(ip, offset, opaque, filldir, darr,
entries, copied);
out_kfree:
@@ -1401,6 +1417,7 @@ int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
filldir_t filldir)
{
struct gfs2_inode *dip = GFS2_I(inode);
+ struct gfs2_sbd *sdp = GFS2_SB(inode);
struct dirent_gather g;
const struct gfs2_dirent **darr, *dent;
struct buffer_head *dibh;
@@ -1423,8 +1440,8 @@ int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
return error;
error = -ENOMEM;
- darr = kmalloc(dip->i_di.di_entries * sizeof(struct gfs2_dirent *),
- GFP_KERNEL);
+ /* 96 is max number of dirents which can be stuffed into an inode */
+ darr = kmalloc(96 * sizeof(struct gfs2_dirent *), GFP_KERNEL);
if (darr) {
g.pdent = darr;
g.offset = 0;
@@ -1434,6 +1451,14 @@ int gfs2_dir_read(struct inode *inode, u64 *offset, void *opaque,
error = PTR_ERR(dent);
goto out;
}
+ if (dip->i_di.di_entries != g.offset) {
+ fs_warn(sdp, "Number of entries corrupt in dir %llu, "
+ "ip->i_di.di_entries (%u) != g.offset (%u)\n",
+ dip->i_num.no_addr, dip->i_di.di_entries,
+ g.offset);
+ error = -EIO;
+ goto out;
+ }
error = do_filldir_main(dip, offset, opaque, filldir, darr,
dip->i_di.di_entries, &copied);
out:
--
1.5.1.2
next prev parent reply other threads:[~2007-05-01 10:19 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-01 9:56 [Cluster-devel] [GFS2] Patches for the current merge window [0/34] Steven Whitehouse
2007-05-01 9:58 ` [Cluster-devel] [GFS2] Add gfs2_tool lockdump support to gfs2 (bz 228540) [1/34] Steven Whitehouse
2007-05-01 9:59 ` [Cluster-devel] [GFS2] fix bz 231369, gfs2 will oops if you specify an invalid mount option [2/34] Steven Whitehouse
2007-05-01 10:28 ` [Cluster-devel] " Christoph Hellwig
2007-05-01 13:41 ` Steven Whitehouse
2007-05-01 9:59 ` [Cluster-devel] [DLM] Fix uninitialised variable in receiving [3/34] Steven Whitehouse
2007-05-01 10:01 ` [Cluster-devel] [GFS2] Fix bz 231380, unlock page before dequeing glocks in gfs2_commit_write [4/34] Steven Whitehouse
2007-05-01 10:02 ` [Cluster-devel] [GFS2] Fix bz 224480 and cleanup glock demotion code [5/34] Steven Whitehouse
2007-05-01 10:02 ` [Cluster-devel] [GFS2] Fix a bug on i386 due to evaluation order [6/34] Steven Whitehouse
2007-05-01 10:03 ` [Cluster-devel] [DLM] Don't delete misc device if lockspace removal fails [7/43] Steven Whitehouse
2007-05-01 10:04 ` [Cluster-devel] [GFS2] Speed up lock_dlm's locking (move sprintf) [8/34] Steven Whitehouse
2007-05-01 10:05 ` [Cluster-devel] [GFS2] Fix log entry list corruption [9/34] Steven Whitehouse
2007-05-01 10:06 ` [Cluster-devel] [GFS2] flush the log if a transaction can't allocate space [10/34] Steven Whitehouse
2007-05-01 10:07 ` [Cluster-devel] [GFS2] Red Hat bz 228540: owner references [11/34] Steven Whitehouse
2007-05-01 10:07 ` [Cluster-devel] [DLM] fix coverity-spotted stupidity [12/34] Steven Whitehouse
2007-05-01 10:09 ` [Cluster-devel] [DLM] overlapping cancel and unlock [13/34] Steven Whitehouse
2007-05-01 10:09 ` [Cluster-devel] [GFS2] use log_error before LM_OUT_ERROR [14/34] Steven Whitehouse
2007-05-01 10:10 ` [Cluster-devel] [GFS2] Set drop_count to 0 (off) by default [15/34] Steven Whitehouse
2007-05-01 10:11 ` [Cluster-devel] [DLM] split create_message function [16/34] Steven Whitehouse
2007-05-01 10:12 ` [Cluster-devel] [DLM] add orphan purging code (1/2) [17/34] Steven Whitehouse
2007-05-01 10:12 ` [Cluster-devel] [DLM] interface for purge (2/2) [18/34] Steven Whitehouse
2007-05-01 10:13 ` [Cluster-devel] [DLM] change lkid format [19/34] Steven Whitehouse
2007-05-01 10:14 ` Steven Whitehouse
2007-05-01 10:14 ` [Cluster-devel] GFS2] Fix bz 234168 (ignoring rgrp flags) [20/34] Steven Whitehouse
2007-05-01 10:15 ` [Cluster-devel] [DLM] Remove redundant assignment [21/34] Steven Whitehouse
2007-05-01 10:16 ` [Cluster-devel] [DLM] Consolidate transport protocols [21/34] Steven Whitehouse
2007-05-01 10:17 ` [Cluster-devel] DLM] fs/dlm/ast.c should #include "ast.h" [23/34] Steven Whitehouse
2007-05-01 10:18 ` [Cluster-devel] [GFS2] bz 236008: Kernel gpf doing cat /debugfs/gfs2/xxx (lock dump) [24/34] Steven Whitehouse
2007-05-01 10:19 ` Steven Whitehouse [this message]
2007-05-01 10:20 ` [Cluster-devel] [GFS2] lockdump improvements [26/34] Steven Whitehouse
2007-05-01 10:20 ` [Cluster-devel] [DLM] fix mode munging [27/34] Steven Whitehouse
2007-05-01 10:21 ` [Cluster-devel] [DLM] Fix dlm_lowcoms_stop hang [28/34] Steven Whitehouse
2007-05-01 10:22 ` [Cluster-devel] [DLM] Lowcomms nodeid range & initialisation fixes [29/34] Steven Whitehouse
2007-05-01 10:22 ` [Cluster-devel] [GFS2] use lib/parser for parsing mount options [30/34] Steven Whitehouse
2007-05-01 10:23 ` [Cluster-devel] [GFS2] Patch to fix mmap of stuffed files [31/34] Steven Whitehouse
2007-05-01 10:24 ` [Cluster-devel] [GFS2] printk warning fixes [32/34] Steven Whitehouse
2007-05-01 10:24 ` [Cluster-devel] [DLM] lowcomms style [33/34] Steven Whitehouse
2007-05-01 10:25 ` [Cluster-devel] [GFS2] Uncomment sprintf_symbol calling code [34/34] Steven Whitehouse
2007-05-01 14:11 ` [Cluster-devel] [GFS2/DLM] Pull request Steven Whitehouse
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=1178014766.5462.180.camel@quoit.chygwyn.com \
--to=swhiteho@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;
as well as URLs for NNTP newsgroup(s).