]> git.baikalelectronics.ru Git - kernel.git/commit
md: avoid signed overflow in slot_store()
authorNeilBrown <neilb@suse.de>
Sun, 5 Mar 2023 22:36:25 +0000 (09:36 +1100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 5 Apr 2023 09:16:42 +0000 (11:16 +0200)
commit8a28d43a7ce7ae73eada022e17bf7f40c5c421ae
tree5e3da680c0845e130272831a57711a061479021f
parenta1f322d448ee2fbe39c36bbfc82e10d94a8b45cc
md: avoid signed overflow in slot_store()

[ Upstream commit 3bc57292278a0b6ac4656cad94c14f2453344b57 ]

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 <error27@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: Song Liu <song@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/md.c