[PATCH 3/4] badblocks: fix slab-out-of-bounds in _badblocks_check()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



From: Li Nan <linan122@xxxxxxxxxx>

prev_badblocks() will return -1 if checked range start < p[0]. Accessing
p[-1] will cause bug as below:

  BUG: KASAN: slab-out-of-bounds in badblocks_check+0x2c4

Fix it by checking 'prev' before accessing badblocks->page.

Fixes: 3ea3354cb9f0 ("badblocks: improve badblocks_check() for multiple ranges handling")
Signed-off-by: Li Nan <linan122@xxxxxxxxxx>
---
 block/badblocks.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/block/badblocks.c b/block/badblocks.c
index 054d05b93641..71a3e43351da 100644
--- a/block/badblocks.c
+++ b/block/badblocks.c
@@ -1316,7 +1316,7 @@ static int _badblocks_check(struct badblocks *bb, sector_t s, int sectors,
 		goto out;
 	}
 
-	if (overlap_front(bb, prev, &bad)) {
+	if (prev >= 0 && overlap_front(bb, prev, &bad)) {
 		if (set == 0) {
 			*first_bad = BB_OFFSET(p[prev]);
 			*bad_sectors = BB_LEN(p[prev]);
-- 
2.39.2





[Index of Archives]     [Linux RAID]     [Linux SCSI]     [Linux ATA RAID]     [IDE]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Device Mapper]

  Powered by Linux