fs: allow statmount to fetch the fs_subtype and sb_source
v4 cover fs: allow statmount to fetch the fs_subtype and sb_source
Meta has some internal logging that scrapes /proc/self/mountinfo today. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.
---
Changes in v4:
- Rename mnt_devname to sb_source
- Break statmount_string() behavior changes out into separate patch
- Link to v3: https://lore.kernel.org/r/[email protected]
Changes in v3:
- Unescape the result of ->show_devname
- Move handling of nothing being emitted out of the switch statement
- Link to v2: https://lore.kernel.org/r/[email protected]
Changes in v2:
- make statmount_fs_subtype
- return fast if no subtype is emitted
- new patch to allow statmount() to return devicename
- Link to v1: https://lore.kernel.org/r/[email protected]
---
Jeff Layton (3):
fs: don't let statmount return empty strings
fs: add the ability for statmount() to report the fs_subtype
fs: add the ability for statmount() to report the sb_source
fs/namespace.c | 68 ++++++++++++++++++++++++++++++++++++++++++---- include/uapi/linux/mount.h | 6 +++- 2 files changed, 67 insertions(+), 7 deletions(-)
---
base-commit: 26213e1a6caa5a7f508b919059b0122b451f4dfe
change-id: 20241106-statmount-3f91a7ed75fa
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
PATCH v4 1/3 fs: don't let statmount return empty strings
When one of the statmount_string() handlers doesn't emit anything to seq, the kernel currently sets the corresponding flag and emits an empty string.
Given that statmount() returns a mask of accessible fields, just leave the bit unset in this case, and skip any NULL termination. If nothing was emitted to the seq, then the EOVERFLOW and EAGAIN cases aren't applicable and the function can just return immediately.
--- fs/namespace.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)
fs/namespace.c +11 -4
@@ -5046,22 +5046,23 @@ static int statmount_string(struct kstatmount *s, u64 flag)size_t kbufsize;struct seq_file *seq = &s->seq;struct statmount *sm = &s->sm; +u32 start = seq->count;switch (flag) {case STATMOUNT_FS_TYPE : - sm->fs_type = seq->count; + sm->fs_type = start; ret =statmount_fs_type (s, seq);break ;case STATMOUNT_MNT_ROOT : - sm->mnt_root = seq->count; + sm->mnt_root = start; ret =statmount_mnt_root (s, seq);break ;case STATMOUNT_MNT_POINT : - sm->mnt_point = seq->count; + sm->mnt_point = start; ret =statmount_mnt_point (s, seq);break ;case STATMOUNT_MNT_OPTS : - sm->mnt_opts = seq->count; + sm->mnt_opts = start; ret =statmount_mnt_opts (s, seq);break ;default :
@@ -5069,6 +5070,12 @@ static int statmount_string(struct kstatmount *s, u64 flag)return -EINVAL ; } +/* +* If nothing was emitted, return to avoid setting the flag +* and terminating the buffer. +*/ +if (seq->count == start) +return ret;if (unlikely (check_add_overflow (sizeof (*sm), seq->count, &kbufsize)))return -EOVERFLOW ;if (kbufsize >= s->bufsize)
Signature · 1 line
2.47.0
Re: [PATCH v4 1/3] fs: don't let statmount return empty strings
Quoted 10 lines · Jeff Layton
When one of the
statmount_string()handlers doesn't emit anything to seq, the kernel currently sets the corresponding flag and emits an empty string.Given that
statmount()returns a mask of accessible fields, just leave the bit unset in this case, and skip any NULL termination. If nothing was emitted to the seq, then the EOVERFLOW and EAGAIN cases aren't applicable and the function can just return immediately.Signed-off-by Jeff Layton <[email protected]>
Looks good. Feel free to add:
Honza
Quoted 53 lines
--- fs/namespace.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-)fs/namespace.c +11
-4@@ -5046,22 +5046,23 @@ static int statmount_string(struct kstatmount *s, u64 flag)size_t kbufsize;struct seq_file *seq = &s->seq;struct statmount *sm = &s->sm; +u32 start = seq->count;switch (flag) {case STATMOUNT_FS_TYPE : - sm->fs_type = seq->count; + sm->fs_type = start; ret =statmount_fs_type (s, seq);break ;case STATMOUNT_MNT_ROOT : - sm->mnt_root = seq->count; + sm->mnt_root = start; ret =statmount_mnt_root (s, seq);break ;case STATMOUNT_MNT_POINT : - sm->mnt_point = seq->count; + sm->mnt_point = start; ret =statmount_mnt_point (s, seq);break ;case STATMOUNT_MNT_OPTS : - sm->mnt_opts = seq->count; + sm->mnt_opts = start; ret =statmount_mnt_opts (s, seq);break ;default :@@ -5069,6 +5070,12 @@ static int statmount_string(struct kstatmount *s, u64 flag)return -EINVAL ; } +/* +* If nothing was emitted, return to avoid setting the flag +* and terminating the buffer. +*/ +if (seq->count == start) +return ret;if (unlikely (check_add_overflow (sizeof (*sm), seq->count, &kbufsize)))return -EOVERFLOW ;if (kbufsize >= s->bufsize)Signature · 2 lines
-- 2.47.0
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
PATCH v4 2/3 fs: add the ability for statmount() to report the fs_subtype
In reply to Jeff Layton/proc/self/mountinfo prints out the sb->s_subtype after the type. This is particularly useful for disambiguating FUSE mounts (at least when the userland driver bothers to set it). Add STATMOUNT_FS_SUBTYPE and claim one of the __spare2 fields to point to the offset into the str[] array.
--- fs/namespace.c | 19 +++++++++++++++++-- include/uapi/linux/mount.h | 5 ++++- 2 files changed, 21 insertions(+), 3 deletions(-)
fs/namespace.c +17 -2
@@ -5006,6 +5006,14 @@ static int statmount_fs_type(struct kstatmount *s, struct seq_file *seq)return 0 ; } +static void statmount_fs_subtype (struct kstatmount *s,struct seq_file *seq) +{ +struct super_block *sb = s->mnt->mnt_sb; + +if (sb->s_subtype) +seq_puts (seq, sb->s_subtype); +} +static void statmount_mnt_ns_id (struct kstatmount *s,struct mnt_namespace *ns) { s->sm.mask |=STATMOUNT_MNT_NS_ID ;
@@ -5042,7 +5050,7 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)static int statmount_string (struct kstatmount *s,u64 flag) { -int ret; +int ret =0 ;size_t kbufsize;struct seq_file *seq = &s->seq;struct statmount *sm = &s->sm;
@@ -5065,6 +5073,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->mnt_opts = start; ret =statmount_mnt_opts (s, seq);break ; +case STATMOUNT_FS_SUBTYPE : + sm->fs_subtype = start; +statmount_fs_subtype (s, seq); +break ;default :WARN_ON_ONCE (true);return -EINVAL ;
@@ -5210,6 +5222,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_MNT_OPTS ) err =statmount_string (s,STATMOUNT_MNT_OPTS ); +if (!err && s->mask &STATMOUNT_FS_SUBTYPE ) + err =statmount_string (s,STATMOUNT_FS_SUBTYPE ); +if (!err && s->mask &STATMOUNT_MNT_NS_ID )statmount_mnt_ns_id (s, ns);
@@ -5231,7 +5246,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size) }#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ - STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS) + STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize,
include/uapi/linux/mount.h +4 -1
@@ -173,7 +173,9 @@ struct statmount {__u32 mnt_root;/* [str] Root of mount relative to root of fs */ __u32 mnt_point;/* [str] Mountpoint relative to current root */ __u64 mnt_ns_id;/* ID of the mount namespace */ -__u64 __spare2[49 ]; +__u32 fs_subtype;/* [str] Subtype of fs_type (if any) */ +__u32 __spare1[1 ]; +__u64 __spare2[48 ];char str[];/* Variable size part containing strings */ };
@@ -207,6 +209,7 @@ struct mnt_id_req {#define STATMOUNT_FS_TYPE 0x00000020U/* Want/got fs_type */ #define STATMOUNT_MNT_NS_ID 0x00000040U/* Want/got mnt_ns_id */ #define STATMOUNT_MNT_OPTS 0x00000080U/* Want/got mnt_opts */ +#define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ /* * Special @mnt_id values that can be passed to listmount
Signature · 1 line
2.47.0
PATCH v4 3/3 fs: add the ability for statmount() to report the sb_source
In reply to Jeff Layton/proc/self/mountinfo displays the source for the mount, but statmount() doesn't yet have a way to return it. Add a new STATMOUNT_SB_SOURCE flag, claim the 32-bit __spare1 field to hold the offset into the str[] array.
--- fs/namespace.c | 36 +++++++++++++++++++++++++++++++++++- include/uapi/linux/mount.h | 3 ++- 2 files changed, 37 insertions(+), 2 deletions(-)
fs/namespace.c +35 -1
@@ -5014,6 +5014,32 @@ static void statmount_fs_subtype(struct kstatmount *s, struct seq_file *seq)seq_puts (seq, sb->s_subtype); } +static int statmount_sb_source (struct kstatmount *s,struct seq_file *seq) +{ +struct super_block *sb = s->mnt->mnt_sb; +struct mount *r =real_mount (s->mnt); + +if (sb->s_op->show_devname) { +size_t start = seq->count; +int ret; + + ret = sb->s_op->show_devname (seq, s->mnt->mnt_root); +if (ret) +return ret; + +if (unlikely (seq_has_overflowed (seq))) +return -EAGAIN ; + +/* Unescape the result */ + seq->buf[seq->count] ='\0' ; + seq->count = start; +seq_commit (seq,string_unescape_inplace (seq->buf + start,UNESCAPE_OCTAL )); + }else if (r->mnt_devname) { +seq_puts (seq, r->mnt_devname); + } +return 0 ; +} +static void statmount_mnt_ns_id (struct kstatmount *s,struct mnt_namespace *ns) { s->sm.mask |=STATMOUNT_MNT_NS_ID ;
@@ -5077,6 +5103,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->fs_subtype = start;statmount_fs_subtype (s, seq);break ; +case STATMOUNT_SB_SOURCE : + sm->sb_source = seq->count; + ret =statmount_sb_source (s, seq); +break ;default :WARN_ON_ONCE (true);return -EINVAL ;
@@ -5225,6 +5255,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_FS_SUBTYPE ) err =statmount_string (s,STATMOUNT_FS_SUBTYPE ); +if (!err && s->mask &STATMOUNT_SB_SOURCE ) + err =statmount_string (s,STATMOUNT_SB_SOURCE ); +if (!err && s->mask &STATMOUNT_MNT_NS_ID )statmount_mnt_ns_id (s, ns);
@@ -5246,7 +5279,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size) }#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ - STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE) + STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \ + STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize,
include/uapi/linux/mount.h +2 -1
@@ -174,7 +174,7 @@ struct statmount {__u32 mnt_point;/* [str] Mountpoint relative to current root */ __u64 mnt_ns_id;/* ID of the mount namespace */ __u32 fs_subtype;/* [str] Subtype of fs_type (if any) */ -__u32 __spare1[1 ]; +__u32 sb_source;/* [str] Source string of the mount */ __u64 __spare2[48 ];char str[];/* Variable size part containing strings */ };
@@ -210,6 +210,7 @@ struct mnt_id_req {#define STATMOUNT_MNT_NS_ID 0x00000040U/* Want/got mnt_ns_id */ #define STATMOUNT_MNT_OPTS 0x00000080U/* Want/got mnt_opts */ #define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ +#define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ /* * Special @mnt_id values that can be passed to listmount
Signature · 1 line
2.47.0
Quoted 7 lines · Jeff Layton
Meta has some internal logging that scrapes
/proc/self/mountinfotoday. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.Signed-off-by Jeff Layton <[email protected]>
When thinking of the naming for the unescaped options, I realized that maybe "source" is better than "sb_soure" which just adds redundant
info. Just a thought, don't bother if you don't agree.
Thanks,
Miklos
Quoted 7 lines · Miklos Szeredi
Quoted 6 lines · Jeff Layton
Meta has some internal logging that scrapes
/proc/self/mountinfotoday. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.
Quoted 8 lines
Quoted 1 line
Signed-off-by Jeff Layton <[email protected]>When thinking of the naming for the unescaped options, I realized that maybe "source" is better than "
sb_soure" which just adds redundant
info. Just a thought, don't bother if you don't agree.Acked-by Miklos Szeredi <[email protected]>
I think sb_source fits better with the convention that the other fields in the struct use. I say we stick with that.
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 6 lines · Jeff Layton
Meta has some internal logging that scrapes
/proc/self/mountinfotoday. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.
Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs.misc
[1/3] fs: don't let statmount return empty strings
https://git.kernel.org/vfs/vfs/c/75ead69a7173 [2/3] fs: add the ability for statmount() to report the fs_subtype https://git.kernel.org/vfs/vfs/c/ed9d95f691c2 [3/3] fs: add the ability for statmount() to report the sb_source https://git.kernel.org/vfs/vfs/c/d31cea0ab403
Quoted 10 lines · Christian Brauner
Quoted 6 lines · Jeff Layton
Meta has some internal logging that scrapes
/proc/self/mountinfotoday. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.
Jeff, thank you for this!
I have already implemented support for statmount() and listmount() in libmount (PR: https://github.com/util-linux/util-linux/pull/3092). The only remaining issue was the mount source and incomplete file system type.
Currently, the library does not use these syscalls when mounting (it still uses /proc/#/mountinfo). However, there is already a library API to fetch mount information from the kernel using listmount+statmount, and it can be accessed from the command line using:
findmnt --kernel=listmount
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.
Karel
Signature · 2 lines
Karel Zak <[email protected]> http://karelzak.blogspot.com
Quoted 4 lines · Karel Zak
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.
IIRC Amir said he'd take this up (this was at LSFMM 2023). I'm also happy to take part in the design and implementation.
Thanks,
Miklos
Quoted 12 lines · Karel Zak
Quoted 10 lines · Christian Brauner
Quoted 6 lines · Jeff Layton
Meta has some internal logging that scrapes
/proc/self/mountinfotoday. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.
Quoted 7 lines
Jeff, thank you for this!
I have already implemented support for
statmount()andlistmount()in libmount (PR: https://github.com/util-linux/util-linux/pull/3092). The only remaining issue was the mount source and incomplete file system type.
Unfortunately, I think we might be missing something else:
The mountinfo (and "mounts") file generator calls show_sb_opts() which generates some strings from the sb->s_flags field and then calls security_sb_show_options(). statmount() will give you the s_flags field (or an equivalent), but it doesn't give you the security options string. So, those aren't currently visible from statmount().
How should we expose those? Should we create a new statmount string field and populate it, or is it better to just tack them onto the end of the statmount.mnt_opts string?
Quoted 7 lines
Currently, the library does not use these syscalls when mounting (it still uses /proc/#/mountinfo). However, there is already a library API to fetch mount information from the kernel using listmount+statmount, and it can be accessed from the command line using:
findmnt --kernel=listmount
Very cool. I need to play with findmnt more.
Quoted 5 lines
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.
New fanotify events for mount table changes, perhaps?
Signature · 1 line
Jeff Layton <[email protected]>
Jan Kara
reviewerQuoted 9 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.New fanotify events for mount table changes, perhaps?
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 12 lines · Jan Kara
Quoted 9 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.New fanotify events for mount table changes, perhaps?
Quoted 7 lines
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like
FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?
Yeah, if memory serves right what we agreed on was that placing a watch on a mount would result in events being generated for mount/umount/move_mount directly under that mount. So this would not be monitoring the entire namespace as poll on /proc/$$/mountinfo does. IIRC Lennart said that this is okay and even desirable for systemd, since it's only interested in a particular set of mounts.
Thanks,
Miklos
Jan Kara
reviewerQuoted 21 lines · Miklos Szeredi
Quoted 12 lines · Jan Kara
Quoted 9 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.New fanotify events for mount table changes, perhaps?
Quoted 7 lines
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like
FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?
Quoted 6 lines
Yeah, if memory serves right what we agreed on was that placing a watch on a mount would result in events being generated for mount/umount/move_mount directly under that mount. So this would not be monitoring the entire namespace as poll on
/proc/$$/mountinfodoes. IIRC Lennart said that this is okay and even desirable for systemd, since it's only interested in a particular set of mounts.
Oh, right. Thanks for reminding me. And yes, this would fit within what fanotify supports quite nicely.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Jan Kara
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.
Quoted 8 lines
Quoted 1 line
New fanotify events for mount table changes, perhaps?
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like
FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?
I still need to have a look at the existing notifications sub-systems but,
tbh, I also don't think they offer the needed functionality.
The thing that was most useful with David's notifications when I was trying
to improve the mounts handling was the queuing interface. It allowed me to
batch notifications up to around a couple of hundred and grab them in one go
for processing. This significantly lowered the overhead of rapid fire event
processing. The ability to go directly to an individual mount and get it's
information only got about half the improvement I saw, the rest come from the
notifications improvement.
Ian
Jan Kara
reviewerQuoted 21 lines · Ian Kent
Quoted 8 lines · Jan Kara
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.Quoted 8 lines
Quoted 1 line
New fanotify events for mount table changes, perhaps?
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like
FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?I still need to have a look at the existing notifications sub-systems but, tbh, I also don't think they offer the needed functionality.
Quoted 7 lines
The thing that was most useful with David's notifications when I was trying to improve the mounts handling was the queuing interface. It allowed me to batch notifications up to around a couple of hundred and grab them in one go for processing. This significantly lowered the overhead of rapid fire event processing. The ability to go directly to an individual mount and get it's information only got about half the improvement I saw, the rest come from the notifications improvement.
Well, if we implemented the mount notification events in fanotify, then the mount events get queued in the notification group queue and you can process the whole batch of events in one go if you want. So I don't see batching as an issue. What I'm more worried about is that watching the whole system for new mounts is going to be somewhat cumbersome when all you can do is to watch new mounts attached under an existing mount / filesystem.
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 3 lines · Jan Kara
What I'm more worried about is that watching the whole system
for new mounts is going to be somewhat cumbersome when all you can do is to watch new mounts attached under an existing mount / filesystem.
We don't even know if there's a use case for that. I think it would make sense to think about it when/if such a use case emerges. The inode notification interfaces went through that evolution too, no?
Thanks,
Miklos
Quoted 28 lines · Jan Kara
Quoted 20 lines · Ian Kent
Quoted 8 lines · Jan Kara
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.Quoted 8 lines
Quoted 1 line
New fanotify events for mount table changes, perhaps?
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like
FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?I still need to have a look at the existing notifications sub-systems but, tbh, I also don't think they offer the needed functionality.
Quoted 7 lines
The thing that was most useful with David's notifications when I was trying to improve the mounts handling was the queuing interface. It allowed me to batch notifications up to around a couple of hundred and grab them in one go for processing. This significantly lowered the overhead of rapid fire event processing. The ability to go directly to an individual mount and get it's information only got about half the improvement I saw, the rest come from the notifications improvement.
Quoted 6 lines
Well, if we implemented the mount notification events in fanotify, then the mount events get queued in the notification group queue and you can process the whole batch of events in one go if you want. So I don't see batching as an issue. What I'm more worried about is that watching the whole system for new mounts is going to be somewhat cumbersome when all you can do is to watch new mounts attached under an existing mount / filesystem.
But, for mounts/unounts for example, isn't it the act of performing the
mount/unmount that triggers the notification if the path in within a file
system that's marked to report such events?
Ian
Jan Kara
reviewerQuoted 36 lines · Ian Kent
Quoted 28 lines · Jan Kara
Quoted 20 lines · Ian Kent
Quoted 8 lines · Jan Kara
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.Quoted 8 lines
Quoted 1 line
New fanotify events for mount table changes, perhaps?
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like
FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?I still need to have a look at the existing notifications sub-systems but, tbh, I also don't think they offer the needed functionality.
Quoted 7 lines
The thing that was most useful with David's notifications when I was trying to improve the mounts handling was the queuing interface. It allowed me to batch notifications up to around a couple of hundred and grab them in one go for processing. This significantly lowered the overhead of rapid fire event processing. The ability to go directly to an individual mount and get it's information only got about half the improvement I saw, the rest come from the notifications improvement.
Quoted 6 lines
Well, if we implemented the mount notification events in fanotify, then the mount events get queued in the notification group queue and you can process the whole batch of events in one go if you want. So I don't see batching as an issue. What I'm more worried about is that watching the whole system for new mounts is going to be somewhat cumbersome when all you can do is to watch new mounts attached under an existing mount / filesystem.
Quoted 3 lines
But, for mounts/unounts for example, isn't it the act of performing the mount/unmount that triggers the notification if the path in within a file system that's marked to report such events?
Obviously it is the act of mounting / unmounting that will trigger the generation of the event. But I guess I don't understand what are you getting at...
Honza
Signature · 2 lines
Jan Kara <[email protected]> SUSE Labs, CR
Quoted 8 lines · Jan Kara
Quoted 7 lines · Jeff Layton
Quoted 6 lines · Karel Zak
On Tue, Nov 12, 2024 at 02:39:21PM GMT, Christian Brauner wrote:
Next on the wish list is a notification (a file descriptor that can be used in epoll) that returns a 64-bit ID when there is a change in the mount node. This will enable us to enhance systemd so that it does not have to read the entire mount table after every change.
Quoted 8 lines
Quoted 1 line
New fanotify events for mount table changes, perhaps?
Now that I'm looking at it I'm not sure fanotify is a great fit for this usecase. A lot of fanotify functionality does not really work for virtual filesystems such as proc and hence we generally try to discourage use of fanotify for them. So just supporting one type of event (like
FAN_MODIFY) on one file inside proc looks as rather inconsistent interface. But I vaguely remember we were discussing some kind of mount event, weren't we? Or was that for something else?
Well, yes, the idea was to be able to avoid the overhead of scanning the
proc mount table(s) pretty much entirely, particularly bad for rapid fire
event handling such as a largish number of rapid mounta or umounts.
Ian
Christian Brauner
maintainerQuoted 29 lines · Jeff Layton
Quoted 12 lines · Karel Zak
Quoted 10 lines · Christian Brauner
Quoted 6 lines · Jeff Layton
Meta has some internal logging that scrapes
/proc/self/mountinfotoday. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.
Quoted 7 lines
Jeff, thank you for this!
I have already implemented support for
statmount()andlistmount()in libmount (PR: https://github.com/util-linux/util-linux/pull/3092). The only remaining issue was the mount source and incomplete file system type.Unfortunately, I think we might be missing something else:
The mountinfo (and "mounts") file generator calls
show_sb_opts()which generates some strings from thesb->s_flagsfield and then callssecurity_sb_show_options().statmount()will give you thes_flagsfield (or an equivalent), but it doesn't give you the security options string. So, those aren't currently visible fromstatmount().
Quoted 3 lines
How should we expose those? Should we create a new statmount string field and populate it, or is it better to just tack them onto the end of the statmount.mnt_opts string?
I'm leaning towards using a separate field because mnt_opts/opts_array is about filesystem specific mount options whereas the security mount options are somewhat generic. So it's easy to tell them apart.
Quoted 30 lines · Christian Brauner
Quoted 29 lines · Jeff Layton
Quoted 12 lines · Karel Zak
Quoted 10 lines · Christian Brauner
Quoted 6 lines · Jeff Layton
Meta has some internal logging that scrapes
/proc/self/mountinfotoday. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them.Applied to the vfs.misc branch of the vfs/vfs.git tree. Patches in the vfs.misc branch should appear in linux-next soon.
Quoted 7 lines
Jeff, thank you for this!
I have already implemented support for
statmount()andlistmount()in libmount (PR: https://github.com/util-linux/util-linux/pull/3092). The only remaining issue was the mount source and incomplete file system type.Unfortunately, I think we might be missing something else:
The mountinfo (and "mounts") file generator calls
show_sb_opts()which generates some strings from thesb->s_flagsfield and then callssecurity_sb_show_options().statmount()will give you thes_flagsfield (or an equivalent), but it doesn't give you the security options string. So, those aren't currently visible fromstatmount().
Quoted 7 lines
Quoted 3 lines
How should we expose those? Should we create a new statmount string field and populate it, or is it better to just tack them onto the end of the statmount.mnt_opts string?
I'm leaning towards using a separate field because mnt_opts/opts_array is about filesystem specific mount options whereas the security mount options are somewhat generic. So it's easy to tell them apart.
Ordinarily, I might agree, but we're now growing a new mount option field that has them separated by NULs. Will we need two extra fields for this? One comma-separated, and one NUL separated?
/proc/#/mountinfo and mounts prepend these to the output of ->show_options, so the simple solution would be to just prepend those there instead of adding a new field. FWIW, only SELinux has any extra mount options to show here.
Tough call -- anyone else have opinions?
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 8 lines · Jeff Layton
Ordinarily, I might agree, but we're now growing a new mount option field that has them separated by NULs. Will we need two extra fields for this? One comma-separated, and one NUL separated?
/proc/#/mountinfo and mounts prepend these to the output of ->show_options, so the simple solution would be to just prepend those there instead of adding a new field. FWIW, only SELinux has any extra mount options to show here.
Compromise: tack them onto the end of the comma separated list, but add a new field for the nul separated security options.
I think this would be logical, since the comma separated list is more useful for having a /proc/$$/mountinfo compatible string than for actually interpreting what's in there.
Thanks,
Miklos
Christian Brauner
maintainerQuoted 11 lines · Miklos Szeredi
Quoted 8 lines · Jeff Layton
Ordinarily, I might agree, but we're now growing a new mount option field that has them separated by NULs. Will we need two extra fields for this? One comma-separated, and one NUL separated?
/proc/#/mountinfo and mounts prepend these to the output of ->show_options, so the simple solution would be to just prepend those there instead of adding a new field. FWIW, only SELinux has any extra mount options to show here.
Quoted 6 lines
Compromise: tack them onto the end of the comma separated list, but add a new field for the nul separated security options.
I think this would be logical, since the comma separated list is more useful for having a
/proc/$$/mountinfocompatible string than for actually interpreting what's in there.
Fair. Here's an incremental for the array of security options.
fs/namespace.c +60 -14
@@ -5072,13 +5072,30 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)return 0 ; } +static inline int statmount_opt_unescape (struct seq_file *seq,char *buf_start) +{ +char *buf_end, *opt_start, *opt_end; +int count =0 ; + + buf_end = seq->buf + seq->count; + *buf_end ='\0' ; +for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { + opt_end =strchrnul (opt_start,',' ); + *opt_end ='\0' ; + buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; +if (WARN_ON_ONCE (++count ==INT_MAX )) +return -EOVERFLOW ; + } + seq->count = buf_start -1 - seq->buf; +return count; +} +static int statmount_opt_array (struct kstatmount *s,struct seq_file *seq) {struct vfsmount *mnt = s->mnt;struct super_block *sb = mnt->mnt_sb;size_t start = seq->count; -char *buf_start, *buf_end, *opt_start, *opt_end; -u32 count =0 ; +char *buf_start;int err;if (!sb->s_op->show_options)
@@ -5095,17 +5112,39 @@ static int statmount_opt_array(struct kstatmount *s, struct seq_file *seq)if (seq->count == start)return 0 ; - buf_end = seq->buf + seq->count; - *buf_end ='\0' ; -for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { - opt_end =strchrnul (opt_start,',' ); - *opt_end ='\0' ; - buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; -if (WARN_ON_ONCE (++count ==0 )) -return -EOVERFLOW ; - } - seq->count = buf_start -1 - seq->buf; - s->sm.opt_num = count; + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_num = err; +return 0 ; +} + +static int statmount_opt_sec_array (struct kstatmount *s,struct seq_file *seq) +{ +struct vfsmount *mnt = s->mnt; +struct super_block *sb = mnt->mnt_sb; +size_t start = seq->count; +char *buf_start; +int err; + + buf_start = seq->buf + start; + + err =security_sb_show_options (seq, sb); +if (!err) +return err; + +if (unlikely (seq_has_overflowed (seq))) +return -EAGAIN ; + +if (seq->count == start) +return 0 ; + + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_sec_num = err;return 0 ; }
@@ -5138,6 +5177,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->opt_array = start; ret =statmount_opt_array (s, seq);break ; +case STATMOUNT_OPT_SEC_ARRAY : + sm->opt_sec_array = start; + ret =statmount_opt_sec_array (s, seq); +break ;case STATMOUNT_FS_SUBTYPE : sm->fs_subtype = start;statmount_fs_subtype (s, seq);
@@ -5294,6 +5337,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_OPT_ARRAY ) err =statmount_string (s,STATMOUNT_OPT_ARRAY ); +if (!err && s->mask &STATMOUNT_OPT_SEC_ARRAY ) + err =statmount_string (s,STATMOUNT_OPT_SEC_ARRAY ); +if (!err && s->mask &STATMOUNT_FS_SUBTYPE ) err =statmount_string (s,STATMOUNT_FS_SUBTYPE );
@@ -5323,7 +5369,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \ STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE | \ - STATMOUNT_OPT_ARRAY) + STATMOUNT_OPT_ARRAY | STATMOUNT_OPT_SEC_ARRAY) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize,
include/uapi/linux/mount.h +4 -1
@@ -177,7 +177,9 @@ struct statmount {__u32 sb_source;/* [str] Source string of the mount */ __u32 opt_num;/* Number of fs options */ __u32 opt_array;/* [str] Array of nul terminated fs options */ -__u64 __spare2[47 ]; +__u32 opt_sec_num;/* Number of security options */ +__u32 opt_sec_array;/* [str] Array of nul terminated security options */ +__u64 __spare2[45 ];char str[];/* Variable size part containing strings */ };
@@ -214,6 +216,7 @@ struct mnt_id_req {#define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ #define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ #define STATMOUNT_OPT_ARRAY 0x00000400U/* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U/* Want/got opt_sec... */ /* * Special @mnt_id values that can be passed to listmount
Quoted 144 lines · Christian Brauner
Quoted 11 lines · Miklos Szeredi
Quoted 8 lines · Jeff Layton
Ordinarily, I might agree, but we're now growing a new mount option field that has them separated by NULs. Will we need two extra fields for this? One comma-separated, and one NUL separated?
/proc/#/mountinfo and mounts prepend these to the output of ->show_options, so the simple solution would be to just prepend those there instead of adding a new field. FWIW, only SELinux has any extra mount options to show here.
Quoted 6 lines
Compromise: tack them onto the end of the comma separated list, but add a new field for the nul separated security options.
I think this would be logical, since the comma separated list is more useful for having a
/proc/$$/mountinfocompatible string than for actually interpreting what's in there.Fair. Here's an incremental for the array of security options.
fs/namespace.c +60
-14@@ -5072,13 +5072,30 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)return 0 ; } +static inline int statmount_opt_unescape (struct seq_file *seq,char *buf_start) +{ +char *buf_end, *opt_start, *opt_end; +int count =0 ; + + buf_end = seq->buf + seq->count; + *buf_end ='\0' ; +for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { + opt_end =strchrnul (opt_start,',' ); + *opt_end ='\0' ; + buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; +if (WARN_ON_ONCE (++count ==INT_MAX )) +return -EOVERFLOW ; + } + seq->count = buf_start -1 - seq->buf; +return count; +} +static int statmount_opt_array (struct kstatmount *s,struct seq_file *seq) {struct vfsmount *mnt = s->mnt;struct super_block *sb = mnt->mnt_sb;size_t start = seq->count; -char *buf_start, *buf_end, *opt_start, *opt_end; -u32 count =0 ; +char *buf_start;int err;if (!sb->s_op->show_options)@@ -5095,17 +5112,39 @@ static int statmount_opt_array(struct kstatmount *s, struct seq_file *seq)if (seq->count == start)return 0 ; - buf_end = seq->buf + seq->count; - *buf_end ='\0' ; -for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { - opt_end =strchrnul (opt_start,',' ); - *opt_end ='\0' ; - buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; -if (WARN_ON_ONCE (++count ==0 )) -return -EOVERFLOW ; - } - seq->count = buf_start -1 - seq->buf; - s->sm.opt_num = count; + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_num = err; +return 0 ; +} + +static int statmount_opt_sec_array (struct kstatmount *s,struct seq_file *seq) +{ +struct vfsmount *mnt = s->mnt; +struct super_block *sb = mnt->mnt_sb; +size_t start = seq->count; +char *buf_start; +int err; + + buf_start = seq->buf + start; + + err =security_sb_show_options (seq, sb); +if (!err) +return err; + +if (unlikely (seq_has_overflowed (seq))) +return -EAGAIN ; + +if (seq->count == start) +return 0 ; + + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_sec_num = err;return 0 ; }@@ -5138,6 +5177,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->opt_array = start; ret =statmount_opt_array (s, seq);break ; +case STATMOUNT_OPT_SEC_ARRAY : + sm->opt_sec_array = start; + ret =statmount_opt_sec_array (s, seq); +break ;case STATMOUNT_FS_SUBTYPE : sm->fs_subtype = start;statmount_fs_subtype (s, seq);@@ -5294,6 +5337,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_OPT_ARRAY ) err =statmount_string (s,STATMOUNT_OPT_ARRAY ); +if (!err && s->mask &STATMOUNT_OPT_SEC_ARRAY ) + err =statmount_string (s,STATMOUNT_OPT_SEC_ARRAY ); +if (!err && s->mask &STATMOUNT_FS_SUBTYPE ) err =statmount_string (s,STATMOUNT_FS_SUBTYPE );@@ -5323,7 +5369,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \ STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE | \ - STATMOUNT_OPT_ARRAY) + STATMOUNT_OPT_ARRAY | STATMOUNT_OPT_SEC_ARRAY) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize,include/uapi/linux/mount.h +0
-0
include/uapi/linux/mount.h struct statmount { · line 182
Quoted 7 lines
include/uapi/linux/mount.h +3
-1@@ -177,7 +177,9 @@ struct statmount {__u32 sb_source;/* [str] Source string of the mount */ __u32 opt_num;/* Number of fs options */ __u32 opt_array;/* [str] Array of nul terminated fs options */ -__u64 __spare2[47 ]; +__u32 opt_sec_num;/* Number of security options */ +__u32 opt_sec_array;/* [str] Array of nul terminated security options */ +__u64 __spare2[45 ];
shouldn't that be 46 ?
include/uapi/linux/mount.h struct mnt_id_req { · line 222
Quoted 11 lines
include/uapi/linux/mount.h +1
-0char str[];/* Variable size part containing strings */ };@@ -214,6 +216,7 @@ struct mnt_id_req {#define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ #define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ #define STATMOUNT_OPT_ARRAY 0x00000400U/* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U/* Want/got opt_sec... */ /* * Special @mnt_id values that can be passed to listmount
The rest looks good to me though!
Signature · 1 line
Jeff Layton <[email protected]>
Christian Brauner
maintainerQuoted 138 lines · Jeff Layton
Quoted 137 lines · Christian Brauner
Quoted 11 lines · Miklos Szeredi
Quoted 8 lines · Jeff Layton
Ordinarily, I might agree, but we're now growing a new mount option field that has them separated by NULs. Will we need two extra fields for this? One comma-separated, and one NUL separated?
/proc/#/mountinfo and mounts prepend these to the output of ->show_options, so the simple solution would be to just prepend those there instead of adding a new field. FWIW, only SELinux has any extra mount options to show here.
Quoted 6 lines
Compromise: tack them onto the end of the comma separated list, but add a new field for the nul separated security options.
I think this would be logical, since the comma separated list is more useful for having a
/proc/$$/mountinfocompatible string than for actually interpreting what's in there.Fair. Here's an incremental for the array of security options.
fs/namespace.c +60
-14@@ -5072,13 +5072,30 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)return 0 ; } +static inline int statmount_opt_unescape (struct seq_file *seq,char *buf_start) +{ +char *buf_end, *opt_start, *opt_end; +int count =0 ; + + buf_end = seq->buf + seq->count; + *buf_end ='\0' ; +for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { + opt_end =strchrnul (opt_start,',' ); + *opt_end ='\0' ; + buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; +if (WARN_ON_ONCE (++count ==INT_MAX )) +return -EOVERFLOW ; + } + seq->count = buf_start -1 - seq->buf; +return count; +} +static int statmount_opt_array (struct kstatmount *s,struct seq_file *seq) {struct vfsmount *mnt = s->mnt;struct super_block *sb = mnt->mnt_sb;size_t start = seq->count; -char *buf_start, *buf_end, *opt_start, *opt_end; -u32 count =0 ; +char *buf_start;int err;if (!sb->s_op->show_options)@@ -5095,17 +5112,39 @@ static int statmount_opt_array(struct kstatmount *s, struct seq_file *seq)if (seq->count == start)return 0 ; - buf_end = seq->buf + seq->count; - *buf_end ='\0' ; -for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { - opt_end =strchrnul (opt_start,',' ); - *opt_end ='\0' ; - buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; -if (WARN_ON_ONCE (++count ==0 )) -return -EOVERFLOW ; - } - seq->count = buf_start -1 - seq->buf; - s->sm.opt_num = count; + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_num = err; +return 0 ; +} + +static int statmount_opt_sec_array (struct kstatmount *s,struct seq_file *seq) +{ +struct vfsmount *mnt = s->mnt; +struct super_block *sb = mnt->mnt_sb; +size_t start = seq->count; +char *buf_start; +int err; + + buf_start = seq->buf + start; + + err =security_sb_show_options (seq, sb); +if (!err) +return err; + +if (unlikely (seq_has_overflowed (seq))) +return -EAGAIN ; + +if (seq->count == start) +return 0 ; + + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_sec_num = err;return 0 ; }@@ -5138,6 +5177,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->opt_array = start; ret =statmount_opt_array (s, seq);break ; +case STATMOUNT_OPT_SEC_ARRAY : + sm->opt_sec_array = start; + ret =statmount_opt_sec_array (s, seq); +break ;case STATMOUNT_FS_SUBTYPE : sm->fs_subtype = start;statmount_fs_subtype (s, seq);@@ -5294,6 +5337,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_OPT_ARRAY ) err =statmount_string (s,STATMOUNT_OPT_ARRAY ); +if (!err && s->mask &STATMOUNT_OPT_SEC_ARRAY ) + err =statmount_string (s,STATMOUNT_OPT_SEC_ARRAY ); +if (!err && s->mask &STATMOUNT_FS_SUBTYPE ) err =statmount_string (s,STATMOUNT_FS_SUBTYPE );@@ -5323,7 +5369,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \ STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE | \ - STATMOUNT_OPT_ARRAY) + STATMOUNT_OPT_ARRAY | STATMOUNT_OPT_SEC_ARRAY)
Quoted 16 lines
Quoted 7 lines
fs/namespace.c +0
-0static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize,include/uapi/linux/mount.h +0
-0include/uapi/linux/mount.h struct statmount { · line 182
Quoted 7 lines
include/uapi/linux/mount.h +3
-1@@ -177,7 +177,9 @@ struct statmount {__u32 sb_source;/* [str] Source string of the mount */ __u32 opt_num;/* Number of fs options */ __u32 opt_array;/* [str] Array of nul terminated fs options */ -__u64 __spare2[47 ]; +__u32 opt_sec_num;/* Number of security options */ +__u32 opt_sec_array;/* [str] Array of nul terminated security options */ +__u64 __spare2[45 ];shouldn't that be 46 ?
Yes, apparently I can't count. Thanks for noticing!
Quoted 16 lines
include/uapi/linux/mount.h struct mnt_id_req { · line 222
Quoted 12 lines
include/uapi/linux/mount.h +1
-0char str[];/* Variable size part containing strings */ };@@ -214,6 +216,7 @@ struct mnt_id_req {#define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ #define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ #define STATMOUNT_OPT_ARRAY 0x00000400U/* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U/* Want/got opt_sec... */ /* * Special @mnt_id values that can be passed to listmount The rest looks good to me though!
Signature · 1 line
Jeff Layton <[email protected]>
Christian Brauner
maintainerPATCH 1/1 statmount: retrieve security mount options
Add the ability to retrieve security mount options. Keep them separate from filesystem specific mount options so it's easy to tell them apart. Also allow to retrieve them separate from other mount options as most of the time users won't be interested in security specific mount options.
---
How do we feel about including this for v6.13 or should I rather delay it?
--- fs/namespace.c | 74 ++++++++++++++++++++++++++++++-------- include/uapi/linux/mount.h | 5 ++- 2 files changed, 64 insertions(+), 15 deletions(-)
fs/namespace.c +60 -14
@@ -5072,13 +5072,30 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)return 0 ; } +static inline int statmount_opt_unescape (struct seq_file *seq,char *buf_start) +{ +char *buf_end, *opt_start, *opt_end; +int count =0 ; + + buf_end = seq->buf + seq->count; + *buf_end ='\0' ; +for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { + opt_end =strchrnul (opt_start,',' ); + *opt_end ='\0' ; + buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; +if (WARN_ON_ONCE (++count ==INT_MAX )) +return -EOVERFLOW ; + } + seq->count = buf_start -1 - seq->buf; +return count; +} +static int statmount_opt_array (struct kstatmount *s,struct seq_file *seq) {struct vfsmount *mnt = s->mnt;struct super_block *sb = mnt->mnt_sb;size_t start = seq->count; -char *buf_start, *buf_end, *opt_start, *opt_end; -u32 count =0 ; +char *buf_start;int err;if (!sb->s_op->show_options)
@@ -5095,17 +5112,39 @@ static int statmount_opt_array(struct kstatmount *s, struct seq_file *seq)if (seq->count == start)return 0 ; - buf_end = seq->buf + seq->count; - *buf_end ='\0' ; -for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { - opt_end =strchrnul (opt_start,',' ); - *opt_end ='\0' ; - buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; -if (WARN_ON_ONCE (++count ==0 )) -return -EOVERFLOW ; - } - seq->count = buf_start -1 - seq->buf; - s->sm.opt_num = count; + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_num = err; +return 0 ; +} + +static int statmount_opt_sec_array (struct kstatmount *s,struct seq_file *seq) +{ +struct vfsmount *mnt = s->mnt; +struct super_block *sb = mnt->mnt_sb; +size_t start = seq->count; +char *buf_start; +int err; + + buf_start = seq->buf + start; + + err =security_sb_show_options (seq, sb); +if (!err) +return err; + +if (unlikely (seq_has_overflowed (seq))) +return -EAGAIN ; + +if (seq->count == start) +return 0 ; + + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_sec_num = err;return 0 ; }
@@ -5138,6 +5177,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->opt_array = start; ret =statmount_opt_array (s, seq);break ; +case STATMOUNT_OPT_SEC_ARRAY : + sm->opt_sec_array = start; + ret =statmount_opt_sec_array (s, seq); +break ;case STATMOUNT_FS_SUBTYPE : sm->fs_subtype = start;statmount_fs_subtype (s, seq);
@@ -5294,6 +5337,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_OPT_ARRAY ) err =statmount_string (s,STATMOUNT_OPT_ARRAY ); +if (!err && s->mask &STATMOUNT_OPT_SEC_ARRAY ) + err =statmount_string (s,STATMOUNT_OPT_SEC_ARRAY ); +if (!err && s->mask &STATMOUNT_FS_SUBTYPE ) err =statmount_string (s,STATMOUNT_FS_SUBTYPE );
@@ -5323,7 +5369,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \ STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE | \ - STATMOUNT_OPT_ARRAY) + STATMOUNT_OPT_ARRAY | STATMOUNT_OPT_SEC_ARRAY) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize,
include/uapi/linux/mount.h +4 -1
@@ -177,7 +177,9 @@ struct statmount {__u32 sb_source;/* [str] Source string of the mount */ __u32 opt_num;/* Number of fs options */ __u32 opt_array;/* [str] Array of nul terminated fs options */ -__u64 __spare2[47 ]; +__u32 opt_sec_num;/* Number of security options */ +__u32 opt_sec_array;/* [str] Array of nul terminated security options */ +__u64 __spare2[46 ];char str[];/* Variable size part containing strings */ };
@@ -214,6 +216,7 @@ struct mnt_id_req {#define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ #define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ #define STATMOUNT_OPT_ARRAY 0x00000400U/* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U/* Want/got opt_sec... */ /* * Special @mnt_id values that can be passed to listmount
Signature · 1 line
2.45.2
Re: [PATCH] statmount: retrieve security mount options
Quoted 8 lines · Christian Brauner
Add the ability to retrieve security mount options. Keep them separate from filesystem specific mount options so it's easy to tell them apart. Also allow to retrieve them separate from other mount options as most of the time users won't be interested in security specific mount options.
Signed-off-by Christian Brauner <[email protected]>---
How do we feel about including this for v6.13 or should I rather delay it?
I say put it in. This is pretty straightforward stuff.
Quoted 139 lines
--- fs/namespace.c | 74 ++++++++++++++++++++++++++++++-------- include/uapi/linux/mount.h | 5 ++- 2 files changed, 64 insertions(+), 15 deletions(-)fs/namespace.c +60
-14@@ -5072,13 +5072,30 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)return 0 ; } +static inline int statmount_opt_unescape (struct seq_file *seq,char *buf_start) +{ +char *buf_end, *opt_start, *opt_end; +int count =0 ; + + buf_end = seq->buf + seq->count; + *buf_end ='\0' ; +for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { + opt_end =strchrnul (opt_start,',' ); + *opt_end ='\0' ; + buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; +if (WARN_ON_ONCE (++count ==INT_MAX )) +return -EOVERFLOW ; + } + seq->count = buf_start -1 - seq->buf; +return count; +} +static int statmount_opt_array (struct kstatmount *s,struct seq_file *seq) {struct vfsmount *mnt = s->mnt;struct super_block *sb = mnt->mnt_sb;size_t start = seq->count; -char *buf_start, *buf_end, *opt_start, *opt_end; -u32 count =0 ; +char *buf_start;int err;if (!sb->s_op->show_options)@@ -5095,17 +5112,39 @@ static int statmount_opt_array(struct kstatmount *s, struct seq_file *seq)if (seq->count == start)return 0 ; - buf_end = seq->buf + seq->count; - *buf_end ='\0' ; -for (opt_start = buf_start +1 ; opt_start < buf_end; opt_start = opt_end +1 ) { - opt_end =strchrnul (opt_start,',' ); - *opt_end ='\0' ; - buf_start +=string_unescape (opt_start, buf_start,0 ,UNESCAPE_OCTAL ) +1 ; -if (WARN_ON_ONCE (++count ==0 )) -return -EOVERFLOW ; - } - seq->count = buf_start -1 - seq->buf; - s->sm.opt_num = count; + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_num = err; +return 0 ; +} + +static int statmount_opt_sec_array (struct kstatmount *s,struct seq_file *seq) +{ +struct vfsmount *mnt = s->mnt; +struct super_block *sb = mnt->mnt_sb; +size_t start = seq->count; +char *buf_start; +int err; + + buf_start = seq->buf + start; + + err =security_sb_show_options (seq, sb); +if (!err) +return err; + +if (unlikely (seq_has_overflowed (seq))) +return -EAGAIN ; + +if (seq->count == start) +return 0 ; + + err =statmount_opt_unescape (seq, buf_start); +if (err <0 ) +return err; + + s->sm.opt_sec_num = err;return 0 ; }@@ -5138,6 +5177,10 @@ static int statmount_string(struct kstatmount *s, u64 flag) sm->opt_array = start; ret =statmount_opt_array (s, seq);break ; +case STATMOUNT_OPT_SEC_ARRAY : + sm->opt_sec_array = start; + ret =statmount_opt_sec_array (s, seq); +break ;case STATMOUNT_FS_SUBTYPE : sm->fs_subtype = start;statmount_fs_subtype (s, seq);@@ -5294,6 +5337,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_OPT_ARRAY ) err =statmount_string (s,STATMOUNT_OPT_ARRAY ); +if (!err && s->mask &STATMOUNT_OPT_SEC_ARRAY ) + err =statmount_string (s,STATMOUNT_OPT_SEC_ARRAY ); +if (!err && s->mask &STATMOUNT_FS_SUBTYPE ) err =statmount_string (s,STATMOUNT_FS_SUBTYPE );@@ -5323,7 +5369,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \ STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \ STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE | \ - STATMOUNT_OPT_ARRAY) + STATMOUNT_OPT_ARRAY | STATMOUNT_OPT_SEC_ARRAY) static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq, struct statmount __user *buf, size_t bufsize,include/uapi/linux/mount.h +3
-1@@ -177,7 +177,9 @@ struct statmount {__u32 sb_source;/* [str] Source string of the mount */ __u32 opt_num;/* Number of fs options */ __u32 opt_array;/* [str] Array of nul terminated fs options */ -__u64 __spare2[47 ]; +__u32 opt_sec_num;/* Number of security options */ +__u32 opt_sec_array;/* [str] Array of nul terminated security options */ +__u64 __spare2[46 ];char str[];/* Variable size part containing strings */ };
include/uapi/linux/mount.h struct mnt_id_req { · line 222
Quoted 7 lines
include/uapi/linux/mount.h +1
-0@@ -214,6 +216,7 @@ struct mnt_id_req {#define STATMOUNT_FS_SUBTYPE 0x00000100U/* Want/got fs_subtype */ #define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ #define STATMOUNT_OPT_ARRAY 0x00000400U/* Want/got opt_... */ +#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U/* Want/got opt_sec... */ /* * Special @mnt_id values that can be passed to listmount