* Re: [PATCH RFC 18/38] proc: don't WARN about a name that is already registered
@ 2026-11-04 18:43 Alexey Dobriyan
0 siblings, 0 replies; 2+ messages in thread
From: Alexey Dobriyan @ 2026-11-04 18:43 UTC (permalink / raw)
To: Christian Brauner
Cc: linux-fsdevel, Linus Torvalds, Chris Mason, Al Viro,
Christoph Hellwig, linux-kernel, stable, akpm
> --- a/fs/proc/generic.c
> +++ b/fs/proc/generic.c
> @@ -401,9 +401,10 @@ struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
> write_lock(&proc_subdir_lock);
> dp->parent = dir;
> if (pde_subdir_insert(dir, dp) == false) {
> - WARN(1, "proc_dir_entry '%s/%s' already registered\n",
> - dir->name, dp->name);
> write_unlock(&proc_subdir_lock);
> + pr_warn("proc_dir_entry '%s/%s' already registered\n",
> + dir->name, dp->name);
> + dump_stack();
> goto out_free_inum;
> }
> write_unlock(&proc_subdir_lock);
I don't like this patch.
WARN is there to make bugs noticeable, /proc entries aren't supposed to be
created randomly unlike regular files so deleting non-existent name or
registering twice is probably a bug.
Now, some names do come from userspace but it is up to subsystems to
find duplicates and return errors (and sanitize for dots/slashes!).
In userspace mkdir;mkdir returns error second time, as well as
unlink;unlink. In kernel error is BUG/WARN (like it is now) and it is up
to subsystem to evade it.
/proc/alexey
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH RFC 18/38] proc: don't WARN about a name that is already registered
2026-11-02 14:21 [PATCH RFC 00/38] proc: fix a few old bugs in /proc handlers Christian Brauner
@ 2026-11-02 14:21 ` Christian Brauner
0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2026-11-02 14:21 UTC (permalink / raw)
To: linux-fsdevel
Cc: Linus Torvalds, Jann Horn, Josef Bacik, Chris Mason, Jeff Layton,
NeilBrown, Eric Dumazet, Thomas Gleixner, Al Viro,
Jonathan Corbet, Christoph Hellwig, Greg Kroah-Hartman,
Joel Granados, Kees Cook, Jan Kara, Jan Kara, linux-kernel,
linux-nfs, linux-acpi, linux-kselftest, linux-s390, linux-scsi,
linux-um, linux-wireless, linuxppc-dev, netdev, ntfs3,
platform-driver-x86, coreteam, kexec, linux-pci, linux-sound,
netfilter-devel, dri-devel, ibm-acpi-devel, jfs-discussion,
linux-alpha, linux-arm-kernel, linux-cifs, linux-fbdev,
linux-hwmon, linux-mm, linux-sh, linux-usb, samba-technical,
sparclinux, linux-m68k, linux-doc, linux-serial,
linux-atm-general, Takashi Iwai, linux-input, linux-raid,
linux-ext4, linux-modules, linux-debuggers,
Christian Brauner (Amutable),
Chuck Lever, stable
proc_register() WARNs when the directory already has an entry of the
same name and fails the registration. Callers that pick their names
themselves should never get there but some take names from userspace.
pktgen creates a file for each device a writer of "add_device" adds,
named after the device. A device can have any name, including "pgctrl"
or "kpktgend_0", the names of pktgen's own files:
ip link set lo name pgctrl
ip link set pgctrl up
echo "add_device pgctrl" > /proc/net/pktgen/kpktgend_0
proc_dir_entry 'pktgen/pgctrl' already registered
WARNING: fs/proc/generic.c:404 at proc_register+0x555/0x8b0, CPU#0: bash/241
Call Trace:
proc_create_data+0x9f/0xf0
pktgen_thread_write+0xd9b/0x1780
proc_reg_write+0x1c2/0x3c0
vfs_write+0x1cd/0xfa0
The files of a network namespace belong to the root of its user
namespace and none of this requires a capability. So once pktgen is
loaded an unprivileged user can taint the kernel, or crash it with
panic_on_warn, from namespaces of its own. pktgen itself copes with
the failed registration just fine.
So go back to what proc_register() did before commit 6c2f91e077f1
("proc: use WARN() rather than printk+backtrace") and what
sysfs_warn_dup() does for sysfs: report the name with pr_warn() and
dump the stack. While at it, do that after dropping proc_subdir_lock
instead of printing a backtrace while holding the lock that every
lookup and readdir in procfs needs.
Reported-by: Chris Mason <mason@kernel.org>
Fixes: 6c2f91e077f1 ("proc: use WARN() rather than printk+backtrace")
Cc: stable@vger.kernel.org
Signed-off-by: Christian Brauner (Amutable) <brauner@kernel.org>
---
fs/proc/generic.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/fs/proc/generic.c b/fs/proc/generic.c
index c560c96a64eb..ef804cd3ec45 100644
--- a/fs/proc/generic.c
+++ b/fs/proc/generic.c
@@ -401,9 +401,10 @@ struct proc_dir_entry *proc_register(struct proc_dir_entry *dir,
write_lock(&proc_subdir_lock);
dp->parent = dir;
if (pde_subdir_insert(dir, dp) == false) {
- WARN(1, "proc_dir_entry '%s/%s' already registered\n",
- dir->name, dp->name);
write_unlock(&proc_subdir_lock);
+ pr_warn("proc_dir_entry '%s/%s' already registered\n",
+ dir->name, dp->name);
+ dump_stack();
goto out_free_inum;
}
write_unlock(&proc_subdir_lock);
--
2.53.0
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-04 18:43 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-04 18:43 [PATCH RFC 18/38] proc: don't WARN about a name that is already registered Alexey Dobriyan
-- strict thread matches above, loose matches on Subject: below --
2026-11-02 14:21 [PATCH RFC 00/38] proc: fix a few old bugs in /proc handlers Christian Brauner
2026-11-02 14:21 ` [PATCH RFC 18/38] proc: don't WARN about a name that is already registered Christian Brauner
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®