Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

mtdchar: prevent integer overflow in a safety check

Commit 6420ac0af95d ("mtdchar: prevent unbounded allocation in MEMWRITE
ioctl") added a safety check to mtdchar_write_ioctl() which attempts to
ensure that the write request sent by user space does not extend beyond
the MTD device's size. However, that check contains an addition of two
struct mtd_write_req fields, 'start' and 'len', both of which are u64
variables. The result of that addition can overflow, allowing the
safety check to be bypassed.

The arguably simplest fix - changing the data types of the relevant
struct mtd_write_req fields - is not feasible as it would break user
space.

Fix by making mtdchar_write_ioctl() truncate the value provided by user
space in the 'len' field of struct mtd_write_req, so that only the lower
32 bits of that field are used, preventing the overflow.

While the 'ooblen' field of struct mtd_write_req is not currently used
in any similarly flawed safety check, also truncate it to 32 bits, for
consistency with the 'len' field and with other MTD routines handling
OOB data.

Update include/uapi/mtd/mtd-abi.h accordingly.

Suggested-by: Richard Weinberger <richard@nod.at>
Signed-off-by: Michał Kępień <kernel@kempniu.pl>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Link: https://lore.kernel.org/linux-mtd/20220516070601.11428-2-kernel@kempniu.pl

authored by

Michał Kępień and committed by
Miquel Raynal
a1eda864 e607879b

+5 -2
+3
drivers/mtd/mtdchar.c
··· 615 615 if (!usr_oob) 616 616 req.ooblen = 0; 617 617 618 + req.len &= 0xffffffff; 619 + req.ooblen &= 0xffffffff; 620 + 618 621 if (req.start + req.len > mtd->size) 619 622 return -EINVAL; 620 623
+2 -2
include/uapi/mtd/mtd-abi.h
··· 69 69 * struct mtd_write_req - data structure for requesting a write operation 70 70 * 71 71 * @start: start address 72 - * @len: length of data buffer 73 - * @ooblen: length of OOB buffer 72 + * @len: length of data buffer (only lower 32 bits are used) 73 + * @ooblen: length of OOB buffer (only lower 32 bits are used) 74 74 * @usr_data: user-provided data buffer 75 75 * @usr_oob: user-provided OOB buffer 76 76 * @mode: MTD mode (see "MTD operation modes")