linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Qu Wenruo <wqu@suse.com>
To: linux-btrfs@vger.kernel.org
Subject: [PATCH 2/2] btrfs: volumes: Make sure no dev extent is beyond device boundary
Date: Fri,  5 Oct 2018 16:25:25 +0800	[thread overview]
Message-ID: <20181005082525.22441-3-wqu@suse.com> (raw)
In-Reply-To: <20181005082525.22441-1-wqu@suse.com>

Add extra dev extent end check against device boundary.

Signed-off-by: Qu Wenruo <wqu@suse.com>
---
 fs/btrfs/volumes.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index bf0b2c16847a..9fb40e30be6a 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -7492,6 +7492,7 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
 	while (1) {
 		struct extent_buffer *leaf = path->nodes[0];
 		struct btrfs_dev_extent *dext;
+		struct btrfs_device *dev;
 		int slot = path->slots[0];
 		u64 chunk_offset;
 		u64 physical_offset;
@@ -7517,6 +7518,22 @@ int btrfs_verify_dev_extents(struct btrfs_fs_info *fs_info)
 			goto out;
 		}
 
+		/* Make sure no dev extent is beyond device bondary */
+		dev = btrfs_find_device(fs_info, devid, NULL, NULL);
+		if (!dev) {
+			btrfs_err(fs_info, "failed to find devid %llu", devid);
+			ret = -EUCLEAN;
+			goto out;
+		}
+		if (physical_offset + physical_len > dev->disk_total_bytes) {
+			btrfs_err(fs_info,
+"dev extent devid %llu physical offset %llu len %llu is beyond device boundary %llu",
+				  devid, physical_offset, physical_len,
+				  dev->disk_total_bytes);
+			ret = -EUCLEAN;
+			goto out;
+		}
+
 		ret = verify_one_dev_extent(fs_info, chunk_offset, devid,
 					    physical_offset, physical_len);
 		if (ret < 0)
-- 
2.19.0


  parent reply	other threads:[~2018-10-05  8:25 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-05  8:25 [PATCH 0/2] Enhance btrfs_verify_dev_extents() to do more checks on dev extents Qu Wenruo
2018-10-05  8:25 ` [PATCH 1/2] btrfs: volumes: Make sure there is no overlap dev extents at mount time Qu Wenruo
2018-10-05  8:56   ` Nikolay Borisov
2018-10-05  9:22     ` Qu Wenruo
2018-10-05 17:23       ` David Sterba
2018-10-05  8:25 ` Qu Wenruo [this message]
2018-10-05  8:55   ` [PATCH 2/2] btrfs: volumes: Make sure no dev extent is beyond device boundary Nikolay Borisov
2018-10-05  9:17     ` Qu Wenruo

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=20181005082525.22441-3-wqu@suse.com \
    --to=wqu@suse.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).