* [PATCH 1/6] w1: Free slave structure in w1_slave_release()
[not found] <cover.1796204137.git.lee@kernel.org>
@ 2026-12-02 9:36 ` Lee Jones
2026-12-02 10:38 ` Krzysztof Kozlowski
2026-12-02 9:36 ` [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks Lee Jones
` (3 subsequent siblings)
4 siblings, 1 reply; 11+ 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] 11+ messages in thread* Re: [PATCH 1/6] w1: Free slave structure in w1_slave_release()
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
0 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 10:38 UTC (permalink / raw)
To: Lee Jones, Evgeniy Polyakov, Greg Kroah-Hartman, David Fries,
linux-kernel
Cc: stable
On 02/12/2026 10:36, Lee Jones wrote:
> 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>
> ---
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 11+ messages in thread* Re: [PATCH 1/6] w1: Free slave structure in w1_slave_release()
2026-12-02 10:38 ` Krzysztof Kozlowski
@ 2026-12-02 10:43 ` Krzysztof Kozlowski
0 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 10:43 UTC (permalink / raw)
To: Lee Jones, Evgeniy Polyakov, Greg Kroah-Hartman, David Fries,
linux-kernel
Cc: stable
On 02/12/2026 11:38, Krzysztof Kozlowski wrote:
> On 02/12/2026 10:36, Lee Jones wrote:
>> 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>
>> ---
>
>
> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
>
This also looks like:
https://patch.msgid.link/20261119-w1-slave-release-v1-0-c2948c825d08@gmail.com
but I was hesitant to take above.
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks
[not found] <cover.1796204137.git.lee@kernel.org>
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 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
` (2 subsequent siblings)
4 siblings, 1 reply; 11+ 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] 11+ messages in thread* Re: [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks
2026-12-02 9:36 ` [PATCH 2/6] w1: Synchronise thread teardown with netlink callbacks Lee Jones
@ 2026-12-02 10:38 ` Krzysztof Kozlowski
0 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 10:38 UTC (permalink / raw)
To: Lee Jones, Evgeniy Polyakov, David Fries, Greg Kroah-Hartman,
linux-kernel
Cc: stable
On 02/12/2026 10:36, Lee Jones wrote:
> 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.
>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 3/6] w1: Return actual bytes read from w1_read_block() and rw_read()
[not found] <cover.1796204137.git.lee@kernel.org>
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 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 9:36 ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Lee Jones
4 siblings, 1 reply; 11+ 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] 11+ messages in thread* Re: [PATCH 3/6] w1: Return actual bytes read from w1_read_block() and rw_read()
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
0 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 10:54 UTC (permalink / raw)
To: Lee Jones, Evgeniy Polyakov, Greg Kroah-Hartman, linux-kernel; +Cc: stable
On 02/12/2026 10:36, Lee Jones wrote:
> 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>
> ---
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal
[not found] <cover.1796204137.git.lee@kernel.org>
` (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 10:44 ` Krzysztof Kozlowski
2026-12-02 9:36 ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Lee Jones
4 siblings, 1 reply; 11+ 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] 11+ messages in thread* Re: [PATCH 4/6] w1: Protect w1_masters traversal with w1_mlock during removal
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
0 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 10:44 UTC (permalink / raw)
To: Lee Jones, Evgeniy Polyakov, linux-kernel; +Cc: stable
On 02/12/2026 10:36, Lee Jones wrote:
> 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>
> ---
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference
[not found] <cover.1796204137.git.lee@kernel.org>
` (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 10:45 ` Krzysztof Kozlowski
4 siblings, 1 reply; 11+ 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] 11+ messages in thread* Re: [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference
2026-12-02 9:36 ` [PATCH 5/6] w1: ds28e04: Always allocate family data to avoid NULL dereference Lee Jones
@ 2026-12-02 10:45 ` Krzysztof Kozlowski
0 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2026-12-02 10:45 UTC (permalink / raw)
To: Lee Jones, Markus Franke, franm, Greg Kroah-Hartman, linux-kernel; +Cc: stable
On 02/12/2026 10:36, Lee Jones wrote:
> 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>
Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@oss.qualcomm.com>
Best regards,
Krzysztof
^ permalink raw reply [flat|nested] 11+ messages in thread