Skip to contentSkip to conversation

audit: add CLONE3 auxiliary record to log process cloning

PATCH In review Ricardo Robaina 4 participants 5 messages Jul 24 – Aug 21

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 audit: add CLONE3 auxiliary record to log process cloning

The clone3(2) syscall moves most parameters to struct clone_args. For this reason, the generic SYSCALL audit record does not capture the structured arguments.

Add a CLONE3 auxiliary record that logs: flags, exit_signal, cgroup, and pidfd fields from struct clone_args. When CLONE_PIDFD is set and the syscall succeeds, the resolved pidfd is logged; otherwise pidfd=(null).

----
type=SYSCALL : syscall=clone3 a0=0x7ffe7f1ec640 a1=0x58 a2=0x0 ... type=CLONE3 : cl3_flags=0x1000 exit_signal=17 cgroup=0 pidfd=3

---
 include/linux/audit.h      | 10 ++++++++++
 include/uapi/linux/audit.h |  1 +
 kernel/auditsc.c           | 20 ++++++++++++++++++++
 kernel/fork.c              |  4 +++-
 4 files changed, 34 insertions(+), 1 deletion(-)
include/linux/audit.h +10 -0
index 45abb3722d30..833f349bf415 100644
@@ -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_clone3(struct kernel_clone_args *kargs, int ret);
 
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{
+	if (!audit_dummy_context())
+		__audit_log_clone3(kargs, ret);
+}
+
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{ }
+
 #define audit_n_rules 0
 #define audit_signals 0
 #endif /* CONFIG_AUDITSYSCALL */
include/uapi/linux/audit.h +1 -0
index e8f5ce677df7..37357e17adbf 100644
@@ -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_CLONE3		1343	/* Record showing clone3 args */
 
 #define AUDIT_AVC		1400	/* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR	1401	/* Internal SE Linux Errors */
kernel/auditsc.c +20 -0
index 6610e667c728..c0106bb71c19 100644
@@ -2882,6 +2882,26 @@ void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
 }
 EXPORT_SYMBOL_GPL(__audit_log_nfcfg);
 
+void __audit_log_clone3(struct kernel_clone_args *kargs, int ret)
+{
+	struct audit_buffer *ab;
+	int pidfd;
+
+	ab = audit_log_start(audit_context(), GFP_KERNEL,
+			     AUDIT_CLONE3);
+	if (!ab)
+		return;
+
+	audit_log_format(ab, "cl3_flags=0x%llx exit_signal=%d cgroup=%d",
+			 kargs->flags, kargs->exit_signal, kargs->cgroup);
+	if ((kargs->flags & CLONE_PIDFD) && ret >= 0 &&
+	    !get_user(pidfd, kargs->pidfd))
+		audit_log_format(ab, " pidfd=%d", pidfd);
+	else
+		audit_log_format(ab, " pidfd=(null)");
+	audit_log_end(ab);
+}
+
 static void audit_log_task(struct audit_buffer *ab)
 {
 	kuid_t auid, uid;
kernel/fork.c +3 -1
index f0e2e131a9a5..0f52e8c0e900 100644
@@ -3047,7 +3047,9 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)
 	if (!clone3_args_valid(&kargs))
 		return -EINVAL;
 
-	return kernel_clone(&kargs);
+	err = kernel_clone(&kargs);
+	audit_log_clone3(&kargs, err);
+	return err;
 }
 
 void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data)
Signature · 1 line
2.53.0
#1 lore raw
Quoted 79 lines · Ricardo Robaina

The clone3(2) syscall moves most parameters to struct clone_args. For this reason, the generic SYSCALL audit record does not capture the structured arguments.

Add a CLONE3 auxiliary record that logs: flags, exit_signal, cgroup, and pidfd fields from struct clone_args. When CLONE_PIDFD is set and the syscall succeeds, the resolved pidfd is logged; otherwise pidfd=(null).

----
type=SYSCALL : syscall=clone3 a0=0x7ffe7f1ec640 a1=0x58 a2=0x0 ... type=CLONE3 : cl3_flags=0x1000 exit_signal=17 cgroup=0 pidfd=3

---
 include/linux/audit.h      | 10 ++++++++++
 include/uapi/linux/audit.h |  1 +
 kernel/auditsc.c           | 20 ++++++++++++++++++++
 kernel/fork.c              |  4 +++-
 4 files changed, 34 insertions(+), 1 deletion(-)
include/linux/audit.h +10 -0
index 45abb3722d30..833f349bf415 100644
@@ -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_clone3(struct kernel_clone_args *kargs, int ret);
 
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{
+	if (!audit_dummy_context())
+		__audit_log_clone3(kargs, ret);
+}
+
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{ }
+
 #define audit_n_rules 0
 #define audit_signals 0
 #endif /* CONFIG_AUDITSYSCALL */
include/uapi/linux/audit.h +1 -0
index e8f5ce677df7..37357e17adbf 100644
@@ -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_CLONE3		1343	/* Record showing clone3 args */
 
 #define AUDIT_AVC		1400	/* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR	1401	/* Internal SE Linux Errors */
kernel/auditsc.c +2 -0
index 6610e667c728..c0106bb71c19 100644
@@ -2882,6 +2882,26 @@ void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
 }
 EXPORT_SYMBOL_GPL(__audit_log_nfcfg);
 
+void __audit_log_clone3(struct kernel_clone_args *kargs, int ret)
+{

kernel/auditsc.c void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, · line 2896

Quoted 10 lines
kernel/auditsc.c +10 -0
+	struct audit_buffer *ab;
+	int pidfd;
+
+	ab = audit_log_start(audit_context(), GFP_KERNEL,
+			     AUDIT_CLONE3);
+	if (!ab)
+		return;
+
+	audit_log_format(ab, "cl3_flags=0x%llx exit_signal=%d cgroup=%d",
+			 kargs->flags, kargs->exit_signal, kargs->cgroup);

Would there be any confusion if this were simply "flags=..." since it is already a record type AUDIT_CLONE3?

kernel/auditsc.c void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, · line 2901

Quoted 5 lines
kernel/auditsc.c +5 -0
+	if ((kargs->flags & CLONE_PIDFD) && ret >= 0 &&
+	    !get_user(pidfd, kargs->pidfd))
+		audit_log_format(ab, " pidfd=%d", pidfd);
+	else
+		audit_log_format(ab, " pidfd=(null)");

Is there any interest in:
child_tid (was captured by generic audit syscall arg 4) parent_tid (was captured by generic audit syscall arg 3 or 4) tls (was captured by generic audit syscall arg 4) set_tid

Is there a situation where a valid pid is returned without CLONE_PIDFD set?

Otherwise, looks reasonable to me.

Quoted 23 lines
kernel/auditsc.c +3 -0
+	audit_log_end(ab);
+}
+
 static void audit_log_task(struct audit_buffer *ab)
 {
 	kuid_t auid, uid;
kernel/fork.c +3 -1
index f0e2e131a9a5..0f52e8c0e900 100644
@@ -3047,7 +3047,9 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)
 	if (!clone3_args_valid(&kargs))
 		return -EINVAL;
 
-	return kernel_clone(&kargs);
+	err = kernel_clone(&kargs);
+	audit_log_clone3(&kargs, err);
+	return err;
 }
 
 void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data)
Signature · 1 line
2.53.0

- RGB

--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
Upstream IRC: SunRaycer
Voice: +1.613.860 2354 SMS: +1.613.518.6570

#2 lore raw
Quoted 72 lines · Eastern Daylight Time Richard Guy Briggs
Quoted 71 lines · Ricardo Robaina

The clone3(2) syscall moves most parameters to struct clone_args. For this reason, the generic SYSCALL audit record does not capture the structured arguments.

Add a CLONE3 auxiliary record that logs: flags, exit_signal, cgroup, and pidfd fields from struct clone_args. When CLONE_PIDFD is set and the syscall succeeds, the resolved pidfd is logged; otherwise pidfd=(null).

----
type=SYSCALL : syscall=clone3 a0=0x7ffe7f1ec640 a1=0x58 a2=0x0 ... type=CLONE3 : cl3_flags=0x1000 exit_signal=17 cgroup=0 pidfd=3

---

 include/linux/audit.h      | 10 ++++++++++
 include/uapi/linux/audit.h |  1 +
 kernel/auditsc.c           | 20 ++++++++++++++++++++
 kernel/fork.c              |  4 +++-
 4 files changed, 34 insertions(+), 1 deletion(-)
include/linux/audit.h +0 -0
index 45abb3722d30..833f349bf415 100644
@@ -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,>

include/linux/audit.h +1 -0
 			      enum audit_nfcfgop op, gfp_t gfp);
 
+extern void __audit_log_clone3(struct kernel_clone_args *kargs, int

ret);

static inline void audit_ipc_obj(struct kern_ipc_perm *ipcp) {

include/linux/audit.h +0 -0
@@ -598,6 +599,12 @@ static inline void audit_log_nfcfg(const char *name,

u8 af,>

include/linux/audit.h +1 -0
 		__audit_log_nfcfg(name, af, nentries, op, gfp);
 
 }
 
+static inline void audit_log_clone3(struct kernel_clone_args *kargs, int

ret) +{

include/linux/audit.h +4 -0
+	if (!audit_dummy_context())
+		__audit_log_clone3(kargs, ret);
+}
+
 
 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,>

include/linux/audit.h +1 -0
 				   enum audit_nfcfgop op, gfp_t gfp)
 
 { }
 
+static inline void audit_log_clone3(struct kernel_clone_args *kargs, int

ret) +{ }
+

#define audit_n_rules 0
#define audit_signals 0
#endif /* CONFIG_AUDITSYSCALL */

Quoted 7 lines

include/uapi/linux/audit.h line 123

Quoted 7 lines
include/uapi/linux/audit.h +0 -0
index e8f5ce677df7..37357e17adbf 100644
@@ -122,6 +122,7 @@
 
 #define AUDIT_OPENAT2		1337	/* Record showing openat2 how args 

*/

Quoted 17 lines
Quoted 17 lines
include/uapi/linux/audit.h +1 -0
 #define AUDIT_DM_CTRL		1338	/* Device Mapper target control */
 #define AUDIT_DM_EVENT		1339	/* Device Mapper events */
 
+#define AUDIT_CLONE3		1343	/* Record showing clone3 args */
 

#define AUDIT_AVC 1400 /* SE Linux avc denial or grant */
#define AUDIT_SELINUX_ERR 1401 /* Internal SE Linux Errors */

kernel/auditsc.c +0 -0
index 6610e667c728..c0106bb71c19 100644
@@ -2882,6 +2882,26 @@ void __audit_log_nfcfg(const char *name, u8 af,

unsigned int nentries,>
}
EXPORT_SYMBOL_GPL(__audit_log_nfcfg);

Quoted 15 lines

kernel/auditsc.c void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, · line 2896

Quoted 12 lines
kernel/auditsc.c +12 -0
+void __audit_log_clone3(struct kernel_clone_args *kargs, int ret)
+{
+	struct audit_buffer *ab;
+	int pidfd;
+
+	ab = audit_log_start(audit_context(), GFP_KERNEL,
+			     AUDIT_CLONE3);
+	if (!ab)
+		return;
+
+	audit_log_format(ab, "cl3_flags=0x%llx exit_signal=%d cgroup=%d",
+			 kargs->flags, kargs->exit_signal, kargs->cgroup);

Would there be any confusion if this were simply "flags=..." since it is already a record type AUDIT_CLONE3?

flags is already used in mmap records and will require workarounds to have the same field name here. Separating them by name is better.

Quoted 11 lines

kernel/auditsc.c void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, · line 2901

Quoted 5 lines
kernel/auditsc.c +5 -0
+	if ((kargs->flags & CLONE_PIDFD) && ret >= 0 &&
+	    !get_user(pidfd, kargs->pidfd))
+		audit_log_format(ab, " pidfd=%d", pidfd);
+	else
+		audit_log_format(ab, " pidfd=(null)");

Is there any interest in:
child_tid (was captured by generic audit syscall arg 4) parent_tid (was captured by generic audit syscall arg 3 or 4) tls (was captured by generic audit syscall arg 4) set_tid

Nope. Those are more resource related and not security focused. Even if you wanted it, these are pointers to the answer and not the answer. The patch has everything needed from a security PoV.

Ack.

Quoted 1 line

Is there a situation where a valid pid is returned without CLONE_PIDFD set?

No idea. The man page makes it sound like it is only valid when CLONE_PIDFD. Besides, its a pointer to an int from what the man page said.

-Steve

Quoted 38 lines

Otherwise, looks reasonable to me.

Quoted 18 lines
kernel/auditsc.c +3 -0
+	audit_log_end(ab);
+}
+
 
 static void audit_log_task(struct audit_buffer *ab)
 {
 
 	kuid_t auid, uid;
kernel/fork.c +0 -0
index f0e2e131a9a5..0f52e8c0e900 100644
@@ -3047,7 +3047,9 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *,

uargs, size_t, size)>

kernel/fork.c +0 -0
 	if (!clone3_args_valid(&kargs))
 
 		return -EINVAL;

kernel/fork.c SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)

Quoted 10 lines
kernel/fork.c +3 -1
 
-	return kernel_clone(&kargs);
+	err = kernel_clone(&kargs);
+	audit_log_clone3(&kargs, err);
+	return err;
 
 }
 
 void walk_process_tree(struct task_struct *top, proc_visitor visitor,
 void *data)

- RGB

--
Richard Guy Briggs <[email protected]>
Sr. S/W Engineer, Kernel Security, Base Operating Systems Remote, Ottawa, Red Hat Canada
Upstream IRC: SunRaycer
Voice: +1.613.860 2354 SMS: +1.613.518.6570

maintainer
#3 lore raw
In reply to Ricardo Robaina
Quoted 83 lines · Ricardo Robaina

The clone3(2) syscall moves most parameters to struct clone_args. For this reason, the generic SYSCALL audit record does not capture the structured arguments.

Add a CLONE3 auxiliary record that logs: flags, exit_signal, cgroup, and pidfd fields from struct clone_args. When CLONE_PIDFD is set and the syscall succeeds, the resolved pidfd is logged; otherwise pidfd=(null).

----
type=SYSCALL : syscall=clone3 a0=0x7ffe7f1ec640 a1=0x58 a2=0x0 ... type=CLONE3 : cl3_flags=0x1000 exit_signal=17 cgroup=0 pidfd=3

---
 include/linux/audit.h      | 10 ++++++++++
 include/uapi/linux/audit.h |  1 +
 kernel/auditsc.c           | 20 ++++++++++++++++++++
 kernel/fork.c              |  4 +++-
 4 files changed, 34 insertions(+), 1 deletion(-)
include/linux/audit.h +10 -0
index 45abb3722d30..833f349bf415 100644
@@ -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_clone3(struct kernel_clone_args *kargs, int ret);
 
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{
+       if (!audit_dummy_context())
+               __audit_log_clone3(kargs, ret);
+}
+
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{ }
+
 #define audit_n_rules 0
 #define audit_signals 0
 #endif /* CONFIG_AUDITSYSCALL */
include/uapi/linux/audit.h +1 -0
index e8f5ce677df7..37357e17adbf 100644
@@ -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_CLONE3           1343    /* Record showing clone3 args */
 
 #define AUDIT_AVC              1400    /* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR      1401    /* Internal SE Linux Errors */
kernel/auditsc.c +5 -0
index 6610e667c728..c0106bb71c19 100644
@@ -2882,6 +2882,26 @@ void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
 }
 EXPORT_SYMBOL_GPL(__audit_log_nfcfg);
 
+void __audit_log_clone3(struct kernel_clone_args *kargs, int ret)
+{
+       struct audit_buffer *ab;
+       int pidfd;
+

kernel/auditsc.c void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, · line 2899

Quoted 10 lines
kernel/auditsc.c +10 -0
+       ab = audit_log_start(audit_context(), GFP_KERNEL,
+                            AUDIT_CLONE3);
+       if (!ab)
+               return;
+
+       audit_log_format(ab, "cl3_flags=0x%llx exit_signal=%d cgroup=%d",
+                        kargs->flags, kargs->exit_signal, kargs->cgroup);
+       if ((kargs->flags & CLONE_PIDFD) && ret >= 0 &&
+           !get_user(pidfd, kargs->pidfd))
+               audit_log_format(ab, " pidfd=%d", pidfd);

Do we care about distinguishing between the combination of CLONE_PIDFD and CLONE_THREAD vs CLONE_PIDFD alone? In other words, do we care if the "pidfd" field sometimes represents a pidfd of the child process vs a thread in the current process?

Quoted 25 lines
kernel/auditsc.c +5 -0
+       else
+               audit_log_format(ab, " pidfd=(null)");
+       audit_log_end(ab);
+}
+
 static void audit_log_task(struct audit_buffer *ab)
 {
        kuid_t auid, uid;
kernel/fork.c +3 -2
index f0e2e131a9a5..0f52e8c0e900 100644
@@ -3047,7 +3047,9 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)
        if (!clone3_args_valid(&kargs))
                return -EINVAL;
 
-       return kernel_clone(&kargs);
+       err = kernel_clone(&kargs);
+       audit_log_clone3(&kargs, err);
+       return err;
 }
 
 void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data)
--

2.53.0

Signature · 1 line
paul-moore.com
#4 lore raw
Quoted 92 lines · Paul Moore
Quoted 90 lines · Ricardo Robaina

The clone3(2) syscall moves most parameters to struct clone_args. For this reason, the generic SYSCALL audit record does not capture the structured arguments.

Add a CLONE3 auxiliary record that logs: flags, exit_signal, cgroup, and pidfd fields from struct clone_args. When CLONE_PIDFD is set and the syscall succeeds, the resolved pidfd is logged; otherwise pidfd=(null).

----
type=SYSCALL : syscall=clone3 a0=0x7ffe7f1ec640 a1=0x58 a2=0x0 ... type=CLONE3 : cl3_flags=0x1000 exit_signal=17 cgroup=0 pidfd=3

---
 include/linux/audit.h      | 10 ++++++++++
 include/uapi/linux/audit.h |  1 +
 kernel/auditsc.c           | 20 ++++++++++++++++++++
 kernel/fork.c              |  4 +++-
 4 files changed, 34 insertions(+), 1 deletion(-)
include/linux/audit.h +10 -0
index 45abb3722d30..833f349bf415 100644
@@ -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_clone3(struct kernel_clone_args *kargs, int ret);
 
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{
+       if (!audit_dummy_context())
+               __audit_log_clone3(kargs, ret);
+}
+
 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_clone3(struct kernel_clone_args *kargs, int ret)
+{ }
+
 #define audit_n_rules 0
 #define audit_signals 0
 #endif /* CONFIG_AUDITSYSCALL */
include/uapi/linux/audit.h +1 -0
index e8f5ce677df7..37357e17adbf 100644
@@ -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_CLONE3           1343    /* Record showing clone3 args */
 
 #define AUDIT_AVC              1400    /* SE Linux avc denial or grant */
 #define AUDIT_SELINUX_ERR      1401    /* Internal SE Linux Errors */
kernel/auditsc.c +12 -0
index 6610e667c728..c0106bb71c19 100644
@@ -2882,6 +2882,26 @@ void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
 }
 EXPORT_SYMBOL_GPL(__audit_log_nfcfg);
 
+void __audit_log_clone3(struct kernel_clone_args *kargs, int ret)
+{
+       struct audit_buffer *ab;
+       int pidfd;
+
+       ab = audit_log_start(audit_context(), GFP_KERNEL,
+                            AUDIT_CLONE3);
+       if (!ab)
+               return;
+
+       audit_log_format(ab, "cl3_flags=0x%llx exit_signal=%d cgroup=%d",
+                        kargs->flags, kargs->exit_signal, kargs->cgroup);
Quoted 9 lines

kernel/auditsc.c void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries, · line 2899

Quoted 3 lines
kernel/auditsc.c +3 -0
+       if ((kargs->flags & CLONE_PIDFD) && ret >= 0 &&
+           !get_user(pidfd, kargs->pidfd))
+               audit_log_format(ab, " pidfd=%d", pidfd);

Do we care about distinguishing between the combination of CLONE_PIDFD and CLONE_THREAD vs CLONE_PIDFD alone? In other words, do we care if the "pidfd" field sometimes represents a pidfd of the child process vs a thread in the current process?

Hi Paul,

Thanks for reviewing this patch.

The flags field can be use to check if CLONE_THREAD is set, so it's possible to determine whether the pidfd refers to a child process or a thread by inspecting the flags. Do you think we should include a dedicated field for that?

Quoted 22 lines
Quoted 22 lines
kernel/auditsc.c +5 -0
+       else
+               audit_log_format(ab, " pidfd=(null)");
+       audit_log_end(ab);
+}
+
 static void audit_log_task(struct audit_buffer *ab)
 {
        kuid_t auid, uid;
kernel/fork.c +3 -1
index f0e2e131a9a5..0f52e8c0e900 100644
@@ -3047,7 +3047,9 @@ SYSCALL_DEFINE2(clone3, struct clone_args __user *, uargs, size_t, size)
        if (!clone3_args_valid(&kargs))
                return -EINVAL;
 
-       return kernel_clone(&kargs);
+       err = kernel_clone(&kargs);
+       audit_log_clone3(&kargs, err);
+       return err;
 }
 
Quoted 7 lines
Quoted 3 lines
kernel/fork.c +0 -1
 void walk_process_tree(struct task_struct *top, proc_visitor visitor, void *data)
--

2.53.0

--
paul-moore.com

-Ricardo