From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D31AF34405B; Tue, 12 May 2026 18:06:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778609174; cv=none; b=tVqjOWefqYVfDUOJCCArgkM1YeWBdsnR6Ua2N7o1QhnhaJpvQpLW1cG/PUA0hAcSL7qCewZBIdWaBHhBoWy/2/6o93SgXfIhqwr3w0ajbESUcfpu3beCuLQVxi9HwMrS6h4Vu2WfxEYP4naov7Ou+/c3733rLGt8aBCfmCsn1E8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778609174; c=relaxed/simple; bh=xMI8b0/l3Yqu0D/U31ZrJpGt/oqSx+tcBE77km+Wyms=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=h6IRAzXQcHTcKD7IEAvL7Z7Q1yc6guWO4W0WEl5qgoyGqNFPj4mme9gZ+KS0QDljP68d4jsItxRARKHwpHNXirIUeZnzg13jTAfF/Al2OLemebD7VWtcD5nFjHEKMPbK7n4QeRXg32ER0jhLOUAX8SA6ZckE7aBs1AddVEzOMC4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=iAh4X45C; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="iAh4X45C" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 69A7BC2BCB0; Tue, 12 May 2026 18:06:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1778609174; bh=xMI8b0/l3Yqu0D/U31ZrJpGt/oqSx+tcBE77km+Wyms=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iAh4X45CTYu2BIZA2s8ZxwPL3UhUGsokkVzCYgSDd/uTySBVwHLeO172LVgcVYhHR Pw4eoG7Eg9M0vYN1npiYGIhRUgBvtlM/SXDKP5eDjk3fBSwBG7w3ZGF3hX8W3MzYzV HyuhtN6qemLqEtaTdvbtwxWg79wJTNFp/bA3wiBM= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Tudor Ambarus , Takahiro Kuwano , Michael Walle , Pratyush Yadav , Miquel Raynal Subject: [PATCH 7.0 094/307] mtd: spi-nor: debugfs: fix out-of-bounds read in spi_nor_params_show() Date: Tue, 12 May 2026 19:38:09 +0200 Message-ID: <20260512173942.110326860@linuxfoundation.org> X-Mailer: git-send-email 2.54.0 In-Reply-To: <20260512173940.117428952@linuxfoundation.org> References: <20260512173940.117428952@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.0-stable review patch. If anyone has any objections, please let me know. ------------------ From: Tudor Ambarus commit e47029b977e747cb3a9174308fd55762cce70147 upstream. Sashiko noticed an out-of-bounds read [1]. In spi_nor_params_show(), the snor_f_names array is passed to spi_nor_print_flags() using sizeof(snor_f_names). Since snor_f_names is an array of pointers, sizeof() returns the total number of bytes occupied by the pointers (element_count * sizeof(void *)) rather than the element count itself. On 64-bit systems, this makes the passed length 8x larger than intended. Inside spi_nor_print_flags(), the 'names_len' argument is used to bounds-check the 'names' array access. An out-of-bounds read occurs if a flag bit is set that exceeds the array's actual element count but is within the inflated byte-size count. Correct this by using ARRAY_SIZE() to pass the actual number of string pointers in the array. Cc: stable@vger.kernel.org Fixes: 0257be79fc4a ("mtd: spi-nor: expose internal parameters via debugfs") Closes: https://sashiko.dev/#/patchset/20260417-die-erase-fix-v2-1-73bb7004ebad%40infineon.com [1] Signed-off-by: Tudor Ambarus Reviewed-by: Takahiro Kuwano Reviewed-by: Michael Walle Reviewed-by: Pratyush Yadav Signed-off-by: Miquel Raynal Signed-off-by: Greg Kroah-Hartman --- drivers/mtd/spi-nor/debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) --- a/drivers/mtd/spi-nor/debugfs.c +++ b/drivers/mtd/spi-nor/debugfs.c @@ -1,5 +1,6 @@ // SPDX-License-Identifier: GPL-2.0 +#include #include #include #include @@ -92,7 +93,8 @@ static int spi_nor_params_show(struct se seq_printf(s, "address nbytes\t%u\n", nor->addr_nbytes); seq_puts(s, "flags\t\t"); - spi_nor_print_flags(s, nor->flags, snor_f_names, sizeof(snor_f_names)); + spi_nor_print_flags(s, nor->flags, snor_f_names, + ARRAY_SIZE(snor_f_names)); seq_puts(s, "\n"); seq_puts(s, "\nopcodes\n");