dm ioctl: Avoid double-fetch of version
authorDemi Marie Obenour <demi@invisiblethingslab.com>
Sat, 3 Jun 2023 14:52:42 +0000 (10:52 -0400)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 19 Jul 2023 14:22:07 +0000 (16:22 +0200)
commitd5eb0375d78a56d08e9fd5fa3da60c2a05ff038c
treea8ae38f263199e3e411cbbdefa21618e66df638f
parent27987794197e71309cb830944a849f470bd20431
dm ioctl: Avoid double-fetch of version

[ Upstream commit 249bed821b4db6d95a99160f7d6d236ea5fe6362 ]

The version is fetched once in check_version(), which then does some
validation and then overwrites the version in userspace with the API
version supported by the kernel.  copy_params() then fetches the version
from userspace *again*, and this time no validation is done.  The result
is that the kernel's version number is completely controllable by
userspace, provided that userspace can win a race condition.

Fix this flaw by not copying the version back to the kernel the second
time.  This is not exploitable as the version is not further used in the
kernel.  However, it could become a problem if future patches start
relying on the version field.

Cc: stable@vger.kernel.org
Signed-off-by: Demi Marie Obenour <demi@invisiblethingslab.com>
Signed-off-by: Mike Snitzer <snitzer@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/dm-ioctl.c