Modern mount tools (util-linux >= 2.39.1) use the new mount API
(fsopen, fsconfig, fsmount, move_mount) instead of the legacy mount(2)
syscall. The generic SYSCALL audit record logs the move_mount syscall
but does not capture the flags argument, creating an audit gap for
mount relocation operations.

Add a MOVE_MOUNT auxiliary record that logs the flags argument passed
to move_mount(2). Pathnames and file descriptors are captured through
existing PATH records and SYSCALL record arguments.

 ----
 type=PATH : item=0 name=/mnt/test_src inode=1 dev=00:41 ...
 type=SYSCALL : arch=x86_64 syscall=move_mount ...
 type=MOVE_MOUNT : fs_flags=0x4
 ----
 type=PATH : item=0 name=/mnt/test_dst inode=27460862 dev=fc:00 ...
 type=SYSCALL : arch=x86_64 syscall=move_mount ...
 type=MOVE_MOUNT : fs_flags=0x4

Link: https://github.com/linux-audit/audit-kernel/issues/152
Link: https://github.com/linux-audit/audit-kernel/issues/153
Signed-off-by: Ricardo Robaina <[email protected]>
---
 fs/namespace.c             |  3 +++
 include/linux/audit.h      | 10 ++++++++++
 include/uapi/linux/audit.h |  1 +
 kernel/auditsc.c           | 13 +++++++++++++
 4 files changed, 27 insertions(+)

diff --git a/fs/namespace.c b/fs/namespace.c
index 3d5cd5bf3b05..a6b0286744d9 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -34,6 +34,7 @@
 #include <linux/mnt_idmapping.h>
 #include <linux/pidfs.h>
 #include <linux/nstree.h>
+#include <linux/audit.h>
 
 #include "pnode.h"
 #include "internal.h"
@@ -4625,6 +4626,8 @@ SYSCALL_DEFINE5(move_mount,
        if (flags & MOVE_MOUNT_F_EMPTY_PATH)
                uflags = AT_EMPTY_PATH;
 
+       audit_log_move_mount(flags);
+
        CLASS(filename_maybe_null,from_name)(from_pathname, uflags);
        if (!from_name && from_dfd >= 0) {
                CLASS(fd_raw, f_from)(from_dfd);
diff --git a/include/linux/audit.h b/include/linux/audit.h
index 45abb3722d30..d1dc4035cb3c 100644
--- a/include/linux/audit.h
+++ b/include/linux/audit.h
@@ -449,6 +449,7 @@ extern void __audit_tk_injoffset(struct timespec64 offset);
 extern void __audit_ntp_log(const struct audit_ntp_data *ad);
 extern void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
                              enum audit_nfcfgop op, gfp_t gfp);
+extern void __audit_log_move_mount(unsigned int flags);
 
 static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp)
 {
@@ -598,6 +599,12 @@ static inline void audit_log_nfcfg(const char *name, u8 af,
                __audit_log_nfcfg(name, af, nentries, op, gfp);
 }
 
+static inline void audit_log_move_mount(unsigned int flags)
+{
+       if (!audit_dummy_context())
+               __audit_log_move_mount(flags);
+}
+
 extern int audit_n_rules;
 extern int audit_signals;
 #else /* CONFIG_AUDITSYSCALL */
@@ -730,6 +737,9 @@ static inline void audit_log_nfcfg(const char *name, u8 af,
                                   enum audit_nfcfgop op, gfp_t gfp)
 { }
 
+static inline void audit_log_move_mount(unsigned int flags)
+{ }
+
 #define audit_n_rules 0
 #define audit_signals 0
 #endif /* CONFIG_AUDITSYSCALL */
diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index e8f5ce677df7..40abf3dfd307 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -122,6 +122,7 @@
 #define AUDIT_OPENAT2          1337    /* Record showing openat2 how args */
 #define AUDIT_DM_CTRL          1338    /* Device Mapper target control */
 #define AUDIT_DM_EVENT         1339    /* Device Mapper events */
+#define AUDIT_MOVE_MOUNT       1342    /* Record showing move_mount flags */
 
 #define AUDIT_AVC              1400    /* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR      1401    /* Internal SE Linux Errors */
diff --git a/kernel/auditsc.c b/kernel/auditsc.c
index 6610e667c728..4aca04d33d00 100644
--- a/kernel/auditsc.c
+++ b/kernel/auditsc.c
@@ -2882,6 +2882,19 @@ void __audit_log_nfcfg(const char *name, u8 af, unsigned 
int nentries,
 }
 EXPORT_SYMBOL_GPL(__audit_log_nfcfg);
 
+void __audit_log_move_mount(unsigned int flags)
+{
+       struct audit_buffer *ab;
+
+       ab = audit_log_start(audit_context(), GFP_KERNEL,
+                            AUDIT_MOVE_MOUNT);
+       if (!ab)
+               return;
+
+       audit_log_format(ab, "fs_flags=0x%x", flags);
+       audit_log_end(ab);
+}
+
 static void audit_log_task(struct audit_buffer *ab)
 {
        kuid_t auid, uid;
-- 
2.53.0


Reply via email to