auditsc.c 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966
  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, 2006 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. * POSIX message queue support added by George Wilson <ltcgcw@us.ibm.com>,
  33. * 2006.
  34. *
  35. * The support of additional filter rules compares (>, <, >=, <=) was
  36. * added by Dustin Kirkland <dustin.kirkland@us.ibm.com>, 2005.
  37. *
  38. * Modified by Amy Griffis <amy.griffis@hp.com> to collect additional
  39. * filesystem information.
  40. *
  41. * Subject and object context labeling support added by <danjones@us.ibm.com>
  42. * and <dustin.kirkland@us.ibm.com> for LSPP certification compliance.
  43. */
  44. #include <linux/init.h>
  45. #include <asm/types.h>
  46. #include <asm/atomic.h>
  47. #include <asm/types.h>
  48. #include <linux/fs.h>
  49. #include <linux/namei.h>
  50. #include <linux/mm.h>
  51. #include <linux/module.h>
  52. #include <linux/mount.h>
  53. #include <linux/socket.h>
  54. #include <linux/mqueue.h>
  55. #include <linux/audit.h>
  56. #include <linux/personality.h>
  57. #include <linux/time.h>
  58. #include <linux/netlink.h>
  59. #include <linux/compiler.h>
  60. #include <asm/unistd.h>
  61. #include <linux/security.h>
  62. #include <linux/list.h>
  63. #include <linux/tty.h>
  64. #include <linux/selinux.h>
  65. #include <linux/binfmts.h>
  66. #include <linux/highmem.h>
  67. #include <linux/syscalls.h>
  68. #include "audit.h"
  69. extern struct list_head audit_filter_list[];
  70. /* No syscall auditing will take place unless audit_enabled != 0. */
  71. extern int audit_enabled;
  72. /* AUDIT_NAMES is the number of slots we reserve in the audit_context
  73. * for saving names from getname(). */
  74. #define AUDIT_NAMES 20
  75. /* AUDIT_NAMES_RESERVED is the number of slots we reserve in the
  76. * audit_context from being used for nameless inodes from
  77. * path_lookup. */
  78. #define AUDIT_NAMES_RESERVED 7
  79. /* Indicates that audit should log the full pathname. */
  80. #define AUDIT_NAME_FULL -1
  81. /* number of audit rules */
  82. int audit_n_rules;
  83. /* When fs/namei.c:getname() is called, we store the pointer in name and
  84. * we don't let putname() free it (instead we free all of the saved
  85. * pointers at syscall exit time).
  86. *
  87. * Further, in fs/namei.c:path_lookup() we store the inode and device. */
  88. struct audit_names {
  89. const char *name;
  90. int name_len; /* number of name's characters to log */
  91. unsigned name_put; /* call __putname() for this name */
  92. unsigned long ino;
  93. dev_t dev;
  94. umode_t mode;
  95. uid_t uid;
  96. gid_t gid;
  97. dev_t rdev;
  98. u32 osid;
  99. };
  100. struct audit_aux_data {
  101. struct audit_aux_data *next;
  102. int type;
  103. };
  104. #define AUDIT_AUX_IPCPERM 0
  105. struct audit_aux_data_mq_open {
  106. struct audit_aux_data d;
  107. int oflag;
  108. mode_t mode;
  109. struct mq_attr attr;
  110. };
  111. struct audit_aux_data_mq_sendrecv {
  112. struct audit_aux_data d;
  113. mqd_t mqdes;
  114. size_t msg_len;
  115. unsigned int msg_prio;
  116. struct timespec abs_timeout;
  117. };
  118. struct audit_aux_data_mq_notify {
  119. struct audit_aux_data d;
  120. mqd_t mqdes;
  121. struct sigevent notification;
  122. };
  123. struct audit_aux_data_mq_getsetattr {
  124. struct audit_aux_data d;
  125. mqd_t mqdes;
  126. struct mq_attr mqstat;
  127. };
  128. struct audit_aux_data_ipcctl {
  129. struct audit_aux_data d;
  130. struct ipc_perm p;
  131. unsigned long qbytes;
  132. uid_t uid;
  133. gid_t gid;
  134. mode_t mode;
  135. u32 osid;
  136. };
  137. struct audit_aux_data_execve {
  138. struct audit_aux_data d;
  139. int argc;
  140. int envc;
  141. char mem[0];
  142. };
  143. struct audit_aux_data_socketcall {
  144. struct audit_aux_data d;
  145. int nargs;
  146. unsigned long args[0];
  147. };
  148. struct audit_aux_data_sockaddr {
  149. struct audit_aux_data d;
  150. int len;
  151. char a[0];
  152. };
  153. struct audit_aux_data_fd_pair {
  154. struct audit_aux_data d;
  155. int fd[2];
  156. };
  157. struct audit_aux_data_path {
  158. struct audit_aux_data d;
  159. struct dentry *dentry;
  160. struct vfsmount *mnt;
  161. };
  162. /* The per-task audit context. */
  163. struct audit_context {
  164. int dummy; /* must be the first element */
  165. int in_syscall; /* 1 if task is in a syscall */
  166. enum audit_state state;
  167. unsigned int serial; /* serial number for record */
  168. struct timespec ctime; /* time of syscall entry */
  169. uid_t loginuid; /* login uid (identity) */
  170. int major; /* syscall number */
  171. unsigned long argv[4]; /* syscall arguments */
  172. int return_valid; /* return code is valid */
  173. long return_code;/* syscall return code */
  174. int auditable; /* 1 if record should be written */
  175. int name_count;
  176. struct audit_names names[AUDIT_NAMES];
  177. char * filterkey; /* key for rule that triggered record */
  178. struct dentry * pwd;
  179. struct vfsmount * pwdmnt;
  180. struct audit_context *previous; /* For nested syscalls */
  181. struct audit_aux_data *aux;
  182. /* Save things to print about task_struct */
  183. pid_t pid, ppid;
  184. uid_t uid, euid, suid, fsuid;
  185. gid_t gid, egid, sgid, fsgid;
  186. unsigned long personality;
  187. int arch;
  188. pid_t target_pid;
  189. u32 target_sid;
  190. #if AUDIT_DEBUG
  191. int put_count;
  192. int ino_count;
  193. #endif
  194. };
  195. #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
  196. static inline int open_arg(int flags, int mask)
  197. {
  198. int n = ACC_MODE(flags);
  199. if (flags & (O_TRUNC | O_CREAT))
  200. n |= AUDIT_PERM_WRITE;
  201. return n & mask;
  202. }
  203. static int audit_match_perm(struct audit_context *ctx, int mask)
  204. {
  205. unsigned n = ctx->major;
  206. switch (audit_classify_syscall(ctx->arch, n)) {
  207. case 0: /* native */
  208. if ((mask & AUDIT_PERM_WRITE) &&
  209. audit_match_class(AUDIT_CLASS_WRITE, n))
  210. return 1;
  211. if ((mask & AUDIT_PERM_READ) &&
  212. audit_match_class(AUDIT_CLASS_READ, n))
  213. return 1;
  214. if ((mask & AUDIT_PERM_ATTR) &&
  215. audit_match_class(AUDIT_CLASS_CHATTR, n))
  216. return 1;
  217. return 0;
  218. case 1: /* 32bit on biarch */
  219. if ((mask & AUDIT_PERM_WRITE) &&
  220. audit_match_class(AUDIT_CLASS_WRITE_32, n))
  221. return 1;
  222. if ((mask & AUDIT_PERM_READ) &&
  223. audit_match_class(AUDIT_CLASS_READ_32, n))
  224. return 1;
  225. if ((mask & AUDIT_PERM_ATTR) &&
  226. audit_match_class(AUDIT_CLASS_CHATTR_32, n))
  227. return 1;
  228. return 0;
  229. case 2: /* open */
  230. return mask & ACC_MODE(ctx->argv[1]);
  231. case 3: /* openat */
  232. return mask & ACC_MODE(ctx->argv[2]);
  233. case 4: /* socketcall */
  234. return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == SYS_BIND);
  235. case 5: /* execve */
  236. return mask & AUDIT_PERM_EXEC;
  237. default:
  238. return 0;
  239. }
  240. }
  241. /* Determine if any context name data matches a rule's watch data */
  242. /* Compare a task_struct with an audit_rule. Return 1 on match, 0
  243. * otherwise. */
  244. static int audit_filter_rules(struct task_struct *tsk,
  245. struct audit_krule *rule,
  246. struct audit_context *ctx,
  247. struct audit_names *name,
  248. enum audit_state *state)
  249. {
  250. int i, j, need_sid = 1;
  251. u32 sid;
  252. for (i = 0; i < rule->field_count; i++) {
  253. struct audit_field *f = &rule->fields[i];
  254. int result = 0;
  255. switch (f->type) {
  256. case AUDIT_PID:
  257. result = audit_comparator(tsk->pid, f->op, f->val);
  258. break;
  259. case AUDIT_PPID:
  260. if (ctx) {
  261. if (!ctx->ppid)
  262. ctx->ppid = sys_getppid();
  263. result = audit_comparator(ctx->ppid, f->op, f->val);
  264. }
  265. break;
  266. case AUDIT_UID:
  267. result = audit_comparator(tsk->uid, f->op, f->val);
  268. break;
  269. case AUDIT_EUID:
  270. result = audit_comparator(tsk->euid, f->op, f->val);
  271. break;
  272. case AUDIT_SUID:
  273. result = audit_comparator(tsk->suid, f->op, f->val);
  274. break;
  275. case AUDIT_FSUID:
  276. result = audit_comparator(tsk->fsuid, f->op, f->val);
  277. break;
  278. case AUDIT_GID:
  279. result = audit_comparator(tsk->gid, f->op, f->val);
  280. break;
  281. case AUDIT_EGID:
  282. result = audit_comparator(tsk->egid, f->op, f->val);
  283. break;
  284. case AUDIT_SGID:
  285. result = audit_comparator(tsk->sgid, f->op, f->val);
  286. break;
  287. case AUDIT_FSGID:
  288. result = audit_comparator(tsk->fsgid, f->op, f->val);
  289. break;
  290. case AUDIT_PERS:
  291. result = audit_comparator(tsk->personality, f->op, f->val);
  292. break;
  293. case AUDIT_ARCH:
  294. if (ctx)
  295. result = audit_comparator(ctx->arch, f->op, f->val);
  296. break;
  297. case AUDIT_EXIT:
  298. if (ctx && ctx->return_valid)
  299. result = audit_comparator(ctx->return_code, f->op, f->val);
  300. break;
  301. case AUDIT_SUCCESS:
  302. if (ctx && ctx->return_valid) {
  303. if (f->val)
  304. result = audit_comparator(ctx->return_valid, f->op, AUDITSC_SUCCESS);
  305. else
  306. result = audit_comparator(ctx->return_valid, f->op, AUDITSC_FAILURE);
  307. }
  308. break;
  309. case AUDIT_DEVMAJOR:
  310. if (name)
  311. result = audit_comparator(MAJOR(name->dev),
  312. f->op, f->val);
  313. else if (ctx) {
  314. for (j = 0; j < ctx->name_count; j++) {
  315. if (audit_comparator(MAJOR(ctx->names[j].dev), f->op, f->val)) {
  316. ++result;
  317. break;
  318. }
  319. }
  320. }
  321. break;
  322. case AUDIT_DEVMINOR:
  323. if (name)
  324. result = audit_comparator(MINOR(name->dev),
  325. f->op, f->val);
  326. else if (ctx) {
  327. for (j = 0; j < ctx->name_count; j++) {
  328. if (audit_comparator(MINOR(ctx->names[j].dev), f->op, f->val)) {
  329. ++result;
  330. break;
  331. }
  332. }
  333. }
  334. break;
  335. case AUDIT_INODE:
  336. if (name)
  337. result = (name->ino == f->val);
  338. else if (ctx) {
  339. for (j = 0; j < ctx->name_count; j++) {
  340. if (audit_comparator(ctx->names[j].ino, f->op, f->val)) {
  341. ++result;
  342. break;
  343. }
  344. }
  345. }
  346. break;
  347. case AUDIT_WATCH:
  348. if (name && rule->watch->ino != (unsigned long)-1)
  349. result = (name->dev == rule->watch->dev &&
  350. name->ino == rule->watch->ino);
  351. break;
  352. case AUDIT_LOGINUID:
  353. result = 0;
  354. if (ctx)
  355. result = audit_comparator(ctx->loginuid, f->op, f->val);
  356. break;
  357. case AUDIT_SUBJ_USER:
  358. case AUDIT_SUBJ_ROLE:
  359. case AUDIT_SUBJ_TYPE:
  360. case AUDIT_SUBJ_SEN:
  361. case AUDIT_SUBJ_CLR:
  362. /* NOTE: this may return negative values indicating
  363. a temporary error. We simply treat this as a
  364. match for now to avoid losing information that
  365. may be wanted. An error message will also be
  366. logged upon error */
  367. if (f->se_rule) {
  368. if (need_sid) {
  369. selinux_get_task_sid(tsk, &sid);
  370. need_sid = 0;
  371. }
  372. result = selinux_audit_rule_match(sid, f->type,
  373. f->op,
  374. f->se_rule,
  375. ctx);
  376. }
  377. break;
  378. case AUDIT_OBJ_USER:
  379. case AUDIT_OBJ_ROLE:
  380. case AUDIT_OBJ_TYPE:
  381. case AUDIT_OBJ_LEV_LOW:
  382. case AUDIT_OBJ_LEV_HIGH:
  383. /* The above note for AUDIT_SUBJ_USER...AUDIT_SUBJ_CLR
  384. also applies here */
  385. if (f->se_rule) {
  386. /* Find files that match */
  387. if (name) {
  388. result = selinux_audit_rule_match(
  389. name->osid, f->type, f->op,
  390. f->se_rule, ctx);
  391. } else if (ctx) {
  392. for (j = 0; j < ctx->name_count; j++) {
  393. if (selinux_audit_rule_match(
  394. ctx->names[j].osid,
  395. f->type, f->op,
  396. f->se_rule, ctx)) {
  397. ++result;
  398. break;
  399. }
  400. }
  401. }
  402. /* Find ipc objects that match */
  403. if (ctx) {
  404. struct audit_aux_data *aux;
  405. for (aux = ctx->aux; aux;
  406. aux = aux->next) {
  407. if (aux->type == AUDIT_IPC) {
  408. struct audit_aux_data_ipcctl *axi = (void *)aux;
  409. if (selinux_audit_rule_match(axi->osid, f->type, f->op, f->se_rule, ctx)) {
  410. ++result;
  411. break;
  412. }
  413. }
  414. }
  415. }
  416. }
  417. break;
  418. case AUDIT_ARG0:
  419. case AUDIT_ARG1:
  420. case AUDIT_ARG2:
  421. case AUDIT_ARG3:
  422. if (ctx)
  423. result = audit_comparator(ctx->argv[f->type-AUDIT_ARG0], f->op, f->val);
  424. break;
  425. case AUDIT_FILTERKEY:
  426. /* ignore this field for filtering */
  427. result = 1;
  428. break;
  429. case AUDIT_PERM:
  430. result = audit_match_perm(ctx, f->val);
  431. break;
  432. }
  433. if (!result)
  434. return 0;
  435. }
  436. if (rule->filterkey)
  437. ctx->filterkey = kstrdup(rule->filterkey, GFP_ATOMIC);
  438. switch (rule->action) {
  439. case AUDIT_NEVER: *state = AUDIT_DISABLED; break;
  440. case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break;
  441. }
  442. return 1;
  443. }
  444. /* At process creation time, we can determine if system-call auditing is
  445. * completely disabled for this task. Since we only have the task
  446. * structure at this point, we can only check uid and gid.
  447. */
  448. static enum audit_state audit_filter_task(struct task_struct *tsk)
  449. {
  450. struct audit_entry *e;
  451. enum audit_state state;
  452. rcu_read_lock();
  453. list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) {
  454. if (audit_filter_rules(tsk, &e->rule, NULL, NULL, &state)) {
  455. rcu_read_unlock();
  456. return state;
  457. }
  458. }
  459. rcu_read_unlock();
  460. return AUDIT_BUILD_CONTEXT;
  461. }
  462. /* At syscall entry and exit time, this filter is called if the
  463. * audit_state is not low enough that auditing cannot take place, but is
  464. * also not high enough that we already know we have to write an audit
  465. * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT).
  466. */
  467. static enum audit_state audit_filter_syscall(struct task_struct *tsk,
  468. struct audit_context *ctx,
  469. struct list_head *list)
  470. {
  471. struct audit_entry *e;
  472. enum audit_state state;
  473. if (audit_pid && tsk->tgid == audit_pid)
  474. return AUDIT_DISABLED;
  475. rcu_read_lock();
  476. if (!list_empty(list)) {
  477. int word = AUDIT_WORD(ctx->major);
  478. int bit = AUDIT_BIT(ctx->major);
  479. list_for_each_entry_rcu(e, list, list) {
  480. if ((e->rule.mask[word] & bit) == bit &&
  481. audit_filter_rules(tsk, &e->rule, ctx, NULL,
  482. &state)) {
  483. rcu_read_unlock();
  484. return state;
  485. }
  486. }
  487. }
  488. rcu_read_unlock();
  489. return AUDIT_BUILD_CONTEXT;
  490. }
  491. /* At syscall exit time, this filter is called if any audit_names[] have been
  492. * collected during syscall processing. We only check rules in sublists at hash
  493. * buckets applicable to the inode numbers in audit_names[].
  494. * Regarding audit_state, same rules apply as for audit_filter_syscall().
  495. */
  496. enum audit_state audit_filter_inodes(struct task_struct *tsk,
  497. struct audit_context *ctx)
  498. {
  499. int i;
  500. struct audit_entry *e;
  501. enum audit_state state;
  502. if (audit_pid && tsk->tgid == audit_pid)
  503. return AUDIT_DISABLED;
  504. rcu_read_lock();
  505. for (i = 0; i < ctx->name_count; i++) {
  506. int word = AUDIT_WORD(ctx->major);
  507. int bit = AUDIT_BIT(ctx->major);
  508. struct audit_names *n = &ctx->names[i];
  509. int h = audit_hash_ino((u32)n->ino);
  510. struct list_head *list = &audit_inode_hash[h];
  511. if (list_empty(list))
  512. continue;
  513. list_for_each_entry_rcu(e, list, list) {
  514. if ((e->rule.mask[word] & bit) == bit &&
  515. audit_filter_rules(tsk, &e->rule, ctx, n, &state)) {
  516. rcu_read_unlock();
  517. return state;
  518. }
  519. }
  520. }
  521. rcu_read_unlock();
  522. return AUDIT_BUILD_CONTEXT;
  523. }
  524. void audit_set_auditable(struct audit_context *ctx)
  525. {
  526. ctx->auditable = 1;
  527. }
  528. static inline struct audit_context *audit_get_context(struct task_struct *tsk,
  529. int return_valid,
  530. int return_code)
  531. {
  532. struct audit_context *context = tsk->audit_context;
  533. if (likely(!context))
  534. return NULL;
  535. context->return_valid = return_valid;
  536. context->return_code = return_code;
  537. if (context->in_syscall && !context->dummy && !context->auditable) {
  538. enum audit_state state;
  539. state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_EXIT]);
  540. if (state == AUDIT_RECORD_CONTEXT) {
  541. context->auditable = 1;
  542. goto get_context;
  543. }
  544. state = audit_filter_inodes(tsk, context);
  545. if (state == AUDIT_RECORD_CONTEXT)
  546. context->auditable = 1;
  547. }
  548. get_context:
  549. tsk->audit_context = NULL;
  550. return context;
  551. }
  552. static inline void audit_free_names(struct audit_context *context)
  553. {
  554. int i;
  555. #if AUDIT_DEBUG == 2
  556. if (context->auditable
  557. ||context->put_count + context->ino_count != context->name_count) {
  558. printk(KERN_ERR "%s:%d(:%d): major=%d in_syscall=%d"
  559. " name_count=%d put_count=%d"
  560. " ino_count=%d [NOT freeing]\n",
  561. __FILE__, __LINE__,
  562. context->serial, context->major, context->in_syscall,
  563. context->name_count, context->put_count,
  564. context->ino_count);
  565. for (i = 0; i < context->name_count; i++) {
  566. printk(KERN_ERR "names[%d] = %p = %s\n", i,
  567. context->names[i].name,
  568. context->names[i].name ?: "(null)");
  569. }
  570. dump_stack();
  571. return;
  572. }
  573. #endif
  574. #if AUDIT_DEBUG
  575. context->put_count = 0;
  576. context->ino_count = 0;
  577. #endif
  578. for (i = 0; i < context->name_count; i++) {
  579. if (context->names[i].name && context->names[i].name_put)
  580. __putname(context->names[i].name);
  581. }
  582. context->name_count = 0;
  583. if (context->pwd)
  584. dput(context->pwd);
  585. if (context->pwdmnt)
  586. mntput(context->pwdmnt);
  587. context->pwd = NULL;
  588. context->pwdmnt = NULL;
  589. }
  590. static inline void audit_free_aux(struct audit_context *context)
  591. {
  592. struct audit_aux_data *aux;
  593. while ((aux = context->aux)) {
  594. if (aux->type == AUDIT_AVC_PATH) {
  595. struct audit_aux_data_path *axi = (void *)aux;
  596. dput(axi->dentry);
  597. mntput(axi->mnt);
  598. }
  599. context->aux = aux->next;
  600. kfree(aux);
  601. }
  602. }
  603. static inline void audit_zero_context(struct audit_context *context,
  604. enum audit_state state)
  605. {
  606. uid_t loginuid = context->loginuid;
  607. memset(context, 0, sizeof(*context));
  608. context->state = state;
  609. context->loginuid = loginuid;
  610. }
  611. static inline struct audit_context *audit_alloc_context(enum audit_state state)
  612. {
  613. struct audit_context *context;
  614. if (!(context = kmalloc(sizeof(*context), GFP_KERNEL)))
  615. return NULL;
  616. audit_zero_context(context, state);
  617. return context;
  618. }
  619. /**
  620. * audit_alloc - allocate an audit context block for a task
  621. * @tsk: task
  622. *
  623. * Filter on the task information and allocate a per-task audit context
  624. * if necessary. Doing so turns on system call auditing for the
  625. * specified task. This is called from copy_process, so no lock is
  626. * needed.
  627. */
  628. int audit_alloc(struct task_struct *tsk)
  629. {
  630. struct audit_context *context;
  631. enum audit_state state;
  632. if (likely(!audit_enabled))
  633. return 0; /* Return if not auditing. */
  634. state = audit_filter_task(tsk);
  635. if (likely(state == AUDIT_DISABLED))
  636. return 0;
  637. if (!(context = audit_alloc_context(state))) {
  638. audit_log_lost("out of memory in audit_alloc");
  639. return -ENOMEM;
  640. }
  641. /* Preserve login uid */
  642. context->loginuid = -1;
  643. if (current->audit_context)
  644. context->loginuid = current->audit_context->loginuid;
  645. tsk->audit_context = context;
  646. set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT);
  647. return 0;
  648. }
  649. static inline void audit_free_context(struct audit_context *context)
  650. {
  651. struct audit_context *previous;
  652. int count = 0;
  653. do {
  654. previous = context->previous;
  655. if (previous || (count && count < 10)) {
  656. ++count;
  657. printk(KERN_ERR "audit(:%d): major=%d name_count=%d:"
  658. " freeing multiple contexts (%d)\n",
  659. context->serial, context->major,
  660. context->name_count, count);
  661. }
  662. audit_free_names(context);
  663. audit_free_aux(context);
  664. kfree(context->filterkey);
  665. kfree(context);
  666. context = previous;
  667. } while (context);
  668. if (count >= 10)
  669. printk(KERN_ERR "audit: freed %d contexts\n", count);
  670. }
  671. void audit_log_task_context(struct audit_buffer *ab)
  672. {
  673. char *ctx = NULL;
  674. unsigned len;
  675. int error;
  676. u32 sid;
  677. selinux_get_task_sid(current, &sid);
  678. if (!sid)
  679. return;
  680. error = selinux_sid_to_string(sid, &ctx, &len);
  681. if (error) {
  682. if (error != -EINVAL)
  683. goto error_path;
  684. return;
  685. }
  686. audit_log_format(ab, " subj=%s", ctx);
  687. kfree(ctx);
  688. return;
  689. error_path:
  690. audit_panic("error in audit_log_task_context");
  691. return;
  692. }
  693. EXPORT_SYMBOL(audit_log_task_context);
  694. static void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
  695. {
  696. char name[sizeof(tsk->comm)];
  697. struct mm_struct *mm = tsk->mm;
  698. struct vm_area_struct *vma;
  699. /* tsk == current */
  700. get_task_comm(name, tsk);
  701. audit_log_format(ab, " comm=");
  702. audit_log_untrustedstring(ab, name);
  703. if (mm) {
  704. down_read(&mm->mmap_sem);
  705. vma = mm->mmap;
  706. while (vma) {
  707. if ((vma->vm_flags & VM_EXECUTABLE) &&
  708. vma->vm_file) {
  709. audit_log_d_path(ab, "exe=",
  710. vma->vm_file->f_path.dentry,
  711. vma->vm_file->f_path.mnt);
  712. break;
  713. }
  714. vma = vma->vm_next;
  715. }
  716. up_read(&mm->mmap_sem);
  717. }
  718. audit_log_task_context(ab);
  719. }
  720. static void audit_log_exit(struct audit_context *context, struct task_struct *tsk)
  721. {
  722. int i, call_panic = 0;
  723. struct audit_buffer *ab;
  724. struct audit_aux_data *aux;
  725. const char *tty;
  726. /* tsk == current */
  727. context->pid = tsk->pid;
  728. if (!context->ppid)
  729. context->ppid = sys_getppid();
  730. context->uid = tsk->uid;
  731. context->gid = tsk->gid;
  732. context->euid = tsk->euid;
  733. context->suid = tsk->suid;
  734. context->fsuid = tsk->fsuid;
  735. context->egid = tsk->egid;
  736. context->sgid = tsk->sgid;
  737. context->fsgid = tsk->fsgid;
  738. context->personality = tsk->personality;
  739. ab = audit_log_start(context, GFP_KERNEL, AUDIT_SYSCALL);
  740. if (!ab)
  741. return; /* audit_panic has been called */
  742. audit_log_format(ab, "arch=%x syscall=%d",
  743. context->arch, context->major);
  744. if (context->personality != PER_LINUX)
  745. audit_log_format(ab, " per=%lx", context->personality);
  746. if (context->return_valid)
  747. audit_log_format(ab, " success=%s exit=%ld",
  748. (context->return_valid==AUDITSC_SUCCESS)?"yes":"no",
  749. context->return_code);
  750. mutex_lock(&tty_mutex);
  751. read_lock(&tasklist_lock);
  752. if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name)
  753. tty = tsk->signal->tty->name;
  754. else
  755. tty = "(none)";
  756. read_unlock(&tasklist_lock);
  757. audit_log_format(ab,
  758. " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
  759. " ppid=%d pid=%d auid=%u uid=%u gid=%u"
  760. " euid=%u suid=%u fsuid=%u"
  761. " egid=%u sgid=%u fsgid=%u tty=%s",
  762. context->argv[0],
  763. context->argv[1],
  764. context->argv[2],
  765. context->argv[3],
  766. context->name_count,
  767. context->ppid,
  768. context->pid,
  769. context->loginuid,
  770. context->uid,
  771. context->gid,
  772. context->euid, context->suid, context->fsuid,
  773. context->egid, context->sgid, context->fsgid, tty);
  774. mutex_unlock(&tty_mutex);
  775. audit_log_task_info(ab, tsk);
  776. if (context->filterkey) {
  777. audit_log_format(ab, " key=");
  778. audit_log_untrustedstring(ab, context->filterkey);
  779. } else
  780. audit_log_format(ab, " key=(null)");
  781. audit_log_end(ab);
  782. for (aux = context->aux; aux; aux = aux->next) {
  783. ab = audit_log_start(context, GFP_KERNEL, aux->type);
  784. if (!ab)
  785. continue; /* audit_panic has been called */
  786. switch (aux->type) {
  787. case AUDIT_MQ_OPEN: {
  788. struct audit_aux_data_mq_open *axi = (void *)aux;
  789. audit_log_format(ab,
  790. "oflag=0x%x mode=%#o mq_flags=0x%lx mq_maxmsg=%ld "
  791. "mq_msgsize=%ld mq_curmsgs=%ld",
  792. axi->oflag, axi->mode, axi->attr.mq_flags,
  793. axi->attr.mq_maxmsg, axi->attr.mq_msgsize,
  794. axi->attr.mq_curmsgs);
  795. break; }
  796. case AUDIT_MQ_SENDRECV: {
  797. struct audit_aux_data_mq_sendrecv *axi = (void *)aux;
  798. audit_log_format(ab,
  799. "mqdes=%d msg_len=%zd msg_prio=%u "
  800. "abs_timeout_sec=%ld abs_timeout_nsec=%ld",
  801. axi->mqdes, axi->msg_len, axi->msg_prio,
  802. axi->abs_timeout.tv_sec, axi->abs_timeout.tv_nsec);
  803. break; }
  804. case AUDIT_MQ_NOTIFY: {
  805. struct audit_aux_data_mq_notify *axi = (void *)aux;
  806. audit_log_format(ab,
  807. "mqdes=%d sigev_signo=%d",
  808. axi->mqdes,
  809. axi->notification.sigev_signo);
  810. break; }
  811. case AUDIT_MQ_GETSETATTR: {
  812. struct audit_aux_data_mq_getsetattr *axi = (void *)aux;
  813. audit_log_format(ab,
  814. "mqdes=%d mq_flags=0x%lx mq_maxmsg=%ld mq_msgsize=%ld "
  815. "mq_curmsgs=%ld ",
  816. axi->mqdes,
  817. axi->mqstat.mq_flags, axi->mqstat.mq_maxmsg,
  818. axi->mqstat.mq_msgsize, axi->mqstat.mq_curmsgs);
  819. break; }
  820. case AUDIT_IPC: {
  821. struct audit_aux_data_ipcctl *axi = (void *)aux;
  822. audit_log_format(ab,
  823. "ouid=%u ogid=%u mode=%x",
  824. axi->uid, axi->gid, axi->mode);
  825. if (axi->osid != 0) {
  826. char *ctx = NULL;
  827. u32 len;
  828. if (selinux_sid_to_string(
  829. axi->osid, &ctx, &len)) {
  830. audit_log_format(ab, " osid=%u",
  831. axi->osid);
  832. call_panic = 1;
  833. } else
  834. audit_log_format(ab, " obj=%s", ctx);
  835. kfree(ctx);
  836. }
  837. break; }
  838. case AUDIT_IPC_SET_PERM: {
  839. struct audit_aux_data_ipcctl *axi = (void *)aux;
  840. audit_log_format(ab,
  841. "qbytes=%lx ouid=%u ogid=%u mode=%x",
  842. axi->qbytes, axi->uid, axi->gid, axi->mode);
  843. break; }
  844. case AUDIT_EXECVE: {
  845. struct audit_aux_data_execve *axi = (void *)aux;
  846. int i;
  847. const char *p;
  848. for (i = 0, p = axi->mem; i < axi->argc; i++) {
  849. audit_log_format(ab, "a%d=", i);
  850. p = audit_log_untrustedstring(ab, p);
  851. audit_log_format(ab, "\n");
  852. }
  853. break; }
  854. case AUDIT_SOCKETCALL: {
  855. int i;
  856. struct audit_aux_data_socketcall *axs = (void *)aux;
  857. audit_log_format(ab, "nargs=%d", axs->nargs);
  858. for (i=0; i<axs->nargs; i++)
  859. audit_log_format(ab, " a%d=%lx", i, axs->args[i]);
  860. break; }
  861. case AUDIT_SOCKADDR: {
  862. struct audit_aux_data_sockaddr *axs = (void *)aux;
  863. audit_log_format(ab, "saddr=");
  864. audit_log_hex(ab, axs->a, axs->len);
  865. break; }
  866. case AUDIT_AVC_PATH: {
  867. struct audit_aux_data_path *axi = (void *)aux;
  868. audit_log_d_path(ab, "path=", axi->dentry, axi->mnt);
  869. break; }
  870. case AUDIT_FD_PAIR: {
  871. struct audit_aux_data_fd_pair *axs = (void *)aux;
  872. audit_log_format(ab, "fd0=%d fd1=%d", axs->fd[0], axs->fd[1]);
  873. break; }
  874. }
  875. audit_log_end(ab);
  876. }
  877. if (context->target_pid) {
  878. ab =audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID);
  879. if (ab) {
  880. char *s = NULL, *t;
  881. u32 len;
  882. if (selinux_sid_to_string(context->target_sid,
  883. &s, &len))
  884. t = "(none)";
  885. else
  886. t = s;
  887. audit_log_format(ab, "opid=%d obj=%s",
  888. context->target_pid, t);
  889. audit_log_end(ab);
  890. kfree(s);
  891. }
  892. }
  893. if (context->pwd && context->pwdmnt) {
  894. ab = audit_log_start(context, GFP_KERNEL, AUDIT_CWD);
  895. if (ab) {
  896. audit_log_d_path(ab, "cwd=", context->pwd, context->pwdmnt);
  897. audit_log_end(ab);
  898. }
  899. }
  900. for (i = 0; i < context->name_count; i++) {
  901. struct audit_names *n = &context->names[i];
  902. ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH);
  903. if (!ab)
  904. continue; /* audit_panic has been called */
  905. audit_log_format(ab, "item=%d", i);
  906. if (n->name) {
  907. switch(n->name_len) {
  908. case AUDIT_NAME_FULL:
  909. /* log the full path */
  910. audit_log_format(ab, " name=");
  911. audit_log_untrustedstring(ab, n->name);
  912. break;
  913. case 0:
  914. /* name was specified as a relative path and the
  915. * directory component is the cwd */
  916. audit_log_d_path(ab, " name=", context->pwd,
  917. context->pwdmnt);
  918. break;
  919. default:
  920. /* log the name's directory component */
  921. audit_log_format(ab, " name=");
  922. audit_log_n_untrustedstring(ab, n->name_len,
  923. n->name);
  924. }
  925. } else
  926. audit_log_format(ab, " name=(null)");
  927. if (n->ino != (unsigned long)-1) {
  928. audit_log_format(ab, " inode=%lu"
  929. " dev=%02x:%02x mode=%#o"
  930. " ouid=%u ogid=%u rdev=%02x:%02x",
  931. n->ino,
  932. MAJOR(n->dev),
  933. MINOR(n->dev),
  934. n->mode,
  935. n->uid,
  936. n->gid,
  937. MAJOR(n->rdev),
  938. MINOR(n->rdev));
  939. }
  940. if (n->osid != 0) {
  941. char *ctx = NULL;
  942. u32 len;
  943. if (selinux_sid_to_string(
  944. n->osid, &ctx, &len)) {
  945. audit_log_format(ab, " osid=%u", n->osid);
  946. call_panic = 2;
  947. } else
  948. audit_log_format(ab, " obj=%s", ctx);
  949. kfree(ctx);
  950. }
  951. audit_log_end(ab);
  952. }
  953. if (call_panic)
  954. audit_panic("error converting sid to string");
  955. }
  956. /**
  957. * audit_free - free a per-task audit context
  958. * @tsk: task whose audit context block to free
  959. *
  960. * Called from copy_process and do_exit
  961. */
  962. void audit_free(struct task_struct *tsk)
  963. {
  964. struct audit_context *context;
  965. context = audit_get_context(tsk, 0, 0);
  966. if (likely(!context))
  967. return;
  968. /* Check for system calls that do not go through the exit
  969. * function (e.g., exit_group), then free context block.
  970. * We use GFP_ATOMIC here because we might be doing this
  971. * in the context of the idle thread */
  972. /* that can happen only if we are called from do_exit() */
  973. if (context->in_syscall && context->auditable)
  974. audit_log_exit(context, tsk);
  975. audit_free_context(context);
  976. }
  977. /**
  978. * audit_syscall_entry - fill in an audit record at syscall entry
  979. * @tsk: task being audited
  980. * @arch: architecture type
  981. * @major: major syscall type (function)
  982. * @a1: additional syscall register 1
  983. * @a2: additional syscall register 2
  984. * @a3: additional syscall register 3
  985. * @a4: additional syscall register 4
  986. *
  987. * Fill in audit context at syscall entry. This only happens if the
  988. * audit context was created when the task was created and the state or
  989. * filters demand the audit context be built. If the state from the
  990. * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT,
  991. * then the record will be written at syscall exit time (otherwise, it
  992. * will only be written if another part of the kernel requests that it
  993. * be written).
  994. */
  995. void audit_syscall_entry(int arch, int major,
  996. unsigned long a1, unsigned long a2,
  997. unsigned long a3, unsigned long a4)
  998. {
  999. struct task_struct *tsk = current;
  1000. struct audit_context *context = tsk->audit_context;
  1001. enum audit_state state;
  1002. BUG_ON(!context);
  1003. /*
  1004. * This happens only on certain architectures that make system
  1005. * calls in kernel_thread via the entry.S interface, instead of
  1006. * with direct calls. (If you are porting to a new
  1007. * architecture, hitting this condition can indicate that you
  1008. * got the _exit/_leave calls backward in entry.S.)
  1009. *
  1010. * i386 no
  1011. * x86_64 no
  1012. * ppc64 yes (see arch/powerpc/platforms/iseries/misc.S)
  1013. *
  1014. * This also happens with vm86 emulation in a non-nested manner
  1015. * (entries without exits), so this case must be caught.
  1016. */
  1017. if (context->in_syscall) {
  1018. struct audit_context *newctx;
  1019. #if AUDIT_DEBUG
  1020. printk(KERN_ERR
  1021. "audit(:%d) pid=%d in syscall=%d;"
  1022. " entering syscall=%d\n",
  1023. context->serial, tsk->pid, context->major, major);
  1024. #endif
  1025. newctx = audit_alloc_context(context->state);
  1026. if (newctx) {
  1027. newctx->previous = context;
  1028. context = newctx;
  1029. tsk->audit_context = newctx;
  1030. } else {
  1031. /* If we can't alloc a new context, the best we
  1032. * can do is to leak memory (any pending putname
  1033. * will be lost). The only other alternative is
  1034. * to abandon auditing. */
  1035. audit_zero_context(context, context->state);
  1036. }
  1037. }
  1038. BUG_ON(context->in_syscall || context->name_count);
  1039. if (!audit_enabled)
  1040. return;
  1041. context->arch = arch;
  1042. context->major = major;
  1043. context->argv[0] = a1;
  1044. context->argv[1] = a2;
  1045. context->argv[2] = a3;
  1046. context->argv[3] = a4;
  1047. state = context->state;
  1048. context->dummy = !audit_n_rules;
  1049. if (!context->dummy && (state == AUDIT_SETUP_CONTEXT || state == AUDIT_BUILD_CONTEXT))
  1050. state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_ENTRY]);
  1051. if (likely(state == AUDIT_DISABLED))
  1052. return;
  1053. context->serial = 0;
  1054. context->ctime = CURRENT_TIME;
  1055. context->in_syscall = 1;
  1056. context->auditable = !!(state == AUDIT_RECORD_CONTEXT);
  1057. context->ppid = 0;
  1058. }
  1059. /**
  1060. * audit_syscall_exit - deallocate audit context after a system call
  1061. * @tsk: task being audited
  1062. * @valid: success/failure flag
  1063. * @return_code: syscall return value
  1064. *
  1065. * Tear down after system call. If the audit context has been marked as
  1066. * auditable (either because of the AUDIT_RECORD_CONTEXT state from
  1067. * filtering, or because some other part of the kernel write an audit
  1068. * message), then write out the syscall information. In call cases,
  1069. * free the names stored from getname().
  1070. */
  1071. void audit_syscall_exit(int valid, long return_code)
  1072. {
  1073. struct task_struct *tsk = current;
  1074. struct audit_context *context;
  1075. context = audit_get_context(tsk, valid, return_code);
  1076. if (likely(!context))
  1077. return;
  1078. if (context->in_syscall && context->auditable)
  1079. audit_log_exit(context, tsk);
  1080. context->in_syscall = 0;
  1081. context->auditable = 0;
  1082. if (context->previous) {
  1083. struct audit_context *new_context = context->previous;
  1084. context->previous = NULL;
  1085. audit_free_context(context);
  1086. tsk->audit_context = new_context;
  1087. } else {
  1088. audit_free_names(context);
  1089. audit_free_aux(context);
  1090. context->target_pid = 0;
  1091. kfree(context->filterkey);
  1092. context->filterkey = NULL;
  1093. tsk->audit_context = context;
  1094. }
  1095. }
  1096. /**
  1097. * audit_getname - add a name to the list
  1098. * @name: name to add
  1099. *
  1100. * Add a name to the list of audit names for this context.
  1101. * Called from fs/namei.c:getname().
  1102. */
  1103. void __audit_getname(const char *name)
  1104. {
  1105. struct audit_context *context = current->audit_context;
  1106. if (IS_ERR(name) || !name)
  1107. return;
  1108. if (!context->in_syscall) {
  1109. #if AUDIT_DEBUG == 2
  1110. printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n",
  1111. __FILE__, __LINE__, context->serial, name);
  1112. dump_stack();
  1113. #endif
  1114. return;
  1115. }
  1116. BUG_ON(context->name_count >= AUDIT_NAMES);
  1117. context->names[context->name_count].name = name;
  1118. context->names[context->name_count].name_len = AUDIT_NAME_FULL;
  1119. context->names[context->name_count].name_put = 1;
  1120. context->names[context->name_count].ino = (unsigned long)-1;
  1121. ++context->name_count;
  1122. if (!context->pwd) {
  1123. read_lock(&current->fs->lock);
  1124. context->pwd = dget(current->fs->pwd);
  1125. context->pwdmnt = mntget(current->fs->pwdmnt);
  1126. read_unlock(&current->fs->lock);
  1127. }
  1128. }
  1129. /* audit_putname - intercept a putname request
  1130. * @name: name to intercept and delay for putname
  1131. *
  1132. * If we have stored the name from getname in the audit context,
  1133. * then we delay the putname until syscall exit.
  1134. * Called from include/linux/fs.h:putname().
  1135. */
  1136. void audit_putname(const char *name)
  1137. {
  1138. struct audit_context *context = current->audit_context;
  1139. BUG_ON(!context);
  1140. if (!context->in_syscall) {
  1141. #if AUDIT_DEBUG == 2
  1142. printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n",
  1143. __FILE__, __LINE__, context->serial, name);
  1144. if (context->name_count) {
  1145. int i;
  1146. for (i = 0; i < context->name_count; i++)
  1147. printk(KERN_ERR "name[%d] = %p = %s\n", i,
  1148. context->names[i].name,
  1149. context->names[i].name ?: "(null)");
  1150. }
  1151. #endif
  1152. __putname(name);
  1153. }
  1154. #if AUDIT_DEBUG
  1155. else {
  1156. ++context->put_count;
  1157. if (context->put_count > context->name_count) {
  1158. printk(KERN_ERR "%s:%d(:%d): major=%d"
  1159. " in_syscall=%d putname(%p) name_count=%d"
  1160. " put_count=%d\n",
  1161. __FILE__, __LINE__,
  1162. context->serial, context->major,
  1163. context->in_syscall, name, context->name_count,
  1164. context->put_count);
  1165. dump_stack();
  1166. }
  1167. }
  1168. #endif
  1169. }
  1170. /* Copy inode data into an audit_names. */
  1171. static void audit_copy_inode(struct audit_names *name, const struct inode *inode)
  1172. {
  1173. name->ino = inode->i_ino;
  1174. name->dev = inode->i_sb->s_dev;
  1175. name->mode = inode->i_mode;
  1176. name->uid = inode->i_uid;
  1177. name->gid = inode->i_gid;
  1178. name->rdev = inode->i_rdev;
  1179. selinux_get_inode_sid(inode, &name->osid);
  1180. }
  1181. /**
  1182. * audit_inode - store the inode and device from a lookup
  1183. * @name: name being audited
  1184. * @inode: inode being audited
  1185. *
  1186. * Called from fs/namei.c:path_lookup().
  1187. */
  1188. void __audit_inode(const char *name, const struct inode *inode)
  1189. {
  1190. int idx;
  1191. struct audit_context *context = current->audit_context;
  1192. if (!context->in_syscall)
  1193. return;
  1194. if (context->name_count
  1195. && context->names[context->name_count-1].name
  1196. && context->names[context->name_count-1].name == name)
  1197. idx = context->name_count - 1;
  1198. else if (context->name_count > 1
  1199. && context->names[context->name_count-2].name
  1200. && context->names[context->name_count-2].name == name)
  1201. idx = context->name_count - 2;
  1202. else {
  1203. /* FIXME: how much do we care about inodes that have no
  1204. * associated name? */
  1205. if (context->name_count >= AUDIT_NAMES - AUDIT_NAMES_RESERVED)
  1206. return;
  1207. idx = context->name_count++;
  1208. context->names[idx].name = NULL;
  1209. #if AUDIT_DEBUG
  1210. ++context->ino_count;
  1211. #endif
  1212. }
  1213. audit_copy_inode(&context->names[idx], inode);
  1214. }
  1215. /**
  1216. * audit_inode_child - collect inode info for created/removed objects
  1217. * @dname: inode's dentry name
  1218. * @inode: inode being audited
  1219. * @parent: inode of dentry parent
  1220. *
  1221. * For syscalls that create or remove filesystem objects, audit_inode
  1222. * can only collect information for the filesystem object's parent.
  1223. * This call updates the audit context with the child's information.
  1224. * Syscalls that create a new filesystem object must be hooked after
  1225. * the object is created. Syscalls that remove a filesystem object
  1226. * must be hooked prior, in order to capture the target inode during
  1227. * unsuccessful attempts.
  1228. */
  1229. void __audit_inode_child(const char *dname, const struct inode *inode,
  1230. const struct inode *parent)
  1231. {
  1232. int idx;
  1233. struct audit_context *context = current->audit_context;
  1234. const char *found_name = NULL;
  1235. int dirlen = 0;
  1236. if (!context->in_syscall)
  1237. return;
  1238. /* determine matching parent */
  1239. if (!dname)
  1240. goto update_context;
  1241. for (idx = 0; idx < context->name_count; idx++)
  1242. if (context->names[idx].ino == parent->i_ino) {
  1243. const char *name = context->names[idx].name;
  1244. if (!name)
  1245. continue;
  1246. if (audit_compare_dname_path(dname, name, &dirlen) == 0) {
  1247. context->names[idx].name_len = dirlen;
  1248. found_name = name;
  1249. break;
  1250. }
  1251. }
  1252. update_context:
  1253. idx = context->name_count;
  1254. if (context->name_count == AUDIT_NAMES) {
  1255. printk(KERN_DEBUG "name_count maxed and losing %s\n",
  1256. found_name ?: "(null)");
  1257. return;
  1258. }
  1259. context->name_count++;
  1260. #if AUDIT_DEBUG
  1261. context->ino_count++;
  1262. #endif
  1263. /* Re-use the name belonging to the slot for a matching parent directory.
  1264. * All names for this context are relinquished in audit_free_names() */
  1265. context->names[idx].name = found_name;
  1266. context->names[idx].name_len = AUDIT_NAME_FULL;
  1267. context->names[idx].name_put = 0; /* don't call __putname() */
  1268. if (!inode)
  1269. context->names[idx].ino = (unsigned long)-1;
  1270. else
  1271. audit_copy_inode(&context->names[idx], inode);
  1272. /* A parent was not found in audit_names, so copy the inode data for the
  1273. * provided parent. */
  1274. if (!found_name) {
  1275. idx = context->name_count;
  1276. if (context->name_count == AUDIT_NAMES) {
  1277. printk(KERN_DEBUG
  1278. "name_count maxed and losing parent inode data: dev=%02x:%02x, inode=%lu",
  1279. MAJOR(parent->i_sb->s_dev),
  1280. MINOR(parent->i_sb->s_dev),
  1281. parent->i_ino);
  1282. return;
  1283. }
  1284. context->name_count++;
  1285. #if AUDIT_DEBUG
  1286. context->ino_count++;
  1287. #endif
  1288. audit_copy_inode(&context->names[idx], parent);
  1289. }
  1290. }
  1291. /**
  1292. * audit_inode_update - update inode info for last collected name
  1293. * @inode: inode being audited
  1294. *
  1295. * When open() is called on an existing object with the O_CREAT flag, the inode
  1296. * data audit initially collects is incorrect. This additional hook ensures
  1297. * audit has the inode data for the actual object to be opened.
  1298. */
  1299. void __audit_inode_update(const struct inode *inode)
  1300. {
  1301. struct audit_context *context = current->audit_context;
  1302. int idx;
  1303. if (!context->in_syscall || !inode)
  1304. return;
  1305. if (context->name_count == 0) {
  1306. context->name_count++;
  1307. #if AUDIT_DEBUG
  1308. context->ino_count++;
  1309. #endif
  1310. }
  1311. idx = context->name_count - 1;
  1312. audit_copy_inode(&context->names[idx], inode);
  1313. }
  1314. /**
  1315. * auditsc_get_stamp - get local copies of audit_context values
  1316. * @ctx: audit_context for the task
  1317. * @t: timespec to store time recorded in the audit_context
  1318. * @serial: serial value that is recorded in the audit_context
  1319. *
  1320. * Also sets the context as auditable.
  1321. */
  1322. void auditsc_get_stamp(struct audit_context *ctx,
  1323. struct timespec *t, unsigned int *serial)
  1324. {
  1325. if (!ctx->serial)
  1326. ctx->serial = audit_serial();
  1327. t->tv_sec = ctx->ctime.tv_sec;
  1328. t->tv_nsec = ctx->ctime.tv_nsec;
  1329. *serial = ctx->serial;
  1330. ctx->auditable = 1;
  1331. }
  1332. /**
  1333. * audit_set_loginuid - set a task's audit_context loginuid
  1334. * @task: task whose audit context is being modified
  1335. * @loginuid: loginuid value
  1336. *
  1337. * Returns 0.
  1338. *
  1339. * Called (set) from fs/proc/base.c::proc_loginuid_write().
  1340. */
  1341. int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
  1342. {
  1343. struct audit_context *context = task->audit_context;
  1344. if (context) {
  1345. /* Only log if audit is enabled */
  1346. if (context->in_syscall) {
  1347. struct audit_buffer *ab;
  1348. ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
  1349. if (ab) {
  1350. audit_log_format(ab, "login pid=%d uid=%u "
  1351. "old auid=%u new auid=%u",
  1352. task->pid, task->uid,
  1353. context->loginuid, loginuid);
  1354. audit_log_end(ab);
  1355. }
  1356. }
  1357. context->loginuid = loginuid;
  1358. }
  1359. return 0;
  1360. }
  1361. /**
  1362. * audit_get_loginuid - get the loginuid for an audit_context
  1363. * @ctx: the audit_context
  1364. *
  1365. * Returns the context's loginuid or -1 if @ctx is NULL.
  1366. */
  1367. uid_t audit_get_loginuid(struct audit_context *ctx)
  1368. {
  1369. return ctx ? ctx->loginuid : -1;
  1370. }
  1371. EXPORT_SYMBOL(audit_get_loginuid);
  1372. /**
  1373. * __audit_mq_open - record audit data for a POSIX MQ open
  1374. * @oflag: open flag
  1375. * @mode: mode bits
  1376. * @u_attr: queue attributes
  1377. *
  1378. * Returns 0 for success or NULL context or < 0 on error.
  1379. */
  1380. int __audit_mq_open(int oflag, mode_t mode, struct mq_attr __user *u_attr)
  1381. {
  1382. struct audit_aux_data_mq_open *ax;
  1383. struct audit_context *context = current->audit_context;
  1384. if (!audit_enabled)
  1385. return 0;
  1386. if (likely(!context))
  1387. return 0;
  1388. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1389. if (!ax)
  1390. return -ENOMEM;
  1391. if (u_attr != NULL) {
  1392. if (copy_from_user(&ax->attr, u_attr, sizeof(ax->attr))) {
  1393. kfree(ax);
  1394. return -EFAULT;
  1395. }
  1396. } else
  1397. memset(&ax->attr, 0, sizeof(ax->attr));
  1398. ax->oflag = oflag;
  1399. ax->mode = mode;
  1400. ax->d.type = AUDIT_MQ_OPEN;
  1401. ax->d.next = context->aux;
  1402. context->aux = (void *)ax;
  1403. return 0;
  1404. }
  1405. /**
  1406. * __audit_mq_timedsend - record audit data for a POSIX MQ timed send
  1407. * @mqdes: MQ descriptor
  1408. * @msg_len: Message length
  1409. * @msg_prio: Message priority
  1410. * @u_abs_timeout: Message timeout in absolute time
  1411. *
  1412. * Returns 0 for success or NULL context or < 0 on error.
  1413. */
  1414. int __audit_mq_timedsend(mqd_t mqdes, size_t msg_len, unsigned int msg_prio,
  1415. const struct timespec __user *u_abs_timeout)
  1416. {
  1417. struct audit_aux_data_mq_sendrecv *ax;
  1418. struct audit_context *context = current->audit_context;
  1419. if (!audit_enabled)
  1420. return 0;
  1421. if (likely(!context))
  1422. return 0;
  1423. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1424. if (!ax)
  1425. return -ENOMEM;
  1426. if (u_abs_timeout != NULL) {
  1427. if (copy_from_user(&ax->abs_timeout, u_abs_timeout, sizeof(ax->abs_timeout))) {
  1428. kfree(ax);
  1429. return -EFAULT;
  1430. }
  1431. } else
  1432. memset(&ax->abs_timeout, 0, sizeof(ax->abs_timeout));
  1433. ax->mqdes = mqdes;
  1434. ax->msg_len = msg_len;
  1435. ax->msg_prio = msg_prio;
  1436. ax->d.type = AUDIT_MQ_SENDRECV;
  1437. ax->d.next = context->aux;
  1438. context->aux = (void *)ax;
  1439. return 0;
  1440. }
  1441. /**
  1442. * __audit_mq_timedreceive - record audit data for a POSIX MQ timed receive
  1443. * @mqdes: MQ descriptor
  1444. * @msg_len: Message length
  1445. * @u_msg_prio: Message priority
  1446. * @u_abs_timeout: Message timeout in absolute time
  1447. *
  1448. * Returns 0 for success or NULL context or < 0 on error.
  1449. */
  1450. int __audit_mq_timedreceive(mqd_t mqdes, size_t msg_len,
  1451. unsigned int __user *u_msg_prio,
  1452. const struct timespec __user *u_abs_timeout)
  1453. {
  1454. struct audit_aux_data_mq_sendrecv *ax;
  1455. struct audit_context *context = current->audit_context;
  1456. if (!audit_enabled)
  1457. return 0;
  1458. if (likely(!context))
  1459. return 0;
  1460. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1461. if (!ax)
  1462. return -ENOMEM;
  1463. if (u_msg_prio != NULL) {
  1464. if (get_user(ax->msg_prio, u_msg_prio)) {
  1465. kfree(ax);
  1466. return -EFAULT;
  1467. }
  1468. } else
  1469. ax->msg_prio = 0;
  1470. if (u_abs_timeout != NULL) {
  1471. if (copy_from_user(&ax->abs_timeout, u_abs_timeout, sizeof(ax->abs_timeout))) {
  1472. kfree(ax);
  1473. return -EFAULT;
  1474. }
  1475. } else
  1476. memset(&ax->abs_timeout, 0, sizeof(ax->abs_timeout));
  1477. ax->mqdes = mqdes;
  1478. ax->msg_len = msg_len;
  1479. ax->d.type = AUDIT_MQ_SENDRECV;
  1480. ax->d.next = context->aux;
  1481. context->aux = (void *)ax;
  1482. return 0;
  1483. }
  1484. /**
  1485. * __audit_mq_notify - record audit data for a POSIX MQ notify
  1486. * @mqdes: MQ descriptor
  1487. * @u_notification: Notification event
  1488. *
  1489. * Returns 0 for success or NULL context or < 0 on error.
  1490. */
  1491. int __audit_mq_notify(mqd_t mqdes, const struct sigevent __user *u_notification)
  1492. {
  1493. struct audit_aux_data_mq_notify *ax;
  1494. struct audit_context *context = current->audit_context;
  1495. if (!audit_enabled)
  1496. return 0;
  1497. if (likely(!context))
  1498. return 0;
  1499. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1500. if (!ax)
  1501. return -ENOMEM;
  1502. if (u_notification != NULL) {
  1503. if (copy_from_user(&ax->notification, u_notification, sizeof(ax->notification))) {
  1504. kfree(ax);
  1505. return -EFAULT;
  1506. }
  1507. } else
  1508. memset(&ax->notification, 0, sizeof(ax->notification));
  1509. ax->mqdes = mqdes;
  1510. ax->d.type = AUDIT_MQ_NOTIFY;
  1511. ax->d.next = context->aux;
  1512. context->aux = (void *)ax;
  1513. return 0;
  1514. }
  1515. /**
  1516. * __audit_mq_getsetattr - record audit data for a POSIX MQ get/set attribute
  1517. * @mqdes: MQ descriptor
  1518. * @mqstat: MQ flags
  1519. *
  1520. * Returns 0 for success or NULL context or < 0 on error.
  1521. */
  1522. int __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
  1523. {
  1524. struct audit_aux_data_mq_getsetattr *ax;
  1525. struct audit_context *context = current->audit_context;
  1526. if (!audit_enabled)
  1527. return 0;
  1528. if (likely(!context))
  1529. return 0;
  1530. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1531. if (!ax)
  1532. return -ENOMEM;
  1533. ax->mqdes = mqdes;
  1534. ax->mqstat = *mqstat;
  1535. ax->d.type = AUDIT_MQ_GETSETATTR;
  1536. ax->d.next = context->aux;
  1537. context->aux = (void *)ax;
  1538. return 0;
  1539. }
  1540. /**
  1541. * audit_ipc_obj - record audit data for ipc object
  1542. * @ipcp: ipc permissions
  1543. *
  1544. * Returns 0 for success or NULL context or < 0 on error.
  1545. */
  1546. int __audit_ipc_obj(struct kern_ipc_perm *ipcp)
  1547. {
  1548. struct audit_aux_data_ipcctl *ax;
  1549. struct audit_context *context = current->audit_context;
  1550. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1551. if (!ax)
  1552. return -ENOMEM;
  1553. ax->uid = ipcp->uid;
  1554. ax->gid = ipcp->gid;
  1555. ax->mode = ipcp->mode;
  1556. selinux_get_ipc_sid(ipcp, &ax->osid);
  1557. ax->d.type = AUDIT_IPC;
  1558. ax->d.next = context->aux;
  1559. context->aux = (void *)ax;
  1560. return 0;
  1561. }
  1562. /**
  1563. * audit_ipc_set_perm - record audit data for new ipc permissions
  1564. * @qbytes: msgq bytes
  1565. * @uid: msgq user id
  1566. * @gid: msgq group id
  1567. * @mode: msgq mode (permissions)
  1568. *
  1569. * Returns 0 for success or NULL context or < 0 on error.
  1570. */
  1571. int __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode)
  1572. {
  1573. struct audit_aux_data_ipcctl *ax;
  1574. struct audit_context *context = current->audit_context;
  1575. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1576. if (!ax)
  1577. return -ENOMEM;
  1578. ax->qbytes = qbytes;
  1579. ax->uid = uid;
  1580. ax->gid = gid;
  1581. ax->mode = mode;
  1582. ax->d.type = AUDIT_IPC_SET_PERM;
  1583. ax->d.next = context->aux;
  1584. context->aux = (void *)ax;
  1585. return 0;
  1586. }
  1587. int audit_bprm(struct linux_binprm *bprm)
  1588. {
  1589. struct audit_aux_data_execve *ax;
  1590. struct audit_context *context = current->audit_context;
  1591. unsigned long p, next;
  1592. void *to;
  1593. if (likely(!audit_enabled || !context || context->dummy))
  1594. return 0;
  1595. ax = kmalloc(sizeof(*ax) + PAGE_SIZE * MAX_ARG_PAGES - bprm->p,
  1596. GFP_KERNEL);
  1597. if (!ax)
  1598. return -ENOMEM;
  1599. ax->argc = bprm->argc;
  1600. ax->envc = bprm->envc;
  1601. for (p = bprm->p, to = ax->mem; p < MAX_ARG_PAGES*PAGE_SIZE; p = next) {
  1602. struct page *page = bprm->page[p / PAGE_SIZE];
  1603. void *kaddr = kmap(page);
  1604. next = (p + PAGE_SIZE) & ~(PAGE_SIZE - 1);
  1605. memcpy(to, kaddr + (p & (PAGE_SIZE - 1)), next - p);
  1606. to += next - p;
  1607. kunmap(page);
  1608. }
  1609. ax->d.type = AUDIT_EXECVE;
  1610. ax->d.next = context->aux;
  1611. context->aux = (void *)ax;
  1612. return 0;
  1613. }
  1614. /**
  1615. * audit_socketcall - record audit data for sys_socketcall
  1616. * @nargs: number of args
  1617. * @args: args array
  1618. *
  1619. * Returns 0 for success or NULL context or < 0 on error.
  1620. */
  1621. int audit_socketcall(int nargs, unsigned long *args)
  1622. {
  1623. struct audit_aux_data_socketcall *ax;
  1624. struct audit_context *context = current->audit_context;
  1625. if (likely(!context || context->dummy))
  1626. return 0;
  1627. ax = kmalloc(sizeof(*ax) + nargs * sizeof(unsigned long), GFP_KERNEL);
  1628. if (!ax)
  1629. return -ENOMEM;
  1630. ax->nargs = nargs;
  1631. memcpy(ax->args, args, nargs * sizeof(unsigned long));
  1632. ax->d.type = AUDIT_SOCKETCALL;
  1633. ax->d.next = context->aux;
  1634. context->aux = (void *)ax;
  1635. return 0;
  1636. }
  1637. /**
  1638. * __audit_fd_pair - record audit data for pipe and socketpair
  1639. * @fd1: the first file descriptor
  1640. * @fd2: the second file descriptor
  1641. *
  1642. * Returns 0 for success or NULL context or < 0 on error.
  1643. */
  1644. int __audit_fd_pair(int fd1, int fd2)
  1645. {
  1646. struct audit_context *context = current->audit_context;
  1647. struct audit_aux_data_fd_pair *ax;
  1648. if (likely(!context)) {
  1649. return 0;
  1650. }
  1651. ax = kmalloc(sizeof(*ax), GFP_KERNEL);
  1652. if (!ax) {
  1653. return -ENOMEM;
  1654. }
  1655. ax->fd[0] = fd1;
  1656. ax->fd[1] = fd2;
  1657. ax->d.type = AUDIT_FD_PAIR;
  1658. ax->d.next = context->aux;
  1659. context->aux = (void *)ax;
  1660. return 0;
  1661. }
  1662. /**
  1663. * audit_sockaddr - record audit data for sys_bind, sys_connect, sys_sendto
  1664. * @len: data length in user space
  1665. * @a: data address in kernel space
  1666. *
  1667. * Returns 0 for success or NULL context or < 0 on error.
  1668. */
  1669. int audit_sockaddr(int len, void *a)
  1670. {
  1671. struct audit_aux_data_sockaddr *ax;
  1672. struct audit_context *context = current->audit_context;
  1673. if (likely(!context || context->dummy))
  1674. return 0;
  1675. ax = kmalloc(sizeof(*ax) + len, GFP_KERNEL);
  1676. if (!ax)
  1677. return -ENOMEM;
  1678. ax->len = len;
  1679. memcpy(ax->a, a, len);
  1680. ax->d.type = AUDIT_SOCKADDR;
  1681. ax->d.next = context->aux;
  1682. context->aux = (void *)ax;
  1683. return 0;
  1684. }
  1685. void __audit_ptrace(struct task_struct *t)
  1686. {
  1687. struct audit_context *context = current->audit_context;
  1688. context->target_pid = t->pid;
  1689. selinux_get_task_sid(t, &context->target_sid);
  1690. }
  1691. /**
  1692. * audit_avc_path - record the granting or denial of permissions
  1693. * @dentry: dentry to record
  1694. * @mnt: mnt to record
  1695. *
  1696. * Returns 0 for success or NULL context or < 0 on error.
  1697. *
  1698. * Called from security/selinux/avc.c::avc_audit()
  1699. */
  1700. int audit_avc_path(struct dentry *dentry, struct vfsmount *mnt)
  1701. {
  1702. struct audit_aux_data_path *ax;
  1703. struct audit_context *context = current->audit_context;
  1704. if (likely(!context))
  1705. return 0;
  1706. ax = kmalloc(sizeof(*ax), GFP_ATOMIC);
  1707. if (!ax)
  1708. return -ENOMEM;
  1709. ax->dentry = dget(dentry);
  1710. ax->mnt = mntget(mnt);
  1711. ax->d.type = AUDIT_AVC_PATH;
  1712. ax->d.next = context->aux;
  1713. context->aux = (void *)ax;
  1714. return 0;
  1715. }
  1716. /**
  1717. * audit_signal_info - record signal info for shutting down audit subsystem
  1718. * @sig: signal value
  1719. * @t: task being signaled
  1720. *
  1721. * If the audit subsystem is being terminated, record the task (pid)
  1722. * and uid that is doing that.
  1723. */
  1724. void __audit_signal_info(int sig, struct task_struct *t)
  1725. {
  1726. extern pid_t audit_sig_pid;
  1727. extern uid_t audit_sig_uid;
  1728. extern u32 audit_sig_sid;
  1729. if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1) {
  1730. struct task_struct *tsk = current;
  1731. struct audit_context *ctx = tsk->audit_context;
  1732. audit_sig_pid = tsk->pid;
  1733. if (ctx)
  1734. audit_sig_uid = ctx->loginuid;
  1735. else
  1736. audit_sig_uid = tsk->uid;
  1737. selinux_get_task_sid(tsk, &audit_sig_sid);
  1738. }
  1739. }