[GIT PULL] vfs procfs

From: Christian Brauner
Date: Fri Sep 13 2024 - 10:45:35 EST


/* Summary */
Hey Linus,

This contains the following changes for procfs:

* Add config options and parameters to block forcing memory writes.

This adds a Kconfig option and boot param to allow removing the
FOLL_FORCE flag from /proc/<pid>/mem write calls as this can be used
in various attacks.

The traditional forcing behavior is kept as default because it can
break GDB and some other use cases.

This is the simpler version that you had requested.

* Restrict overmounting of ephemeral entities.

It is currently possible to mount on top of various ephemeral entities
in procfs. This specifically includes magic links. To recap, magic
links are links of the form /proc/<pid>/fd/<nr>. They serve as
references to a target file and during path lookup they cause a jump
to the target path. Such magic links disappear if the corresponding
file descriptor is closed.

Currently it is possible to overmount such magic links. This is mostly
interesting for an attacker that wants to somehow trick a process into
e.g., reopening something that it didn't intend to reopen or to hide
a malicious file descriptor.

But also it risks leaking mounts for long-running processes. When
overmounting a magic link like above, the mount will not be detached
when the file descriptor is closed. Only the target mountpoint will
disappear. Which has the consequence of making it impossible to unmount
that mount afterwards. So the mount will stick around until the process
exits and the /proc/<pid>/ directory is cleaned up during
proc_flush_pid() when the dentries are pruned and invalidated.

That in turn means it's possible for a program to accidentally leak
mounts and it's also possible to make a task leak mounts without it's
knowledge if the attacker just keeps overmounting things under
/proc/<pid>/fd/<nr>.

Disallow overmounting of such ephemeral entities.

* Cleanup the readdir method naming in some procfs file operations.

* Replace kmalloc() and strcpy() with a simple kmemdup() call.

/* Testing */

gcc version 14.2.0 (Debian 14.2.0-3)
Debian clang version 16.0.6 (27+b1)

All patches are based on v6.11-rc1 and have been sitting in linux-next.
No build failures or warnings were observed.

/* Conflicts */

Merge conflicts with mainline
=============================

None.

Merge conflicts with other trees
================================

None.

The following changes since commit 8400291e289ee6b2bf9779ff1c83a291501f017b:

Linux 6.11-rc1 (2024-07-28 14:19:55 -0700)

are available in the Git repository at:

git@xxxxxxxxxxxxxxxxxxx:pub/scm/linux/kernel/git/vfs/vfs tags/vfs-6.12.procfs

for you to fetch changes up to 4ad5f9a021bd7e3a48a8d11c52cef36d5e05ffcc:

proc: fold kmalloc() + strcpy() into kmemdup() (2024-09-09 10:51:20 +0200)

Please consider pulling these changes from the signed vfs-6.12.procfs tag.

Thanks!
Christian

----------------------------------------------------------------
vfs-6.12.procfs

----------------------------------------------------------------
Adrian Ratiu (1):
proc: add config & param to block forcing mem writes

Alexey Dobriyan (1):
proc: fold kmalloc() + strcpy() into kmemdup()

Christian Brauner (7):
proc: proc_readfd() -> proc_fd_iterate()
proc: proc_readfdinfo() -> proc_fdinfo_iterate()
proc: add proc_splice_unmountable()
proc: block mounting on top of /proc/<pid>/map_files/*
proc: block mounting on top of /proc/<pid>/fd/*
proc: block mounting on top of /proc/<pid>/fdinfo/*
Merge patch series "proc: restrict overmounting of ephemeral entities"

Documentation/admin-guide/kernel-parameters.txt | 10 ++++
fs/proc/base.c | 65 +++++++++++++++++++++++--
fs/proc/fd.c | 16 +++---
fs/proc/generic.c | 4 +-
fs/proc/internal.h | 13 +++++
security/Kconfig | 32 ++++++++++++
6 files changed, 127 insertions(+), 13 deletions(-)