mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org
Cc: linux-kernel@vger.kernel.org, stable@vger.kernel.org,
	Anatolij Gustschin <agust@denx.de>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Srinivas Kandagatla <srini@kernel.org>
Subject: [PATCH 06/10] nvmem: eeprom_93xx46: Reject unaligned writes on 16-bit devices
Date: Thu,  3 Dec 2026 08:26:07 +0000	[thread overview]
Message-ID: <b890bde52c395a2ee9cf649cb1f051118d5d0412.1796286324.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796286324.git.lee@kernel.org>

eeprom_93xx46_probe() hardcodes nvmem_config.word_size to 1 even for
16-bit (EE_ADDR16) devices, while eeprom_93xx46_write() silently masks
off the low bit of count and returns 0 on success.  A 1-byte write
therefore silently writes nothing and reports success, and an odd
offset is shifted down by eeprom_93xx46_write_word(), overwriting the
adjacent byte.

Set nvmem_config.word_size to 2 for EE_ADDR16 devices and reject odd
offsets or byte counts in eeprom_93xx46_write() with -EINVAL.

Fixes: a8ab316ab125 ("nvmem: 93xx46: remove nvmem regmap dependency")
Closes: https://sashiko.dev/#/bug/linux-2aded405-6835-472f-bb94-d76d40cc2d96
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---

Cc: Anatolij Gustschin <agust@denx.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Srinivas Kandagatla <srini@kernel.org>

 drivers/nvmem/eeprom_93xx46.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/drivers/nvmem/eeprom_93xx46.c b/drivers/nvmem/eeprom_93xx46.c
index f9c3ab52c2f9..6b159d5fa08e 100644
--- a/drivers/nvmem/eeprom_93xx46.c
+++ b/drivers/nvmem/eeprom_93xx46.c
@@ -282,10 +282,11 @@ static int eeprom_93xx46_write(void *priv, unsigned int off,
 	if (unlikely(!count))
 		return count;
 
-	/* only write even number of bytes on 16-bit devices */
+	/* only write even offsets and counts on 16-bit devices */
 	if (edev->pdata->flags & EE_ADDR16) {
+		if ((off & 1) || (count & 1))
+			return -EINVAL;
 		step = 2;
-		count &= ~1;
 	}
 
 	/* erase/write enable */
@@ -513,7 +514,7 @@ static int eeprom_93xx46_probe(struct spi_device *spi)
 	edev->nvmem_config.reg_write = eeprom_93xx46_write;
 	edev->nvmem_config.priv = edev;
 	edev->nvmem_config.stride = 4;
-	edev->nvmem_config.word_size = 1;
+	edev->nvmem_config.word_size = (pd->flags & EE_ADDR16) ? 2 : 1;
 	edev->nvmem_config.size = edev->size;
 
 	edev->nvmem = devm_nvmem_register(&spi->dev, &edev->nvmem_config);
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-03  8:26 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-03  8:26 [PATCH 00/10] nvmem: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-03  8:26 ` [PATCH 01/10] nvmem: meson-efuse: Reject negative or zero SMC size in meson_efuse_probe() Lee Jones
2026-12-03  8:26 ` [PATCH 02/10] nvmem: core: Prevent integer underflow in nvmem_cell_attr_read() Lee Jones
2026-12-03  8:26 ` [PATCH 03/10] nvmem: sprd: Avoid out-of-bounds read on partial writes in sprd_efuse_raw_prog() Lee Jones
2026-12-03  8:26 ` [PATCH 04/10] nvmem: core: Handle multi-byte bit offsets in nvmem_cell_prepare_write_buffer() Lee Jones
2026-12-03  8:26 ` [PATCH 05/10] nvmem: core: Serialise writes when toggling the write-protect GPIO Lee Jones
2026-12-03  8:26 ` Lee Jones [this message]
2026-12-03  8:26 ` [PATCH 07/10] nvmem: eeprom_93xx46: Hold device lock across erase/write enable sequences Lee Jones
2026-12-03  8:26 ` [PATCH 08/10] nvmem: eeprom_93xx46: Use DMA-safe command buffer for SPI transfers Lee Jones
2026-12-03  8:26 ` [PATCH 09/10] nvmem: meson-efuse: Detect short reads and writes from Secure Monitor Lee Jones
2026-12-03  8:26 ` [PATCH 10/10] nvmem: stm32: Avoid OP-TEE session leak on unaligned writes Lee Jones
2026-12-03 10:16   ` Patrick DELAUNAY

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b890bde52c395a2ee9cf649cb1f051118d5d0412.1796286324.git.lee@kernel.org \
    --to=lee@kernel.org \
    --cc=agust@denx.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=srini@kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®