All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko
@ 2026-12-02  9:36 Lee Jones
  2026-12-02  9:36 ` [PATCH 1/6] w1: Free slave structure in w1_slave_release() Lee Jones
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02  9:36 UTC (permalink / raw)
  To: lee
  Cc: linux-kernel, Bjorn Helgaas, Danilo Krummrich, David Fries,
	Evgeniy Polyakov, franm, Greg Kroah-Hartman, Krzysztof Kozlowski,
	Markus Franke, Takashi Sakamoto, Thomas Bogendoerfer,
	Uwe Kleine-König (The Capable Hub)

These issues were reported by Sashiko.

This series addresses all open Critical and High severity reports in
the 1-Wire (w1) subsystem.  It is based on v7.4-rc4 as it builds on
the w1 locking fixes merged in char-misc-7.4-rc4.  It fixes a slave
device lifetime use-after-free, a kthread teardown / netlink race, an
uninitialised heap leak and byte-count truncation in block reads,
unlocked w1_masters removal traversal, a runtime crccheck NULL pointer
dereference, and an unbounded MMIO polling loop.

Cc: Bjorn Helgaas <bhelgaas@google.com>
Cc: Danilo Krummrich <dakr@kernel.org>
Cc: David Fries <David@Fries.net>
Cc: Evgeniy Polyakov <zbr@ioremap.net>
Cc: franm@hrz.tu-chemnitz.de
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Krzysztof Kozlowski <krzk@kernel.org>
Cc: Markus Franke <franke.m@sebakmt.com>
Cc: Takashi Sakamoto <o-takashi@sakamocchi.jp>
Cc: Thomas Bogendoerfer <tbogendoerfer@suse.de>
Cc: "Uwe Kleine-König (The Capable Hub)" <u.kleine-koenig@baylibre.com>

Lee Jones (6):
  w1: Free slave structure in w1_slave_release()
  w1: Synchronise thread teardown with netlink callbacks
  w1: Return actual bytes read from w1_read_block() and rw_read()
  w1: Protect w1_masters traversal with w1_mlock during removal
  w1: ds28e04: Always allocate family data to avoid NULL dereference
  w1: sgi: Add timeout to sgi_w1_wait() polling loop

 drivers/w1/masters/ds2490.c    |  2 +-
 drivers/w1/masters/sgi_w1.c    |  9 ++++++---
 drivers/w1/slaves/w1_ds28e04.c | 18 +++++++----------
 drivers/w1/w1.c                | 35 +++++++++++++++++++++-------------
 drivers/w1/w1_int.c            | 16 +++++++++++-----
 drivers/w1/w1_io.c             |  7 +++++--
 drivers/w1/w1_netlink.c        |  9 +++++++--
 include/linux/w1.h             |  4 ++--
 8 files changed, 61 insertions(+), 39 deletions(-)

-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply	[flat|nested] 8+ messages in thread

* [PATCH 1/6] w1: Free slave structure in w1_slave_release()
  2026-12-02  9:36 [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Lee Jones
@ 2026-12-02  9:36 ` Lee Jones
  2026-12-02  9:36 ` [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks Lee Jones
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02  9:36 UTC (permalink / raw)
  To: lee, Krzysztof Kozlowski, Evgeniy Polyakov, Greg Kroah-Hartman,
	David Fries, linux-kernel
  Cc: stable

w1_unref_slave() calls kfree(sl) immediately after device_unregister(),
violating the driver model lifetime rules.  If another thread holds a
reference on sl->dev (such as via sysfs or device iteration), the
embedded struct device is freed while still in use, causing a
use-after-free when w1_slave_release() later runs.  Similarly,
__w1_attach_slave_device() calls put_device(&sl->dev) on registration
failure, so freeing sl in w1_slave_release() means
w1_attach_slave_device() must not touch or free sl afterwards.

Move kfree(sl) and the final atomic_dec(&master->refcnt) into
w1_slave_release() so both the slave and its master remain valid until
the final device reference is released.  Adjust w1_unref_slave() to
decrement dev->refcnt only when refcnt remains non-zero, and update the
error path in w1_attach_slave_device() accordingly.

Fixes: 9fcbbac5ded4 ("w1: process w1 netlink commands in w1_process thread")
Closes: https://sashiko.dev/#/bug/linux-8d066669-dde3-4c3f-a842-12383edebc99
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/w1/w1.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 4eb785c643c9..048cf8cb7f6b 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -75,11 +75,17 @@ static void w1_master_release(struct device *dev)
 static void w1_slave_release(struct device *dev)
 {
 	struct w1_slave *sl = dev_to_w1_slave(dev);
+	struct w1_master *master = sl->master;
 
 	dev_dbg(dev, "%s: Releasing %s [%p]\n", __func__, sl->name, sl);
 
 	w1_family_put(sl->family);
-	sl->master->slave_count--;
+	master->slave_count--;
+#ifdef DEBUG
+	memset(sl, 0, sizeof(*sl));
+#endif
+	kfree(sl);
+	atomic_dec(&master->refcnt);
 }
 
 static ssize_t name_show(struct device *dev, struct device_attribute *attr, char *buf)
@@ -761,10 +767,8 @@ int w1_attach_slave_device(struct w1_master *dev, struct w1_reg_num *rn)
 
 	err = __w1_attach_slave_device(sl);
 	if (err < 0) {
-		dev_err(&dev->dev, "%s: Attaching %s failed.\n", __func__,
-			 sl->name);
-		atomic_dec(&sl->master->refcnt);
-		kfree(sl);
+		dev_err(&dev->dev, "%s: Attaching %02x-%012llx failed.\n",
+			__func__, rn->family, (unsigned long long)rn->id);
 		return err;
 	}
 
@@ -806,12 +810,9 @@ int w1_unref_slave(struct w1_slave *sl)
 
 		w1_family_notify(BUS_NOTIFY_DEL_DEVICE, sl);
 		device_unregister(&sl->dev);
-		#ifdef DEBUG
-		memset(sl, 0, sizeof(*sl));
-		#endif
-		kfree(sl);
+	} else {
+		atomic_dec(&dev->refcnt);
 	}
-	atomic_dec(&dev->refcnt);
 	return refcnt;
 }
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks
  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  9:36 ` Lee Jones
  2026-12-02  9:36 ` [PATCH 3/6] w1: Return actual bytes read from w1_read_block() and rw_read() Lee Jones
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02  9:36 UTC (permalink / raw)
  To: lee, Krzysztof Kozlowski, Evgeniy Polyakov, David Fries,
	Greg Kroah-Hartman, linux-kernel
  Cc: stable

When __w1_remove_master_device() stops dev->thread via kthread_stop(),
a concurrent w1_cn_callback() that already holds a reference on dev can
still call wake_up_process(dev->thread) after the kthread task_struct
has been freed, causing a use-after-free.  In addition, draining queued
netlink commands via w1_process_cb() during teardown can execute
W1_CMD_SLAVE_ADD or W1_CMD_SEARCH after the master has already detached
all slaves, re-attaching a slave and leaving dev->refcnt permanently
non-zero.

Clear dev->thread under dev->list_mutex before calling kthread_stop(),
only call wake_up_process(dev->thread) in w1_cn_callback() when
dev->thread is non-NULL, and fail queued commands with -ENODEV in
w1_process_cb() once W1_ABORT_SEARCH is set.

Fixes: 9fcbbac5ded4 ("w1: process w1 netlink commands in w1_process thread")
Closes: https://sashiko.dev/#/bug/linux-9bfa25b6-f273-41d6-9b56-ad4779ba6dd2
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/w1/w1_int.c     | 8 +++++++-
 drivers/w1/w1_netlink.c | 9 +++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index 3fcc9ee56727..c5bc7e662294 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -168,6 +168,7 @@ EXPORT_SYMBOL(w1_add_master_device);
 
 void __w1_remove_master_device(struct w1_master *dev)
 {
+	struct task_struct *thread;
 	struct w1_netlink_msg msg;
 	struct w1_slave *sl, *sln;
 
@@ -183,7 +184,12 @@ void __w1_remove_master_device(struct w1_master *dev)
 	 */
 	w1_destroy_master_attributes(dev);
 
-	kthread_stop(dev->thread);
+	mutex_lock(&dev->list_mutex);
+	thread = dev->thread;
+	dev->thread = NULL;
+	mutex_unlock(&dev->list_mutex);
+
+	kthread_stop(thread);
 
 	mutex_lock(&dev->mutex);
 	mutex_lock(&dev->list_mutex);
diff --git a/drivers/w1/w1_netlink.c b/drivers/w1/w1_netlink.c
index 40fbb96a793e..c1104886d707 100644
--- a/drivers/w1/w1_netlink.c
+++ b/drivers/w1/w1_netlink.c
@@ -451,8 +451,12 @@ static void w1_process_cb(struct w1_master *dev, struct w1_async_cmd *async_cmd)
 
 	mutex_lock(&dev->bus_mutex);
 	dev->priv = node->block;
-	if (sl && w1_reset_select_slave(sl))
+	if (test_bit(W1_ABORT_SEARCH, &dev->flags)) {
 		err = -ENODEV;
+		cmd = NULL;
+	} else if (sl && w1_reset_select_slave(sl)) {
+		err = -ENODEV;
+	}
 	node->block->cur_msg = node->msg;
 
 	while (mlen && !err) {
@@ -688,7 +692,8 @@ static void w1_cn_callback(struct cn_msg *cn, struct netlink_skb_parms *nsp)
 
 		mutex_lock(&dev->list_mutex);
 		list_add_tail(&node->async.async_entry, &dev->async_list);
-		wake_up_process(dev->thread);
+		if (dev->thread)
+			wake_up_process(dev->thread);
 		mutex_unlock(&dev->list_mutex);
 		++node;
 
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 3/6] w1: Return actual bytes read from w1_read_block() and rw_read()
  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  9:36 ` [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks Lee Jones
@ 2026-12-02  9:36 ` Lee Jones
  2026-12-02  9:36 ` [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal Lee Jones
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02  9:36 UTC (permalink / raw)
  To: lee, Krzysztof Kozlowski, Evgeniy Polyakov, Greg Kroah-Hartman,
	linux-kernel
  Cc: stable

rw_read() discards the return value of w1_read_block() and always
returns the requested count.  When a bus master's read_block callback
fails (for instance ds9490r_read_block() returning 0 on a USB error or
allocation failure), buf is left untouched and rw_read() exposes up to
PAGE_SIZE bytes of uninitialised kernel heap memory to userspace.  In
addition, w1_bus_master::read_block, w1_read_block(), and
ds9490r_read_block() return u8, which truncates counts of 256 bytes or
more (such as a PAGE_SIZE read).

Widen the return type of read_block, w1_read_block(), and
ds9490r_read_block() from u8 to int, return 0 in w1_read_block() when
len is non-positive, and return the byte count from w1_read_block() in
rw_read().

Fixes: f522d2396138 ("[PATCH] w1: Added default generic read/write operations.")
Closes: https://sashiko.dev/#/bug/linux-ea892b13-33ef-4375-ae35-db4cafb332c0
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/w1/masters/ds2490.c | 2 +-
 drivers/w1/w1.c             | 2 +-
 drivers/w1/w1_io.c          | 7 +++++--
 include/linux/w1.h          | 4 ++--
 4 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/drivers/w1/masters/ds2490.c b/drivers/w1/masters/ds2490.c
index b4e1415573c1..b40145441fd5 100644
--- a/drivers/w1/masters/ds2490.c
+++ b/drivers/w1/masters/ds2490.c
@@ -921,7 +921,7 @@ static void ds9490r_write_block(void *data, const u8 *buf, int len)
 	kfree(tbuf);
 }
 
-static u8 ds9490r_read_block(void *data, u8 *buf, int len)
+static int ds9490r_read_block(void *data, u8 *buf, int len)
 {
 	struct ds_device *dev = data;
 	int err;
diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 048cf8cb7f6b..7ed2a01c8571 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -142,7 +142,7 @@ static ssize_t rw_read(struct file *filp, struct kobject *kobj,
 	struct w1_slave *sl = kobj_to_w1_slave(kobj);
 
 	mutex_lock(&sl->master->bus_mutex);
-	w1_read_block(sl->master, buf, count);
+	count = w1_read_block(sl->master, buf, count);
 	mutex_unlock(&sl->master->bus_mutex);
 	return count;
 }
diff --git a/drivers/w1/w1_io.c b/drivers/w1/w1_io.c
index db3c9522a8a2..445a60a18e6c 100644
--- a/drivers/w1/w1_io.c
+++ b/drivers/w1/w1_io.c
@@ -293,10 +293,13 @@ EXPORT_SYMBOL_GPL(w1_touch_block);
  * @len:	the number of bytes to read
  * Return:	the number of bytes read
  */
-u8 w1_read_block(struct w1_master *dev, u8 *buf, int len)
+int w1_read_block(struct w1_master *dev, u8 *buf, int len)
 {
 	int i;
-	u8 ret;
+	int ret;
+
+	if (len <= 0)
+		return 0;
 
 	if (dev->bus_master->read_block)
 		ret = dev->bus_master->read_block(dev->bus_master->data, buf, len);
diff --git a/include/linux/w1.h b/include/linux/w1.h
index 064805bfae3f..985537c51a27 100644
--- a/include/linux/w1.h
+++ b/include/linux/w1.h
@@ -142,7 +142,7 @@ struct w1_bus_master {
 
 	void		(*write_byte)(void *, u8);
 
-	u8		(*read_block)(void *, u8 *, int);
+	int		(*read_block)(void *data, u8 *buf, int len);
 
 	void		(*write_block)(void *, const u8 *, int);
 
@@ -300,7 +300,7 @@ int w1_reset_bus(struct w1_master *);
 u8 w1_calc_crc8(u8 *, int);
 void w1_write_block(struct w1_master *, const u8 *, int);
 void w1_touch_block(struct w1_master *, u8 *, int);
-u8 w1_read_block(struct w1_master *, u8 *, int);
+int w1_read_block(struct w1_master *dev, u8 *buf, int len);
 int w1_reset_select_slave(struct w1_slave *sl);
 int w1_reset_resume_command(struct w1_master *);
 void w1_next_pullup(struct w1_master *, int);
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal
  2026-12-02  9:36 [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (2 preceding siblings ...)
  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  9:36 ` Lee Jones
  2026-12-02  9:36 ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Lee Jones
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02  9:36 UTC (permalink / raw)
  To: lee, Krzysztof Kozlowski, Evgeniy Polyakov, linux-kernel; +Cc: stable

w1_remove_master_device() and w1_fini() iterate over the global
w1_masters list without holding w1_mlock, racing with concurrent
w1_add_master_device() and w1_remove_master_device() calls that mutate
the list.  In addition, leaving list_del() to
__w1_remove_master_device() creates a window in which two concurrent
removals can find and tear down the same master device.

Hold w1_mlock across lookup and list_del() in both
w1_remove_master_device() and w1_fini(), and remove the now-redundant
locking and list_del() from __w1_remove_master_device().

Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Closes: https://sashiko.dev/#/bug/linux-568be2be-e67b-4b92-8416-512e4968f535
Cc: stable@vger.kernel.org
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/w1/w1.c     | 12 ++++++++++--
 drivers/w1/w1_int.c |  8 ++++----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/drivers/w1/w1.c b/drivers/w1/w1.c
index 7ed2a01c8571..73505cf53572 100644
--- a/drivers/w1/w1.c
+++ b/drivers/w1/w1.c
@@ -1263,11 +1263,19 @@ static int __init w1_init(void)
 
 static void __exit w1_fini(void)
 {
-	struct w1_master *dev, *n;
+	struct w1_master *dev;
 
 	/* Set netlink removal messages and some cleanup */
-	list_for_each_entry_safe(dev, n, &w1_masters, w1_master_entry)
+	mutex_lock(&w1_mlock);
+	while (!list_empty(&w1_masters)) {
+		dev = list_first_entry(&w1_masters, struct w1_master,
+				       w1_master_entry);
+		list_del(&dev->w1_master_entry);
+		mutex_unlock(&w1_mlock);
 		__w1_remove_master_device(dev);
+		mutex_lock(&w1_mlock);
+	}
+	mutex_unlock(&w1_mlock);
 
 	w1_fini_netlink();
 
diff --git a/drivers/w1/w1_int.c b/drivers/w1/w1_int.c
index c5bc7e662294..c76f22bfd394 100644
--- a/drivers/w1/w1_int.c
+++ b/drivers/w1/w1_int.c
@@ -166,16 +166,13 @@ int w1_add_master_device(struct w1_bus_master *master)
 }
 EXPORT_SYMBOL(w1_add_master_device);
 
+/* Caller must have removed @dev from w1_masters under w1_mlock. */
 void __w1_remove_master_device(struct w1_master *dev)
 {
 	struct task_struct *thread;
 	struct w1_netlink_msg msg;
 	struct w1_slave *sl, *sln;
 
-	mutex_lock(&w1_mlock);
-	list_del(&dev->w1_master_entry);
-	mutex_unlock(&w1_mlock);
-
 	set_bit(W1_ABORT_SEARCH, &dev->flags);
 
 	/*
@@ -232,15 +229,18 @@ void w1_remove_master_device(struct w1_bus_master *bm)
 {
 	struct w1_master *dev, *found = NULL;
 
+	mutex_lock(&w1_mlock);
 	list_for_each_entry(dev, &w1_masters, w1_master_entry) {
 		if (!dev->initialized)
 			continue;
 
 		if (dev->bus_master->data == bm->data) {
 			found = dev;
+			list_del(&dev->w1_master_entry);
 			break;
 		}
 	}
+	mutex_unlock(&w1_mlock);
 
 	if (!found) {
 		pr_err("Device doesn't exist.\n");
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference
  2026-12-02  9:36 [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (3 preceding siblings ...)
  2026-12-02  9:36 ` [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal Lee Jones
@ 2026-12-02  9:36 ` Lee Jones
  2026-12-02  9:36 ` [PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop Lee Jones
  2026-12-02  9:45 ` [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Greg Kroah-Hartman
  6 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02  9:36 UTC (permalink / raw)
  To: lee, Krzysztof Kozlowski, Markus Franke, franm,
	Greg Kroah-Hartman, linux-kernel
  Cc: stable

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* [PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop
  2026-12-02  9:36 [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (4 preceding siblings ...)
  2026-12-02  9:36 ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Lee Jones
@ 2026-12-02  9:36 ` Lee Jones
  2026-12-02  9:45 ` [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Greg Kroah-Hartman
  6 siblings, 0 replies; 8+ messages in thread
From: Lee Jones @ 2026-12-02  9:36 UTC (permalink / raw)
  To: lee, Krzysztof Kozlowski, Danilo Krummrich,
	Uwe Kleine-König (The Capable Hub), Bjorn Helgaas,
	Takashi Sakamoto, Greg Kroah-Hartman, Thomas Bogendoerfer,
	linux-kernel

sgi_w1_wait() busy-waits in an unbounded loop until MCR_DONE is set.
If the hardware fails to assert MCR_DONE due to a fault or missing
clock, the CPU hangs indefinitely.

Replace the open-coded loop with readl_poll_timeout_atomic() using a
10 ms timeout, and return 1 (no device present / bus idle) on timeout.

Fixes: 74ded38a8e18 ("w1: add 1-wire master driver for IP block found in SGI ASICs")
Closes: https://sashiko.dev/#/bug/linux-e5c06baa-f504-46e1-80df-e43a94a75fa1
Signed-off-by: Lee Jones <lee@kernel.org>
---
 drivers/w1/masters/sgi_w1.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/drivers/w1/masters/sgi_w1.c b/drivers/w1/masters/sgi_w1.c
index 2bc2459b3605..744a06741a7e 100644
--- a/drivers/w1/masters/sgi_w1.c
+++ b/drivers/w1/masters/sgi_w1.c
@@ -6,6 +6,7 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/io.h>
+#include <linux/iopoll.h>
 #include <linux/jiffies.h>
 #include <linux/module.h>
 #include <linux/platform_device.h>
@@ -27,10 +28,12 @@ struct sgi_w1_device {
 static u8 sgi_w1_wait(u32 __iomem *mcr)
 {
 	u32 mcr_val;
+	int ret;
 
-	do {
-		mcr_val = readl(mcr);
-	} while (!(mcr_val & MCR_DONE));
+	ret = readl_poll_timeout_atomic(mcr, mcr_val, mcr_val & MCR_DONE,
+					0, 10 * USEC_PER_MSEC);
+	if (ret)
+		return 1;
 
 	return (mcr_val & MCR_RD_DATA) ? 1 : 0;
 }
-- 
2.56.1.911.g883d8bcb20-goog


^ permalink raw reply related	[flat|nested] 8+ messages in thread

* Re: [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko
  2026-12-02  9:36 [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Lee Jones
                   ` (5 preceding siblings ...)
  2026-12-02  9:36 ` [PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop Lee Jones
@ 2026-12-02  9:45 ` Greg Kroah-Hartman
  6 siblings, 0 replies; 8+ messages in thread
From: Greg Kroah-Hartman @ 2026-12-02  9:45 UTC (permalink / raw)
  To: Lee Jones
  Cc: linux-kernel, Bjorn Helgaas, Danilo Krummrich, David Fries,
	Evgeniy Polyakov, franm, Krzysztof Kozlowski, Markus Franke,
	Takashi Sakamoto, Thomas Bogendoerfer,
	Uwe Kleine-König (The Capable Hub)

On Wed, Dec 02, 2026 at 09:36:42AM +0000, Lee Jones wrote:
> These issues were reported by Sashiko.
> 
> This series addresses all open Critical and High severity reports in
> the 1-Wire (w1) subsystem.  It is based on v7.4-rc4 as it builds on
> the w1 locking fixes merged in char-misc-7.4-rc4.  It fixes a slave
> device lifetime use-after-free, a kthread teardown / netlink race, an
> uninitialised heap leak and byte-count truncation in block reads,
> unlocked w1_masters removal traversal, a runtime crccheck NULL pointer
> dereference, and an unbounded MMIO polling loop.
> 
> Cc: Bjorn Helgaas <bhelgaas@google.com>
> Cc: Danilo Krummrich <dakr@kernel.org>
> Cc: David Fries <David@Fries.net>
> Cc: Evgeniy Polyakov <zbr@ioremap.net>
> Cc: franm@hrz.tu-chemnitz.de
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Krzysztof Kozlowski <krzk@kernel.org>
> Cc: Markus Franke <franke.m@sebakmt.com>
> Cc: Takashi Sakamoto <o-takashi@sakamocchi.jp>
> Cc: Thomas Bogendoerfer <tbogendoerfer@suse.de>
> Cc: "Uwe Kleine-König (The Capable Hub)" <u.kleine-koenig@baylibre.com>
> 
> Lee Jones (6):
>   w1: Free slave structure in w1_slave_release()
>   w1: Synchronise thread teardown with netlink callbacks
>   w1: Return actual bytes read from w1_read_block() and rw_read()
>   w1: Protect w1_masters traversal with w1_mlock during removal
>   w1: ds28e04: Always allocate family data to avoid NULL dereference
>   w1: sgi: Add timeout to sgi_w1_wait() polling loop
> 
>  drivers/w1/masters/ds2490.c    |  2 +-
>  drivers/w1/masters/sgi_w1.c    |  9 ++++++---
>  drivers/w1/slaves/w1_ds28e04.c | 18 +++++++----------
>  drivers/w1/w1.c                | 35 +++++++++++++++++++++-------------
>  drivers/w1/w1_int.c            | 16 +++++++++++-----
>  drivers/w1/w1_io.c             |  7 +++++--
>  drivers/w1/w1_netlink.c        |  9 +++++++--
>  include/linux/w1.h             |  4 ++--
>  8 files changed, 61 insertions(+), 39 deletions(-)

Krzysztof, if you ack these, I can take them directly if they look good
to you.

"Odd" that the "other" AI model didn't find these issues before, I guess
different models "know" different things...

thanks,


greg k-h

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-12-02  9:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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  9:36 ` [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks Lee Jones
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  9:36 ` [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal Lee Jones
2026-12-02  9:36 ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Lee Jones
2026-12-02  9:36 ` [PATCH 6/6] w1: sgi: Add timeout to sgi_w1_wait() polling loop Lee Jones
2026-12-02  9:45 ` [PATCH 0/6] w1: Fix Critical and High issues reported by Sashiko Greg Kroah-Hartman

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.