From: Anand Jain <anand.jain@oracle.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 1/2] btrfs: verify checksum when superblock is read for mount
Date: Fri, 23 Mar 2018 20:53:48 +0800 [thread overview]
Message-ID: <20180323125349.26893-2-anand.jain@oracle.com> (raw)
In-Reply-To: <20180323125349.26893-1-anand.jain@oracle.com>
During mount context, we aren't verifying the superblock checksum
for all the devices, instead, we verify it only for the
struct btrfs_fs_device::latest_bdev. This patch fixes it
by moving the checksum verification code from the function open_ctree()
into the function btrfs_read_dev_one_super().
By doing this now we are verifying the superblock checksum
in the mount-context, device-replace and device-delete context.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
fs/btrfs/disk-io.c | 33 +++++++++++++++++----------------
1 file changed, 17 insertions(+), 16 deletions(-)
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c
index 062b3e0c7fd1..c4600d5eca9c 100644
--- a/fs/btrfs/disk-io.c
+++ b/fs/btrfs/disk-io.c
@@ -2564,22 +2564,6 @@ int open_ctree(struct super_block *sb,
goto fail_alloc;
}
- /*
- * We want to check superblock checksum, the type is stored inside.
- * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).
- */
- err = btrfs_check_super_csum(bh->b_data);
- if (err) {
- if (err == -EINVAL)
- pr_err("BTRFS error (device %pg): unsupported checksum algorithm",
- fs_devices->latest_bdev);
- else if (err == -EUCLEAN)
- pr_err("BTRFS error (device %pg): superblock checksum mismatch",
- fs_devices->latest_bdev);
- brelse(bh);
- goto fail_alloc;
- }
-
/*
* super_copy is zeroed at allocation time and we never touch the
* following bytes up to INFO_SIZE, the checksum is calculated from
@@ -3126,6 +3110,7 @@ int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
struct buffer_head *bh;
struct btrfs_super_block *super;
u64 bytenr;
+ int err;
bytenr = btrfs_sb_offset(copy_num);
if (bytenr + BTRFS_SUPER_INFO_SIZE >= i_size_read(bdev->bd_inode))
@@ -3146,6 +3131,22 @@ int btrfs_read_dev_one_super(struct block_device *bdev, int copy_num,
return -EINVAL;
}
+ /*
+ * Check the superblock checksum, the type is stored inside.
+ * Pass the whole disk block of size BTRFS_SUPER_INFO_SIZE (4k).
+ */
+ err = btrfs_check_super_csum(bh->b_data);
+ if (err) {
+ if (err == -EINVAL)
+ pr_err("BTRFS error (device %pg): unsupported checksum algorithm",
+ bdev);
+ else if (err == -EUCLEAN)
+ pr_err("BTRFS error (device %pg): superblock checksum mismatch",
+ bdev);
+ brelse(bh);
+ return err;
+ }
+
*bh_ret = bh;
return 0;
}
--
2.15.0
next prev parent reply other threads:[~2018-03-23 12:52 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-03-23 12:53 [PATCH 0/2] verify superblock checksum Anand Jain
2018-03-23 12:53 ` Anand Jain [this message]
2018-03-23 12:53 ` [PATCH 2/2] btrfs: verify checksum when superblock is read for scan Anand Jain
2018-03-26 6:34 ` [PATCH 0/2] verify superblock checksum Anand Jain
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=20180323125349.26893-2-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=linux-btrfs@vger.kernel.org \
/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).