* [PATCH 7.3 1120/2651] debugfs: make debugfs_create_str() read-only
2026-11-18 14:20 [PATCH 7.3 0000/2651] 7.3.6-rc1 review Greg Kroah-Hartman
@ 2026-11-18 14:39 ` Greg Kroah-Hartman
0 siblings, 0 replies; 3+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-18 14:39 UTC (permalink / raw)
To: stable; +Cc: Greg Kroah-Hartman, patches, Yichong Chen, Sasha Levin
7.3-stable review patch. If anyone has any objections, please let me know.
------------------
From: Yichong Chen <chenyichong@uniontech.com>
[ Upstream commit 5ec78be9552035e1e71de218f968c03c44181bf0 ]
debugfs_create_str() supports replacing the backing string from userspace.
Concurrent writers can race and free the same old string twice.
All writable in-tree users have been converted to local file operations.
Remove the generic write support from debugfs_create_str(), and refuse to
create a file when the caller passes write permission bits.
This makes unsupported writable use visible instead of silently creating a
file with different permissions.
Fixes: 86b5488121db ("debugfs: Add write support to debugfs_create_str()")
Signed-off-by: Yichong Chen <chenyichong@uniontech.com>
Link: https://patch.msgid.link/20260807100053.1089834-4-chenyichong@uniontech.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
fs/debugfs/file.c | 81 ++++++-----------------------------------------
1 file changed, 10 insertions(+), 71 deletions(-)
diff --git a/fs/debugfs/file.c b/fs/debugfs/file.c
index 08de6652a4f31..170feb75317ff 100644
--- a/fs/debugfs/file.c
+++ b/fs/debugfs/file.c
@@ -1049,98 +1049,37 @@ ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
return ret;
}
-static ssize_t debugfs_write_file_str(struct file *file, const char __user *user_buf,
- size_t count, loff_t *ppos)
-{
- struct dentry *dentry = F_DENTRY(file);
- char *old, *new = NULL;
- int pos = *ppos;
- int r;
-
- r = debugfs_file_get(dentry);
- if (unlikely(r))
- return r;
-
- old = *(char **)file->private_data;
-
- /* only allow strict concatenation */
- r = -EINVAL;
- if (pos && pos != strlen(old))
- goto error;
-
- r = -E2BIG;
- if (pos + count + 1 > PAGE_SIZE)
- goto error;
-
- r = -ENOMEM;
- new = kmalloc(pos + count + 1, GFP_KERNEL);
- if (!new)
- goto error;
-
- if (pos)
- memcpy(new, old, pos);
-
- r = -EFAULT;
- if (copy_from_user(new + pos, user_buf, count))
- goto error;
-
- new[pos + count] = '\0';
- strim(new);
-
- rcu_assign_pointer(*(char __rcu **)file->private_data, new);
- synchronize_rcu();
- kfree(old);
-
- debugfs_file_put(dentry);
- return count;
-
-error:
- kfree(new);
- debugfs_file_put(dentry);
- return r;
-}
-
static const struct file_operations fops_str = {
.read = debugfs_read_file_str,
- .write = debugfs_write_file_str,
- .open = simple_open,
- .llseek = default_llseek,
-};
-
-static const struct file_operations fops_str_ro = {
- .read = debugfs_read_file_str,
- .open = simple_open,
- .llseek = default_llseek,
-};
-
-static const struct file_operations fops_str_wo = {
- .write = debugfs_write_file_str,
.open = simple_open,
.llseek = default_llseek,
};
/**
- * debugfs_create_str - create a debugfs file that is used to read and write a string value
+ * debugfs_create_str - create a debugfs file that is used to read a string value
* @name: a pointer to a string containing the name of the file to create.
* @mode: the permission that the file should have
* @parent: a pointer to the parent dentry for this file. This should be a
* directory dentry if set. If this parameter is %NULL, then the
* file will be created in the root of the debugfs filesystem.
- * @value: a pointer to the variable that the file should read to and write
- * from. This pointer and the string it points to must not be %NULL.
+ * @value: a pointer to the variable that the file should read from. This
+ * pointer and the string it points to must not be %NULL.
*
* This function creates a file in debugfs with the given name that
- * contains the value of the variable @value. If the @mode variable is so
- * set, it can be read from, and written to.
+ * contains the value of the variable @value. The file can be read from.
+ * Writable files are not supported; if @mode contains write permission bits,
+ * no file is created.
*/
void debugfs_create_str(const char *name, umode_t mode,
struct dentry *parent, char **value)
{
if (WARN_ON(!value || !*value))
return;
+ if (WARN(mode & 0222,
+ "%s() does not support writable files\n", __func__))
+ return;
- debugfs_create_mode_unsafe(name, mode, parent, value, &fops_str,
- &fops_str_ro, &fops_str_wo);
+ debugfs_create_file_unsafe(name, mode, parent, value, &fops_str);
}
EXPORT_SYMBOL_GPL(debugfs_create_str);
--
2.53.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH 7.3 1120/2651] debugfs: make debugfs_create_str() read-only
@ 2026-11-19 3:24 Sergey Lebedev
2026-11-19 16:08 ` Sasha Levin
0 siblings, 1 reply; 3+ messages in thread
From: Sergey Lebedev @ 2026-11-19 3:24 UTC (permalink / raw)
To: Greg Kroah-Hartman; +Cc: stable, patches, Yichong Chen, Sasha Levin
Hi Greg,
This is 3/3 of a series, and the two before it are not queued:
493daf5bf2b9 ("interconnect: debugfs: replace writable string helper")
98421ba5925f ("soundwire: debugfs: replace writable string helper")
Without them, drivers/soundwire/debugfs.c and
drivers/interconnect/debugfs-client.c still pass write permission to
debugfs_create_str(), so the new check warns and the files are not
created. On a Surface Pro 11 (Lunar Lake, SoundWire), 7.3.6-rc1 warns
twice at boot:
debugfs_create_str() does not support writable files
WARNING: fs/debugfs/file.c:1078 at debugfs_create_str+0x57/0x80
sdw_slave_debugfs_init+0x18a/0x1d0 [soundwire_bus]
6.18.65-rc1 (0934/2151) and 6.12.119-rc1 (0740/1756) queue the same
patch, and both trees have the same two callers. 6.6.163-rc1 (2497/3318)
queues it too; there only the interconnect callers remain. Please take
the conversions first, or drop this one.
Sergey
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH 7.3 1120/2651] debugfs: make debugfs_create_str() read-only
2026-11-19 3:24 [PATCH 7.3 1120/2651] debugfs: make debugfs_create_str() read-only Sergey Lebedev
@ 2026-11-19 16:08 ` Sasha Levin
0 siblings, 0 replies; 3+ messages in thread
From: Sasha Levin @ 2026-11-19 16:08 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Sasha Levin, stable, patches, Yichong Chen, Sergey Lebedev
> This is 3/3 of a series, and the two before it are not queued:
>
> 493daf5bf2b9 ("interconnect: debugfs: replace writable string helper")
> 98421ba5925f ("soundwire: debugfs: replace writable string helper")
Queued the soundwire conversion for 7.3 and 6.18.
493daf5bf2b9 ("interconnect: debugfs: replace writable string helper") is not
needed: drivers/interconnect/debugfs-client.c is compiled out (#undef
INTERCONNECT_ALLOW_WRITE_DEBUGFS) on 7.3, 6.18, 6.12 and 6.6, so it does not
warn there.
--
Thanks,
Sasha
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-11-19 16:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-19 3:24 [PATCH 7.3 1120/2651] debugfs: make debugfs_create_str() read-only Sergey Lebedev
2026-11-19 16:08 ` Sasha Levin
-- strict thread matches above, loose matches on Subject: below --
2026-11-18 14:20 [PATCH 7.3 0000/2651] 7.3.6-rc1 review Greg Kroah-Hartman
2026-11-18 14:39 ` [PATCH 7.3 1120/2651] debugfs: make debugfs_create_str() read-only Greg Kroah-Hartman
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox