From: "Danilo Krummrich" <dakr@kernel.org>
To: "Aldo Ariel Panzardo" <qwe.aldo@gmail.com>
Cc: <gregkh@linuxfoundation.org>, <rafael@kernel.org>,
<johan@kernel.org>, <driver-core@lists.linux.dev>,
<linux-kernel@vger.kernel.org>, <stable@vger.kernel.org>,
"sashiko . dev" <sashiko-bot@kernel.org>
Subject: Re: [PATCH v3 1/2] debugfs: fix use-after-free in debugfs_read_file_str()
Date: Sat, 26 Sep 2026 17:53:41 +0200 [thread overview]
Message-ID: <DLPDB44JJRGJ.3K6JNS746M7QC@kernel.org> (raw)
In-Reply-To: <20260926140918.1077347-1-qwe.aldo@gmail.com>
On Sat Sep 26, 2026 at 4:09 PM CEST, Aldo Ariel Panzardo wrote:
> Switch to kmemdup() with GFP_ATOMIC so the allocation stays within the RCU
> critical section.
I'd like to avoid GFP_ATOMIC for this, as this doesn't seem to justify accessing
memory reserves.
There are a couple of alternatives for RCU:
(1) Measure under RCU, allocate, re-check and copy under RCU, or grow the
buffer and retry.
(2) Use GFP_NOWAIT and just fail under memory pressure.
(3) Allocate what userspace wants to read, not what the actual size of the
string is, i.e. min(count, PAGE_SIZE).
For this specific issue I'd probably go with (1).
However, I think that the whole debugfs_create_str() API is a bit of a footgun
to begin with as it implicitly imposes the same RCU constraints on the caller of
debugfs_create_str() (which also incentivises GFP_ATOMIC usage because it is
convinient).
For instance, icc_get_set() [1] has to do the same RCU dance and uses
GFP_ATOMIC.
Other users, such as soundwire, just get it wrong and just pass the unprotected
pointer to e.g. request_firmware() [2], which is a potential UAF.
So, I think this API lacks a proper synchronization contract;
debugfs_create_str() doesn't mention anything at all, which may be why soundwire
got it wrong.
I suggest to add a new type, e.g.
struct debugfs_string {
char __rcu *value;
}
or if we want to just use a mutex for synchronization (which simplifies the
allocation issue) we can just make it:
struct debugfs_string {
char *value;
struct mutex lock;
}
And then we can have helpers, such as
int debugfs_string_set(struct debugfs_string *s, const char *value);
and
char *debugfs_string_dup(struct debugfs_string *s);
which take care of the synchronization for the caller.
Personally, I'd just go for the mutex, as it avoids the need for the allocation
dance and also allows us to provide a guard if we want to access the string and
avoid a duplication of the string in the first place, e.g.
scoped_guard(debugfs_string, s)
matches = !strcmp(debugfs_string_read_locked(s), pattern);
Thanks,
Danilo
[1] https://elixir.bootlin.com/linux/v7.2.7/source/drivers/interconnect/debugfs-client.c#L51
[2] https://elixir.bootlin.com/linux/v7.2.7/source/drivers/soundwire/debugfs.c#L268
next prev parent reply other threads:[~2026-09-26 15:53 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-25 17:58 [PATCH] debugfs: fix UAF and double-free in debugfs_str read/write Aldo Ariel Panzardo
2026-09-26 6:53 ` Greg KH
2026-09-26 13:47 ` [PATCH v2 0/2] " Aldo Ariel Panzardo
2026-09-26 13:47 ` [PATCH v2 1/2] debugfs: fix use-after-free in debugfs_read_file_str() Aldo Ariel Panzardo
2026-09-26 13:48 ` [PATCH v2 2/2] debugfs: serialize concurrent writers in debugfs_write_file_str() Aldo Ariel Panzardo
2026-09-26 14:09 ` [PATCH v3 0/2] debugfs: fix UAF and double-free in debugfs_str read/write Aldo Ariel Panzardo
2026-09-26 14:09 ` [PATCH v3 1/2] debugfs: fix use-after-free in debugfs_read_file_str() Aldo Ariel Panzardo
2026-09-26 15:53 ` Danilo Krummrich [this message]
2026-09-26 14:09 ` [PATCH v3 2/2] debugfs: serialize concurrent writers in debugfs_write_file_str() Aldo Ariel Panzardo
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=DLPDB44JJRGJ.3K6JNS746M7QC@kernel.org \
--to=dakr@kernel.org \
--cc=driver-core@lists.linux.dev \
--cc=gregkh@linuxfoundation.org \
--cc=johan@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=qwe.aldo@gmail.com \
--cc=rafael@kernel.org \
--cc=sashiko-bot@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®