Check in ext4 hardening bug fixes
[ext4-patch-queue.git] / always-verify-magic-number-in-xattr-blocks
blob179555bc79203768b7aea8f904dbf6598f4d3b23
1 ext4: always verify the magic number in xattr blocks
3 If there an inode points to a block which is also some other type of
4 metadata block (such as a block allocation bitmap), the
5 buffer_verified flag can be set when it was validated as that other
6 metadata block type; however, it would make a really terrible external
7 attribute block.  The reason why we use the verified flag is to avoid
8 constantly reverifying the block.  However, it doesn't take much
9 overhead to make sure the magic number of the xattr block is correct,
10 and this will avoid potential crashes.
12 https://bugzilla.kernel.org/show_bug.cgi?id=200001
14 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
15 Reviewed-by: Andreas Dilger <adilger@dilger.ca>
16 ---
17  fs/ext4/xattr.c | 6 +++---
18  1 file changed, 3 insertions(+), 3 deletions(-)
20 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
21 index 230ba79715f6..0263692979ec 100644
22 --- a/fs/ext4/xattr.c
23 +++ b/fs/ext4/xattr.c
24 @@ -230,12 +230,12 @@ __ext4_xattr_check_block(struct inode *inode, struct buffer_head *bh,
25  {
26         int error = -EFSCORRUPTED;
28 -       if (buffer_verified(bh))
29 -               return 0;
31         if (BHDR(bh)->h_magic != cpu_to_le32(EXT4_XATTR_MAGIC) ||
32             BHDR(bh)->h_blocks != cpu_to_le32(1))
33                 goto errout;
34 +       if (buffer_verified(bh))
35 +               return 0;
37         error = -EFSBADCRC;
38         if (!ext4_xattr_block_csum_verify(inode, bh))
39                 goto errout;