Harden public RAID API argument validation
Some checks are pending
Build / build-mac (push) Waiting to run
Build / build-linux (push) Waiting to run
Build / build-arm32 (push) Waiting to run
Build / build-win (push) Waiting to run
CodeQL Advanced / Analyze (c-cpp) (push) Waiting to run
CodeQL Advanced / Analyze (actions) (push) Waiting to run

This commit is contained in:
Andrea Mazzoleni 2026-08-24 14:05:56 +02:00
parent d609056592
commit 05fc4de79e
3 changed files with 83 additions and 18 deletions

View file

@ -113,10 +113,20 @@ int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v)
/* enforce limit on size */
BUG_ON(size % 64 != 0);
/* enforce limit on number of failures */
BUG_ON(nr >= np); /* >= because we check with extra parity */
/* enforce limit on number of data blocks */
BUG_ON(nd < 1 || nd > RAID_DATA_MAX);
/* enforce limit on number of parity blocks */
BUG_ON(np < 1);
BUG_ON(np > RAID_PARITY_MAX || (raid_mode_active == RAID_MODE_VANDERMONDE_RAID && np > 3));
/* enforce limit on number of failures */
BUG_ON(nr < 0 || nr >= np); /* >= because we check with extra parity */
/* enforce valid vectors */
BUG_ON(v == 0);
BUG_ON(nr > 0 && ir == 0);
/* enforce order in index vector */
BUG_ON(nr >= 2 && ir[0] >= ir[1]);
BUG_ON(nr >= 3 && ir[1] >= ir[2]);
@ -125,6 +135,7 @@ int raid_check(int nr, int *ir, int nd, int np, size_t size, void **v)
BUG_ON(nr >= 6 && ir[4] >= ir[5]);
/* enforce limit on index vector */
BUG_ON(nr > 0 && ir[0] < 0);
BUG_ON(nr > 0 && ir[nr - 1] >= nd + np);
/* count failed data disk */
@ -153,6 +164,20 @@ int raid_scan(int *ir, int nd, int np, size_t size, void **v)
{
int r;
/* enforce limit on size */
BUG_ON(size % 64 != 0);
/* enforce limit on number of data blocks */
BUG_ON(nd < 1 || nd > RAID_DATA_MAX);
/* enforce limit on number of parity blocks */
BUG_ON(np < 0);
BUG_ON(np > RAID_PARITY_MAX || (raid_mode_active == RAID_MODE_VANDERMONDE_RAID && np > 3));
/* enforce valid vectors */
BUG_ON(v == 0);
BUG_ON(np > 1 && ir == 0);
/* check the special case of no failure */
if (np != 0 && raid_check(0, 0, nd, np, size, v) == 0)
return 0;