History

Merge tag 'vfs-6.11.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs

Pull vfs mount query updates from Christian Brauner: "This contains work to extend the abilities of listmount() and statmount() and various fixes and cleanups. Features: - Allow iterating through mounts via listmount() from newest to oldest. This makes it possible for mount(8) to keep iterating the mount table in reverse order so it gets newest mounts first. - Relax permissions on listmount() and statmount(). It's not necessary to have capabilities in the initial namespace: it is sufficient to have capabilities in the owning namespace of the mount namespace we're located in to list unreachable mounts in that namespace. - Extend both listmount() and statmount() to list and stat mounts in foreign mount namespaces. Currently the only way to iterate over mount entries in mount namespaces that aren't in the caller's mount namespace is by crawling through /proc in order to find /proc/<pid>/mountinfo for the relevant mount namespace. This is both very clumsy and hugely inefficient. So extend struct mnt_id_req with a new member that allows to specify the mount namespace id of the mount namespace we want to look at. Luckily internally we already have most of the infrastructure for this so we just need to expose it to userspace. Give userspace a way to retrieve the id of a mount namespace via statmount() and through a new nsfs ioctl() on mount namespace file descriptor. This comes with appropriate selftests. - Expose mount options through statmount(). Currently if userspace wants to get mount options for a mount and with statmount(), they still have to open /proc/<pid>/mountinfo to parse mount options. Simply the information through statmount() directly. Afterwards it's possible to only rely on statmount() and listmount() to retrieve all and more information than /proc/<pid>/mountinfo provides. This comes with appropriate selftests. Fixes: - Avoid copying to userspace under the namespace semaphore in listmount. Cleanups: - Simplify the error handling in listmount by relying on our newly added cleanup infrastructure. - Refuse invalid mount ids early for both listmount and statmount" * tag 'vfs-6.11.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs: fs: reject invalid last mount id early fs: refuse mnt id requests with invalid ids early fs: find rootfs mount of the mount namespace fs: only copy to userspace on success in listmount() sefltests: extend the statmount test for mount options fs: use guard for namespace_sem in statmount() fs: export mount options via statmount() fs: rename show_mnt_opts -> show_vfsmnt_opts selftests: add a test for the foreign mnt ns extensions fs: add an ioctl to get the mnt ns id from nsfs fs: Allow statmount() in foreign mount namespace fs: Allow listmount() in foreign mount namespace fs: export the mount ns id via statmount fs: keep an index of current mount namespaces fs: relax permissions for statmount() listmount: allow listing in reverse order fs: relax permissions for listmount() fs: simplify error handling fs: don't copy to userspace under namespace semaphore path: add cleanup helper

Linus Torvalds committed 2 years ago

Commit f608cab2 parents 2aae1d6 4bed84311 files · +926 −123Browse files

Showing the changes to include/uapi (2 of 11 files). Show all

Unified · Split

2 files
  1. include/uapi/linux/mount.h +8 −2
  2. include/uapi/linux/nsfs.h +2 −0
include/uapi/linux/mount.h+8−2
@@ -154,7 +154,7 @@ struct mount_attr { · 153 unmodified lines
154154 */
155155 struct statmount {
156156 __u32 size; /* Total size, including strings */
157− __u32 __spare1;
157+ __u32 mnt_opts; /* [str] Mount options of the mount */
158158 __u64 mask; /* What results were written */
159159 __u32 sb_dev_major; /* Device ID */
160160 __u32 sb_dev_minor;
@@ -172,7 +172,8 @@ struct statmount { · 11 unmodified lines
172172 __u64 propagate_from; /* Propagation from in current namespace */
173173 __u32 mnt_root; /* [str] Root of mount relative to root of fs */
174174 __u32 mnt_point; /* [str] Mountpoint relative to current root */
175− __u64 __spare2[50];
175+ __u64 mnt_ns_id; /* ID of the mount namespace */
176+ __u64 __spare2[49];
176177 char str[]; /* Variable size part containing strings */
177178 };
178179
@@ -188,10 +189,12 @@ struct mnt_id_req { · 9 unmodified lines
188189 __u32 spare;
189190 __u64 mnt_id;
190191 __u64 param;
192+ __u64 mnt_ns_id;
191193 };
192194
193195 /* List of all mnt_id_req versions. */
194196 #define MNT_ID_REQ_SIZE_VER0 24 /* sizeof first published struct */
197+#define MNT_ID_REQ_SIZE_VER1 32 /* sizeof second published struct */
195198
196199 /*
197200 * @mask bits for statmount(2)
@@ -202,10 +205,13 @@ struct mnt_id_req { · 4 unmodified lines
202205 #define STATMOUNT_MNT_ROOT 0x00000008U /* Want/got mnt_root */
203206 #define STATMOUNT_MNT_POINT 0x00000010U /* Want/got mnt_point */
204207 #define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */
208+#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */
209+#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
205210
206211 /*
207212 * Special @mnt_id values that can be passed to listmount
208213 */
209214 #define LSMT_ROOT 0xffffffffffffffff /* root mount */
215+#define LISTMOUNT_REVERSE (1 << 0) /* List later mounts first */
210216
211217 #endif /* _UAPI_LINUX_MOUNT_H */
include/uapi/linux/nsfs.h+2−0
@@ -15,5 +15,7 @@ · 14 unmodified lines
1515 #define NS_GET_NSTYPE _IO(NSIO, 0x3)
1616 /* Get owner UID (in the caller's user namespace) for a user namespace */
1717 #define NS_GET_OWNER_UID _IO(NSIO, 0x4)
18+/* Get the id for a mount namespace */
19+#define NS_GET_MNTNS_ID _IO(NSIO, 0x5)
1820
1921 #endif /* __LINUX_NSFS_H */

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t