Skip to content

Commit 7e4081c

Browse files
committed
audit: use task_tgid_nr() instead of task_pid_nr()
JIRA: https://issues.redhat.com/browse/RHEL-78967 This patch is a backport of the following upstream commit: commit 61c6097 Author: Ricardo Robaina <rrobaina@redhat.com> Date: Wed Aug 28 08:25:06 2024 -0300 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. Link: linux-audit/audit-kernel#126 Reviewed-by: Richard Guy Briggs <rgb@redhat.com> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com> Signed-off-by: Paul Moore <paul@paul-moore.com> Signed-off-by: Ricardo Robaina <rrobaina@redhat.com>
1 parent 06792db commit 7e4081c

3 files changed

Lines changed: 3 additions & 3 deletions

File tree

kernel/audit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ static void audit_log_multicast(int group, const char *op, int err)
16121612
cred = current_cred();
16131613
tty = audit_get_tty();
16141614
audit_log_format(ab, "pid=%u uid=%u auid=%u tty=%s ses=%u",
1615-
task_pid_nr(current),
1615+
task_tgid_nr(current),
16161616
from_kuid(&init_user_ns, cred->uid),
16171617
from_kuid(&init_user_ns, audit_get_loginuid(current)),
16181618
tty ? tty_name(tty) : "(none)",

kernel/auditfilter.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ int audit_filter(int msgtype, unsigned int listtype)
13431343

13441344
switch (f->type) {
13451345
case AUDIT_PID:
1346-
pid = task_pid_nr(current);
1346+
pid = task_tgid_nr(current);
13471347
result = audit_comparator(pid, f->op, f->val);
13481348
break;
13491349
case AUDIT_UID:

kernel/auditsc.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2937,7 +2937,7 @@ void __audit_log_nfcfg(const char *name, u8 af, unsigned int nentries,
29372937
audit_log_format(ab, "table=%s family=%u entries=%u op=%s",
29382938
name, af, nentries, audit_nfcfgs[op].s);
29392939

2940-
audit_log_format(ab, " pid=%u", task_pid_nr(current));
2940+
audit_log_format(ab, " pid=%u", task_tgid_nr(current));
29412941
audit_log_task_context(ab); /* subj= */
29422942
audit_log_format(ab, " comm=");
29432943
audit_log_untrustedstring(ab, get_task_comm(comm, current));

0 commit comments

Comments
 (0)