linux-raid.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH mdadm] super1: report truncated device
@ 2022-07-12  1:00 NeilBrown
       [not found] ` <cff69e79-d681-c9d6-c719-8b10999a558a@molgen.mpg.de>
  0 siblings, 1 reply; 13+ messages in thread
From: NeilBrown @ 2022-07-12  1:00 UTC (permalink / raw)
  To: Jes Sorensen; +Cc: linux-raid


When the metadata is at the start of the device, it is possible that it
describes a device large than the one it is actually stored on.  When
this happens, report it loudly in --examine.

Also report in --assemble so that the failure which the kernel will
report will be explained.

Signed-off-by: NeilBrown <neilb@suse.de>
---
 super1.c | 34 +++++++++++++++++++++++++++-------
 1 file changed, 27 insertions(+), 7 deletions(-)

diff --git a/super1.c b/super1.c
index 71af860c0e3e..4d8dba8a5a44 100644
--- a/super1.c
+++ b/super1.c
@@ -406,12 +406,18 @@ static void examine_super1(struct supertype *st, char *homehost)
 
 	st->ss->getinfo_super(st, &info, NULL);
 	if (info.space_after != 1 &&
-	    !(__le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
-		printf("   Unused Space : before=%llu sectors, after=%llu sectors\n",
-		       info.space_before, info.space_after);
-
-	printf("          State : %s\n",
-	       (__le64_to_cpu(sb->resync_offset)+1)? "active":"clean");
+	    !(__le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET)) {
+		printf("   Unused Space : before=%llu sectors, ",
+		       info.space_before);
+		if (info.space_after < INT64_MAX)
+			printf("after=%llu sectors\n", info.space_after);
+		else
+			printf("after=-%llu sectors DEVICE TOO SMALL\n",
+			       UINT64_MAX - info.space_after);
+	}
+	printf("          State : %s%s\n",
+	       (__le64_to_cpu(sb->resync_offset)+1)? "active":"clean",
+	       info.space_after > INT64_MAX ? " TRUNCATED DEVICE" : "");
 	printf("    Device UUID : ");
 	for (i=0; i<16; i++) {
 		if ((i&3)==0 && i != 0)
@@ -2206,6 +2212,7 @@ static int load_super1(struct supertype *st, int fd, char *devname)
 		tst.ss = &super1;
 		for (tst.minor_version = 0; tst.minor_version <= 2;
 		     tst.minor_version++) {
+			tst.ignore_hw_compat = st->ignore_hw_compat;
 			switch(load_super1(&tst, fd, devname)) {
 			case 0: super = tst.sb;
 				if (bestvers == -1 ||
@@ -2312,7 +2319,6 @@ static int load_super1(struct supertype *st, int fd, char *devname)
 		free(super);
 		return 2;
 	}
-	st->sb = super;
 
 	bsb = (struct bitmap_super_s *)(((char*)super)+MAX_SB_SIZE);
 
@@ -2322,6 +2328,20 @@ static int load_super1(struct supertype *st, int fd, char *devname)
 	if (st->data_offset == INVALID_SECTORS)
 		st->data_offset = __le64_to_cpu(super->data_offset);
 
+	if (st->minor_version >= 1 &&
+	    st->ignore_hw_compat == 0 &&
+	    (__le64_to_cpu(super->data_offset) +
+	     __le64_to_cpu(super->size) > dsize ||
+	     __le64_to_cpu(super->data_offset) +
+	     __le64_to_cpu(super->data_size) > dsize)) {
+		if (devname)
+			pr_err("Device %s is not large enough for data described in superblock\n",
+			       devname);
+		free(super);
+		return 2;
+	}
+	st->sb = super;
+
 	/* Now check on the bitmap superblock */
 	if ((__le32_to_cpu(super->feature_map)&MD_FEATURE_BITMAP_OFFSET) == 0)
 		return 0;
-- 
2.36.1


^ permalink raw reply related	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2022-08-29 15:46 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-07-12  1:00 [PATCH mdadm] super1: report truncated device NeilBrown
     [not found] ` <cff69e79-d681-c9d6-c719-8b10999a558a@molgen.mpg.de>
2022-07-13  3:48   ` [PATCH mdadm v2] " NeilBrown
2022-07-21  8:19     ` Mariusz Tkaczyk
2022-07-21 16:21       ` Ternary Operator (was: [PATCH mdadm v2] super1: report truncated device) Paul Menzel
2022-07-22  6:55         ` Mariusz Tkaczyk
2022-07-23  4:37       ` [PATCH mdadm v2] super1: report truncated device NeilBrown
2022-07-25  7:42         ` Mariusz Tkaczyk
2022-08-24 15:58           ` Jes Sorensen
2022-08-25  0:24             ` NeilBrown
2022-08-25  7:59               ` Mariusz Tkaczyk
2022-08-25 13:42                 ` Jes Sorensen
2022-08-25 22:55                   ` [PATCH v3] " NeilBrown
2022-08-29 15:46                     ` Jes Sorensen

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).