* [PATCH 1/2] nvmet: preserve device path on allocation failure.
@ 2026-09-08 3:35 Julian Sun
2026-09-08 3:35 ` [PATCH 2/2] nvmet: reject enabling a namespace without a device path Julian Sun
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Julian Sun @ 2026-09-08 3:35 UTC (permalink / raw)
To: linux-nvme; +Cc: hch, sagi, kch, armenx.baloyan, james.p.freyensee, ming.l
nvmet_ns_device_path_store() frees the old path before allocating its
replacement, losing the existing configuration if allocation fails.
Allocate the new path before freeing the old one.
Fixes: a07b4970f464 ("nvmet: add a generic NVMe target")
Signed-off-by: Julian Sun <sunjunchao@bytedance.com>
---
drivers/nvme/target/configfs.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/drivers/nvme/target/configfs.c b/drivers/nvme/target/configfs.c
index 413ee2d16d29..37998bb91408 100644
--- a/drivers/nvme/target/configfs.c
+++ b/drivers/nvme/target/configfs.c
@@ -534,6 +534,7 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
struct nvmet_subsys *subsys = ns->subsys;
size_t len;
int ret;
+ char *new_path = NULL;
mutex_lock(&subsys->lock);
ret = -EBUSY;
@@ -545,12 +546,14 @@ static ssize_t nvmet_ns_device_path_store(struct config_item *item,
if (!len)
goto out_unlock;
- kfree(ns->device_path);
ret = -ENOMEM;
- ns->device_path = kmemdup_nul(page, len, GFP_KERNEL);
- if (!ns->device_path)
+ new_path = kmemdup_nul(page, len, GFP_KERNEL);
+ if (!new_path)
goto out_unlock;
+ kfree(ns->device_path);
+ ns->device_path = new_path;
+
mutex_unlock(&subsys->lock);
return count;
--
2.39.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* [PATCH 2/2] nvmet: reject enabling a namespace without a device path
2026-09-08 3:35 [PATCH 1/2] nvmet: preserve device path on allocation failure Julian Sun
@ 2026-09-08 3:35 ` Julian Sun
2026-09-10 5:42 ` Christoph Hellwig
2026-09-10 5:25 ` [PATCH 1/2] nvmet: preserve device path on allocation failure Christoph Hellwig
` (2 subsequent siblings)
3 siblings, 1 reply; 9+ messages in thread
From: Julian Sun @ 2026-09-08 3:35 UTC (permalink / raw)
To: linux-nvme; +Cc: hch, sagi, kch, armenx.baloyan, james.p.freyensee, ming.l
With buffered I/O enabled, nvmet_bdev_ns_enable() returns -ENOTBLK
before validating the device path. Enabling a namespace without setting
device_path therefore passes NULL to filp_open() and crashes in
getname_kernel().
Reject enabling a namespace if no device path has been configured.
Fixes: 6f6d604b4ef8 ("nvmet: allow bdev in buffered_io mode")
Reported-by: syzbot+6c46a179b56c651c4c96@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=6c46a179b56c651c4c96
Signed-off-by: Julian Sun <sunjunchao@bytedance.com>
---
drivers/nvme/target/core.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/drivers/nvme/target/core.c b/drivers/nvme/target/core.c
index d74c01c98f19..d73524947d63 100644
--- a/drivers/nvme/target/core.c
+++ b/drivers/nvme/target/core.c
@@ -591,6 +591,10 @@ int nvmet_ns_enable(struct nvmet_ns *ns)
if (ns->enabled)
goto out_unlock;
+ ret = -EINVAL;
+ if (!ns->device_path)
+ goto out_unlock;
+
ret = nvmet_bdev_ns_enable(ns);
if (ret == -ENOTBLK)
ret = nvmet_file_ns_enable(ns);
--
2.39.5
^ permalink raw reply related [flat|nested] 9+ messages in thread* Re: [PATCH 2/2] nvmet: reject enabling a namespace without a device path
2026-09-08 3:35 ` [PATCH 2/2] nvmet: reject enabling a namespace without a device path Julian Sun
@ 2026-09-10 5:42 ` Christoph Hellwig
2026-09-10 5:47 ` Julian Sun
0 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2026-09-10 5:42 UTC (permalink / raw)
To: Julian Sun
Cc: linux-nvme, hch, sagi, kch, armenx.baloyan, james.p.freyensee,
ming.l
On Tue, Sep 08, 2026 at 11:35:19AM +0800, Julian Sun wrote:
> With buffered I/O enabled, nvmet_bdev_ns_enable() returns -ENOTBLK
> before validating the device path. Enabling a namespace without setting
> device_path therefore passes NULL to filp_open() and crashes in
> getname_kernel().
>
> Reject enabling a namespace if no device path has been configured.
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
Can you add test for this to blktests?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 2/2] nvmet: reject enabling a namespace without a device path
2026-09-10 5:42 ` Christoph Hellwig
@ 2026-09-10 5:47 ` Julian Sun
0 siblings, 0 replies; 9+ messages in thread
From: Julian Sun @ 2026-09-10 5:47 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: linux-nvme, sagi, kch, ming.l
On 9/10/26 1:42 PM, Christoph Hellwig wrote:
> On Tue, Sep 08, 2026 at 11:35:19AM +0800, Julian Sun wrote:
>> With buffered I/O enabled, nvmet_bdev_ns_enable() returns -ENOTBLK
>> before validating the device path. Enabling a namespace without setting
>> device_path therefore passes NULL to filp_open() and crashes in
>> getname_kernel().
>>
>> Reject enabling a namespace if no device path has been configured.
>
> Looks good:
>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
>
> Can you add test for this to blktests?
I noticed that this has already been fixed:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit?id=09d0c07bd9ce3b2f2d993f672698d32a17543c32
But sure, I'll add a test to blktests.
Thanks,
--
Julian Sun <sunjunchao@bytedance.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] nvmet: preserve device path on allocation failure.
2026-09-08 3:35 [PATCH 1/2] nvmet: preserve device path on allocation failure Julian Sun
2026-09-08 3:35 ` [PATCH 2/2] nvmet: reject enabling a namespace without a device path Julian Sun
@ 2026-09-10 5:25 ` Christoph Hellwig
2026-09-10 5:35 ` Julian Sun
2026-09-10 5:42 ` Christoph Hellwig
2026-09-11 14:45 ` Keith Busch
3 siblings, 1 reply; 9+ messages in thread
From: Christoph Hellwig @ 2026-09-10 5:25 UTC (permalink / raw)
To: Julian Sun
Cc: linux-nvme, hch, sagi, kch, armenx.baloyan, james.p.freyensee,
ming.l, Runyu Xiao
Can you coordinate this with the configfs path checking series
from Runyu Xiao? That one had a few resends, so I'd like to get it in
first.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] nvmet: preserve device path on allocation failure.
2026-09-10 5:25 ` [PATCH 1/2] nvmet: preserve device path on allocation failure Christoph Hellwig
@ 2026-09-10 5:35 ` Julian Sun
2026-09-10 5:37 ` Christoph Hellwig
0 siblings, 1 reply; 9+ messages in thread
From: Julian Sun @ 2026-09-10 5:35 UTC (permalink / raw)
To: Christoph Hellwig
Cc: linux-nvme, sagi, kch, armenx.baloyan, james.p.freyensee, ming.l,
Runyu Xiao
On 9/10/26 1:25 PM, Christoph Hellwig wrote:
> Can you coordinate this with the configfs path checking series
> from Runyu Xiao? That one had a few resends, so I'd like to get it in
> first.
Sure, I'll rebase and resend once you've merged Runyu's patches.
Thanks,
--
Julian Sun <sunjunchao@bytedance.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] nvmet: preserve device path on allocation failure.
2026-09-10 5:35 ` Julian Sun
@ 2026-09-10 5:37 ` Christoph Hellwig
0 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-09-10 5:37 UTC (permalink / raw)
To: Julian Sun
Cc: Christoph Hellwig, linux-nvme, sagi, kch, armenx.baloyan,
james.p.freyensee, ming.l, Runyu Xiao
On Thu, Sep 10, 2026 at 01:35:10PM +0800, Julian Sun wrote:
> On 9/10/26 1:25 PM, Christoph Hellwig wrote:
>> Can you coordinate this with the configfs path checking series
>> from Runyu Xiao? That one had a few resends, so I'd like to get it in
>> first.
>
> Sure, I'll rebase and resend once you've merged Runyu's patches.
Actually I noticed we need another respin of that anyway. Let me review
your patches and see if we can fast track them in.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] nvmet: preserve device path on allocation failure.
2026-09-08 3:35 [PATCH 1/2] nvmet: preserve device path on allocation failure Julian Sun
2026-09-08 3:35 ` [PATCH 2/2] nvmet: reject enabling a namespace without a device path Julian Sun
2026-09-10 5:25 ` [PATCH 1/2] nvmet: preserve device path on allocation failure Christoph Hellwig
@ 2026-09-10 5:42 ` Christoph Hellwig
2026-09-11 14:45 ` Keith Busch
3 siblings, 0 replies; 9+ messages in thread
From: Christoph Hellwig @ 2026-09-10 5:42 UTC (permalink / raw)
To: Julian Sun
Cc: linux-nvme, hch, sagi, kch, armenx.baloyan, james.p.freyensee,
ming.l
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 1/2] nvmet: preserve device path on allocation failure.
2026-09-08 3:35 [PATCH 1/2] nvmet: preserve device path on allocation failure Julian Sun
` (2 preceding siblings ...)
2026-09-10 5:42 ` Christoph Hellwig
@ 2026-09-11 14:45 ` Keith Busch
3 siblings, 0 replies; 9+ messages in thread
From: Keith Busch @ 2026-09-11 14:45 UTC (permalink / raw)
To: Julian Sun
Cc: linux-nvme, hch, sagi, kch, armenx.baloyan, james.p.freyensee,
ming.l
On Tue, Sep 08, 2026 at 11:35:18AM +0800, Julian Sun wrote:
> nvmet_ns_device_path_store() frees the old path before allocating its
> replacement, losing the existing configuration if allocation fails.
> Allocate the new path before freeing the old one.
Thanks, applied to nvme-7.3.
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-09-11 14:46 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08 3:35 [PATCH 1/2] nvmet: preserve device path on allocation failure Julian Sun
2026-09-08 3:35 ` [PATCH 2/2] nvmet: reject enabling a namespace without a device path Julian Sun
2026-09-10 5:42 ` Christoph Hellwig
2026-09-10 5:47 ` Julian Sun
2026-09-10 5:25 ` [PATCH 1/2] nvmet: preserve device path on allocation failure Christoph Hellwig
2026-09-10 5:35 ` Julian Sun
2026-09-10 5:37 ` Christoph Hellwig
2026-09-10 5:42 ` Christoph Hellwig
2026-09-11 14:45 ` Keith Busch
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.