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 235983C3C16 for ; Thu, 14 May 2026 11:45:49 +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=1778759151; cv=none; b=lwhn0cJDB2MOCrd5HYO+WeL6Wq6LAdqj9PD57IOhHGbvpbfG3NPasqCQx7y5NsCAb+ZCeMVnYNwHOtWKRuuAIxvIDcSeDlpXZchELB54xr7wK+RKFHlBOU6qRzg7eY8Sdl/urSf2iRIhl21IrQRF8OBxM5LnxxgCvbKtndgUxK0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778759151; c=relaxed/simple; bh=GHZZySsFO8ATubKotpsoPYxs6gOdw3DfTkpc07KIhVE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ZJT2VAPcAr8MX3htm6J+0bM9bbFFfcqHlRnwaWqU8RfOkmQFDtk4cTS5npJv+zY8A0IFtsXBdSjMRBpBkKnlimvNypN3cRHnibBYASUKBdZO4Tp3bFgTmbW+qeFAjrRA5rPdDG5GkUEDTxuW58kITaGl+mNkSbYnW0V9MCro7fM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=jIGOWmV2; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="jIGOWmV2" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2DB69C2BCB8; Thu, 14 May 2026 11:45:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1778759148; bh=GHZZySsFO8ATubKotpsoPYxs6gOdw3DfTkpc07KIhVE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jIGOWmV2LCY0yUIQP154eLRS7gtmwj2QMh1Dd6EJKfW5oHItB5qVLEOecl8vP1MYH oT8k6i3f3CuAH5Hv5a4UdvGOMeBbg+ct0I5l13narWQS+TyPfW0GgHL8b8cJmdY714 05vzoNc3mC2kgsOabqqT1eZgF5ZEsgZ1OZZu3M6PPM90BZWRhsHzjlLst1vWy+FlVQ NQ2IkzNd1LNB9yXwq3h4Y2yFF2WxRkqeUrXJZ+5AgZOnKaN2e67tumDYZhD6Y3QgyL MUvBwEHO/5+iJqcpzDO90c5ScNpRX8cD37p5PYnbNd6yxsc4IQjWr53mnXFsBcB1Aj lpKdoiGLrxu9Q== From: Sasha Levin To: stable@vger.kernel.org Cc: Tudor Ambarus , Takahiro Kuwano , Michael Walle , Pratyush Yadav , Miquel Raynal , Sasha Levin Subject: [PATCH 6.1.y 2/2] mtd: spi-nor: debugfs: fix out-of-bounds read in spi_nor_params_show() Date: Thu, 14 May 2026 07:45:40 -0400 Message-ID: <20260514114540.178942-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260514114540.178942-1-sashal@kernel.org> References: <2026051244-bonelike-likewise-bea8@gregkh> <20260514114540.178942-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Tudor Ambarus [ Upstream commit e47029b977e747cb3a9174308fd55762cce70147 ] 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 [ adjusted include-block context to keep 6.1.y's existing non-alphabetical header order while still adding `#include ` at the top ] Signed-off-by: Sasha Levin --- drivers/mtd/spi-nor/debugfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/mtd/spi-nor/debugfs.c b/drivers/mtd/spi-nor/debugfs.c index 6d6bd559db8fd..9d7e95c1902c9 100644 --- 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 @@ -91,7 +92,8 @@ static int spi_nor_params_show(struct seq_file *s, void *data) 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"); -- 2.53.0