{"id":2222452,"url":"http://patchwork.ozlabs.org/api/patches/2222452/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/patch/2a62dc1a58f2f8467d95444fa4b37a0af27aeb45.1775951973.git.daniel@makrotopia.org/","project":{"id":3,"url":"http://patchwork.ozlabs.org/api/projects/3/?format=json","name":"Linux MTD development","link_name":"linux-mtd","list_id":"linux-mtd.lists.infradead.org","list_email":"linux-mtd@lists.infradead.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<2a62dc1a58f2f8467d95444fa4b37a0af27aeb45.1775951973.git.daniel@makrotopia.org>","list_archive_url":null,"date":"2026-04-12T00:05:23","name":"mtd: nand: bbt: clamp GENMASK high bit to word boundary","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"11a80cfaa152e7afcad3ffcca0f314a49f6fb0b6","submitter":{"id":64091,"url":"http://patchwork.ozlabs.org/api/people/64091/?format=json","name":"Daniel Golle","email":"daniel@makrotopia.org"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-mtd/patch/2a62dc1a58f2f8467d95444fa4b37a0af27aeb45.1775951973.git.daniel@makrotopia.org/mbox/","series":[{"id":499580,"url":"http://patchwork.ozlabs.org/api/series/499580/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/list/?series=499580","date":"2026-04-12T00:05:23","name":"mtd: nand: bbt: clamp GENMASK high bit to word boundary","version":1,"mbox":"http://patchwork.ozlabs.org/series/499580/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/2222452/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/2222452/checks/","tags":{},"related":[],"headers":{"Return-Path":"\n <linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@legolas.ozlabs.org","Authentication-Results":["legolas.ozlabs.org;\n\tdkim=pass (2048-bit key;\n secure) header.d=lists.infradead.org header.i=@lists.infradead.org\n header.a=rsa-sha256 header.s=bombadil.20210309 header.b=rO7sy5en;\n\tdkim-atps=neutral","legolas.ozlabs.org;\n spf=temperror (SPF Temporary Error: DNS Timeout)\n smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133;\n helo=bombadil.infradead.org;\n envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n receiver=patchwork.ozlabs.org)"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n [IPv6:2607:7c80:54:3::133])\n\t(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)\n\t key-exchange x25519 server-signature ECDSA (secp384r1) server-digest SHA384)\n\t(No client certificate requested)\n\tby legolas.ozlabs.org (Postfix) with ESMTPS id 4ftW6C0tjXz1yCv\n\tfor <incoming@patchwork.ozlabs.org>; Sun, 12 Apr 2026 10:05:49 +1000 (AEST)","from localhost ([::1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wBiKY-0000000DtyA-0C4Z;\n\tSun, 12 Apr 2026 00:05:38 +0000","from pidgin.makrotopia.org ([2a07:2ec0:3002::65])\n\tby bombadil.infradead.org with esmtps (Exim 4.98.2 #2 (Red Hat Linux))\n\tid 1wBiKV-0000000DtxC-0jK5\n\tfor linux-mtd@lists.infradead.org;\n\tSun, 12 Apr 2026 00:05:36 +0000","from local\n\tby pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256)\n\t (Exim 4.99)\n\t(envelope-from <daniel@makrotopia.org>)\n\tid 1wBiKL-000000005c9-2I2c;\n\tSun, 12 Apr 2026 00:05:25 +0000"],"DKIM-Signature":"v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20210309; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post:\n\tList-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Subject:To:From\n\t:Date:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From:\n\tResent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:\n\tList-Owner; bh=YCfp4W/wSPj3ZAEz28cN+mOTBvNfWfjYsP/vTuxmKgI=; b=rO7sy5enqe2ugl\n\tkaqyDzssSoVYk9EByKRi0WtEIcHZppo+cqwCHjb3B7roY/ZQu7uHTmRMNPvZmqjkhKbkB4hAbQC3L\n\tK/Juq1XP1qTH4E80YVgUd18bftVd7P/K3HDRfqX54pTT1WxptGBrTZFAw6vJ313hF6t8aKhddWitq\n\txNqNLAKOvNjvSPusSH00AVoiywA9DU38NwqHdtm3TzD2Ks07JIKwQnA0XhMGfOcrWO6xJd8FuX4Ni\n\tPMZqyZ56NF+/2tvUBwaQevwtsI7GvFJF4felYSvt97NOSGO0ZZxKv4jncFBoQtlAH/NsGJA/kUWSV\n\tOjfe273c99LFps0hud3w==;","Date":"Sun, 12 Apr 2026 01:05:23 +0100","From":"Daniel Golle <daniel@makrotopia.org>","To":"Miquel Raynal <miquel.raynal@bootlin.com>,\n\tRichard Weinberger <richard@nod.at>,\n\tVignesh Raghavendra <vigneshr@ti.com>,\n\tBoris Brezillon <bbrezillon@kernel.org>,\n\tlinux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org","Subject":"[PATCH] mtd: nand: bbt: clamp GENMASK high bit to word boundary","Message-ID":"\n <2a62dc1a58f2f8467d95444fa4b37a0af27aeb45.1775951973.git.daniel@makrotopia.org>","MIME-Version":"1.0","Content-Disposition":"inline","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20260411_170535_237354_915FADFA ","X-CRM114-Status":"UNSURE (   9.88  )","X-CRM114-Notice":"Please train this message.","X-Spam-Score":"-1.9 (-)","X-Spam-Report":"Spam detection software,\n running on the system \"bombadil.infradead.org\",\n has NOT identified this incoming email as spam.  The original\n message has been attached to this so you can view it or label\n similar future email.  If you have any questions, see\n the administrator of that system for details.\n Content preview:  When a BBT entry straddles an unsigned long boundary, the\n   GENMASK in nanddev_bbt_set_block_status() can potentially overflow because\n    offs + bits_per_block - 1 can theoretically exceed BITS_PER_LONG - [...]\n Content analysis details:   (-1.9 points, 5.0 required)\n  pts rule name              description\n ---- ----------------------\n --------------------------------------------------\n -0.0 SPF_PASS               SPF: sender matches SPF record\n  0.0 SPF_HELO_NONE          SPF: HELO does not publish an SPF Record\n -1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n                             [score: 0.0000]","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.34","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n <mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"When a BBT entry straddles an unsigned long boundary, the GENMASK in\nnanddev_bbt_set_block_status() can potentially overflow because\noffs + bits_per_block - 1 can theoretically exceed BITS_PER_LONG - 1.\nClamp the high bit so only bits within the current word are masked.\nThe cross-word portion is already handled by the pos[1] block below.\n\nDiscovered by UBSAN: shift-out-of-bounds in\ndrivers/mtd/nand/bbt.c:116:13\nshift exponent 18446744073709551614 is too large for 64-bit type\n'long unsigned int'\n\nFixes: 9c3736a3de21 (\"mtd: nand: Add core infrastructure to deal with NAND devices\")\nSigned-off-by: Daniel Golle <daniel@makrotopia.org>\n---\n drivers/mtd/nand/bbt.c | 3 ++-\n 1 file changed, 2 insertions(+), 1 deletion(-)","diff":"diff --git a/drivers/mtd/nand/bbt.c b/drivers/mtd/nand/bbt.c\nindex db4f93a903e48..dfe4a6a991c15 100644\n--- a/drivers/mtd/nand/bbt.c\n+++ b/drivers/mtd/nand/bbt.c\n@@ -113,7 +113,8 @@ int nanddev_bbt_set_block_status(struct nand_device *nand, unsigned int entry,\n \tif (entry >= nanddev_neraseblocks(nand))\n \t\treturn -ERANGE;\n \n-\tpos[0] &= ~GENMASK(offs + bits_per_block - 1, offs);\n+\tpos[0] &= ~GENMASK(min(offs + bits_per_block - 1,\n+\t\t\t       BITS_PER_LONG - 1), offs);\n \tpos[0] |= val << offs;\n \n \tif (bits_per_block + offs > BITS_PER_LONG) {\n","prefixes":[]}