Commit f1dc4867ff41b7bcca57fa19449d1fe7ad517ac1

Authored by Richard Guy Briggs
Committed by Eric Paris
1 parent c92cdeb45e

audit: anchor all pid references in the initial pid namespace

Store and log all PIDs with reference to the initial PID namespace and
use the access functions task_pid_nr() and task_tgid_nr() for task->pid
and task->tgid.

Cc: "Eric W. Biederman" <ebiederm@xmission.com>
(informed by ebiederman's c776b5d2)
Signed-off-by: Richard Guy Briggs <rgb@redhat.com>

Showing 6 changed files with 38 additions and 16 deletions Side-by-side Diff

drivers/tty/tty_audit.c
... ... @@ -65,6 +65,7 @@
65 65 {
66 66 struct audit_buffer *ab;
67 67 struct task_struct *tsk = current;
  68 + pid_t pid = task_pid_nr(tsk);
68 69 uid_t uid = from_kuid(&init_user_ns, task_uid(tsk));
69 70 uid_t loginuid = from_kuid(&init_user_ns, audit_get_loginuid(tsk));
70 71 unsigned int sessionid = audit_get_sessionid(tsk);
... ... @@ -74,7 +75,7 @@
74 75 char name[sizeof(tsk->comm)];
75 76  
76 77 audit_log_format(ab, "%s pid=%u uid=%u auid=%u ses=%u major=%d"
77   - " minor=%d comm=", description, tsk->pid, uid,
  78 + " minor=%d comm=", description, pid, uid,
78 79 loginuid, sessionid, major, minor);
79 80 get_task_comm(name, tsk);
80 81 audit_log_untrustedstring(ab, name);
... ... @@ -649,6 +649,7 @@
649 649 {
650 650 int rc = 0;
651 651 uid_t uid = from_kuid(&init_user_ns, current_uid());
  652 + pid_t pid = task_tgid_nr(current);
652 653  
653 654 if (!audit_enabled && msg_type != AUDIT_USER_AVC) {
654 655 *ab = NULL;
... ... @@ -658,7 +659,7 @@
658 659 *ab = audit_log_start(NULL, GFP_KERNEL, msg_type);
659 660 if (unlikely(!*ab))
660 661 return rc;
661   - audit_log_format(*ab, "pid=%d uid=%u", task_tgid_vnr(current), uid);
  662 + audit_log_format(*ab, "pid=%d uid=%u", pid, uid);
662 663 audit_log_session_info(*ab);
663 664 audit_log_task_context(*ab);
664 665  
... ... @@ -1823,7 +1824,7 @@
1823 1824 " euid=%u suid=%u fsuid=%u"
1824 1825 " egid=%u sgid=%u fsgid=%u tty=%s ses=%u",
1825 1826 task_ppid_nr(tsk),
1826   - tsk->pid,
  1827 + task_pid_nr(tsk),
1827 1828 from_kuid(&init_user_ns, audit_get_loginuid(tsk)),
1828 1829 from_kuid(&init_user_ns, cred->uid),
1829 1830 from_kgid(&init_user_ns, cred->gid),
kernel/auditfilter.c
... ... @@ -433,6 +433,19 @@
433 433 f->val = 0;
434 434 }
435 435  
  436 + if ((f->type == AUDIT_PID) || (f->type == AUDIT_PPID)) {
  437 + struct pid *pid;
  438 + rcu_read_lock();
  439 + pid = find_vpid(f->val);
  440 + if (!pid) {
  441 + rcu_read_unlock();
  442 + err = -ESRCH;
  443 + goto exit_free;
  444 + }
  445 + f->val = pid_nr(pid);
  446 + rcu_read_unlock();
  447 + }
  448 +
436 449 err = audit_field_valid(entry, f);
437 450 if (err)
438 451 goto exit_free;
439 452  
... ... @@ -1242,12 +1255,14 @@
1242 1255  
1243 1256 for (i = 0; i < rule->field_count; i++) {
1244 1257 struct audit_field *f = &rule->fields[i];
  1258 + pid_t pid;
1245 1259 int result = 0;
1246 1260 u32 sid;
1247 1261  
1248 1262 switch (f->type) {
1249 1263 case AUDIT_PID:
1250   - result = audit_comparator(task_pid_vnr(current), f->op, f->val);
  1264 + pid = task_pid_nr(current);
  1265 + result = audit_comparator(pid, f->op, f->val);
1251 1266 break;
1252 1267 case AUDIT_UID:
1253 1268 result = audit_uid_comparator(current_uid(), f->op, f->uid);
... ... @@ -457,10 +457,12 @@
457 457 struct audit_field *f = &rule->fields[i];
458 458 struct audit_names *n;
459 459 int result = 0;
  460 + pid_t pid;
460 461  
461 462 switch (f->type) {
462 463 case AUDIT_PID:
463   - result = audit_comparator(tsk->pid, f->op, f->val);
  464 + pid = task_pid_nr(tsk);
  465 + result = audit_comparator(pid, f->op, f->val);
464 466 break;
465 467 case AUDIT_PPID:
466 468 if (ctx) {
... ... @@ -2051,7 +2053,7 @@
2051 2053 audit_log_format(ab, "pid=%d uid=%u"
2052 2054 " old-auid=%u new-auid=%u old-ses=%u new-ses=%u"
2053 2055 " res=%d",
2054   - current->pid, uid,
  2056 + task_pid_nr(current), uid,
2055 2057 oldloginuid, loginuid, oldsessionid, sessionid,
2056 2058 !rc);
2057 2059 audit_log_end(ab);
... ... @@ -2275,7 +2277,7 @@
2275 2277 {
2276 2278 struct audit_context *context = current->audit_context;
2277 2279  
2278   - context->target_pid = t->pid;
  2280 + context->target_pid = task_pid_nr(t);
2279 2281 context->target_auid = audit_get_loginuid(t);
2280 2282 context->target_uid = task_uid(t);
2281 2283 context->target_sessionid = audit_get_sessionid(t);
... ... @@ -2300,7 +2302,7 @@
2300 2302  
2301 2303 if (audit_pid && t->tgid == audit_pid) {
2302 2304 if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1 || sig == SIGUSR2) {
2303   - audit_sig_pid = tsk->pid;
  2305 + audit_sig_pid = task_pid_nr(tsk);
2304 2306 if (uid_valid(tsk->loginuid))
2305 2307 audit_sig_uid = tsk->loginuid;
2306 2308 else
... ... @@ -2314,7 +2316,7 @@
2314 2316 /* optimize the common case by putting first signal recipient directly
2315 2317 * in audit_context */
2316 2318 if (!ctx->target_pid) {
2317   - ctx->target_pid = t->tgid;
  2319 + ctx->target_pid = task_tgid_nr(t);
2318 2320 ctx->target_auid = audit_get_loginuid(t);
2319 2321 ctx->target_uid = t_uid;
2320 2322 ctx->target_sessionid = audit_get_sessionid(t);
... ... @@ -2335,7 +2337,7 @@
2335 2337 }
2336 2338 BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS);
2337 2339  
2338   - axp->target_pid[axp->pid_count] = t->tgid;
  2340 + axp->target_pid[axp->pid_count] = task_tgid_nr(t);
2339 2341 axp->target_auid[axp->pid_count] = audit_get_loginuid(t);
2340 2342 axp->target_uid[axp->pid_count] = t_uid;
2341 2343 axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t);
... ... @@ -2435,7 +2437,7 @@
2435 2437 from_kgid(&init_user_ns, gid),
2436 2438 sessionid);
2437 2439 audit_log_task_context(ab);
2438   - audit_log_format(ab, " pid=%d comm=", current->pid);
  2440 + audit_log_format(ab, " pid=%d comm=", task_pid_nr(current));
2439 2441 audit_log_untrustedstring(ab, current->comm);
2440 2442 if (mm) {
2441 2443 down_read(&mm->mmap_sem);
security/integrity/integrity_audit.c
... ... @@ -39,7 +39,7 @@
39 39  
40 40 ab = audit_log_start(current->audit_context, GFP_KERNEL, audit_msgno);
41 41 audit_log_format(ab, "pid=%d uid=%u auid=%u ses=%u",
42   - current->pid,
  42 + task_pid_nr(current),
43 43 from_kuid(&init_user_ns, current_cred()->uid),
44 44 from_kuid(&init_user_ns, audit_get_loginuid(current)),
45 45 audit_get_sessionid(current));
security/lsm_audit.c
... ... @@ -220,7 +220,7 @@
220 220 */
221 221 BUILD_BUG_ON(sizeof(a->u) > sizeof(void *)*2);
222 222  
223   - audit_log_format(ab, " pid=%d comm=", tsk->pid);
  223 + audit_log_format(ab, " pid=%d comm=", task_pid_nr(tsk));
224 224 audit_log_untrustedstring(ab, tsk->comm);
225 225  
226 226 switch (a->type) {
... ... @@ -278,9 +278,12 @@
278 278 }
279 279 case LSM_AUDIT_DATA_TASK:
280 280 tsk = a->u.tsk;
281   - if (tsk && tsk->pid) {
282   - audit_log_format(ab, " pid=%d comm=", tsk->pid);
283   - audit_log_untrustedstring(ab, tsk->comm);
  281 + if (tsk) {
  282 + pid_t pid = task_pid_nr(tsk);
  283 + if (pid) {
  284 + audit_log_format(ab, " pid=%d comm=", pid);
  285 + audit_log_untrustedstring(ab, tsk->comm);
  286 + }
284 287 }
285 288 break;
286 289 case LSM_AUDIT_DATA_NET: