Skip to content

Commit 3bc5729

Browse files
neilbrownliu-song-6
authored andcommitted
md: avoid signed overflow in slot_store()
slot_store() uses kstrtouint() to get a slot number, but stores the result in an "int" variable (by casting a pointer). This can result in a negative slot number if the unsigned int value is very large. A negative number means that the slot is empty, but setting a negative slot number this way will not remove the device from the array. I don't think this is a serious problem, but it could cause confusion and it is best to fix it. Reported-by: Dan Carpenter <[email protected]> Signed-off-by: NeilBrown <[email protected]> Signed-off-by: Song Liu <[email protected]>
1 parent 3e45352 commit 3bc5729

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

drivers/md/md.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3128,6 +3128,9 @@ slot_store(struct md_rdev *rdev, const char *buf, size_t len)
31283128
err = kstrtouint(buf, 10, (unsigned int *)&slot);
31293129
if (err < 0)
31303130
return err;
3131+
if (slot < 0)
3132+
/* overflow */
3133+
return -ENOSPC;
31313134
}
31323135
if (rdev->mddev->pers && slot == -1) {
31333136
/* Setting 'slot' on an active array requires also

0 commit comments

Comments
 (0)