mtd: key superblock by device number
authorChristian Brauner <brauner@kernel.org>
Tue, 29 Aug 2023 15:23:57 +0000 (17:23 +0200)
committerChristian Brauner <brauner@kernel.org>
Thu, 31 Aug 2023 10:47:15 +0000 (12:47 +0200)
commitec952aa253c0f49a70d9de7b44b5f5c93e2dfe54
tree7b90079309020da73f388c8a8aac97e8316ef922
parent69881be3d9a00cca770886af40913cfc5274b2d0
mtd: key superblock by device number

The mtd driver has similar problems than the one that was fixed in
commit dc3216b14160 ("super: ensure valid info").

The kill_mtd_super() helper calls shuts the superblock down but leaves
the superblock on fs_supers as the devices are still in use but puts the
mtd device and cleans out the superblock's s_mtd field.

This means another mounter can find the superblock on the list accessing
its s_mtd field while it is curently in the process of being freed or
already freed.

Prevent that from happening by keying superblock by dev_t just as we do
in the generic code.

Link: https://lore.kernel.org/linux-fsdevel/20230829-weitab-lauwarm-49c40fc85863@brauner
Acked-by: Richard Weinberger <richard@nod.at>
Reviewed-by: Jan Kara <jack@suse.cz>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Message-Id: <20230829-vfs-super-mtd-v1-2-fecb572e5df3@kernel.org>
Signed-off-by: Christian Brauner <brauner@kernel.org>
drivers/mtd/mtdsuper.c