FAILED: patch "[PATCH] libnvdimm/dimm: Avoid race between probe and" failed to apply to 4.19-stable tree
Subsystems (2)
[email protected]
maintainerThe patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
thanks,
greg k-h
------------------ original commit in Linus's tree ------------------
From 7018c897c2f243d4b5f1b94bc6b4831a7eab80fb Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Mon, 1 Feb 2021 16:20:40 -0800
Subject: [PATCH] libnvdimm/dimm: Avoid race between probe and
available_slots_show()
Richard reports that the following test:
(while true; do
cat /sys/bus/nd/devices/nmem*/available_slots 2>&1 > /dev/null
done) &
while true; do
for i in $(seq 0 4); do
echo nmem$i > /sys/bus/nd/drivers/nvdimm/bind
done
for i in $(seq 0 4); do
echo nmem$i > /sys/bus/nd/drivers/nvdimm/unbind
done
done
...fails with a crash signature like:
divide error: 0000 [#1] SMP KASAN PTI
RIP: 0010:nd_label_nfree+0x134/0x1a0 [libnvdimm]
[..]
Call Trace:
available_slots_show+0x4e/0x120 [libnvdimm]
dev_attr_show+0x42/0x80
? memset+0x20/0x40
sysfs_kf_seq_show+0x218/0x410The root cause is that available_slots_show() consults driver-data, but fails to synchronize against device-unbind setting up a TOCTOU race to access uninitialized memory.
Validate driver-data under the device-lock.
drivers/nvdimm/dimm_devs.c +15 -3
@@ -335,16 +335,16 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RO (state); -static ssize_t available_slots_show (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t __available_slots_show (struct nvdimm_drvdata *ndd,char *buf) { -struct nvdimm_drvdata *ndd =dev_get_drvdata (dev); +struct device *dev;ssize_t rc;u32 nfree;if (!ndd)return -ENXIO ; + dev = ndd->dev;nvdimm_bus_lock (dev); nfree =nd_label_nfree (ndd);if (nfree -1 > nfree) {
@@ -356,6 +356,18 @@ static ssize_t available_slots_show(struct device *dev,nvdimm_bus_unlock (dev);return rc; } + +static ssize_t available_slots_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t rc; + +nd_device_lock (dev); + rc =__available_slots_show (dev_get_drvdata (dev), buf); +nd_device_unlock (dev); + +return rc; +}static DEVICE_ATTR_RO (available_slots); __weak ssize_t security_show(struct device *dev,
Sudip Mukherjee
Acked-by Richard PalethorpeHi Greg,
Quoted 5 lines · On Mon, Feb 08, 2021 at 11:24:57AM +0100, [email protected] wrote:
The patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.
Here is the backport. Will apply to all branches till 4.4-stable.
--
Regards
Sudip
From 49a07391dd8bef6e40bb44ca5636dd429f86e81a Mon Sep 17 00:00:00 2001
From: Dan Williams <[email protected]>
Date: Mon, 1 Feb 2021 16:20:40 -0800
Subject: [PATCH] libnvdimm/dimm: Avoid race between probe and
available_slots_show()
commit 7018c897c2f243d4b5f1b94bc6b4831a7eab80fb upstream
Richard reports that the following test:
(while true; do
cat /sys/bus/nd/devices/nmem*/available_slots 2>&1 > /dev/null
done) &
while true; do
for i in $(seq 0 4); do
echo nmem$i > /sys/bus/nd/drivers/nvdimm/bind
done
for i in $(seq 0 4); do
echo nmem$i > /sys/bus/nd/drivers/nvdimm/unbind
done
done
...fails with a crash signature like:
divide error: 0000 [#1] SMP KASAN PTI
RIP: 0010:nd_label_nfree+0x134/0x1a0 [libnvdimm]
[..]
Call Trace:
available_slots_show+0x4e/0x120 [libnvdimm]
dev_attr_show+0x42/0x80
? memset+0x20/0x40
sysfs_kf_seq_show+0x218/0x410The root cause is that available_slots_show() consults driver-data, but fails to synchronize against device-unbind setting up a TOCTOU race to access uninitialized memory.
Validate driver-data under the device-lock.
--- drivers/nvdimm/dimm_devs.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-)
drivers/nvdimm/dimm_devs.c +15 -3
@@ -359,16 +359,16 @@ static ssize_t state_show(struct device *dev, struct device_attribute *attr, }static DEVICE_ATTR_RO (state); -static ssize_t available_slots_show (struct device *dev, -struct device_attribute *attr,char *buf) +static ssize_t __available_slots_show (struct nvdimm_drvdata *ndd,char *buf) { -struct nvdimm_drvdata *ndd =dev_get_drvdata (dev); +struct device *dev;ssize_t rc;u32 nfree;if (!ndd)return -ENXIO ; + dev = ndd->dev;nvdimm_bus_lock (dev); nfree =nd_label_nfree (ndd);if (nfree -1 > nfree) {
@@ -380,6 +380,18 @@ static ssize_t available_slots_show(struct device *dev,nvdimm_bus_unlock (dev);return rc; } + +static ssize_t available_slots_show (struct device *dev, +struct device_attribute *attr,char *buf) +{ +ssize_t rc; + +device_lock (dev); + rc =__available_slots_show (dev_get_drvdata (dev), buf); +device_unlock (dev); + +return rc; +}static DEVICE_ATTR_RO (available_slots);static struct attribute *nvdimm_attributes[] = {
Signature · 1 line
2.30.0
Quoted 11 lines · Sudip Mukherjee
Hi Greg,
Quoted 5 lines · On Mon, Feb 08, 2021 at 11:24:57AM +0100, [email protected] wrote:
The patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.Here is the backport. Will apply to all branches till 4.4-stable.
Backport looks good to me. Thanks Sudip!
Greg KH
maintainerQuoted 10 lines · Sudip Mukherjee
Hi Greg,
Quoted 5 lines · On Mon, Feb 08, 2021 at 11:24:57AM +0100, [email protected] wrote:
The patch below does not apply to the 4.19-stable tree.
If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to <[email protected]>.Here is the backport. Will apply to all branches till 4.4-stable.
thanks, now queued up.
greg k-h