Add ext4-printk-throttling patch
[ext4-patch-queue.git] / ext4-printk-throttling
blob58c6ae833f63cb4fac4e49e1b2c911d66de89dfe
1 ext4: Avoid printk floods in the face of directory corruption
3 Note: some people thinks this represents a security bug, since it
4 might make the system go away while it is printing a large number of
5 console messages, especially if a serial console is involved.  Hence,
6 it has been assigned CVE-2008-3528, but it requires that the attacker
7 either has physical access to your machine to insert a USB disk with a
8 corrupted filesystem image (at which point why not just hit the power
9 button), or is otherwise able to convince the system administrator to
10 mount an arbitrary filesystem image (at which point why not just
11 include a setuid shell or world-writable hard disk device file or some
12 such).  Me, I think they're just being silly.
14 Signed-off-by: Eric Sandeen <sandeen@redhat.com>
15 Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
16 Cc: linux-ext4@vger.kernel.org
17 Cc: Eugene Teo <eugeneteo@kernel.sg>
18 ---
19 Index: linux-2.6.26.x86_64/fs/ext4/dir.c
20 ===================================================================
21 --- linux-2.6.26.x86_64.orig/fs/ext4/dir.c
22 +++ linux-2.6.26.x86_64/fs/ext4/dir.c
23 @@ -102,6 +102,7 @@ static int ext4_readdir(struct file * fi
24         int err;
25         struct inode *inode = filp->f_path.dentry->d_inode;
26         int ret = 0;
27 +       int dir_has_error = 0;
29         sb = inode->i_sb;
31 @@ -147,9 +148,12 @@ static int ext4_readdir(struct file * fi
32                  * of recovering data when there's a bad sector
33                  */
34                 if (!bh) {
35 -                       ext4_error (sb, "ext4_readdir",
36 -                               "directory #%lu contains a hole at offset %lu",
37 -                               inode->i_ino, (unsigned long)filp->f_pos);
38 +                       if (!dir_has_error) {
39 +                               ext4_error(sb, __func__, "directory #%lu "
40 +                                       "contains a hole at offset %lld",
41 +                                       inode->i_ino, filp->f_pos);
42 +                               dir_has_error = 1;
43 +                       }
44                         /* corrupt size?  Maybe no more blocks to read */
45                         if (filp->f_pos > inode->i_blocks << 9)
46                                 break;