Skip to content

Commit 61c6097

Browse files
rprobainapcmoore
authored andcommitted
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 <[email protected]> Signed-off-by: Ricardo Robaina <[email protected]> Signed-off-by: Paul Moore <[email protected]>
1 parent 8400291 commit 61c6097

File tree

3 files changed

+3
-3
lines changed

3 files changed

+3
-3
lines changed

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
@@ -1344,7 +1344,7 @@ int audit_filter(int msgtype, unsigned int listtype)
13441344

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

kernel/auditsc.c

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

2936-
audit_log_format(ab, " pid=%u", task_pid_nr(current));
2936+
audit_log_format(ab, " pid=%u", task_tgid_nr(current));
29372937
audit_log_task_context(ab); /* subj= */
29382938
audit_log_format(ab, " comm=");
29392939
audit_log_untrustedstring(ab, get_task_comm(comm, current));

0 commit comments

Comments
 (0)