mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Lee Jones <lee@kernel.org>
To: lee@kernel.org, Krzysztof Kozlowski <krzk@kernel.org>,
	Markus Franke <franke.m@sebakmt.com>,
	franm@hrz.tu-chemnitz.de,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-kernel@vger.kernel.org
Cc: stable@vger.kernel.org
Subject: [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference
Date: Wed,  2 Dec 2026 09:36:47 +0000	[thread overview]
Message-ID: <3e5017163c7ead0b39fb65a1245583bf62aa7c8a.1796204137.git.lee@kernel.org> (raw)
In-Reply-To: <cover.1796204137.git.lee@kernel.org>

w1_f1C_add_slave() only allocates sl->family_data when
w1_enable_crccheck is enabled at attach time.  Because
w1_enable_crccheck can be toggled at runtime through the crccheck sysfs
attribute, enabling it after a slave has attached causes subsequent
EEPROM reads and writes to dereference a NULL sl->family_data pointer.
Conversely, writing while crccheck is disabled skips invalidating
f1C->validcrc, leaving stale cached pages if crccheck is later
re-enabled.

Unconditionally allocate sl->family_data in w1_f1C_add_slave() and
always invalidate the page CRC cache entry in w1_f1C_write().

Fixes: fbf7f7b4e2ae ("w1: Add 1-wire slave device driver for DS28E04-100")
Closes: https://sashiko.dev/#/bug/linux-2eaa9a0e-9abb-4060-9da4-7d85a0bb8f0a
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/w1/slaves/w1_ds28e04.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)

diff --git a/drivers/w1/slaves/w1_ds28e04.c b/drivers/w1/slaves/w1_ds28e04.c
index 30fb8415b659..dca64d608ea8 100644
--- a/drivers/w1/slaves/w1_ds28e04.c
+++ b/drivers/w1/slaves/w1_ds28e04.c
@@ -211,10 +211,8 @@ static int w1_f1C_write(struct w1_slave *sl, int addr, int len, const u8 *data)
 	if (!w1_strong_pullup)
 		msleep(tm);
 
-	if (w1_enable_crccheck) {
-		/* invalidate cached data */
-		f1C->validcrc &= ~(1 << (addr >> W1_PAGE_BITS));
-	}
+	/* invalidate cached data */
+	f1C->validcrc &= ~(1 << (addr >> W1_PAGE_BITS));
 
 	/* Reset the bus to wake up the EEPROM (this may not be needed) */
 	w1_reset_bus(sl->master);
@@ -381,14 +379,12 @@ static const struct attribute_group *w1_f1C_groups[] = {
 
 static int w1_f1C_add_slave(struct w1_slave *sl)
 {
-	struct w1_f1C_data *data = NULL;
+	struct w1_f1C_data *data;
 
-	if (w1_enable_crccheck) {
-		data = kzalloc_obj(struct w1_f1C_data);
-		if (!data)
-			return -ENOMEM;
-		sl->family_data = data;
-	}
+	data = kzalloc_obj(struct w1_f1C_data);
+	if (!data)
+		return -ENOMEM;
+	sl->family_data = data;
 
 	return 0;
 }
-- 
2.56.1.911.g883d8bcb20-goog


  parent reply	other threads:[~2026-12-02  9:38 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-12-02  9:36 [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Lee Jones
2026-12-02  9:36 ` [PATCH 1/6] w1: Free slave structure in w1_slave_release() Lee Jones
2026-12-02 10:38   ` Krzysztof Kozlowski
2026-12-02 10:43     ` Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks Lee Jones
2026-12-02 10:38   ` Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 3/6] w1: Return actual bytes read from w1_read_block() and rw_read() Lee Jones
2026-12-02 10:54   ` Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal Lee Jones
2026-12-02 10:44   ` Krzysztof Kozlowski
2026-12-02  9:36 ` Lee Jones [this message]
2026-12-02 10:45   ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Krzysztof Kozlowski
2026-12-02  9:36 ` [PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop Lee Jones
2026-12-02 10:46   ` Krzysztof Kozlowski
2026-12-02  9:45 ` [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Greg Kroah-Hartman
2026-12-02 10:23   ` Lee Jones
2026-12-02 10:30     ` Greg Kroah-Hartman

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=3e5017163c7ead0b39fb65a1245583bf62aa7c8a.1796204137.git.lee@kernel.org \
    --to=lee@kernel.org \
    --cc=franke.m@sebakmt.com \
    --cc=franm@hrz.tu-chemnitz.de \
    --cc=gregkh@linuxfoundation.org \
    --cc=krzk@kernel.org \
    --cc=linux-kernel@vger.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®