auditsc.c 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343
  1. /* auditsc.c -- System-call auditing support
  2. * Handles all system-call specific auditing features.
  3. *
  4. * Copyright 2003-2004 Red Hat Inc., Durham, North Carolina.
  5. * Copyright 2005 Hewlett-Packard Development Company, L.P.
  6. * Copyright (C) 2005 IBM Corporation
  7. * All Rights Reserved.
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License as published by
  11. * the Free Software Foundation; either version 2 of the License, or
  12. * (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  22. *
  23. * Written by Rickard E. (Rik) Faith <faith@redhat.com>
  24. *
  25. * Many of the ideas implemented here are from Stephen C. Tweedie,
  26. * especially the idea of avoiding a copy by using getname.
  27. *
  28. * The method for actual interception of syscall entry and exit (not in
  29. * this file -- see entry.S) is based on a GPL'd patch written by
  30. * okir@suse.de and Copyright 2003 SuSE Linux AG.
  31. *
  32. * The support of additional filter rules compares (>, <, >=, <=) was
  33. * added by Dustin Kirkland <dustin.kirkland@us.ibm.com>, 2005.
  34. *
  35. * Modified by Amy Griffis <amy.griffis@hp.com> to collect additional
  36. * filesystem information.
  37. *
  38. * Subject and object context labeling support added by <danjones@us.ibm.com>
  39. * and <dustin.kirkland@us.ibm.com> for LSPP certification compliance.
  40. */
  41. #include <linux/init.h>
  42. #include <asm/types.h>
  43. #include <asm/atomic.h>
  44. #include <asm/types.h>
  45. #include <linux/fs.h>
  46. #include <linux/namei.h>
  47. #include <linux/mm.h>
  48. #include <linux/module.h>
  49. #include <linux/mount.h>
  50. #include <linux/socket.h>
  51. #include <linux/audit.h>
  52. #include <linux/personality.h>
  53. #include <linux/time.h>
  54. #include <linux/netlink.h>
  55. #include <linux/compiler.h>
  56. #include <asm/unistd.h>
  57. #include <linux/security.h>
  58. #include <linux/list.h>
  59. #include <linux/tty.h>
  60. #include <linux/selinux.h>
  61. #include "audit.h"
  62. extern struct list_head audit_filter_list[];
  63. /* No syscall auditing will take place unless audit_enabled != 0. */
  64. extern int audit_enabled;
  65. /* AUDIT_NAMES is the number of slots we reserve in the audit_context
  66. * for saving names from getname(). */
  67. #define AUDIT_NAMES 20
  68. /* AUDIT_NAMES_RESERVED is the number of slots we reserve in the
  69. * audit_context from being used for nameless inodes from
  70. * path_lookup. */
  71. #define AUDIT_NAMES_RESERVED 7
  72. /* When fs/namei.c:getname() is called, we store the pointer in name and
  73. * we don't let putname() free it (instead we free all of the saved
  74. * pointers at syscall exit time).
  75. *
  76. * Further, in fs/namei.c:path_lookup() we store the inode and device. */
  77. struct audit_names {
  78. const char *name;
  79. unsigned long ino;
  80. unsigned long pino;
  81. dev_t dev;
  82. umode_t mode;
  83. uid_t uid;
  84. gid_t gid;
  85. dev_t rdev;
  86. u32 osid;
  87. };
  88. struct audit_aux_data {
  89. struct audit_aux_data *next;
  90. int type;
  91. };
  92. #define AUDIT_AUX_IPCPERM 0
  93. struct audit_aux_data_ipcctl {
  94. struct audit_aux_data d;
  95. struct ipc_perm p;
  96. unsigned long qbytes;
  97. uid_t uid;
  98. gid_t gid;
  99. mode_t mode;
  100. u32 osid;
  101. };
  102. struct audit_aux_data_socketcall {
  103. struct audit_aux_data d;
  104. int nargs;
  105. unsigned long args[0];
  106. };
  107. struct audit_aux_data_sockaddr {
  108. struct audit_aux_data d;
  109. int len;
  110. char a[0];
  111. };
  112. struct audit_aux_data_path {
  113. struct audit_aux_data d;
  114. struct dentry *dentry;
  115. struct vfsmount *mnt;
  116. };
  117. /* The per-task audit context. */
  118. struct audit_context {
  119. int in_syscall; /* 1 if task is in a syscall */
  120. enum audit_state state;
  121. unsigned int serial; /* serial number for record */
  122. struct timespec ctime; /* time of syscall entry */
  123. uid_t loginuid; /* login uid (identity) */
  124. int major; /* syscall number */
  125. unsigned long argv[4]; /* syscall arguments */
  126. int return_valid; /* return code is valid */
  127. long return_code;/* syscall return code */
  128. int auditable; /* 1 if record should be written */
  129. int name_count;
  130. struct audit_names names[AUDIT_NAMES];
  131. struct dentry * pwd;
  132. struct vfsmount * pwdmnt;
  133. struct audit_context *previous; /* For nested syscalls */
  134. struct audit_aux_data *aux;
  135. /* Save things to print about task_struct */
  136. pid_t pid;
  137. uid_t uid, euid, suid, fsuid;
  138. gid_t gid, egid, sgid, fsgid;
  139. unsigned long personality;
  140. int arch;
  141. #if AUDIT_DEBUG
  142. int put_count;
  143. int ino_count;
  144. #endif
  145. };
  146. /* Compare a task_struct with an audit_rule. Return 1 on match, 0
  147. * otherwise. */
  148. static int audit_filter_rules(struct task_struct *tsk,
  149. struct audit_krule *rule,
  150. struct audit_context *ctx,
  151. enum audit_state *state)
  152. {
  153. int i, j, need_sid = 1;
  154. u32 sid;
  155. for (i = 0; i < rule->field_count; i++) {
  156. struct audit_field *f = &rule->fields[i];
  157. int result = 0;
  158. switch (f->type) {
  159. case AUDIT_PID:
  160. result = audit_comparator(tsk->pid, f->op, f->val);
  161. break;
  162. case AUDIT_UID:
  163. result = audit_comparator(tsk->uid, f->op, f->val);
  164. break;
  165. case AUDIT_EUID:
  166. result = audit_comparator(tsk->euid, f->op, f->val);
  167. break;
  168. case AUDIT_SUID:
  169. result = audit_comparator(tsk->suid, f->op, f->val);
  170. break;
  171. case AUDIT_FSUID:
  172. result = audit_comparator(tsk->fsuid, f->op, f->val);
  173. break;
  174. case AUDIT_GID:
  175. result = audit_comparator(tsk->gid, f->op, f->val);
  176. break;
  177. case AUDIT_EGID:
  178. result = audit_comparator(tsk->egid, f->op, f->val);
  179. break;
  180. case AUDIT_SGID:
  181. result = audit_comparator(tsk->sgid, f->op, f->val);
  182. break;
  183. case AUDIT_FSGID:
  184. result = audit_comparator(tsk->fsgid, f->op, f->val);
  185. break;
  186. case AUDIT_PERS:
  187. result = audit_comparator(tsk->personality, f->op, f->val);
  188. break;
  189. case AUDIT_ARCH:
  190. if (ctx)
  191. result = audit_comparator(ctx->arch, f->op, f->val);
  192. break;
  193. case AUDIT_EXIT:
  194. if (ctx && ctx->return_valid)
  195. result = audit_comparator(ctx->return_code, f->op, f->val);
  196. break;
  197. case AUDIT_SUCCESS:
  198. if (ctx && ctx->return_valid) {
  199. if (f->val)
  200. result = audit_comparator(ctx->return_valid, f->op, AUDITSC_SUCCESS);
  201. else
  202. result = audit_comparator(ctx->return_valid, f->op, AUDITSC_FAILURE);
  203. }
  204. break;
  205. case AUDIT_DEVMAJOR:
  206. if (ctx) {
  207. for (j = 0; j < ctx->name_count; j++) {
  208. if (audit_comparator(MAJOR(ctx->names[j].dev), f->op, f->val)) {
  209. ++result;
  210. break;
  211. }
  212. }
  213. }
  214. break;
  215. case AUDIT_DEVMINOR:
  216. if (ctx) {
  217. for (j = 0; j < ctx->name_count; j++) {
  218. if (audit_comparator(MINOR(ctx->names[j].dev), f->op, f->val)) {
  219. ++result;
  220. break;
  221. }
  222. }
  223. }
  224. break;
  225. case AUDIT_INODE:
  226. if (ctx) {
  227. for (j = 0; j < ctx->name_count; j++) {
  228. if (audit_comparator(ctx->names[j].ino, f->op, f->val) ||
  229. audit_comparator(ctx->names[j].pino, f->op, f->val)) {
  230. ++result;
  231. break;
  232. }
  233. }
  234. }
  235. break;
  236. case AUDIT_LOGINUID:
  237. result = 0;
  238. if (ctx)
  239. result = audit_comparator(ctx->loginuid, f->op, f->val);
  240. break;
  241. case AUDIT_SE_USER:
  242. case AUDIT_SE_ROLE:
  243. case AUDIT_SE_TYPE:
  244. case AUDIT_SE_SEN:
  245. case AUDIT_SE_CLR:
  246. /* NOTE: this may return negative values indicating
  247. a temporary error. We simply treat this as a
  248. match for now to avoid losing information that
  249. may be wanted. An error message will also be
  250. logged upon error */
  251. if (f->se_rule) {
  252. if (need_sid) {
  253. selinux_task_ctxid(tsk, &sid);
  254. need_sid = 0;
  255. }
  256. result = selinux_audit_rule_match(sid, f->type,
  257. f->op,
  258. f->se_rule,
  259. ctx);
  260. }
  261. break;
  262. case AUDIT_ARG0:
  263. case AUDIT_ARG1:
  264. case AUDIT_ARG2:
  265. case AUDIT_ARG3:
  266. if (ctx)
  267. result = audit_comparator(ctx->argv[f->type-AUDIT_ARG0], f->op, f->val);
  268. break;
  269. }
  270. if (!result)
  271. return 0;
  272. }
  273. switch (rule->action) {
  274. case AUDIT_NEVER: *state = AUDIT_DISABLED; break;
  275. case AUDIT_POSSIBLE: *state = AUDIT_BUILD_CONTEXT; break;
  276. case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break;
  277. }
  278. return 1;
  279. }
  280. /* At process creation time, we can determine if system-call auditing is
  281. * completely disabled for this task. Since we only have the task
  282. * structure at this point, we can only check uid and gid.
  283. */
  284. static enum audit_state audit_filter_task(struct task_struct *tsk)
  285. {
  286. struct audit_entry *e;
  287. enum audit_state state;
  288. rcu_read_lock();
  289. list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) {
  290. if (audit_filter_rules(tsk, &e->rule, NULL, &state)) {
  291. rcu_read_unlock();
  292. return state;
  293. }
  294. }
  295. rcu_read_unlock();
  296. return AUDIT_BUILD_CONTEXT;
  297. }
  298. /* At syscall entry and exit time, this filter is called if the
  299. * audit_state is not low enough that auditing cannot take place, but is
  300. * also not high enough that we already know we have to write an audit
  301. * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT).
  302. */
  303. static enum audit_state audit_filter_syscall(struct task_struct *tsk,
  304. struct audit_context *ctx,
  305. struct list_head *list)
  306. {
  307. struct audit_entry *e;
  308. enum audit_state state;
  309. if (audit_pid && tsk->tgid == audit_pid)
  310. return AUDIT_DISABLED;
  311. rcu_read_lock();
  312. if (!list_empty(list)) {
  313. int word = AUDIT_WORD(ctx->major);
  314. int bit = AUDIT_BIT(ctx->major);
  315. list_for_each_entry_rcu(e, list, list) {
  316. if ((e->rule.mask[word] & bit) == bit
  317. && audit_filter_rules(tsk, &e->rule, ctx, &state)) {
  318. rcu_read_unlock();
  319. return state;
  320. }
  321. }
  322. }
  323. rcu_read_unlock();
  324. return AUDIT_BUILD_CONTEXT;
  325. }
  326. static inline struct audit_context *audit_get_context(struct task_struct *tsk,
  327. int return_valid,
  328. int return_code)
  329. {
  330. struct audit_context *context = tsk->audit_context;
  331. if (likely(!context))
  332. return NULL;
  333. context->return_valid = return_valid;
  334. context->return_code = return_code;
  335. if (context->in_syscall && !context->auditable) {
  336. enum audit_state state;
  337. state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_EXIT]);
  338. if (state == AUDIT_RECORD_CONTEXT)
  339. context->auditable = 1;
  340. }
  341. context->pid = tsk->pid;
  342. context->uid = tsk->uid;
  343. context->gid = tsk->gid;
  344. context->euid = tsk->euid;
  345. context->suid = tsk->suid;
  346. context->fsuid = tsk->fsuid;
  347. context->egid = tsk->egid;
  348. context->sgid = tsk->sgid;
  349. context->fsgid = tsk->fsgid;
  350. context->personality = tsk->personality;
  351. tsk->audit_context = NULL;
  352. return context;
  353. }
  354. static inline void audit_free_names(struct audit_context *context)
  355. {
  356. int i;
  357. #if AUDIT_DEBUG == 2
  358. if (context->auditable
  359. ||context->put_count + context->ino_count != context->name_count) {
  360. printk(KERN_ERR "%s:%d(:%d): major=%d in_syscall=%d"
  361. " name_count=%d put_count=%d"
  362. " ino_count=%d [NOT freeing]\n",
  363. __FILE__, __LINE__,
  364. context->serial, context->major, context->in_syscall,
  365. context->name_count, context->put_count,
  366. context->ino_count);
  367. for (i = 0; i < context->name_count; i++) {
  368. printk(KERN_ERR "names[%d] = %p = %s\n", i,
  369. context->names[i].name,
  370. context->names[i].name ?: "(null)");
  371. }
  372. dump_stack();
  373. return;
  374. }
  375. #endif
  376. #if AUDIT_DEBUG
  377. context->put_count = 0;
  378. context->ino_count = 0;
  379. #endif
  380. for (i = 0; i < context->name_count; i++) {
  381. if (context->names[i].name)
  382. __putname(context->names[i].name);
  383. }
  384. context->name_count = 0;
  385. if (context->pwd)
  386. dput(context->pwd);
  387. if (context->pwdmnt)
  388. mntput(context->pwdmnt);
  389. context->pwd = NULL;
  390. context->pwdmnt = NULL;
  391. }
  392. static inline void audit_free_aux(struct audit_context *context)
  393. {
  394. struct audit_aux_data *aux;
  395. while ((aux = context->aux)) {
  396. if (aux->type == AUDIT_AVC_PATH) {
  397. struct audit_aux_data_path *axi = (void *)aux;
  398. dput(axi->dentry);
  399. mntput(axi->mnt);
  400. }
  401. context->aux = aux->next;
  402. kfree(aux);
  403. }
  404. }
  405. static inline void audit_zero_context(struct audit_context *context,
  406. enum audit_state state)
  407. {
  408. uid_t loginuid = context->loginuid;
  409. memset(context, 0, sizeof(*context));
  410. context->state = state;
  411. context->loginuid = loginuid;
  412. }
  413. static inline struct audit_context *audit_alloc_context(enum audit_state state)
  414. {
  415. struct audit_context *context;
  416. if (!(context = kmalloc(sizeof(*context), GFP_KERNEL)))
  417. return NULL;
  418. audit_zero_context(context, state);
  419. return context;
  420. }
  421. /**
  422. * audit_alloc - allocate an audit context block for a task
  423. * @tsk: task
  424. *
  425. * Filter on the task information and allocate a per-task audit context
  426. * if necessary. Doing so turns on system call auditing for the
  427. * specified task. This is called from copy_process, so no lock is
  428. * needed.
  429. */
  430. int audit_alloc(struct task_struct *tsk)
  431. {
  432. struct audit_context *context;
  433. enum audit_state state;
  434. if (likely(!audit_enabled))
  435. return 0; /* Return if not auditing. */
  436. state = audit_filter_task(tsk);
  437. if (likely(state == AUDIT_DISABLED))
  438. return 0;
  439. if (!(context = audit_alloc_context(state))) {
  440. audit_log_lost("out of memory in audit_alloc");
  441. return -ENOMEM;
  442. }
  443. /* Preserve login uid */
  444. context->loginuid = -1;
  445. if (current->audit_context)
  446. context->loginuid = current->audit_context->loginuid;
  447. tsk->audit_context = context;
  448. set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT);
  449. return 0;
  450. }
  451. static inline void audit_free_context(struct audit_context *context)
  452. {
  453. struct audit_context *previous;
  454. int count = 0;
  455. do {
  456. previous = context->previous;
  457. if (previous || (count && count < 10)) {
  458. ++count;
  459. printk(KERN_ERR "audit(:%d): major=%d name_count=%d:"
  460. " freeing multiple contexts (%d)\n",
  461. context->serial, context->major,
  462. context->name_count, count);
  463. }
  464. audit_free_names(context);
  465. audit_free_aux(context);
  466. kfree(context);
  467. context = previous;
  468. } while (context);
  469. if (count >= 10)
  470. printk(KERN_ERR "audit: freed %d contexts\n", count);
  471. }
  472. static void audit_log_task_context(struct audit_buffer *ab)
  473. {
  474. char *ctx = NULL;
  475. ssize_t len = 0;
  476. len = security_getprocattr(current, "current", NULL, 0);
  477. if (len < 0) {
  478. if (len != -EINVAL)
  479. goto error_path;
  480. return;
  481. }
  482. ctx = kmalloc(len, GFP_KERNEL);
  483. if (!ctx)
  484. goto error_path;
  485. len = security_getprocattr(current, "current", ctx, len);
  486. if (len < 0 )
  487. goto error_path;
  488. audit_log_format(ab, " subj=%s", ctx);
  489. return;
  490. error_path:
  491. if (ctx)
  492. kfree(ctx);
  493. audit_panic("error in audit_log_task_context");
  494. return;
  495. }
  496. static void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
  497. {
  498. char name[sizeof(tsk->comm)];
  499. struct mm_struct *mm = tsk->mm;
  500. struct vm_area_struct *vma;
  501. /* tsk == current */
  502. get_task_comm(name, tsk);
  503. audit_log_format(ab, " comm=");
  504. audit_log_untrustedstring(ab, name);
  505. if (mm) {
  506. down_read(&mm->mmap_sem);
  507. vma = mm->mmap;
  508. while (vma) {
  509. if ((vma->vm_flags & VM_EXECUTABLE) &&
  510. vma->vm_file) {
  511. audit_log_d_path(ab, "exe=",
  512. vma->vm_file->f_dentry,
  513. vma->vm_file->f_vfsmnt);
  514. break;
  515. }
  516. vma = vma->vm_next;
  517. }
  518. up_read(&mm->mmap_sem);
  519. }
  520. audit_log_task_context(ab);
  521. }
  522. static void audit_log_exit(struct audit_context *context, struct task_struct *tsk)
  523. {
  524. int i, call_panic = 0;
  525. struct audit_buffer *ab;
  526. struct audit_aux_data *aux;
  527. const char *tty;
  528. /* tsk == current */
  529. ab = audit_log_start(context, GFP_KERNEL, AUDIT_SYSCALL);
  530. if (!ab)
  531. return; /* audit_panic has been called */
  532. audit_log_format(ab, "arch=%x syscall=%d",
  533. context->arch, context->major);
  534. if (context->personality != PER_LINUX)
  535. audit_log_format(ab, " per=%lx", context->personality);
  536. if (context->return_valid)
  537. audit_log_format(ab, " success=%s exit=%ld",
  538. (context->return_valid==AUDITSC_SUCCESS)?"yes":"no",
  539. context->return_code);
  540. if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name)
  541. tty = tsk->signal->tty->name;
  542. else
  543. tty = "(none)";
  544. audit_log_format(ab,
  545. " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
  546. " pid=%d auid=%u uid=%u gid=%u"
  547. " euid=%u suid=%u fsuid=%u"
  548. " egid=%u sgid=%u fsgid=%u tty=%s",
  549. context->argv[0],
  550. context->argv[1],
  551. context->argv[2],
  552. context->argv[3],
  553. context->name_count,
  554. context->pid,
  555. context->loginuid,
  556. context->uid,
  557. context->gid,
  558. context->euid, context->suid, context->fsuid,
  559. context->egid, context->sgid, context->fsgid, tty);
  560. audit_log_task_info(ab, tsk);
  561. audit_log_end(ab);
  562. for (aux = context->aux; aux; aux = aux->next) {
  563. ab = audit_log_start(context, GFP_KERNEL, aux->type);
  564. if (!ab)
  565. continue; /* audit_panic has been called */
  566. switch (aux->type) {
  567. case AUDIT_IPC: {
  568. struct audit_aux_data_ipcctl *axi = (void *)aux;
  569. audit_log_format(ab,
  570. " qbytes=%lx iuid=%u igid=%u mode=%x",
  571. axi->qbytes, axi->uid, axi->gid, axi->mode);
  572. if (axi->osid != 0) {
  573. char *ctx = NULL;
  574. u32 len;
  575. if (selinux_ctxid_to_string(
  576. axi->osid, &ctx, &len)) {
  577. audit_log_format(ab, " osid=%u",
  578. axi->osid);
  579. call_panic = 1;
  580. } else
  581. audit_log_format(ab, " obj=%s", ctx);
  582. kfree(ctx);
  583. }
  584. break; }
  585. case AUDIT_IPC_SET_PERM: {
  586. struct audit_aux_data_ipcctl *axi = (void *)aux;
  587. audit_log_format(ab,
  588. " new qbytes=%lx new iuid=%u new igid=%u new mode=%x",
  589. axi->qbytes, axi->uid, axi->gid, axi->mode);
  590. if (axi->osid != 0) {
  591. char *ctx = NULL;
  592. u32 len;
  593. if (selinux_ctxid_to_string(
  594. axi->osid, &ctx, &len)) {
  595. audit_log_format(ab, " osid=%u",
  596. axi->osid);
  597. call_panic = 1;
  598. } else
  599. audit_log_format(ab, " obj=%s", ctx);
  600. kfree(ctx);
  601. }
  602. break; }
  603. case AUDIT_SOCKETCALL: {
  604. int i;
  605. struct audit_aux_data_socketcall *axs = (void *)aux;
  606. audit_log_format(ab, "nargs=%d", axs->nargs);
  607. for (i=0; i<axs->nargs; i++)
  608. audit_log_format(ab, " a%d=%lx", i, axs->args[i]);
  609. break; }
  610. case AUDIT_SOCKADDR: {
  611. struct audit_aux_data_sockaddr *axs = (void *)aux;
  612. audit_log_format(ab, "saddr=");
  613. audit_log_hex(ab, axs->a, axs->len);
  614. break; }
  615. case AUDIT_AVC_PATH: {
  616. struct audit_aux_data_path *axi = (void *)aux;
  617. audit_log_d_path(ab, "path=", axi->dentry, axi->mnt);
  618. break; }
  619. }
  620. audit_log_end(ab);
  621. }
  622. if (context->pwd && context->pwdmnt) {
  623. ab = audit_log_start(context, GFP_KERNEL, AUDIT_CWD);
  624. if (ab) {
  625. audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt);
  626. audit_log_end(ab);
  627. }
  628. }
  629. for (i = 0; i < context->name_count; i++) {
  630. unsigned long ino = context->names[i].ino;
  631. unsigned long pino = context->names[i].pino;
  632. ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH);
  633. if (!ab)
  634. continue; /* audit_panic has been called */
  635. audit_log_format(ab, "item=%d", i);
  636. audit_log_format(ab, " name=");
  637. if (context->names[i].name)
  638. audit_log_untrustedstring(ab, context->names[i].name);
  639. else
  640. audit_log_format(ab, "(null)");
  641. if (pino != (unsigned long)-1)
  642. audit_log_format(ab, " parent=%lu", pino);
  643. if (ino != (unsigned long)-1)
  644. audit_log_format(ab, " inode=%lu", ino);
  645. if ((pino != (unsigned long)-1) || (ino != (unsigned long)-1))
  646. audit_log_format(ab, " dev=%02x:%02x mode=%#o"
  647. " ouid=%u ogid=%u rdev=%02x:%02x",
  648. MAJOR(context->names[i].dev),
  649. MINOR(context->names[i].dev),
  650. context->names[i].mode,
  651. context->names[i].uid,
  652. context->names[i].gid,
  653. MAJOR(context->names[i].rdev),
  654. MINOR(context->names[i].rdev));
  655. if (context->names[i].osid != 0) {
  656. char *ctx = NULL;
  657. u32 len;
  658. if (selinux_ctxid_to_string(
  659. context->names[i].osid, &ctx, &len)) {
  660. audit_log_format(ab, " osid=%u",
  661. context->names[i].osid);
  662. call_panic = 2;
  663. } else
  664. audit_log_format(ab, " obj=%s", ctx);
  665. kfree(ctx);
  666. }
  667. audit_log_end(ab);
  668. }
  669. if (call_panic)
  670. audit_panic("error converting sid to string");
  671. }
  672. /**
  673. * audit_free - free a per-task audit context
  674. * @tsk: task whose audit context block to free
  675. *
  676. * Called from copy_process and do_exit
  677. */
  678. void audit_free(struct task_struct *tsk)
  679. {
  680. struct audit_context *context;
  681. context = audit_get_context(tsk, 0, 0);
  682. if (likely(!context))
  683. return;
  684. /* Check for system calls that do not go through the exit
  685. * function (e.g., exit_group), then free context block.
  686. * We use GFP_ATOMIC here because we might be doing this
  687. * in the context of the idle thread */
  688. /* that can happen only if we are called from do_exit() */
  689. if (context->in_syscall && context->auditable)
  690. audit_log_exit(context, tsk);
  691. audit_free_context(context);
  692. }
  693. /**
  694. * audit_syscall_entry - fill in an audit record at syscall entry
  695. * @tsk: task being audited
  696. * @arch: architecture type
  697. * @major: major syscall type (function)
  698. * @a1: additional syscall register 1
  699. * @a2: additional syscall register 2
  700. * @a3: additional syscall register 3
  701. * @a4: additional syscall register 4
  702. *
  703. * Fill in audit context at syscall entry. This only happens if the
  704. * audit context was created when the task was created and the state or
  705. * filters demand the audit context be built. If the state from the
  706. * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT,
  707. * then the record will be written at syscall exit time (otherwise, it
  708. * will only be written if another part of the kernel requests that it
  709. * be written).
  710. */
  711. void audit_syscall_entry(int arch, int major,
  712. unsigned long a1, unsigned long a2,
  713. unsigned long a3, unsigned long a4)
  714. {
  715. struct task_struct *tsk = current;
  716. struct audit_context *context = tsk->audit_context;
  717. enum audit_state state;
  718. BUG_ON(!context);
  719. /*
  720. * This happens only on certain architectures that make system
  721. * calls in kernel_thread via the entry.S interface, instead of
  722. * with direct calls. (If you are porting to a new
  723. * architecture, hitting this condition can indicate that you
  724. * got the _exit/_leave calls backward in entry.S.)
  725. *
  726. * i386 no
  727. * x86_64 no
  728. * ppc64 yes (see arch/powerpc/platforms/iseries/misc.S)
  729. *
  730. * This also happens with vm86 emulation in a non-nested manner
  731. * (entries without exits), so this case must be caught.
  732. */
  733. if (context->in_syscall) {
  734. struct audit_context *newctx;
  735. #if AUDIT_DEBUG
  736. printk(KERN_ERR
  737. "audit(:%d) pid=%d in syscall=%d;"
  738. " entering syscall=%d\n",
  739. context->serial, tsk->pid, context->major, major);
  740. #endif
  741. newctx = audit_alloc_context(context->state);
  742. if (newctx) {
  743. newctx->previous = context;
  744. context = newctx;
  745. tsk->audit_context = newctx;
  746. } else {
  747. /* If we can't alloc a new context, the best we
  748. * can do is to leak memory (any pending putname
  749. * will be lost). The only other alternative is
  750. * to abandon auditing. */
  751. audit_zero_context(context, context->state);
  752. }
  753. }
  754. BUG_ON(context->in_syscall || context->name_count);
  755. if (!audit_enabled)
  756. return;
  757. context->arch = arch;
  758. context->major = major;
  759. context->argv[0] = a1;
  760. context->argv[1] = a2;
  761. context->argv[2] = a3;
  762. context->argv[3] = a4;
  763. state = context->state;
  764. if (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT)
  765. state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_ENTRY]);
  766. if (likely(state == AUDIT_DISABLED))
  767. return;
  768. context->serial = 0;
  769. context->ctime = CURRENT_TIME;
  770. context->in_syscall = 1;
  771. context->auditable = !!(state == AUDIT_RECORD_CONTEXT);
  772. }
  773. /**
  774. * audit_syscall_exit - deallocate audit context after a system call
  775. * @tsk: task being audited
  776. * @valid: success/failure flag
  777. * @return_code: syscall return value
  778. *
  779. * Tear down after system call. If the audit context has been marked as
  780. * auditable (either because of the AUDIT_RECORD_CONTEXT state from
  781. * filtering, or because some other part of the kernel write an audit
  782. * message), then write out the syscall information. In call cases,
  783. * free the names stored from getname().
  784. */
  785. void audit_syscall_exit(int valid, long return_code)
  786. {
  787. struct task_struct *tsk = current;
  788. struct audit_context *context;
  789. context = audit_get_context(tsk, valid, return_code);
  790. if (likely(!context))
  791. return;
  792. if (context->in_syscall && context->auditable)
  793. audit_log_exit(context, tsk);
  794. context->in_syscall = 0;
  795. context->auditable = 0;
  796. if (context->previous) {
  797. struct audit_context *new_context = context->previous;
  798. context->previous = NULL;
  799. audit_free_context(context);
  800. tsk->audit_context = new_context;
  801. } else {
  802. audit_free_names(context);
  803. audit_free_aux(context);
  804. tsk->audit_context = context;
  805. }
  806. }
  807. /**
  808. * audit_getname - add a name to the list
  809. * @name: name to add
  810. *
  811. * Add a name to the list of audit names for this context.
  812. * Called from fs/namei.c:getname().
  813. */
  814. void audit_getname(const char *name)
  815. {
  816. struct audit_context *context = current->audit_context;
  817. if (!context || IS_ERR(name) || !name)
  818. return;
  819. if (!context->in_syscall) {
  820. #if AUDIT_DEBUG == 2
  821. printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n",
  822. __FILE__, __LINE__, context->serial, name);
  823. dump_stack();
  824. #endif
  825. return;
  826. }
  827. BUG_ON(context->name_count >= AUDIT_NAMES);
  828. context->names[context->name_count].name = name;
  829. context->names[context->name_count].ino = (unsigned long)-1;
  830. ++context->name_count;
  831. if (!context->pwd) {
  832. read_lock(&current->fs->lock);
  833. context->pwd = dget(current->fs->pwd);
  834. context->pwdmnt = mntget(current->fs->pwdmnt);
  835. read_unlock(&current->fs->lock);
  836. }
  837. }
  838. /* audit_putname - intercept a putname request
  839. * @name: name to intercept and delay for putname
  840. *
  841. * If we have stored the name from getname in the audit context,
  842. * then we delay the putname until syscall exit.
  843. * Called from include/linux/fs.h:putname().
  844. */
  845. void audit_putname(const char *name)
  846. {
  847. struct audit_context *context = current->audit_context;
  848. BUG_ON(!context);
  849. if (!context->in_syscall) {
  850. #if AUDIT_DEBUG == 2
  851. printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n",
  852. __FILE__, __LINE__, context->serial, name);
  853. if (context->name_count) {
  854. int i;
  855. for (i = 0; i < context->name_count; i++)
  856. printk(KERN_ERR "name[%d] = %p = %s\n", i,
  857. context->names[i].name,
  858. context->names[i].name ?: "(null)");
  859. }
  860. #endif
  861. __putname(name);
  862. }
  863. #if AUDIT_DEBUG
  864. else {
  865. ++context->put_count;
  866. if (context->put_count > context->name_count) {
  867. printk(KERN_ERR "%s:%d(:%d): major=%d"
  868. " in_syscall=%d putname(%p) name_count=%d"
  869. " put_count=%d\n",
  870. __FILE__, __LINE__,
  871. context->serial, context->major,
  872. context->in_syscall, name, context->name_count,
  873. context->put_count);
  874. dump_stack();
  875. }
  876. }
  877. #endif
  878. }
  879. static void audit_inode_context(int idx, const struct inode *inode)
  880. {
  881. struct audit_context *context = current->audit_context;
  882. selinux_get_inode_sid(inode, &context->names[idx].osid);
  883. }
  884. /**
  885. * audit_inode - store the inode and device from a lookup
  886. * @name: name being audited
  887. * @inode: inode being audited
  888. * @flags: lookup flags (as used in path_lookup())
  889. *
  890. * Called from fs/namei.c:path_lookup().
  891. */
  892. void __audit_inode(const char *name, const struct inode *inode, unsigned flags)
  893. {
  894. int idx;
  895. struct audit_context *context = current->audit_context;
  896. if (!context->in_syscall)
  897. return;
  898. if (context->name_count
  899. && context->names[context->name_count-1].name
  900. && context->names[context->name_count-1].name == name)
  901. idx = context->name_count - 1;
  902. else if (context->name_count > 1
  903. && context->names[context->name_count-2].name
  904. && context->names[context->name_count-2].name == name)
  905. idx = context->name_count - 2;
  906. else {
  907. /* FIXME: how much do we care about inodes that have no
  908. * associated name? */
  909. if (context->name_count >= AUDIT_NAMES - AUDIT_NAMES_RESERVED)
  910. return;
  911. idx = context->name_count++;
  912. context->names[idx].name = NULL;
  913. #if AUDIT_DEBUG
  914. ++context->ino_count;
  915. #endif
  916. }
  917. context->names[idx].dev = inode->i_sb->s_dev;
  918. context->names[idx].mode = inode->i_mode;
  919. context->names[idx].uid = inode->i_uid;
  920. context->names[idx].gid = inode->i_gid;
  921. context->names[idx].rdev = inode->i_rdev;
  922. audit_inode_context(idx, inode);
  923. if ((flags & LOOKUP_PARENT) && (strcmp(name, "/") != 0) &&
  924. (strcmp(name, ".") != 0)) {
  925. context->names[idx].ino = (unsigned long)-1;
  926. context->names[idx].pino = inode->i_ino;
  927. } else {
  928. context->names[idx].ino = inode->i_ino;
  929. context->names[idx].pino = (unsigned long)-1;
  930. }
  931. }
  932. /**
  933. * audit_inode_child - collect inode info for created/removed objects
  934. * @dname: inode's dentry name
  935. * @inode: inode being audited
  936. * @pino: inode number of dentry parent
  937. *
  938. * For syscalls that create or remove filesystem objects, audit_inode
  939. * can only collect information for the filesystem object's parent.
  940. * This call updates the audit context with the child's information.
  941. * Syscalls that create a new filesystem object must be hooked after
  942. * the object is created. Syscalls that remove a filesystem object
  943. * must be hooked prior, in order to capture the target inode during
  944. * unsuccessful attempts.
  945. */
  946. void __audit_inode_child(const char *dname, const struct inode *inode,
  947. unsigned long pino)
  948. {
  949. int idx;
  950. struct audit_context *context = current->audit_context;
  951. if (!context->in_syscall)
  952. return;
  953. /* determine matching parent */
  954. if (dname)
  955. for (idx = 0; idx < context->name_count; idx++)
  956. if (context->names[idx].pino == pino) {
  957. const char *n;
  958. const char *name = context->names[idx].name;
  959. int dlen = strlen(dname);
  960. int nlen = name ? strlen(name) : 0;
  961. if (nlen < dlen)
  962. continue;
  963. /* disregard trailing slashes */
  964. n = name + nlen - 1;
  965. while ((*n == '/') && (n > name))
  966. n--;
  967. /* find last path component */
  968. n = n - dlen + 1;
  969. if (n < name)
  970. continue;
  971. else if (n > name) {
  972. if (*--n != '/')
  973. continue;
  974. else
  975. n++;
  976. }
  977. if (strncmp(n, dname, dlen) == 0)
  978. goto update_context;
  979. }
  980. /* catch-all in case match not found */
  981. idx = context->name_count++;
  982. context->names[idx].name = NULL;
  983. context->names[idx].pino = pino;
  984. #if AUDIT_DEBUG
  985. context->ino_count++;
  986. #endif
  987. update_context:
  988. if (inode) {
  989. context->names[idx].ino = inode->i_ino;
  990. context->names[idx].dev = inode->i_sb->s_dev;
  991. context->names[idx].mode = inode->i_mode;
  992. context->names[idx].uid = inode->i_uid;
  993. context->names[idx].gid = inode->i_gid;
  994. context->names[idx].rdev = inode->i_rdev;
  995. audit_inode_context(idx, inode);
  996. }
  997. }
  998. /**
  999. * auditsc_get_stamp - get local copies of audit_context values
  1000. * @ctx: audit_context for the task
  1001. * @t: timespec to store time recorded in the audit_context
  1002. * @serial: serial value that is recorded in the audit_context
  1003. *
  1004. * Also sets the context as auditable.
  1005. */
  1006. void auditsc_get_stamp(struct audit_context *ctx,
  1007. struct timespec *t, unsigned int *serial)
  1008. {
  1009. if (!ctx->serial)
  1010. ctx->serial = audit_serial();
  1011. t->tv_sec = ctx->ctime.tv_sec;
  1012. t->tv_nsec = ctx->ctime.tv_nsec;
  1013. *serial = ctx->serial;
  1014. ctx->auditable = 1;
  1015. }
  1016. /**
  1017. * audit_set_loginuid - set a task's audit_context loginuid
  1018. * @task: task whose audit context is being modified
  1019. * @loginuid: loginuid value
  1020. *
  1021. * Returns 0.
  1022. *
  1023. * Called (set) from fs/proc/base.c::proc_loginuid_write().
  1024. */
  1025. int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
  1026. {
  1027. if (task->audit_context) {
  1028. struct audit_buffer *ab;
  1029. ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
  1030. if (ab) {
  1031. audit_log_format(ab, "login pid=%d uid=%u "
  1032. "old auid=%u new auid=%u",
  1033. task->pid, task->uid,
  1034. task->audit_context->loginuid, loginuid);
  1035. audit_log_end(ab);
  1036. }
  1037. task->audit_context->loginuid = loginuid;
  1038. }
  1039. return 0;
  1040. }
  1041. /**
  1042. * audit_get_loginuid - get the loginuid for an audit_context
  1043. * @ctx: the audit_context
  1044. *
  1045. * Returns the context's loginuid or -1 if @ctx is NULL.
  1046. */
  1047. uid_t audit_get_loginuid(struct audit_context *ctx)
  1048. {
  1049. return ctx ? ctx->loginuid : -1;
  1050. }
  1051. /**
  1052. * audit_ipc_obj - record audit data for ipc object
  1053. * @ipcp: ipc permissions
  1054. *
  1055. * Returns 0 for success or NULL context or < 0 on error.
  1056. */
  1057. int audit_ipc_obj(struct kern_ipc_perm *ipcp)
  1058. {
  1059. struct audit_aux_data_ipcctl *ax;
  1060. struct audit_context *context = current->audit_context;
  1061. if (likely(!context))
  1062. return 0;
  1063. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1064. if (!ax)
  1065. return -ENOMEM;
  1066. ax->uid = ipcp->uid;
  1067. ax->gid = ipcp->gid;
  1068. ax->mode = ipcp->mode;
  1069. selinux_get_ipc_sid(ipcp, &ax->osid);
  1070. ax->d.type = AUDIT_IPC;
  1071. ax->d.next = context->aux;
  1072. context->aux = (void *)ax;
  1073. return 0;
  1074. }
  1075. /**
  1076. * audit_ipc_set_perm - record audit data for new ipc permissions
  1077. * @qbytes: msgq bytes
  1078. * @uid: msgq user id
  1079. * @gid: msgq group id
  1080. * @mode: msgq mode (permissions)
  1081. *
  1082. * Returns 0 for success or NULL context or < 0 on error.
  1083. */
  1084. int audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode, struct kern_ipc_perm *ipcp)
  1085. {
  1086. struct audit_aux_data_ipcctl *ax;
  1087. struct audit_context *context = current->audit_context;
  1088. if (likely(!context))
  1089. return 0;
  1090. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1091. if (!ax)
  1092. return -ENOMEM;
  1093. ax->qbytes = qbytes;
  1094. ax->uid = uid;
  1095. ax->gid = gid;
  1096. ax->mode = mode;
  1097. selinux_get_ipc_sid(ipcp, &ax->osid);
  1098. ax->d.type = AUDIT_IPC_SET_PERM;
  1099. ax->d.next = context->aux;
  1100. context->aux = (void *)ax;
  1101. return 0;
  1102. }
  1103. /**
  1104. * audit_socketcall - record audit data for sys_socketcall
  1105. * @nargs: number of args
  1106. * @args: args array
  1107. *
  1108. * Returns 0 for success or NULL context or < 0 on error.
  1109. */
  1110. int audit_socketcall(int nargs, unsigned long *args)
  1111. {
  1112. struct audit_aux_data_socketcall *ax;
  1113. struct audit_context *context = current->audit_context;
  1114. if (likely(!context))
  1115. return 0;
  1116. ax = kmalloc(sizeof(*ax) + nargs * sizeof(unsigned long), GFP_KERNEL);
  1117. if (!ax)
  1118. return -ENOMEM;
  1119. ax->nargs = nargs;
  1120. memcpy(ax->args, args, nargs * sizeof(unsigned long));
  1121. ax->d.type = AUDIT_SOCKETCALL;
  1122. ax->d.next = context->aux;
  1123. context->aux = (void *)ax;
  1124. return 0;
  1125. }
  1126. /**
  1127. * audit_sockaddr - record audit data for sys_bind, sys_connect, sys_sendto
  1128. * @len: data length in user space
  1129. * @a: data address in kernel space
  1130. *
  1131. * Returns 0 for success or NULL context or < 0 on error.
  1132. */
  1133. int audit_sockaddr(int len, void *a)
  1134. {
  1135. struct audit_aux_data_sockaddr *ax;
  1136. struct audit_context *context = current->audit_context;
  1137. if (likely(!context))
  1138. return 0;
  1139. ax = kmalloc(sizeof(*ax) + len, GFP_KERNEL);
  1140. if (!ax)
  1141. return -ENOMEM;
  1142. ax->len = len;
  1143. memcpy(ax->a, a, len);
  1144. ax->d.type = AUDIT_SOCKADDR;
  1145. ax->d.next = context->aux;
  1146. context->aux = (void *)ax;
  1147. return 0;
  1148. }
  1149. /**
  1150. * audit_avc_path - record the granting or denial of permissions
  1151. * @dentry: dentry to record
  1152. * @mnt: mnt to record
  1153. *
  1154. * Returns 0 for success or NULL context or < 0 on error.
  1155. *
  1156. * Called from security/selinux/avc.c::avc_audit()
  1157. */
  1158. int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt)
  1159. {
  1160. struct audit_aux_data_path *ax;
  1161. struct audit_context *context = current->audit_context;
  1162. if (likely(!context))
  1163. return 0;
  1164. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1165. if (!ax)
  1166. return -ENOMEM;
  1167. ax->dentry = dget(dentry);
  1168. ax->mnt = mntget(mnt);
  1169. ax->d.type = AUDIT_AVC_PATH;
  1170. ax->d.next = context->aux;
  1171. context->aux = (void *)ax;
  1172. return 0;
  1173. }
  1174. /**
  1175. * audit_signal_info - record signal info for shutting down audit subsystem
  1176. * @sig: signal value
  1177. * @t: task being signaled
  1178. *
  1179. * If the audit subsystem is being terminated, record the task (pid)
  1180. * and uid that is doing that.
  1181. */
  1182. void audit_signal_info(int sig, struct task_struct *t)
  1183. {
  1184. extern pid_t audit_sig_pid;
  1185. extern uid_t audit_sig_uid;
  1186. if (unlikely(audit_pid && t->tgid == audit_pid)) {
  1187. if (sig == SIGTERM || sig == SIGHUP) {
  1188. struct audit_context *ctx = current->audit_context;
  1189. audit_sig_pid = current->pid;
  1190. if (ctx)
  1191. audit_sig_uid = ctx->loginuid;
  1192. else
  1193. audit_sig_uid = current->uid;
  1194. }
  1195. }
  1196. }