[PATCH] md: reject v0.90 arrays with too many devices

Jérémy Jean posted 1 patch 1 month, 1 week ago
drivers/md/md.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
[PATCH] md: reject v0.90 arrays with too many devices
Posted by Jérémy Jean 1 month, 1 week ago
The v0.90 superblock has room for MD_SB_DISKS device descriptors, but
super_90_load() only rejects nonpositive raid_disks values. A crafted
superblock can therefore copy a larger value into mddev->raid_disks. When
metadata is next updated, super_90_sync() walks sb->disks[] up to that
count and reads and writes beyond the 4 KiB superblock buffer.

A checksum-valid RAID1 member advertising 64 devices can be assembled by
mdadm --incremental --run. The first write to the array then produces
out-of-bounds writes from super_90_sync() under KASAN.

Reject device counts that cannot be represented by the v0.90 format while
loading the superblock.

Assisted-by: Codex:gpt-5
Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
---
 drivers/md/md.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/md/md.c b/drivers/md/md.c
index d1465bcd86c8..873a0e5fce7d 100644
--- a/drivers/md/md.c
+++ b/drivers/md/md.c
@@ -1398,7 +1398,7 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
 		goto abort;
 	}
 
-	if (sb->raid_disks <= 0)
+	if (sb->raid_disks <= 0 || sb->raid_disks > MD_SB_DISKS)
 		goto abort;
 
 	if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {
-- 
2.47.3

Re: [PATCH] md: reject v0.90 arrays with too many devices
Posted by yu kuai 3 weeks, 2 days ago
在 2026/8/21 5:07, Jérémy Jean 写道:

> The v0.90 superblock has room for MD_SB_DISKS device descriptors, but
> super_90_load() only rejects nonpositive raid_disks values. A crafted
> superblock can therefore copy a larger value into mddev->raid_disks. When
> metadata is next updated, super_90_sync() walks sb->disks[] up to that
> count and reads and writes beyond the 4 KiB superblock buffer.
>
> A checksum-valid RAID1 member advertising 64 devices can be assembled by
> mdadm --incremental --run. The first write to the array then produces
> out-of-bounds writes from super_90_sync() under KASAN.
>
> Reject device counts that cannot be represented by the v0.90 format while
> loading the superblock.
>
> Assisted-by: Codex:gpt-5
> Signed-off-by: Jérémy Jean <Jeremy.Jean@oss.cyber.gouv.fr>
> ---
>   drivers/md/md.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)

This is a long term problem, applied to md-7.3 with fix tag:

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")

>
> diff --git a/drivers/md/md.c b/drivers/md/md.c
> index d1465bcd86c8..873a0e5fce7d 100644
> --- a/drivers/md/md.c
> +++ b/drivers/md/md.c
> @@ -1398,7 +1398,7 @@ static int super_90_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor
>   		goto abort;
>   	}
>   
> -	if (sb->raid_disks <= 0)
> +	if (sb->raid_disks <= 0 || sb->raid_disks > MD_SB_DISKS)
>   		goto abort;
>   
>   	if (md_csum_fold(calc_sb_csum(sb)) != md_csum_fold(sb->sb_csum)) {

-- 
Thanks,
Kuai