Skip to contentSkip to conversation

mdadm/ddf: Abort when raid disk is smaller in getinfo_super_ddf

PATCH Applied Xiao Ni 3 participants 4 messages Oct 11, 2023 – Oct 26, 2023 MD RAID

lore
Share & tools
lore

Xiao Ni

author
#0 lore raw

PATCH 1/1 mdadm/ddf: Abort when raid disk is smaller in getinfo_super_ddf

The metadata is corrupted when the raid_disk<0. So abort directly.
This also can avoid a building error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’

---
 super-ddf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
super-ddf.c +4 -2
index 7213284e0a59..7b98333ecd51 100644
@@ -1984,12 +1984,14 @@ static void getinfo_super_ddf(struct supertype *st, struct mdinfo *info, char *m
 		info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum);
 		info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);
 
+		if (info->disk.raid_disk < 0)
+			return;
+
 		info->data_offset = be64_to_cpu(ddf->phys->
 						  entries[info->disk.raid_disk].
 						  config_size);
 		info->component_size = ddf->dlist->size - info->data_offset;
-		if (info->disk.raid_disk >= 0)
-			pde = ddf->phys->entries + info->disk.raid_disk;
+		pde = ddf->phys->entries + info->disk.raid_disk;
 		if (pde &&
 		    !(be16_to_cpu(pde->state) & DDF_Failed) &&
 		    !(be16_to_cpu(pde->state) & DDF_Missing))
Signature · 1 line
2.32.0 (Apple Git-132)
author
#1 lore raw

Sorry, the title should be [PATCH 1/1] mdadm/ddf: Abort when raid disk is smaller than 0 in getinfo_super_ddf

If you want me to send v2, I can do it.

Best Regards
Xiao

Quoted 35 lines · Xiao Ni

The metadata is corrupted when the raid_disk<0. So abort directly.
This also can avoid a building error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’

---
 super-ddf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
super-ddf.c +4 -3
index 7213284e0a59..7b98333ecd51 100644
@@ -1984,12 +1984,14 @@ static void getinfo_super_ddf(struct supertype *st, struct mdinfo *info, char *m
                info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum);
                info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);
 
+               if (info->disk.raid_disk < 0)
+                       return;
+
                info->data_offset = be64_to_cpu(ddf->phys->
                                                  entries[info->disk.raid_disk].
                                                  config_size);
                info->component_size = ddf->dlist->size - info->data_offset;
-               if (info->disk.raid_disk >= 0)
-                       pde = ddf->phys->entries + info->disk.raid_disk;
+               pde = ddf->phys->entries + info->disk.raid_disk;
                if (pde &&
                    !(be16_to_cpu(pde->state) & DDF_Failed) &&
                    !(be16_to_cpu(pde->state) & DDF_Missing))
--

2.32.0 (Apple Git-132)

#2 lore raw
Quoted 31 lines · On Wed, 11 Oct 2023 21:25:37 +0800 Xiao Ni <[email protected]> wrote:

Sorry, the title should be [PATCH 1/1] mdadm/ddf: Abort when raid disk is smaller than 0 in getinfo_super_ddf

If you want me to send v2, I can do it.

Best Regards
Xiao

Quoted 21 lines · Xiao Ni

The metadata is corrupted when the raid_disk<0. So abort directly. This also can avoid a building error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’

---
 super-ddf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
super-ddf.c +0 -0
index 7213284e0a59..7b98333ecd51 100644
@@ -1984,12 +1984,14 @@ static void getinfo_super_ddf(struct supertype *st,

struct mdinfo *info, char *m info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum); info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);

Quoted 17 lines
Quoted 14 lines
super-ddf.c +4 -3
+               if (info->disk.raid_disk < 0)
+                       return;
+
                info->data_offset = be64_to_cpu(ddf->phys->
                                                  entries[info->disk.raid_disk].
                                                  config_size);
                info->component_size = ddf->dlist->size - info->data_offset;
-               if (info->disk.raid_disk >= 0)
-                       pde = ddf->phys->entries + info->disk.raid_disk;
+               pde = ddf->phys->entries + info->disk.raid_disk;
                if (pde &&
                    !(be16_to_cpu(pde->state) & DDF_Failed) &&
                    !(be16_to_cpu(pde->state) & DDF_Missing))
--
Quoted 2 lines

2.32.0 (Apple Git-132)

Hi Xiao,
I don't see a need to send v2. Moving to awaiting upstream:

Thanks,
Mariusz

Applied
#3 lore raw
Quoted 52 lines · Mariusz Tkaczyk
Quoted 31 lines · On Wed, 11 Oct 2023 21:25:37 +0800 Xiao Ni <[email protected]> wrote:

Sorry, the title should be [PATCH 1/1] mdadm/ddf: Abort when raid disk is smaller than 0 in getinfo_super_ddf

If you want me to send v2, I can do it.

Best Regards
Xiao

Quoted 21 lines · Xiao Ni

The metadata is corrupted when the raid_disk<0. So abort directly. This also can avoid a building error:
super-ddf.c:1988:58: error: array subscript -1 is below array bounds of ‘struct phys_disk_entry[0]’

---
 super-ddf.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
super-ddf.c +0 -0
index 7213284e0a59..7b98333ecd51 100644
@@ -1984,12 +1984,14 @@ static void getinfo_super_ddf(struct supertype *st,

struct mdinfo *info, char *m info->disk.number = be32_to_cpu(ddf->dlist->disk.refnum); info->disk.raid_disk = find_phys(ddf, ddf->dlist->disk.refnum);

Quoted 17 lines
Quoted 14 lines
super-ddf.c +4 -3
+               if (info->disk.raid_disk < 0)
+                       return;
+
                info->data_offset = be64_to_cpu(ddf->phys->
                                                  entries[info->disk.raid_disk].
                                                  config_size);
                info->component_size = ddf->dlist->size - info->data_offset;
-               if (info->disk.raid_disk >= 0)
-                       pde = ddf->phys->entries + info->disk.raid_disk;
+               pde = ddf->phys->entries + info->disk.raid_disk;
                if (pde &&
                    !(be16_to_cpu(pde->state) & DDF_Failed) &&
                    !(be16_to_cpu(pde->state) & DDF_Missing))
--
Quoted 2 lines

2.32.0 (Apple Git-132)

Quoted 4 lines

Hi Xiao,
I don't see a need to send v2. Moving to awaiting upstream:

Applied!

Thanks,
Jes