<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/linux.git/drivers/mtd/mtdchar.c, branch linux-6.0.y</title>
<subtitle>Linux kernel stable tree (mirror)</subtitle>
<id>https://git.radix-linux.su/kernel/linux.git/atom?h=linux-6.0.y</id>
<link rel='self' href='https://git.radix-linux.su/kernel/linux.git/atom?h=linux-6.0.y'/>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/'/>
<updated>2022-06-09T13:03:32+00:00</updated>
<entry>
<title>mtdchar: use kvmalloc() for potentially large allocations</title>
<updated>2022-06-09T13:03:32+00:00</updated>
<author>
<name>Michał Kępień</name>
<email>kernel@kempniu.pl</email>
</author>
<published>2022-05-16T07:06:01+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=83208e106a8e8a859110ebb04a5e927ced911afb'/>
<id>urn:sha1:83208e106a8e8a859110ebb04a5e927ced911afb</id>
<content type='text'>
mtdchar_write_ioctl() calls kmalloc() with the 'size' argument set to
the smaller of two values: the write request's data/OOB length provided
by user space and the erase block size of the MTD device.  If the latter
is large, kmalloc() may not be able to serve such allocation requests.
Use kvmalloc() instead.  Correspondingly, replace kfree() calls with
kvfree() calls.

Suggested-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Michał Kępień &lt;kernel@kempniu.pl&gt;
Acked-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20220516070601.11428-3-kernel@kempniu.pl
</content>
</entry>
<entry>
<title>mtdchar: prevent integer overflow in a safety check</title>
<updated>2022-06-09T13:03:32+00:00</updated>
<author>
<name>Michał Kępień</name>
<email>kernel@kempniu.pl</email>
</author>
<published>2022-05-16T07:06:00+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=a1eda864c04cf24ea1130334963c6199318f6f95'/>
<id>urn:sha1:a1eda864c04cf24ea1130334963c6199318f6f95</id>
<content type='text'>
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 &lt;richard@nod.at&gt;
Signed-off-by: Michał Kępień &lt;kernel@kempniu.pl&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20220516070601.11428-2-kernel@kempniu.pl
</content>
</entry>
<entry>
<title>mtdchar: prevent unbounded allocation in MEMWRITE ioctl</title>
<updated>2021-12-09T16:52:29+00:00</updated>
<author>
<name>Michał Kępień</name>
<email>kernel@kempniu.pl</email>
</author>
<published>2021-11-30T11:31:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=6420ac0af95dbcb2fd8452e2d551ab50e1bbad83'/>
<id>urn:sha1:6420ac0af95dbcb2fd8452e2d551ab50e1bbad83</id>
<content type='text'>
In the mtdchar_write_ioctl() function, memdup_user() is called with its
'len' parameter set to verbatim values provided by user space via a
struct mtd_write_req.  Both the 'len' and 'ooblen' fields of that
structure are 64-bit unsigned integers, which means the MEMWRITE ioctl
can trigger unbounded kernel memory allocation requests.

Fix by iterating over the buffers provided by user space in a loop,
processing at most mtd-&gt;erasesize bytes in each iteration.  Adopt some
checks from mtd_check_oob_ops() to retain backward user space
compatibility.

Suggested-by: Boris Brezillon &lt;boris.brezillon@collabora.com&gt;
Signed-off-by: Michał Kępień &lt;kernel@kempniu.pl&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20211130113149.21848-1-kernel@kempniu.pl
</content>
</entry>
<entry>
<title>mtd: add OTP (one-time-programmable) erase ioctl</title>
<updated>2021-03-28T17:24:54+00:00</updated>
<author>
<name>Michael Walle</name>
<email>michael@walle.cc</email>
</author>
<published>2021-03-03T20:18:19+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=e3c1f1c92d6ede3cfa09d6a103d3d1c1ef645e35'/>
<id>urn:sha1:e3c1f1c92d6ede3cfa09d6a103d3d1c1ef645e35</id>
<content type='text'>
This may sound like a contradiction but some SPI-NOR flashes really
support erasing their OTP region until it is finally locked. Having the
possibility to erase an OTP region might come in handy during
development.

The ioctl argument follows the OTPLOCK style.

Signed-off-by: Michael Walle &lt;michael@walle.cc&gt;
Acked-by: Vignesh Raghavendra &lt;vigneshr@ti.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210303201819.2752-1-michael@walle.cc
</content>
</entry>
<entry>
<title>mtd: require write permissions for locking and badblock ioctls</title>
<updated>2021-03-28T17:20:11+00:00</updated>
<author>
<name>Michael Walle</name>
<email>michael@walle.cc</email>
</author>
<published>2021-03-03T15:57:35+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1e97743fd180981bef5f01402342bb54bf1c6366'/>
<id>urn:sha1:1e97743fd180981bef5f01402342bb54bf1c6366</id>
<content type='text'>
MEMLOCK, MEMUNLOCK and OTPLOCK modify protection bits. Thus require
write permission. Depending on the hardware MEMLOCK might even be
write-once, e.g. for SPI-NOR flashes with their WP# tied to GND. OTPLOCK
is always write-once.

MEMSETBADBLOCK modifies the bad block table.

Fixes: f7e6b19bc764 ("mtd: properly check all write ioctls for permissions")
Signed-off-by: Michael Walle &lt;michael@walle.cc&gt;
Reviewed-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
Acked-by: Rafał Miłecki &lt;rafal@milecki.pl&gt;
Acked-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210303155735.25887-1-michael@walle.cc
</content>
</entry>
<entry>
<title>mtd: mtdchar: Fix fall-through warnings for Clang</title>
<updated>2021-03-11T11:17:42+00:00</updated>
<author>
<name>Gustavo A. R. Silva</name>
<email>gustavoars@kernel.org</email>
</author>
<published>2021-03-05T08:22:24+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=0975b633871cb77c3be7f1deb9feb885e3e86b9c'/>
<id>urn:sha1:0975b633871cb77c3be7f1deb9feb885e3e86b9c</id>
<content type='text'>
In preparation to enable -Wimplicit-fallthrough for Clang, fix a warning
by explicitly adding a break statement instead of letting the code fall
through to the next case.

Link: https://github.com/KSPP/linux/issues/115
Signed-off-by: Gustavo A. R. Silva &lt;gustavoars@kernel.org&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210305082224.GA137360@embeddedor
</content>
</entry>
<entry>
<title>mtd: char: Get rid of Big MTD Lock</title>
<updated>2021-03-11T08:37:49+00:00</updated>
<author>
<name>Alexander Sverdlin</name>
<email>alexander.sverdlin@nokia.com</email>
</author>
<published>2021-02-17T21:18:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=1ad55288829c78e85bfe7d0c86d75415adf5f305'/>
<id>urn:sha1:1ad55288829c78e85bfe7d0c86d75415adf5f305</id>
<content type='text'>
Get rid of central chrdev MTD lock, which prevents simultaneous operations
on completely independent physical MTD chips. Replace it with newly
introduced per-master mutex.

Signed-off-by: Alexander Sverdlin &lt;alexander.sverdlin@nokia.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210217211845.43364-2-alexander.sverdlin@nokia.com
</content>
</entry>
<entry>
<title>mtd: char: Drop mtd_mutex usage from mtdchar_open()</title>
<updated>2021-03-11T08:37:49+00:00</updated>
<author>
<name>Alexander Sverdlin</name>
<email>alexander.sverdlin@nokia.com</email>
</author>
<published>2021-02-17T21:18:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=ecd400ce5f97e03aed6bef9bc4efb1befdbf779b'/>
<id>urn:sha1:ecd400ce5f97e03aed6bef9bc4efb1befdbf779b</id>
<content type='text'>
It looks unnecessary in the function, remove it from the function
having in mind to remove it completely.

Signed-off-by: Alexander Sverdlin &lt;alexander.sverdlin@nokia.com&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20210217211845.43364-1-alexander.sverdlin@nokia.com
</content>
</entry>
<entry>
<title>mtd: remove unneeded break</title>
<updated>2020-10-28T10:58:11+00:00</updated>
<author>
<name>Tom Rix</name>
<email>trix@redhat.com</email>
</author>
<published>2020-10-19T19:16:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=232b67c399424948107fbffe4402a102121a2622'/>
<id>urn:sha1:232b67c399424948107fbffe4402a102121a2622</id>
<content type='text'>
A break is not needed if it is preceded by a return

Signed-off-by: Tom Rix &lt;trix@redhat.com&gt;
Acked-by: Richard Weinberger &lt;richard@nod.at&gt;
Signed-off-by: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Link: https://lore.kernel.org/linux-mtd/20201019191631.9604-1-trix@redhat.com
</content>
</entry>
<entry>
<title>mtd: properly check all write ioctls for permissions</title>
<updated>2020-07-24T21:03:11+00:00</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2020-07-16T11:53:46+00:00</published>
<link rel='alternate' type='text/html' href='https://git.radix-linux.su/kernel/linux.git/commit/?id=f7e6b19bc76471ba03725fe58e0c218a3d6266c3'/>
<id>urn:sha1:f7e6b19bc76471ba03725fe58e0c218a3d6266c3</id>
<content type='text'>
When doing a "write" ioctl call, properly check that we have permissions
to do so before copying anything from userspace or anything else so we
can "fail fast".  This includes also covering the MEMWRITE ioctl which
previously missed checking for this.

Cc: Miquel Raynal &lt;miquel.raynal@bootlin.com&gt;
Cc: Richard Weinberger &lt;richard@nod.at&gt;
Cc: Vignesh Raghavendra &lt;vigneshr@ti.com&gt;
Cc: stable &lt;stable@kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
[rw: Fixed locking issue]
Signed-off-by: Richard Weinberger &lt;richard@nod.at&gt;
</content>
</entry>
</feed>
