From patchwork Mon May 10 22:21:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 1477008 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1:d65d:64ff:fe57:4e05; helo=desiato.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=desiato.20200630 header.b=gk7u5MYI; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=ESuGZBun; dkim-atps=neutral Received: from desiato.infradead.org (desiato.infradead.org [IPv6:2001:8b0:10b:1:d65d:64ff:fe57:4e05]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FfXtv3YTJz9t10 for ; Tue, 11 May 2021 19:39:19 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=uVATlZlb8gJna3U28qGdXDaPfHBTWALM13ohqdvvf/Q=; b=gk7u5MYIKF7zhSbGPWD6K/GGh slWW1K3iEWY5mMyJugkmld/gOdLvFp03XfIpV03JnI2YkIV2TNCXpyLyDsiTyM82tpPvLu2fPUBFk 6foBPxoobRYkFH5JoqMpwHMnP+LdQif2YEV6X6l+vk/fh5ThcpuS4rDLjbGAzyTjD0oHgOZrsn9cK uAY1t2ga6rXAFPRYrTjtkUkdf64SkkfTvyTBmH27ZbHxpP9OIwVidbuK2ckGpG1t6bnl/7EOqnKgN hj1LVL/WHhbau477wOfhUhfJPpDCoQHwdx3tsTU1/I6JZwez2r/kMgOtRxoZ0+C0OTLuMzwWBw6Jk KRnZ+o7Zg==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lgOqX-00Gj91-7t; Tue, 11 May 2021 09:38:33 +0000 Received: from [2607:7c80:54:e::133] (helo=bombadil.infradead.org) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgEHK-00Foaz-92 for linux-mtd@desiato.infradead.org; Mon, 10 May 2021 22:21:32 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=R80nzKmBt48bS63oBckXuoJLmt6rsTMMI2W6M87C7mg=; b=ESuGZBundC9dZ+/2/0bf9Cojqi wlZFpIacX31/KvAdKdFieiYq3UbYFZTLsRAHCfxuLERqn3yA/noxj/yCFaFpXJW0lCtRBnvR6lFKU U7E4KWYJlnGIBHWinOzYjoJ1wLI+30c8Xg0JelD1PJK8/buHb4dqGZBdEDWbWZ9fwJ2wp5zeDe10t fDumhe0G/hVcqhnxsrhWkYe+CUavZuTGPtZD5BXwgLlGj5eyd3+b6N0Oyj6zPsuvbteuGZDalPZsG MfsKg4vLk4d9RSqbBml4qHfUtQCXESef62flqpK6ZWtBuPmzSjBB66l/H7rq8IdGfEgbqgliFZFmU Wfbos92g==; Received: from fudo.makrotopia.org ([2a07:2ec0:3002::71]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lgEHH-0099fx-Nh for linux-mtd@lists.infradead.org; Mon, 10 May 2021 22:21:29 +0000 Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1lgEHG-0001GW-0P; Tue, 11 May 2021 00:21:26 +0200 Date: Mon, 10 May 2021 23:21:17 +0100 From: Daniel Golle To: Miquel Raynal Cc: linux-mtd@lists.infradead.org, Vignesh Raghavendra , Richard Weinberger , David Woodhouse , Christoph Hellwig , Jan Kara , Hannes Reinecke Subject: [PATCH v4] mtd: super: don't rely on mtdblock device minor Message-ID: References: <20210510121837.14274d4f@xps13> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20210510121837.14274d4f@xps13> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_152127_795409_F52E08E9 X-CRM114-Status: GOOD ( 15.15 ) X-Spam-Score: 0.0 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: For blktrans devices with partitions (ie. part_bits != 0) the assumption that the minor number of the mtdblock device matches the mtdnum doesn't hold true. Properly resolve mtd device from blktrans la [...] Content analysis details: (0.0 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record /bin/ln: failed to access 'reaver_cache/texts/20210510_152127_795409_F52E08E9': No such file or directory X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210510_152127_795409_F52E08E9 X-CRM114-Status: GOOD ( 12.06 ) X-Spam-Score: 0.1 (/) X-Spam-Report: Spam detection software, running on the system "desiato.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: For blktrans devices with partitions (ie. part_bits != 0) the assumption that the minor number of the mtdblock device matches the mtdnum doesn't hold true. Properly resolve mtd device from blktrans la [...] Content analysis details: (0.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [2607:7c80:54:e:0:0:0:133 listed in] [list.dnswl.org] 0.0 T_SPF_HELO_TEMPERROR SPF: test of HELO record failed (temperror) 0.9 SPF_FAIL SPF: sender does not match SPF record (fail) [SPF failed: Please see http://www.openspf.org/Why?s=mfrom; id=daniel%40makrotopia.org; ip=2607%3A7c80%3A54%3Ae%3A%3A133; r=desiato.infradead.org] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS 0.1 DKIM_INVALID DKIM or DK signature exists, but is not valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org For blktrans devices with partitions (ie. part_bits != 0) the assumption that the minor number of the mtdblock device matches the mtdnum doesn't hold true. Properly resolve mtd device from blktrans layer instead. Signed-off-by: Daniel Golle --- v4: rebase on v5.13-rc1, improve error handling v3: fix typo in patch description v2: remove BUG() calls as requested by Miquel Raynal drivers/mtd/mtdsuper.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/drivers/mtd/mtdsuper.c b/drivers/mtd/mtdsuper.c index 38b6aa849c638..40bb63e7bc7f6 100644 --- a/drivers/mtd/mtdsuper.c +++ b/drivers/mtd/mtdsuper.c @@ -9,6 +9,7 @@ */ #include +#include #include #include #include @@ -120,8 +121,9 @@ int get_tree_mtd(struct fs_context *fc, struct fs_context *fc)) { #ifdef CONFIG_BLOCK - dev_t dev; - int ret; + struct block_device *bdev; + struct mtd_blktrans_dev *blktrans_dev; + int ret, part_bits; #endif int mtdnr; @@ -169,16 +171,32 @@ int get_tree_mtd(struct fs_context *fc, /* try the old way - the hack where we allowed users to mount * /dev/mtdblock$(n) but didn't actually _use_ the blockdev */ - ret = lookup_bdev(fc->source, &dev); - if (ret) { + bdev = blkdev_get_by_path(fc->source, FMODE_READ, NULL); + if (IS_ERR(bdev)) { + ret = PTR_ERR(bdev); errorf(fc, "MTD: Couldn't look up '%s': %d", fc->source, ret); return ret; } - pr_debug("MTDSB: lookup_bdev() returned 0\n"); + pr_debug("MTDSB: blkdev_get_by_path() returned 0\n"); + + if (MAJOR(bdev->bd_dev) == MTD_BLOCK_MAJOR) { + if (!bdev->bd_disk) + goto error_mtdblock; - if (MAJOR(dev) == MTD_BLOCK_MAJOR) - return mtd_get_sb_by_nr(fc, MINOR(dev), fill_super); + blktrans_dev = (struct mtd_blktrans_dev *)(bdev->bd_disk->private_data); + if (!blktrans_dev || !blktrans_dev->tr) + goto error_mtdblock; + mtdnr = blktrans_dev->devnum; + part_bits = blktrans_dev->tr->part_bits; + if (MINOR(bdev->bd_dev) != (mtdnr << part_bits)) + goto error_mtdblock; + + blkdev_put(bdev, FMODE_READ); + return mtd_get_sb_by_nr(fc, mtdnr, fill_super); + } +error_mtdblock: + blkdev_put(bdev, FMODE_READ); #endif /* CONFIG_BLOCK */ if (!(fc->sb_flags & SB_SILENT))