diff options
| author | Naveen Kumar Chaudhary <[email protected]> | 2026-07-08 20:03:04 +0530 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2026-07-21 13:52:50 -0600 |
| commit | 1b8283bd3220e898d338fb98929f0b06ed63da84 (patch) | |
| tree | 7813878214c0c726a9865fa46bd1f90e6d6120f9 /board/synopsys/nsim/Kconfig | |
| parent | 72d780b5ccc0644f935eb48fdffb92b1177c4fb3 (diff) | |
The bounds check in do_rw() was written as:
if (cnt + blk > limit)
with cnt and blk declared as uint (unsigned int) and limit as ulong.
C's usual arithmetic conversions are applied per binary operator, so
"cnt + blk" is evaluated entirely in unsigned int and wraps modulo
2^32 before the result is widened for the comparison against limit.
With cnt = 0xFFFFFFFF and blk = 1 the sum wraps to 0 and the guard
passes, allowing blk_dread()/blk_dwrite() to be issued with a 4 GiB
transfer count that runs past the partition (or, when no partition
is selected, the entire device).
Rewrite the check as two comparisons that do not overflow:
if (blk > limit || cnt > limit - blk)
The subtraction is performed in ulong (limit's type), so no truncation
occurs, and the two sub-conditions cover both "start block past end"
and "count would push us past end" failure modes.
Signed-off-by: Naveen Kumar Chaudhary <[email protected]>
Reviewed-by: Simon Glass <[email protected]>
Diffstat (limited to 'board/synopsys/nsim/Kconfig')
0 files changed, 0 insertions, 0 deletions
