audit: use task_tgid_nr() instead of task_pid_nr()
PATCH v2 1/1 audit: use task_tgid_nr() instead of task_pid_nr()
In a few audit records, PIDs were being recorded with task_pid_nr() instead of task_tgid_nr().
$ grep "task_pid_nr" kernel/audit*.c audit.c: task_pid_nr(current), auditfilter.c: pid = task_pid_nr(current); auditsc.c: audit_log_format(ab, " pid=%u", task_pid_nr(current));
For single-thread applications, the process id (pid) and the thread group id (tgid) are the same. However, on multi-thread applications, task_pid_nr() returns the current thread id (user-space's TID), while task_tgid_nr() returns the main thread id (user-space's PID). Since the users are more interested in the process id (pid), rather than the thread id (tid), this patch converts these callers to the correct method.
---
V1 -> V2: Added a more detailed commit description
kernel/audit.c | 2 +- kernel/auditfilter.c | 2 +- kernel/auditsc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
kernel/audit.c +1 -1
@@ -1612,7 +1612,7 @@ static void audit_log_multicast(int group, const char *op, int err) cred =current_cred (); tty =audit_get_tty (); audit_log_format(ab, "pid=%u uid=%u auid=%u tty=%s ses=%u", - task_pid_nr(current), + task_tgid_nr(current), from_kuid(&init_user_ns, cred->uid), from_kuid(&init_user_ns, audit_get_loginuid(current)), tty ? tty_name(tty) : "(none)",
kernel/auditfilter.c +1 -1
@@ -1344,7 +1344,7 @@ int audit_filter(int msgtype, unsigned int listtype)switch (f->type) {case AUDIT_PID : - pid =task_pid_nr (current); + pid =task_tgid_nr (current); result =audit_comparator (pid, f->op, f->val);break ;case AUDIT_UID :
kernel/auditsc.c +1 -1
@@ -2933,7 +2933,7 @@ void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,audit_log_format (ab,"table=%s family=%u entries=%u op=%s" , name, af, nentries, audit_nfcfgs[op].s); -audit_log_format (ab," pid=%u" ,task_pid_nr (current)); +audit_log_format (ab," pid=%u" ,task_tgid_nr (current));audit_log_task_context (ab);/* subj= */ audit_log_format (ab," comm=" );audit_log_untrustedstring (ab,get_task_comm (comm, current));
Signature · 1 line
2.46.0
Paul Moore
maintainerQuoted 20 lines · On Aug 28, 2024 Ricardo Robaina <[email protected]> wrote:
In a few audit records, PIDs were being recorded with
task_pid_nr()instead oftask_tgid_nr().$ grep "task_pid_nr" kernel/audit*.c audit.c: task_pid_nr(current), auditfilter.c: pid = task_pid_nr(current); auditsc.c: audit_log_format(ab, " pid=%u", task_pid_nr(current));For single-thread applications, the process id (pid) and the thread group id (tgid) are the same. However, on multi-thread applications,
task_pid_nr()returns the current thread id (user-space's TID), whiletask_tgid_nr()returns the main thread id (user-space's PID). Since the users are more interested in the process id (pid), rather than the thread id (tid), this patch converts these callers to the correct method.Reviewed-by Richard Guy Briggs <[email protected]>Signed-off-by Ricardo Robaina <[email protected]>
Quoted 7 lines
---
V1 -> V2: Added a more detailed commit descriptionkernel/audit.c | 2 +- kernel/auditfilter.c | 2 +- kernel/auditsc.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
Looks good to me, merged into audit/dev, thanks!
--
paul-moore.com