auditsc.c 66 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520
  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 <linux/fs.h>
  48. #include <linux/namei.h>
  49. #include <linux/mm.h>
  50. #include <linux/module.h>
  51. #include <linux/mount.h>
  52. #include <linux/socket.h>
  53. #include <linux/mqueue.h>
  54. #include <linux/audit.h>
  55. #include <linux/personality.h>
  56. #include <linux/time.h>
  57. #include <linux/netlink.h>
  58. #include <linux/compiler.h>
  59. #include <asm/unistd.h>
  60. #include <linux/security.h>
  61. #include <linux/list.h>
  62. #include <linux/tty.h>
  63. #include <linux/binfmts.h>
  64. #include <linux/highmem.h>
  65. #include <linux/syscalls.h>
  66. #include <linux/inotify.h>
  67. #include <linux/capability.h>
  68. #include "audit.h"
  69. /* AUDIT_NAMES is the number of slots we reserve in the audit_context
  70. * for saving names from getname(). */
  71. #define AUDIT_NAMES 20
  72. /* Indicates that audit should log the full pathname. */
  73. #define AUDIT_NAME_FULL -1
  74. /* no execve audit message should be longer than this (userspace limits) */
  75. #define MAX_EXECVE_AUDIT_LEN 7500
  76. /* number of audit rules */
  77. int audit_n_rules;
  78. /* determines whether we collect data for signals sent */
  79. int audit_signals;
  80. struct audit_cap_data {
  81. kernel_cap_t permitted;
  82. kernel_cap_t inheritable;
  83. union {
  84. unsigned int fE; /* effective bit of a file capability */
  85. kernel_cap_t effective; /* effective set of a process */
  86. };
  87. };
  88. /* When fs/namei.c:getname() is called, we store the pointer in name and
  89. * we don't let putname() free it (instead we free all of the saved
  90. * pointers at syscall exit time).
  91. *
  92. * Further, in fs/namei.c:path_lookup() we store the inode and device. */
  93. struct audit_names {
  94. const char *name;
  95. int name_len; /* number of name's characters to log */
  96. unsigned name_put; /* call __putname() for this name */
  97. unsigned long ino;
  98. dev_t dev;
  99. umode_t mode;
  100. uid_t uid;
  101. gid_t gid;
  102. dev_t rdev;
  103. u32 osid;
  104. struct audit_cap_data fcap;
  105. unsigned int fcap_ver;
  106. };
  107. struct audit_aux_data {
  108. struct audit_aux_data *next;
  109. int type;
  110. };
  111. #define AUDIT_AUX_IPCPERM 0
  112. /* Number of target pids per aux struct. */
  113. #define AUDIT_AUX_PIDS 16
  114. struct audit_aux_data_execve {
  115. struct audit_aux_data d;
  116. int argc;
  117. int envc;
  118. struct mm_struct *mm;
  119. };
  120. struct audit_aux_data_pids {
  121. struct audit_aux_data d;
  122. pid_t target_pid[AUDIT_AUX_PIDS];
  123. uid_t target_auid[AUDIT_AUX_PIDS];
  124. uid_t target_uid[AUDIT_AUX_PIDS];
  125. unsigned int target_sessionid[AUDIT_AUX_PIDS];
  126. u32 target_sid[AUDIT_AUX_PIDS];
  127. char target_comm[AUDIT_AUX_PIDS][TASK_COMM_LEN];
  128. int pid_count;
  129. };
  130. struct audit_aux_data_bprm_fcaps {
  131. struct audit_aux_data d;
  132. struct audit_cap_data fcap;
  133. unsigned int fcap_ver;
  134. struct audit_cap_data old_pcap;
  135. struct audit_cap_data new_pcap;
  136. };
  137. struct audit_aux_data_capset {
  138. struct audit_aux_data d;
  139. pid_t pid;
  140. struct audit_cap_data cap;
  141. };
  142. struct audit_tree_refs {
  143. struct audit_tree_refs *next;
  144. struct audit_chunk *c[31];
  145. };
  146. /* The per-task audit context. */
  147. struct audit_context {
  148. int dummy; /* must be the first element */
  149. int in_syscall; /* 1 if task is in a syscall */
  150. enum audit_state state, current_state;
  151. unsigned int serial; /* serial number for record */
  152. struct timespec ctime; /* time of syscall entry */
  153. int major; /* syscall number */
  154. unsigned long argv[4]; /* syscall arguments */
  155. int return_valid; /* return code is valid */
  156. long return_code;/* syscall return code */
  157. u64 prio;
  158. int name_count;
  159. struct audit_names names[AUDIT_NAMES];
  160. char * filterkey; /* key for rule that triggered record */
  161. struct path pwd;
  162. struct audit_context *previous; /* For nested syscalls */
  163. struct audit_aux_data *aux;
  164. struct audit_aux_data *aux_pids;
  165. struct sockaddr_storage *sockaddr;
  166. size_t sockaddr_len;
  167. /* Save things to print about task_struct */
  168. pid_t pid, ppid;
  169. uid_t uid, euid, suid, fsuid;
  170. gid_t gid, egid, sgid, fsgid;
  171. unsigned long personality;
  172. int arch;
  173. pid_t target_pid;
  174. uid_t target_auid;
  175. uid_t target_uid;
  176. unsigned int target_sessionid;
  177. u32 target_sid;
  178. char target_comm[TASK_COMM_LEN];
  179. struct audit_tree_refs *trees, *first_trees;
  180. int tree_count;
  181. int type;
  182. union {
  183. struct {
  184. int nargs;
  185. long args[6];
  186. } socketcall;
  187. struct {
  188. uid_t uid;
  189. gid_t gid;
  190. mode_t mode;
  191. u32 osid;
  192. int has_perm;
  193. uid_t perm_uid;
  194. gid_t perm_gid;
  195. mode_t perm_mode;
  196. unsigned long qbytes;
  197. } ipc;
  198. struct {
  199. mqd_t mqdes;
  200. struct mq_attr mqstat;
  201. } mq_getsetattr;
  202. struct {
  203. mqd_t mqdes;
  204. int sigev_signo;
  205. } mq_notify;
  206. struct {
  207. mqd_t mqdes;
  208. size_t msg_len;
  209. unsigned int msg_prio;
  210. struct timespec abs_timeout;
  211. } mq_sendrecv;
  212. struct {
  213. int oflag;
  214. mode_t mode;
  215. struct mq_attr attr;
  216. } mq_open;
  217. struct {
  218. pid_t pid;
  219. struct audit_cap_data cap;
  220. } capset;
  221. };
  222. int fds[2];
  223. #if AUDIT_DEBUG
  224. int put_count;
  225. int ino_count;
  226. #endif
  227. };
  228. #define ACC_MODE(x) ("\004\002\006\006"[(x)&O_ACCMODE])
  229. static inline int open_arg(int flags, int mask)
  230. {
  231. int n = ACC_MODE(flags);
  232. if (flags & (O_TRUNC | O_CREAT))
  233. n |= AUDIT_PERM_WRITE;
  234. return n & mask;
  235. }
  236. static int audit_match_perm(struct audit_context *ctx, int mask)
  237. {
  238. unsigned n;
  239. if (unlikely(!ctx))
  240. return 0;
  241. n = ctx->major;
  242. switch (audit_classify_syscall(ctx->arch, n)) {
  243. case 0: /* native */
  244. if ((mask & AUDIT_PERM_WRITE) &&
  245. audit_match_class(AUDIT_CLASS_WRITE, n))
  246. return 1;
  247. if ((mask & AUDIT_PERM_READ) &&
  248. audit_match_class(AUDIT_CLASS_READ, n))
  249. return 1;
  250. if ((mask & AUDIT_PERM_ATTR) &&
  251. audit_match_class(AUDIT_CLASS_CHATTR, n))
  252. return 1;
  253. return 0;
  254. case 1: /* 32bit on biarch */
  255. if ((mask & AUDIT_PERM_WRITE) &&
  256. audit_match_class(AUDIT_CLASS_WRITE_32, n))
  257. return 1;
  258. if ((mask & AUDIT_PERM_READ) &&
  259. audit_match_class(AUDIT_CLASS_READ_32, n))
  260. return 1;
  261. if ((mask & AUDIT_PERM_ATTR) &&
  262. audit_match_class(AUDIT_CLASS_CHATTR_32, n))
  263. return 1;
  264. return 0;
  265. case 2: /* open */
  266. return mask & ACC_MODE(ctx->argv[1]);
  267. case 3: /* openat */
  268. return mask & ACC_MODE(ctx->argv[2]);
  269. case 4: /* socketcall */
  270. return ((mask & AUDIT_PERM_WRITE) && ctx->argv[0] == SYS_BIND);
  271. case 5: /* execve */
  272. return mask & AUDIT_PERM_EXEC;
  273. default:
  274. return 0;
  275. }
  276. }
  277. static int audit_match_filetype(struct audit_context *ctx, int which)
  278. {
  279. unsigned index = which & ~S_IFMT;
  280. mode_t mode = which & S_IFMT;
  281. if (unlikely(!ctx))
  282. return 0;
  283. if (index >= ctx->name_count)
  284. return 0;
  285. if (ctx->names[index].ino == -1)
  286. return 0;
  287. if ((ctx->names[index].mode ^ mode) & S_IFMT)
  288. return 0;
  289. return 1;
  290. }
  291. /*
  292. * We keep a linked list of fixed-sized (31 pointer) arrays of audit_chunk *;
  293. * ->first_trees points to its beginning, ->trees - to the current end of data.
  294. * ->tree_count is the number of free entries in array pointed to by ->trees.
  295. * Original condition is (NULL, NULL, 0); as soon as it grows we never revert to NULL,
  296. * "empty" becomes (p, p, 31) afterwards. We don't shrink the list (and seriously,
  297. * it's going to remain 1-element for almost any setup) until we free context itself.
  298. * References in it _are_ dropped - at the same time we free/drop aux stuff.
  299. */
  300. #ifdef CONFIG_AUDIT_TREE
  301. static int put_tree_ref(struct audit_context *ctx, struct audit_chunk *chunk)
  302. {
  303. struct audit_tree_refs *p = ctx->trees;
  304. int left = ctx->tree_count;
  305. if (likely(left)) {
  306. p->c[--left] = chunk;
  307. ctx->tree_count = left;
  308. return 1;
  309. }
  310. if (!p)
  311. return 0;
  312. p = p->next;
  313. if (p) {
  314. p->c[30] = chunk;
  315. ctx->trees = p;
  316. ctx->tree_count = 30;
  317. return 1;
  318. }
  319. return 0;
  320. }
  321. static int grow_tree_refs(struct audit_context *ctx)
  322. {
  323. struct audit_tree_refs *p = ctx->trees;
  324. ctx->trees = kzalloc(sizeof(struct audit_tree_refs), GFP_KERNEL);
  325. if (!ctx->trees) {
  326. ctx->trees = p;
  327. return 0;
  328. }
  329. if (p)
  330. p->next = ctx->trees;
  331. else
  332. ctx->first_trees = ctx->trees;
  333. ctx->tree_count = 31;
  334. return 1;
  335. }
  336. #endif
  337. static void unroll_tree_refs(struct audit_context *ctx,
  338. struct audit_tree_refs *p, int count)
  339. {
  340. #ifdef CONFIG_AUDIT_TREE
  341. struct audit_tree_refs *q;
  342. int n;
  343. if (!p) {
  344. /* we started with empty chain */
  345. p = ctx->first_trees;
  346. count = 31;
  347. /* if the very first allocation has failed, nothing to do */
  348. if (!p)
  349. return;
  350. }
  351. n = count;
  352. for (q = p; q != ctx->trees; q = q->next, n = 31) {
  353. while (n--) {
  354. audit_put_chunk(q->c[n]);
  355. q->c[n] = NULL;
  356. }
  357. }
  358. while (n-- > ctx->tree_count) {
  359. audit_put_chunk(q->c[n]);
  360. q->c[n] = NULL;
  361. }
  362. ctx->trees = p;
  363. ctx->tree_count = count;
  364. #endif
  365. }
  366. static void free_tree_refs(struct audit_context *ctx)
  367. {
  368. struct audit_tree_refs *p, *q;
  369. for (p = ctx->first_trees; p; p = q) {
  370. q = p->next;
  371. kfree(p);
  372. }
  373. }
  374. static int match_tree_refs(struct audit_context *ctx, struct audit_tree *tree)
  375. {
  376. #ifdef CONFIG_AUDIT_TREE
  377. struct audit_tree_refs *p;
  378. int n;
  379. if (!tree)
  380. return 0;
  381. /* full ones */
  382. for (p = ctx->first_trees; p != ctx->trees; p = p->next) {
  383. for (n = 0; n < 31; n++)
  384. if (audit_tree_match(p->c[n], tree))
  385. return 1;
  386. }
  387. /* partial */
  388. if (p) {
  389. for (n = ctx->tree_count; n < 31; n++)
  390. if (audit_tree_match(p->c[n], tree))
  391. return 1;
  392. }
  393. #endif
  394. return 0;
  395. }
  396. /* Determine if any context name data matches a rule's watch data */
  397. /* Compare a task_struct with an audit_rule. Return 1 on match, 0
  398. * otherwise. */
  399. static int audit_filter_rules(struct task_struct *tsk,
  400. struct audit_krule *rule,
  401. struct audit_context *ctx,
  402. struct audit_names *name,
  403. enum audit_state *state)
  404. {
  405. const struct cred *cred = get_task_cred(tsk);
  406. int i, j, need_sid = 1;
  407. u32 sid;
  408. for (i = 0; i < rule->field_count; i++) {
  409. struct audit_field *f = &rule->fields[i];
  410. int result = 0;
  411. switch (f->type) {
  412. case AUDIT_PID:
  413. result = audit_comparator(tsk->pid, f->op, f->val);
  414. break;
  415. case AUDIT_PPID:
  416. if (ctx) {
  417. if (!ctx->ppid)
  418. ctx->ppid = sys_getppid();
  419. result = audit_comparator(ctx->ppid, f->op, f->val);
  420. }
  421. break;
  422. case AUDIT_UID:
  423. result = audit_comparator(cred->uid, f->op, f->val);
  424. break;
  425. case AUDIT_EUID:
  426. result = audit_comparator(cred->euid, f->op, f->val);
  427. break;
  428. case AUDIT_SUID:
  429. result = audit_comparator(cred->suid, f->op, f->val);
  430. break;
  431. case AUDIT_FSUID:
  432. result = audit_comparator(cred->fsuid, f->op, f->val);
  433. break;
  434. case AUDIT_GID:
  435. result = audit_comparator(cred->gid, f->op, f->val);
  436. break;
  437. case AUDIT_EGID:
  438. result = audit_comparator(cred->egid, f->op, f->val);
  439. break;
  440. case AUDIT_SGID:
  441. result = audit_comparator(cred->sgid, f->op, f->val);
  442. break;
  443. case AUDIT_FSGID:
  444. result = audit_comparator(cred->fsgid, f->op, f->val);
  445. break;
  446. case AUDIT_PERS:
  447. result = audit_comparator(tsk->personality, f->op, f->val);
  448. break;
  449. case AUDIT_ARCH:
  450. if (ctx)
  451. result = audit_comparator(ctx->arch, f->op, f->val);
  452. break;
  453. case AUDIT_EXIT:
  454. if (ctx && ctx->return_valid)
  455. result = audit_comparator(ctx->return_code, f->op, f->val);
  456. break;
  457. case AUDIT_SUCCESS:
  458. if (ctx && ctx->return_valid) {
  459. if (f->val)
  460. result = audit_comparator(ctx->return_valid, f->op, AUDITSC_SUCCESS);
  461. else
  462. result = audit_comparator(ctx->return_valid, f->op, AUDITSC_FAILURE);
  463. }
  464. break;
  465. case AUDIT_DEVMAJOR:
  466. if (name)
  467. result = audit_comparator(MAJOR(name->dev),
  468. f->op, f->val);
  469. else if (ctx) {
  470. for (j = 0; j < ctx->name_count; j++) {
  471. if (audit_comparator(MAJOR(ctx->names[j].dev), f->op, f->val)) {
  472. ++result;
  473. break;
  474. }
  475. }
  476. }
  477. break;
  478. case AUDIT_DEVMINOR:
  479. if (name)
  480. result = audit_comparator(MINOR(name->dev),
  481. f->op, f->val);
  482. else if (ctx) {
  483. for (j = 0; j < ctx->name_count; j++) {
  484. if (audit_comparator(MINOR(ctx->names[j].dev), f->op, f->val)) {
  485. ++result;
  486. break;
  487. }
  488. }
  489. }
  490. break;
  491. case AUDIT_INODE:
  492. if (name)
  493. result = (name->ino == f->val);
  494. else if (ctx) {
  495. for (j = 0; j < ctx->name_count; j++) {
  496. if (audit_comparator(ctx->names[j].ino, f->op, f->val)) {
  497. ++result;
  498. break;
  499. }
  500. }
  501. }
  502. break;
  503. case AUDIT_WATCH:
  504. if (name && rule->watch->ino != (unsigned long)-1)
  505. result = (name->dev == rule->watch->dev &&
  506. name->ino == rule->watch->ino);
  507. break;
  508. case AUDIT_DIR:
  509. if (ctx)
  510. result = match_tree_refs(ctx, rule->tree);
  511. break;
  512. case AUDIT_LOGINUID:
  513. result = 0;
  514. if (ctx)
  515. result = audit_comparator(tsk->loginuid, f->op, f->val);
  516. break;
  517. case AUDIT_SUBJ_USER:
  518. case AUDIT_SUBJ_ROLE:
  519. case AUDIT_SUBJ_TYPE:
  520. case AUDIT_SUBJ_SEN:
  521. case AUDIT_SUBJ_CLR:
  522. /* NOTE: this may return negative values indicating
  523. a temporary error. We simply treat this as a
  524. match for now to avoid losing information that
  525. may be wanted. An error message will also be
  526. logged upon error */
  527. if (f->lsm_rule) {
  528. if (need_sid) {
  529. security_task_getsecid(tsk, &sid);
  530. need_sid = 0;
  531. }
  532. result = security_audit_rule_match(sid, f->type,
  533. f->op,
  534. f->lsm_rule,
  535. ctx);
  536. }
  537. break;
  538. case AUDIT_OBJ_USER:
  539. case AUDIT_OBJ_ROLE:
  540. case AUDIT_OBJ_TYPE:
  541. case AUDIT_OBJ_LEV_LOW:
  542. case AUDIT_OBJ_LEV_HIGH:
  543. /* The above note for AUDIT_SUBJ_USER...AUDIT_SUBJ_CLR
  544. also applies here */
  545. if (f->lsm_rule) {
  546. /* Find files that match */
  547. if (name) {
  548. result = security_audit_rule_match(
  549. name->osid, f->type, f->op,
  550. f->lsm_rule, ctx);
  551. } else if (ctx) {
  552. for (j = 0; j < ctx->name_count; j++) {
  553. if (security_audit_rule_match(
  554. ctx->names[j].osid,
  555. f->type, f->op,
  556. f->lsm_rule, ctx)) {
  557. ++result;
  558. break;
  559. }
  560. }
  561. }
  562. /* Find ipc objects that match */
  563. if (!ctx || ctx->type != AUDIT_IPC)
  564. break;
  565. if (security_audit_rule_match(ctx->ipc.osid,
  566. f->type, f->op,
  567. f->lsm_rule, ctx))
  568. ++result;
  569. }
  570. break;
  571. case AUDIT_ARG0:
  572. case AUDIT_ARG1:
  573. case AUDIT_ARG2:
  574. case AUDIT_ARG3:
  575. if (ctx)
  576. result = audit_comparator(ctx->argv[f->type-AUDIT_ARG0], f->op, f->val);
  577. break;
  578. case AUDIT_FILTERKEY:
  579. /* ignore this field for filtering */
  580. result = 1;
  581. break;
  582. case AUDIT_PERM:
  583. result = audit_match_perm(ctx, f->val);
  584. break;
  585. case AUDIT_FILETYPE:
  586. result = audit_match_filetype(ctx, f->val);
  587. break;
  588. }
  589. if (!result) {
  590. put_cred(cred);
  591. return 0;
  592. }
  593. }
  594. if (ctx) {
  595. if (rule->prio <= ctx->prio)
  596. return 0;
  597. if (rule->filterkey) {
  598. kfree(ctx->filterkey);
  599. ctx->filterkey = kstrdup(rule->filterkey, GFP_ATOMIC);
  600. }
  601. ctx->prio = rule->prio;
  602. }
  603. switch (rule->action) {
  604. case AUDIT_NEVER: *state = AUDIT_DISABLED; break;
  605. case AUDIT_ALWAYS: *state = AUDIT_RECORD_CONTEXT; break;
  606. }
  607. put_cred(cred);
  608. return 1;
  609. }
  610. /* At process creation time, we can determine if system-call auditing is
  611. * completely disabled for this task. Since we only have the task
  612. * structure at this point, we can only check uid and gid.
  613. */
  614. static enum audit_state audit_filter_task(struct task_struct *tsk)
  615. {
  616. struct audit_entry *e;
  617. enum audit_state state;
  618. rcu_read_lock();
  619. list_for_each_entry_rcu(e, &audit_filter_list[AUDIT_FILTER_TASK], list) {
  620. if (audit_filter_rules(tsk, &e->rule, NULL, NULL, &state)) {
  621. rcu_read_unlock();
  622. return state;
  623. }
  624. }
  625. rcu_read_unlock();
  626. return AUDIT_BUILD_CONTEXT;
  627. }
  628. /* At syscall entry and exit time, this filter is called if the
  629. * audit_state is not low enough that auditing cannot take place, but is
  630. * also not high enough that we already know we have to write an audit
  631. * record (i.e., the state is AUDIT_SETUP_CONTEXT or AUDIT_BUILD_CONTEXT).
  632. */
  633. static enum audit_state audit_filter_syscall(struct task_struct *tsk,
  634. struct audit_context *ctx,
  635. struct list_head *list)
  636. {
  637. struct audit_entry *e;
  638. enum audit_state state;
  639. if (audit_pid && tsk->tgid == audit_pid)
  640. return AUDIT_DISABLED;
  641. rcu_read_lock();
  642. if (!list_empty(list)) {
  643. int word = AUDIT_WORD(ctx->major);
  644. int bit = AUDIT_BIT(ctx->major);
  645. list_for_each_entry_rcu(e, list, list) {
  646. if ((e->rule.mask[word] & bit) == bit &&
  647. audit_filter_rules(tsk, &e->rule, ctx, NULL,
  648. &state)) {
  649. rcu_read_unlock();
  650. ctx->current_state = state;
  651. return state;
  652. }
  653. }
  654. }
  655. rcu_read_unlock();
  656. return AUDIT_BUILD_CONTEXT;
  657. }
  658. /* At syscall exit time, this filter is called if any audit_names[] have been
  659. * collected during syscall processing. We only check rules in sublists at hash
  660. * buckets applicable to the inode numbers in audit_names[].
  661. * Regarding audit_state, same rules apply as for audit_filter_syscall().
  662. */
  663. void audit_filter_inodes(struct task_struct *tsk, struct audit_context *ctx)
  664. {
  665. int i;
  666. struct audit_entry *e;
  667. enum audit_state state;
  668. if (audit_pid && tsk->tgid == audit_pid)
  669. return;
  670. rcu_read_lock();
  671. for (i = 0; i < ctx->name_count; i++) {
  672. int word = AUDIT_WORD(ctx->major);
  673. int bit = AUDIT_BIT(ctx->major);
  674. struct audit_names *n = &ctx->names[i];
  675. int h = audit_hash_ino((u32)n->ino);
  676. struct list_head *list = &audit_inode_hash[h];
  677. if (list_empty(list))
  678. continue;
  679. list_for_each_entry_rcu(e, list, list) {
  680. if ((e->rule.mask[word] & bit) == bit &&
  681. audit_filter_rules(tsk, &e->rule, ctx, n, &state)) {
  682. rcu_read_unlock();
  683. ctx->current_state = state;
  684. return;
  685. }
  686. }
  687. }
  688. rcu_read_unlock();
  689. }
  690. static void audit_set_auditable(struct audit_context *ctx)
  691. {
  692. if (!ctx->prio) {
  693. ctx->prio = 1;
  694. ctx->current_state = AUDIT_RECORD_CONTEXT;
  695. }
  696. }
  697. static inline struct audit_context *audit_get_context(struct task_struct *tsk,
  698. int return_valid,
  699. int return_code)
  700. {
  701. struct audit_context *context = tsk->audit_context;
  702. if (likely(!context))
  703. return NULL;
  704. context->return_valid = return_valid;
  705. /*
  706. * we need to fix up the return code in the audit logs if the actual
  707. * return codes are later going to be fixed up by the arch specific
  708. * signal handlers
  709. *
  710. * This is actually a test for:
  711. * (rc == ERESTARTSYS ) || (rc == ERESTARTNOINTR) ||
  712. * (rc == ERESTARTNOHAND) || (rc == ERESTART_RESTARTBLOCK)
  713. *
  714. * but is faster than a bunch of ||
  715. */
  716. if (unlikely(return_code <= -ERESTARTSYS) &&
  717. (return_code >= -ERESTART_RESTARTBLOCK) &&
  718. (return_code != -ENOIOCTLCMD))
  719. context->return_code = -EINTR;
  720. else
  721. context->return_code = return_code;
  722. if (context->in_syscall && !context->dummy) {
  723. audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_EXIT]);
  724. audit_filter_inodes(tsk, context);
  725. }
  726. tsk->audit_context = NULL;
  727. return context;
  728. }
  729. static inline void audit_free_names(struct audit_context *context)
  730. {
  731. int i;
  732. #if AUDIT_DEBUG == 2
  733. if (context->put_count + context->ino_count != context->name_count) {
  734. printk(KERN_ERR "%s:%d(:%d): major=%d in_syscall=%d"
  735. " name_count=%d put_count=%d"
  736. " ino_count=%d [NOT freeing]\n",
  737. __FILE__, __LINE__,
  738. context->serial, context->major, context->in_syscall,
  739. context->name_count, context->put_count,
  740. context->ino_count);
  741. for (i = 0; i < context->name_count; i++) {
  742. printk(KERN_ERR "names[%d] = %p = %s\n", i,
  743. context->names[i].name,
  744. context->names[i].name ?: "(null)");
  745. }
  746. dump_stack();
  747. return;
  748. }
  749. #endif
  750. #if AUDIT_DEBUG
  751. context->put_count = 0;
  752. context->ino_count = 0;
  753. #endif
  754. for (i = 0; i < context->name_count; i++) {
  755. if (context->names[i].name && context->names[i].name_put)
  756. __putname(context->names[i].name);
  757. }
  758. context->name_count = 0;
  759. path_put(&context->pwd);
  760. context->pwd.dentry = NULL;
  761. context->pwd.mnt = NULL;
  762. }
  763. static inline void audit_free_aux(struct audit_context *context)
  764. {
  765. struct audit_aux_data *aux;
  766. while ((aux = context->aux)) {
  767. context->aux = aux->next;
  768. kfree(aux);
  769. }
  770. while ((aux = context->aux_pids)) {
  771. context->aux_pids = aux->next;
  772. kfree(aux);
  773. }
  774. }
  775. static inline void audit_zero_context(struct audit_context *context,
  776. enum audit_state state)
  777. {
  778. memset(context, 0, sizeof(*context));
  779. context->state = state;
  780. context->prio = state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
  781. }
  782. static inline struct audit_context *audit_alloc_context(enum audit_state state)
  783. {
  784. struct audit_context *context;
  785. if (!(context = kmalloc(sizeof(*context), GFP_KERNEL)))
  786. return NULL;
  787. audit_zero_context(context, state);
  788. return context;
  789. }
  790. /**
  791. * audit_alloc - allocate an audit context block for a task
  792. * @tsk: task
  793. *
  794. * Filter on the task information and allocate a per-task audit context
  795. * if necessary. Doing so turns on system call auditing for the
  796. * specified task. This is called from copy_process, so no lock is
  797. * needed.
  798. */
  799. int audit_alloc(struct task_struct *tsk)
  800. {
  801. struct audit_context *context;
  802. enum audit_state state;
  803. if (likely(!audit_ever_enabled))
  804. return 0; /* Return if not auditing. */
  805. state = audit_filter_task(tsk);
  806. if (likely(state == AUDIT_DISABLED))
  807. return 0;
  808. if (!(context = audit_alloc_context(state))) {
  809. audit_log_lost("out of memory in audit_alloc");
  810. return -ENOMEM;
  811. }
  812. tsk->audit_context = context;
  813. set_tsk_thread_flag(tsk, TIF_SYSCALL_AUDIT);
  814. return 0;
  815. }
  816. static inline void audit_free_context(struct audit_context *context)
  817. {
  818. struct audit_context *previous;
  819. int count = 0;
  820. do {
  821. previous = context->previous;
  822. if (previous || (count && count < 10)) {
  823. ++count;
  824. printk(KERN_ERR "audit(:%d): major=%d name_count=%d:"
  825. " freeing multiple contexts (%d)\n",
  826. context->serial, context->major,
  827. context->name_count, count);
  828. }
  829. audit_free_names(context);
  830. unroll_tree_refs(context, NULL, 0);
  831. free_tree_refs(context);
  832. audit_free_aux(context);
  833. kfree(context->filterkey);
  834. kfree(context->sockaddr);
  835. kfree(context);
  836. context = previous;
  837. } while (context);
  838. if (count >= 10)
  839. printk(KERN_ERR "audit: freed %d contexts\n", count);
  840. }
  841. void audit_log_task_context(struct audit_buffer *ab)
  842. {
  843. char *ctx = NULL;
  844. unsigned len;
  845. int error;
  846. u32 sid;
  847. security_task_getsecid(current, &sid);
  848. if (!sid)
  849. return;
  850. error = security_secid_to_secctx(sid, &ctx, &len);
  851. if (error) {
  852. if (error != -EINVAL)
  853. goto error_path;
  854. return;
  855. }
  856. audit_log_format(ab, " subj=%s", ctx);
  857. security_release_secctx(ctx, len);
  858. return;
  859. error_path:
  860. audit_panic("error in audit_log_task_context");
  861. return;
  862. }
  863. EXPORT_SYMBOL(audit_log_task_context);
  864. static void audit_log_task_info(struct audit_buffer *ab, struct task_struct *tsk)
  865. {
  866. char name[sizeof(tsk->comm)];
  867. struct mm_struct *mm = tsk->mm;
  868. struct vm_area_struct *vma;
  869. /* tsk == current */
  870. get_task_comm(name, tsk);
  871. audit_log_format(ab, " comm=");
  872. audit_log_untrustedstring(ab, name);
  873. if (mm) {
  874. down_read(&mm->mmap_sem);
  875. vma = mm->mmap;
  876. while (vma) {
  877. if ((vma->vm_flags & VM_EXECUTABLE) &&
  878. vma->vm_file) {
  879. audit_log_d_path(ab, "exe=",
  880. &vma->vm_file->f_path);
  881. break;
  882. }
  883. vma = vma->vm_next;
  884. }
  885. up_read(&mm->mmap_sem);
  886. }
  887. audit_log_task_context(ab);
  888. }
  889. static int audit_log_pid_context(struct audit_context *context, pid_t pid,
  890. uid_t auid, uid_t uid, unsigned int sessionid,
  891. u32 sid, char *comm)
  892. {
  893. struct audit_buffer *ab;
  894. char *ctx = NULL;
  895. u32 len;
  896. int rc = 0;
  897. ab = audit_log_start(context, GFP_KERNEL, AUDIT_OBJ_PID);
  898. if (!ab)
  899. return rc;
  900. audit_log_format(ab, "opid=%d oauid=%d ouid=%d oses=%d", pid, auid,
  901. uid, sessionid);
  902. if (security_secid_to_secctx(sid, &ctx, &len)) {
  903. audit_log_format(ab, " obj=(none)");
  904. rc = 1;
  905. } else {
  906. audit_log_format(ab, " obj=%s", ctx);
  907. security_release_secctx(ctx, len);
  908. }
  909. audit_log_format(ab, " ocomm=");
  910. audit_log_untrustedstring(ab, comm);
  911. audit_log_end(ab);
  912. return rc;
  913. }
  914. /*
  915. * to_send and len_sent accounting are very loose estimates. We aren't
  916. * really worried about a hard cap to MAX_EXECVE_AUDIT_LEN so much as being
  917. * within about 500 bytes (next page boundry)
  918. *
  919. * why snprintf? an int is up to 12 digits long. if we just assumed when
  920. * logging that a[%d]= was going to be 16 characters long we would be wasting
  921. * space in every audit message. In one 7500 byte message we can log up to
  922. * about 1000 min size arguments. That comes down to about 50% waste of space
  923. * if we didn't do the snprintf to find out how long arg_num_len was.
  924. */
  925. static int audit_log_single_execve_arg(struct audit_context *context,
  926. struct audit_buffer **ab,
  927. int arg_num,
  928. size_t *len_sent,
  929. const char __user *p,
  930. char *buf)
  931. {
  932. char arg_num_len_buf[12];
  933. const char __user *tmp_p = p;
  934. /* how many digits are in arg_num? 3 is the length of a=\n */
  935. size_t arg_num_len = snprintf(arg_num_len_buf, 12, "%d", arg_num) + 3;
  936. size_t len, len_left, to_send;
  937. size_t max_execve_audit_len = MAX_EXECVE_AUDIT_LEN;
  938. unsigned int i, has_cntl = 0, too_long = 0;
  939. int ret;
  940. /* strnlen_user includes the null we don't want to send */
  941. len_left = len = strnlen_user(p, MAX_ARG_STRLEN) - 1;
  942. /*
  943. * We just created this mm, if we can't find the strings
  944. * we just copied into it something is _very_ wrong. Similar
  945. * for strings that are too long, we should not have created
  946. * any.
  947. */
  948. if (unlikely((len == -1) || len > MAX_ARG_STRLEN - 1)) {
  949. WARN_ON(1);
  950. send_sig(SIGKILL, current, 0);
  951. return -1;
  952. }
  953. /* walk the whole argument looking for non-ascii chars */
  954. do {
  955. if (len_left > MAX_EXECVE_AUDIT_LEN)
  956. to_send = MAX_EXECVE_AUDIT_LEN;
  957. else
  958. to_send = len_left;
  959. ret = copy_from_user(buf, tmp_p, to_send);
  960. /*
  961. * There is no reason for this copy to be short. We just
  962. * copied them here, and the mm hasn't been exposed to user-
  963. * space yet.
  964. */
  965. if (ret) {
  966. WARN_ON(1);
  967. send_sig(SIGKILL, current, 0);
  968. return -1;
  969. }
  970. buf[to_send] = '\0';
  971. has_cntl = audit_string_contains_control(buf, to_send);
  972. if (has_cntl) {
  973. /*
  974. * hex messages get logged as 2 bytes, so we can only
  975. * send half as much in each message
  976. */
  977. max_execve_audit_len = MAX_EXECVE_AUDIT_LEN / 2;
  978. break;
  979. }
  980. len_left -= to_send;
  981. tmp_p += to_send;
  982. } while (len_left > 0);
  983. len_left = len;
  984. if (len > max_execve_audit_len)
  985. too_long = 1;
  986. /* rewalk the argument actually logging the message */
  987. for (i = 0; len_left > 0; i++) {
  988. int room_left;
  989. if (len_left > max_execve_audit_len)
  990. to_send = max_execve_audit_len;
  991. else
  992. to_send = len_left;
  993. /* do we have space left to send this argument in this ab? */
  994. room_left = MAX_EXECVE_AUDIT_LEN - arg_num_len - *len_sent;
  995. if (has_cntl)
  996. room_left -= (to_send * 2);
  997. else
  998. room_left -= to_send;
  999. if (room_left < 0) {
  1000. *len_sent = 0;
  1001. audit_log_end(*ab);
  1002. *ab = audit_log_start(context, GFP_KERNEL, AUDIT_EXECVE);
  1003. if (!*ab)
  1004. return 0;
  1005. }
  1006. /*
  1007. * first record needs to say how long the original string was
  1008. * so we can be sure nothing was lost.
  1009. */
  1010. if ((i == 0) && (too_long))
  1011. audit_log_format(*ab, "a%d_len=%zu ", arg_num,
  1012. has_cntl ? 2*len : len);
  1013. /*
  1014. * normally arguments are small enough to fit and we already
  1015. * filled buf above when we checked for control characters
  1016. * so don't bother with another copy_from_user
  1017. */
  1018. if (len >= max_execve_audit_len)
  1019. ret = copy_from_user(buf, p, to_send);
  1020. else
  1021. ret = 0;
  1022. if (ret) {
  1023. WARN_ON(1);
  1024. send_sig(SIGKILL, current, 0);
  1025. return -1;
  1026. }
  1027. buf[to_send] = '\0';
  1028. /* actually log it */
  1029. audit_log_format(*ab, "a%d", arg_num);
  1030. if (too_long)
  1031. audit_log_format(*ab, "[%d]", i);
  1032. audit_log_format(*ab, "=");
  1033. if (has_cntl)
  1034. audit_log_n_hex(*ab, buf, to_send);
  1035. else
  1036. audit_log_format(*ab, "\"%s\"", buf);
  1037. audit_log_format(*ab, "\n");
  1038. p += to_send;
  1039. len_left -= to_send;
  1040. *len_sent += arg_num_len;
  1041. if (has_cntl)
  1042. *len_sent += to_send * 2;
  1043. else
  1044. *len_sent += to_send;
  1045. }
  1046. /* include the null we didn't log */
  1047. return len + 1;
  1048. }
  1049. static void audit_log_execve_info(struct audit_context *context,
  1050. struct audit_buffer **ab,
  1051. struct audit_aux_data_execve *axi)
  1052. {
  1053. int i;
  1054. size_t len, len_sent = 0;
  1055. const char __user *p;
  1056. char *buf;
  1057. if (axi->mm != current->mm)
  1058. return; /* execve failed, no additional info */
  1059. p = (const char __user *)axi->mm->arg_start;
  1060. audit_log_format(*ab, "argc=%d ", axi->argc);
  1061. /*
  1062. * we need some kernel buffer to hold the userspace args. Just
  1063. * allocate one big one rather than allocating one of the right size
  1064. * for every single argument inside audit_log_single_execve_arg()
  1065. * should be <8k allocation so should be pretty safe.
  1066. */
  1067. buf = kmalloc(MAX_EXECVE_AUDIT_LEN + 1, GFP_KERNEL);
  1068. if (!buf) {
  1069. audit_panic("out of memory for argv string\n");
  1070. return;
  1071. }
  1072. for (i = 0; i < axi->argc; i++) {
  1073. len = audit_log_single_execve_arg(context, ab, i,
  1074. &len_sent, p, buf);
  1075. if (len <= 0)
  1076. break;
  1077. p += len;
  1078. }
  1079. kfree(buf);
  1080. }
  1081. static void audit_log_cap(struct audit_buffer *ab, char *prefix, kernel_cap_t *cap)
  1082. {
  1083. int i;
  1084. audit_log_format(ab, " %s=", prefix);
  1085. CAP_FOR_EACH_U32(i) {
  1086. audit_log_format(ab, "%08x", cap->cap[(_KERNEL_CAPABILITY_U32S-1) - i]);
  1087. }
  1088. }
  1089. static void audit_log_fcaps(struct audit_buffer *ab, struct audit_names *name)
  1090. {
  1091. kernel_cap_t *perm = &name->fcap.permitted;
  1092. kernel_cap_t *inh = &name->fcap.inheritable;
  1093. int log = 0;
  1094. if (!cap_isclear(*perm)) {
  1095. audit_log_cap(ab, "cap_fp", perm);
  1096. log = 1;
  1097. }
  1098. if (!cap_isclear(*inh)) {
  1099. audit_log_cap(ab, "cap_fi", inh);
  1100. log = 1;
  1101. }
  1102. if (log)
  1103. audit_log_format(ab, " cap_fe=%d cap_fver=%x", name->fcap.fE, name->fcap_ver);
  1104. }
  1105. static void show_special(struct audit_context *context, int *call_panic)
  1106. {
  1107. struct audit_buffer *ab;
  1108. int i;
  1109. ab = audit_log_start(context, GFP_KERNEL, context->type);
  1110. if (!ab)
  1111. return;
  1112. switch (context->type) {
  1113. case AUDIT_SOCKETCALL: {
  1114. int nargs = context->socketcall.nargs;
  1115. audit_log_format(ab, "nargs=%d", nargs);
  1116. for (i = 0; i < nargs; i++)
  1117. audit_log_format(ab, " a%d=%lx", i,
  1118. context->socketcall.args[i]);
  1119. break; }
  1120. case AUDIT_IPC: {
  1121. u32 osid = context->ipc.osid;
  1122. audit_log_format(ab, "ouid=%u ogid=%u mode=%#o",
  1123. context->ipc.uid, context->ipc.gid, context->ipc.mode);
  1124. if (osid) {
  1125. char *ctx = NULL;
  1126. u32 len;
  1127. if (security_secid_to_secctx(osid, &ctx, &len)) {
  1128. audit_log_format(ab, " osid=%u", osid);
  1129. *call_panic = 1;
  1130. } else {
  1131. audit_log_format(ab, " obj=%s", ctx);
  1132. security_release_secctx(ctx, len);
  1133. }
  1134. }
  1135. if (context->ipc.has_perm) {
  1136. audit_log_end(ab);
  1137. ab = audit_log_start(context, GFP_KERNEL,
  1138. AUDIT_IPC_SET_PERM);
  1139. audit_log_format(ab,
  1140. "qbytes=%lx ouid=%u ogid=%u mode=%#o",
  1141. context->ipc.qbytes,
  1142. context->ipc.perm_uid,
  1143. context->ipc.perm_gid,
  1144. context->ipc.perm_mode);
  1145. if (!ab)
  1146. return;
  1147. }
  1148. break; }
  1149. case AUDIT_MQ_OPEN: {
  1150. audit_log_format(ab,
  1151. "oflag=0x%x mode=%#o mq_flags=0x%lx mq_maxmsg=%ld "
  1152. "mq_msgsize=%ld mq_curmsgs=%ld",
  1153. context->mq_open.oflag, context->mq_open.mode,
  1154. context->mq_open.attr.mq_flags,
  1155. context->mq_open.attr.mq_maxmsg,
  1156. context->mq_open.attr.mq_msgsize,
  1157. context->mq_open.attr.mq_curmsgs);
  1158. break; }
  1159. case AUDIT_MQ_SENDRECV: {
  1160. audit_log_format(ab,
  1161. "mqdes=%d msg_len=%zd msg_prio=%u "
  1162. "abs_timeout_sec=%ld abs_timeout_nsec=%ld",
  1163. context->mq_sendrecv.mqdes,
  1164. context->mq_sendrecv.msg_len,
  1165. context->mq_sendrecv.msg_prio,
  1166. context->mq_sendrecv.abs_timeout.tv_sec,
  1167. context->mq_sendrecv.abs_timeout.tv_nsec);
  1168. break; }
  1169. case AUDIT_MQ_NOTIFY: {
  1170. audit_log_format(ab, "mqdes=%d sigev_signo=%d",
  1171. context->mq_notify.mqdes,
  1172. context->mq_notify.sigev_signo);
  1173. break; }
  1174. case AUDIT_MQ_GETSETATTR: {
  1175. struct mq_attr *attr = &context->mq_getsetattr.mqstat;
  1176. audit_log_format(ab,
  1177. "mqdes=%d mq_flags=0x%lx mq_maxmsg=%ld mq_msgsize=%ld "
  1178. "mq_curmsgs=%ld ",
  1179. context->mq_getsetattr.mqdes,
  1180. attr->mq_flags, attr->mq_maxmsg,
  1181. attr->mq_msgsize, attr->mq_curmsgs);
  1182. break; }
  1183. case AUDIT_CAPSET: {
  1184. audit_log_format(ab, "pid=%d", context->capset.pid);
  1185. audit_log_cap(ab, "cap_pi", &context->capset.cap.inheritable);
  1186. audit_log_cap(ab, "cap_pp", &context->capset.cap.permitted);
  1187. audit_log_cap(ab, "cap_pe", &context->capset.cap.effective);
  1188. break; }
  1189. }
  1190. audit_log_end(ab);
  1191. }
  1192. static void audit_log_exit(struct audit_context *context, struct task_struct *tsk)
  1193. {
  1194. const struct cred *cred;
  1195. int i, call_panic = 0;
  1196. struct audit_buffer *ab;
  1197. struct audit_aux_data *aux;
  1198. const char *tty;
  1199. /* tsk == current */
  1200. context->pid = tsk->pid;
  1201. if (!context->ppid)
  1202. context->ppid = sys_getppid();
  1203. cred = current_cred();
  1204. context->uid = cred->uid;
  1205. context->gid = cred->gid;
  1206. context->euid = cred->euid;
  1207. context->suid = cred->suid;
  1208. context->fsuid = cred->fsuid;
  1209. context->egid = cred->egid;
  1210. context->sgid = cred->sgid;
  1211. context->fsgid = cred->fsgid;
  1212. context->personality = tsk->personality;
  1213. ab = audit_log_start(context, GFP_KERNEL, AUDIT_SYSCALL);
  1214. if (!ab)
  1215. return; /* audit_panic has been called */
  1216. audit_log_format(ab, "arch=%x syscall=%d",
  1217. context->arch, context->major);
  1218. if (context->personality != PER_LINUX)
  1219. audit_log_format(ab, " per=%lx", context->personality);
  1220. if (context->return_valid)
  1221. audit_log_format(ab, " success=%s exit=%ld",
  1222. (context->return_valid==AUDITSC_SUCCESS)?"yes":"no",
  1223. context->return_code);
  1224. spin_lock_irq(&tsk->sighand->siglock);
  1225. if (tsk->signal && tsk->signal->tty && tsk->signal->tty->name)
  1226. tty = tsk->signal->tty->name;
  1227. else
  1228. tty = "(none)";
  1229. spin_unlock_irq(&tsk->sighand->siglock);
  1230. audit_log_format(ab,
  1231. " a0=%lx a1=%lx a2=%lx a3=%lx items=%d"
  1232. " ppid=%d pid=%d auid=%u uid=%u gid=%u"
  1233. " euid=%u suid=%u fsuid=%u"
  1234. " egid=%u sgid=%u fsgid=%u tty=%s ses=%u",
  1235. context->argv[0],
  1236. context->argv[1],
  1237. context->argv[2],
  1238. context->argv[3],
  1239. context->name_count,
  1240. context->ppid,
  1241. context->pid,
  1242. tsk->loginuid,
  1243. context->uid,
  1244. context->gid,
  1245. context->euid, context->suid, context->fsuid,
  1246. context->egid, context->sgid, context->fsgid, tty,
  1247. tsk->sessionid);
  1248. audit_log_task_info(ab, tsk);
  1249. if (context->filterkey) {
  1250. audit_log_format(ab, " key=");
  1251. audit_log_untrustedstring(ab, context->filterkey);
  1252. } else
  1253. audit_log_format(ab, " key=(null)");
  1254. audit_log_end(ab);
  1255. for (aux = context->aux; aux; aux = aux->next) {
  1256. ab = audit_log_start(context, GFP_KERNEL, aux->type);
  1257. if (!ab)
  1258. continue; /* audit_panic has been called */
  1259. switch (aux->type) {
  1260. case AUDIT_EXECVE: {
  1261. struct audit_aux_data_execve *axi = (void *)aux;
  1262. audit_log_execve_info(context, &ab, axi);
  1263. break; }
  1264. case AUDIT_BPRM_FCAPS: {
  1265. struct audit_aux_data_bprm_fcaps *axs = (void *)aux;
  1266. audit_log_format(ab, "fver=%x", axs->fcap_ver);
  1267. audit_log_cap(ab, "fp", &axs->fcap.permitted);
  1268. audit_log_cap(ab, "fi", &axs->fcap.inheritable);
  1269. audit_log_format(ab, " fe=%d", axs->fcap.fE);
  1270. audit_log_cap(ab, "old_pp", &axs->old_pcap.permitted);
  1271. audit_log_cap(ab, "old_pi", &axs->old_pcap.inheritable);
  1272. audit_log_cap(ab, "old_pe", &axs->old_pcap.effective);
  1273. audit_log_cap(ab, "new_pp", &axs->new_pcap.permitted);
  1274. audit_log_cap(ab, "new_pi", &axs->new_pcap.inheritable);
  1275. audit_log_cap(ab, "new_pe", &axs->new_pcap.effective);
  1276. break; }
  1277. }
  1278. audit_log_end(ab);
  1279. }
  1280. if (context->type)
  1281. show_special(context, &call_panic);
  1282. if (context->fds[0] >= 0) {
  1283. ab = audit_log_start(context, GFP_KERNEL, AUDIT_FD_PAIR);
  1284. if (ab) {
  1285. audit_log_format(ab, "fd0=%d fd1=%d",
  1286. context->fds[0], context->fds[1]);
  1287. audit_log_end(ab);
  1288. }
  1289. }
  1290. if (context->sockaddr_len) {
  1291. ab = audit_log_start(context, GFP_KERNEL, AUDIT_SOCKADDR);
  1292. if (ab) {
  1293. audit_log_format(ab, "saddr=");
  1294. audit_log_n_hex(ab, (void *)context->sockaddr,
  1295. context->sockaddr_len);
  1296. audit_log_end(ab);
  1297. }
  1298. }
  1299. for (aux = context->aux_pids; aux; aux = aux->next) {
  1300. struct audit_aux_data_pids *axs = (void *)aux;
  1301. for (i = 0; i < axs->pid_count; i++)
  1302. if (audit_log_pid_context(context, axs->target_pid[i],
  1303. axs->target_auid[i],
  1304. axs->target_uid[i],
  1305. axs->target_sessionid[i],
  1306. axs->target_sid[i],
  1307. axs->target_comm[i]))
  1308. call_panic = 1;
  1309. }
  1310. if (context->target_pid &&
  1311. audit_log_pid_context(context, context->target_pid,
  1312. context->target_auid, context->target_uid,
  1313. context->target_sessionid,
  1314. context->target_sid, context->target_comm))
  1315. call_panic = 1;
  1316. if (context->pwd.dentry && context->pwd.mnt) {
  1317. ab = audit_log_start(context, GFP_KERNEL, AUDIT_CWD);
  1318. if (ab) {
  1319. audit_log_d_path(ab, "cwd=", &context->pwd);
  1320. audit_log_end(ab);
  1321. }
  1322. }
  1323. for (i = 0; i < context->name_count; i++) {
  1324. struct audit_names *n = &context->names[i];
  1325. ab = audit_log_start(context, GFP_KERNEL, AUDIT_PATH);
  1326. if (!ab)
  1327. continue; /* audit_panic has been called */
  1328. audit_log_format(ab, "item=%d", i);
  1329. if (n->name) {
  1330. switch(n->name_len) {
  1331. case AUDIT_NAME_FULL:
  1332. /* log the full path */
  1333. audit_log_format(ab, " name=");
  1334. audit_log_untrustedstring(ab, n->name);
  1335. break;
  1336. case 0:
  1337. /* name was specified as a relative path and the
  1338. * directory component is the cwd */
  1339. audit_log_d_path(ab, " name=", &context->pwd);
  1340. break;
  1341. default:
  1342. /* log the name's directory component */
  1343. audit_log_format(ab, " name=");
  1344. audit_log_n_untrustedstring(ab, n->name,
  1345. n->name_len);
  1346. }
  1347. } else
  1348. audit_log_format(ab, " name=(null)");
  1349. if (n->ino != (unsigned long)-1) {
  1350. audit_log_format(ab, " inode=%lu"
  1351. " dev=%02x:%02x mode=%#o"
  1352. " ouid=%u ogid=%u rdev=%02x:%02x",
  1353. n->ino,
  1354. MAJOR(n->dev),
  1355. MINOR(n->dev),
  1356. n->mode,
  1357. n->uid,
  1358. n->gid,
  1359. MAJOR(n->rdev),
  1360. MINOR(n->rdev));
  1361. }
  1362. if (n->osid != 0) {
  1363. char *ctx = NULL;
  1364. u32 len;
  1365. if (security_secid_to_secctx(
  1366. n->osid, &ctx, &len)) {
  1367. audit_log_format(ab, " osid=%u", n->osid);
  1368. call_panic = 2;
  1369. } else {
  1370. audit_log_format(ab, " obj=%s", ctx);
  1371. security_release_secctx(ctx, len);
  1372. }
  1373. }
  1374. audit_log_fcaps(ab, n);
  1375. audit_log_end(ab);
  1376. }
  1377. /* Send end of event record to help user space know we are finished */
  1378. ab = audit_log_start(context, GFP_KERNEL, AUDIT_EOE);
  1379. if (ab)
  1380. audit_log_end(ab);
  1381. if (call_panic)
  1382. audit_panic("error converting sid to string");
  1383. }
  1384. /**
  1385. * audit_free - free a per-task audit context
  1386. * @tsk: task whose audit context block to free
  1387. *
  1388. * Called from copy_process and do_exit
  1389. */
  1390. void audit_free(struct task_struct *tsk)
  1391. {
  1392. struct audit_context *context;
  1393. context = audit_get_context(tsk, 0, 0);
  1394. if (likely(!context))
  1395. return;
  1396. /* Check for system calls that do not go through the exit
  1397. * function (e.g., exit_group), then free context block.
  1398. * We use GFP_ATOMIC here because we might be doing this
  1399. * in the context of the idle thread */
  1400. /* that can happen only if we are called from do_exit() */
  1401. if (context->in_syscall && context->current_state == AUDIT_RECORD_CONTEXT)
  1402. audit_log_exit(context, tsk);
  1403. audit_free_context(context);
  1404. }
  1405. /**
  1406. * audit_syscall_entry - fill in an audit record at syscall entry
  1407. * @arch: architecture type
  1408. * @major: major syscall type (function)
  1409. * @a1: additional syscall register 1
  1410. * @a2: additional syscall register 2
  1411. * @a3: additional syscall register 3
  1412. * @a4: additional syscall register 4
  1413. *
  1414. * Fill in audit context at syscall entry. This only happens if the
  1415. * audit context was created when the task was created and the state or
  1416. * filters demand the audit context be built. If the state from the
  1417. * per-task filter or from the per-syscall filter is AUDIT_RECORD_CONTEXT,
  1418. * then the record will be written at syscall exit time (otherwise, it
  1419. * will only be written if another part of the kernel requests that it
  1420. * be written).
  1421. */
  1422. void audit_syscall_entry(int arch, int major,
  1423. unsigned long a1, unsigned long a2,
  1424. unsigned long a3, unsigned long a4)
  1425. {
  1426. struct task_struct *tsk = current;
  1427. struct audit_context *context = tsk->audit_context;
  1428. enum audit_state state;
  1429. if (unlikely(!context))
  1430. return;
  1431. /*
  1432. * This happens only on certain architectures that make system
  1433. * calls in kernel_thread via the entry.S interface, instead of
  1434. * with direct calls. (If you are porting to a new
  1435. * architecture, hitting this condition can indicate that you
  1436. * got the _exit/_leave calls backward in entry.S.)
  1437. *
  1438. * i386 no
  1439. * x86_64 no
  1440. * ppc64 yes (see arch/powerpc/platforms/iseries/misc.S)
  1441. *
  1442. * This also happens with vm86 emulation in a non-nested manner
  1443. * (entries without exits), so this case must be caught.
  1444. */
  1445. if (context->in_syscall) {
  1446. struct audit_context *newctx;
  1447. #if AUDIT_DEBUG
  1448. printk(KERN_ERR
  1449. "audit(:%d) pid=%d in syscall=%d;"
  1450. " entering syscall=%d\n",
  1451. context->serial, tsk->pid, context->major, major);
  1452. #endif
  1453. newctx = audit_alloc_context(context->state);
  1454. if (newctx) {
  1455. newctx->previous = context;
  1456. context = newctx;
  1457. tsk->audit_context = newctx;
  1458. } else {
  1459. /* If we can't alloc a new context, the best we
  1460. * can do is to leak memory (any pending putname
  1461. * will be lost). The only other alternative is
  1462. * to abandon auditing. */
  1463. audit_zero_context(context, context->state);
  1464. }
  1465. }
  1466. BUG_ON(context->in_syscall || context->name_count);
  1467. if (!audit_enabled)
  1468. return;
  1469. context->arch = arch;
  1470. context->major = major;
  1471. context->argv[0] = a1;
  1472. context->argv[1] = a2;
  1473. context->argv[2] = a3;
  1474. context->argv[3] = a4;
  1475. state = context->state;
  1476. context->dummy = !audit_n_rules;
  1477. if (!context->dummy && state == AUDIT_BUILD_CONTEXT) {
  1478. context->prio = 0;
  1479. state = audit_filter_syscall(tsk, context, &audit_filter_list[AUDIT_FILTER_ENTRY]);
  1480. }
  1481. if (likely(state == AUDIT_DISABLED))
  1482. return;
  1483. context->serial = 0;
  1484. context->ctime = CURRENT_TIME;
  1485. context->in_syscall = 1;
  1486. context->current_state = state;
  1487. context->ppid = 0;
  1488. }
  1489. void audit_finish_fork(struct task_struct *child)
  1490. {
  1491. struct audit_context *ctx = current->audit_context;
  1492. struct audit_context *p = child->audit_context;
  1493. if (!p || !ctx)
  1494. return;
  1495. if (!ctx->in_syscall || ctx->current_state != AUDIT_RECORD_CONTEXT)
  1496. return;
  1497. p->arch = ctx->arch;
  1498. p->major = ctx->major;
  1499. memcpy(p->argv, ctx->argv, sizeof(ctx->argv));
  1500. p->ctime = ctx->ctime;
  1501. p->dummy = ctx->dummy;
  1502. p->in_syscall = ctx->in_syscall;
  1503. p->filterkey = kstrdup(ctx->filterkey, GFP_KERNEL);
  1504. p->ppid = current->pid;
  1505. p->prio = ctx->prio;
  1506. p->current_state = ctx->current_state;
  1507. }
  1508. /**
  1509. * audit_syscall_exit - deallocate audit context after a system call
  1510. * @valid: success/failure flag
  1511. * @return_code: syscall return value
  1512. *
  1513. * Tear down after system call. If the audit context has been marked as
  1514. * auditable (either because of the AUDIT_RECORD_CONTEXT state from
  1515. * filtering, or because some other part of the kernel write an audit
  1516. * message), then write out the syscall information. In call cases,
  1517. * free the names stored from getname().
  1518. */
  1519. void audit_syscall_exit(int valid, long return_code)
  1520. {
  1521. struct task_struct *tsk = current;
  1522. struct audit_context *context;
  1523. context = audit_get_context(tsk, valid, return_code);
  1524. if (likely(!context))
  1525. return;
  1526. if (context->in_syscall && context->current_state == AUDIT_RECORD_CONTEXT)
  1527. audit_log_exit(context, tsk);
  1528. context->in_syscall = 0;
  1529. context->prio = context->state == AUDIT_RECORD_CONTEXT ? ~0ULL : 0;
  1530. if (context->previous) {
  1531. struct audit_context *new_context = context->previous;
  1532. context->previous = NULL;
  1533. audit_free_context(context);
  1534. tsk->audit_context = new_context;
  1535. } else {
  1536. audit_free_names(context);
  1537. unroll_tree_refs(context, NULL, 0);
  1538. audit_free_aux(context);
  1539. context->aux = NULL;
  1540. context->aux_pids = NULL;
  1541. context->target_pid = 0;
  1542. context->target_sid = 0;
  1543. context->sockaddr_len = 0;
  1544. context->type = 0;
  1545. context->fds[0] = -1;
  1546. kfree(context->filterkey);
  1547. context->filterkey = NULL;
  1548. tsk->audit_context = context;
  1549. }
  1550. }
  1551. static inline void handle_one(const struct inode *inode)
  1552. {
  1553. #ifdef CONFIG_AUDIT_TREE
  1554. struct audit_context *context;
  1555. struct audit_tree_refs *p;
  1556. struct audit_chunk *chunk;
  1557. int count;
  1558. if (likely(list_empty(&inode->inotify_watches)))
  1559. return;
  1560. context = current->audit_context;
  1561. p = context->trees;
  1562. count = context->tree_count;
  1563. rcu_read_lock();
  1564. chunk = audit_tree_lookup(inode);
  1565. rcu_read_unlock();
  1566. if (!chunk)
  1567. return;
  1568. if (likely(put_tree_ref(context, chunk)))
  1569. return;
  1570. if (unlikely(!grow_tree_refs(context))) {
  1571. printk(KERN_WARNING "out of memory, audit has lost a tree reference\n");
  1572. audit_set_auditable(context);
  1573. audit_put_chunk(chunk);
  1574. unroll_tree_refs(context, p, count);
  1575. return;
  1576. }
  1577. put_tree_ref(context, chunk);
  1578. #endif
  1579. }
  1580. static void handle_path(const struct dentry *dentry)
  1581. {
  1582. #ifdef CONFIG_AUDIT_TREE
  1583. struct audit_context *context;
  1584. struct audit_tree_refs *p;
  1585. const struct dentry *d, *parent;
  1586. struct audit_chunk *drop;
  1587. unsigned long seq;
  1588. int count;
  1589. context = current->audit_context;
  1590. p = context->trees;
  1591. count = context->tree_count;
  1592. retry:
  1593. drop = NULL;
  1594. d = dentry;
  1595. rcu_read_lock();
  1596. seq = read_seqbegin(&rename_lock);
  1597. for(;;) {
  1598. struct inode *inode = d->d_inode;
  1599. if (inode && unlikely(!list_empty(&inode->inotify_watches))) {
  1600. struct audit_chunk *chunk;
  1601. chunk = audit_tree_lookup(inode);
  1602. if (chunk) {
  1603. if (unlikely(!put_tree_ref(context, chunk))) {
  1604. drop = chunk;
  1605. break;
  1606. }
  1607. }
  1608. }
  1609. parent = d->d_parent;
  1610. if (parent == d)
  1611. break;
  1612. d = parent;
  1613. }
  1614. if (unlikely(read_seqretry(&rename_lock, seq) || drop)) { /* in this order */
  1615. rcu_read_unlock();
  1616. if (!drop) {
  1617. /* just a race with rename */
  1618. unroll_tree_refs(context, p, count);
  1619. goto retry;
  1620. }
  1621. audit_put_chunk(drop);
  1622. if (grow_tree_refs(context)) {
  1623. /* OK, got more space */
  1624. unroll_tree_refs(context, p, count);
  1625. goto retry;
  1626. }
  1627. /* too bad */
  1628. printk(KERN_WARNING
  1629. "out of memory, audit has lost a tree reference\n");
  1630. unroll_tree_refs(context, p, count);
  1631. audit_set_auditable(context);
  1632. return;
  1633. }
  1634. rcu_read_unlock();
  1635. #endif
  1636. }
  1637. /**
  1638. * audit_getname - add a name to the list
  1639. * @name: name to add
  1640. *
  1641. * Add a name to the list of audit names for this context.
  1642. * Called from fs/namei.c:getname().
  1643. */
  1644. void __audit_getname(const char *name)
  1645. {
  1646. struct audit_context *context = current->audit_context;
  1647. if (IS_ERR(name) || !name)
  1648. return;
  1649. if (!context->in_syscall) {
  1650. #if AUDIT_DEBUG == 2
  1651. printk(KERN_ERR "%s:%d(:%d): ignoring getname(%p)\n",
  1652. __FILE__, __LINE__, context->serial, name);
  1653. dump_stack();
  1654. #endif
  1655. return;
  1656. }
  1657. BUG_ON(context->name_count >= AUDIT_NAMES);
  1658. context->names[context->name_count].name = name;
  1659. context->names[context->name_count].name_len = AUDIT_NAME_FULL;
  1660. context->names[context->name_count].name_put = 1;
  1661. context->names[context->name_count].ino = (unsigned long)-1;
  1662. context->names[context->name_count].osid = 0;
  1663. ++context->name_count;
  1664. if (!context->pwd.dentry) {
  1665. read_lock(&current->fs->lock);
  1666. context->pwd = current->fs->pwd;
  1667. path_get(&current->fs->pwd);
  1668. read_unlock(&current->fs->lock);
  1669. }
  1670. }
  1671. /* audit_putname - intercept a putname request
  1672. * @name: name to intercept and delay for putname
  1673. *
  1674. * If we have stored the name from getname in the audit context,
  1675. * then we delay the putname until syscall exit.
  1676. * Called from include/linux/fs.h:putname().
  1677. */
  1678. void audit_putname(const char *name)
  1679. {
  1680. struct audit_context *context = current->audit_context;
  1681. BUG_ON(!context);
  1682. if (!context->in_syscall) {
  1683. #if AUDIT_DEBUG == 2
  1684. printk(KERN_ERR "%s:%d(:%d): __putname(%p)\n",
  1685. __FILE__, __LINE__, context->serial, name);
  1686. if (context->name_count) {
  1687. int i;
  1688. for (i = 0; i < context->name_count; i++)
  1689. printk(KERN_ERR "name[%d] = %p = %s\n", i,
  1690. context->names[i].name,
  1691. context->names[i].name ?: "(null)");
  1692. }
  1693. #endif
  1694. __putname(name);
  1695. }
  1696. #if AUDIT_DEBUG
  1697. else {
  1698. ++context->put_count;
  1699. if (context->put_count > context->name_count) {
  1700. printk(KERN_ERR "%s:%d(:%d): major=%d"
  1701. " in_syscall=%d putname(%p) name_count=%d"
  1702. " put_count=%d\n",
  1703. __FILE__, __LINE__,
  1704. context->serial, context->major,
  1705. context->in_syscall, name, context->name_count,
  1706. context->put_count);
  1707. dump_stack();
  1708. }
  1709. }
  1710. #endif
  1711. }
  1712. static int audit_inc_name_count(struct audit_context *context,
  1713. const struct inode *inode)
  1714. {
  1715. if (context->name_count >= AUDIT_NAMES) {
  1716. if (inode)
  1717. printk(KERN_DEBUG "name_count maxed, losing inode data: "
  1718. "dev=%02x:%02x, inode=%lu\n",
  1719. MAJOR(inode->i_sb->s_dev),
  1720. MINOR(inode->i_sb->s_dev),
  1721. inode->i_ino);
  1722. else
  1723. printk(KERN_DEBUG "name_count maxed, losing inode data\n");
  1724. return 1;
  1725. }
  1726. context->name_count++;
  1727. #if AUDIT_DEBUG
  1728. context->ino_count++;
  1729. #endif
  1730. return 0;
  1731. }
  1732. static inline int audit_copy_fcaps(struct audit_names *name, const struct dentry *dentry)
  1733. {
  1734. struct cpu_vfs_cap_data caps;
  1735. int rc;
  1736. memset(&name->fcap.permitted, 0, sizeof(kernel_cap_t));
  1737. memset(&name->fcap.inheritable, 0, sizeof(kernel_cap_t));
  1738. name->fcap.fE = 0;
  1739. name->fcap_ver = 0;
  1740. if (!dentry)
  1741. return 0;
  1742. rc = get_vfs_caps_from_disk(dentry, &caps);
  1743. if (rc)
  1744. return rc;
  1745. name->fcap.permitted = caps.permitted;
  1746. name->fcap.inheritable = caps.inheritable;
  1747. name->fcap.fE = !!(caps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE);
  1748. name->fcap_ver = (caps.magic_etc & VFS_CAP_REVISION_MASK) >> VFS_CAP_REVISION_SHIFT;
  1749. return 0;
  1750. }
  1751. /* Copy inode data into an audit_names. */
  1752. static void audit_copy_inode(struct audit_names *name, const struct dentry *dentry,
  1753. const struct inode *inode)
  1754. {
  1755. name->ino = inode->i_ino;
  1756. name->dev = inode->i_sb->s_dev;
  1757. name->mode = inode->i_mode;
  1758. name->uid = inode->i_uid;
  1759. name->gid = inode->i_gid;
  1760. name->rdev = inode->i_rdev;
  1761. security_inode_getsecid(inode, &name->osid);
  1762. audit_copy_fcaps(name, dentry);
  1763. }
  1764. /**
  1765. * audit_inode - store the inode and device from a lookup
  1766. * @name: name being audited
  1767. * @dentry: dentry being audited
  1768. *
  1769. * Called from fs/namei.c:path_lookup().
  1770. */
  1771. void __audit_inode(const char *name, const struct dentry *dentry)
  1772. {
  1773. int idx;
  1774. struct audit_context *context = current->audit_context;
  1775. const struct inode *inode = dentry->d_inode;
  1776. if (!context->in_syscall)
  1777. return;
  1778. if (context->name_count
  1779. && context->names[context->name_count-1].name
  1780. && context->names[context->name_count-1].name == name)
  1781. idx = context->name_count - 1;
  1782. else if (context->name_count > 1
  1783. && context->names[context->name_count-2].name
  1784. && context->names[context->name_count-2].name == name)
  1785. idx = context->name_count - 2;
  1786. else {
  1787. /* FIXME: how much do we care about inodes that have no
  1788. * associated name? */
  1789. if (audit_inc_name_count(context, inode))
  1790. return;
  1791. idx = context->name_count - 1;
  1792. context->names[idx].name = NULL;
  1793. }
  1794. handle_path(dentry);
  1795. audit_copy_inode(&context->names[idx], dentry, inode);
  1796. }
  1797. /**
  1798. * audit_inode_child - collect inode info for created/removed objects
  1799. * @dname: inode's dentry name
  1800. * @dentry: dentry being audited
  1801. * @parent: inode of dentry parent
  1802. *
  1803. * For syscalls that create or remove filesystem objects, audit_inode
  1804. * can only collect information for the filesystem object's parent.
  1805. * This call updates the audit context with the child's information.
  1806. * Syscalls that create a new filesystem object must be hooked after
  1807. * the object is created. Syscalls that remove a filesystem object
  1808. * must be hooked prior, in order to capture the target inode during
  1809. * unsuccessful attempts.
  1810. */
  1811. void __audit_inode_child(const char *dname, const struct dentry *dentry,
  1812. const struct inode *parent)
  1813. {
  1814. int idx;
  1815. struct audit_context *context = current->audit_context;
  1816. const char *found_parent = NULL, *found_child = NULL;
  1817. const struct inode *inode = dentry->d_inode;
  1818. int dirlen = 0;
  1819. if (!context->in_syscall)
  1820. return;
  1821. if (inode)
  1822. handle_one(inode);
  1823. /* determine matching parent */
  1824. if (!dname)
  1825. goto add_names;
  1826. /* parent is more likely, look for it first */
  1827. for (idx = 0; idx < context->name_count; idx++) {
  1828. struct audit_names *n = &context->names[idx];
  1829. if (!n->name)
  1830. continue;
  1831. if (n->ino == parent->i_ino &&
  1832. !audit_compare_dname_path(dname, n->name, &dirlen)) {
  1833. n->name_len = dirlen; /* update parent data in place */
  1834. found_parent = n->name;
  1835. goto add_names;
  1836. }
  1837. }
  1838. /* no matching parent, look for matching child */
  1839. for (idx = 0; idx < context->name_count; idx++) {
  1840. struct audit_names *n = &context->names[idx];
  1841. if (!n->name)
  1842. continue;
  1843. /* strcmp() is the more likely scenario */
  1844. if (!strcmp(dname, n->name) ||
  1845. !audit_compare_dname_path(dname, n->name, &dirlen)) {
  1846. if (inode)
  1847. audit_copy_inode(n, NULL, inode);
  1848. else
  1849. n->ino = (unsigned long)-1;
  1850. found_child = n->name;
  1851. goto add_names;
  1852. }
  1853. }
  1854. add_names:
  1855. if (!found_parent) {
  1856. if (audit_inc_name_count(context, parent))
  1857. return;
  1858. idx = context->name_count - 1;
  1859. context->names[idx].name = NULL;
  1860. audit_copy_inode(&context->names[idx], NULL, parent);
  1861. }
  1862. if (!found_child) {
  1863. if (audit_inc_name_count(context, inode))
  1864. return;
  1865. idx = context->name_count - 1;
  1866. /* Re-use the name belonging to the slot for a matching parent
  1867. * directory. All names for this context are relinquished in
  1868. * audit_free_names() */
  1869. if (found_parent) {
  1870. context->names[idx].name = found_parent;
  1871. context->names[idx].name_len = AUDIT_NAME_FULL;
  1872. /* don't call __putname() */
  1873. context->names[idx].name_put = 0;
  1874. } else {
  1875. context->names[idx].name = NULL;
  1876. }
  1877. if (inode)
  1878. audit_copy_inode(&context->names[idx], NULL, inode);
  1879. else
  1880. context->names[idx].ino = (unsigned long)-1;
  1881. }
  1882. }
  1883. EXPORT_SYMBOL_GPL(__audit_inode_child);
  1884. /**
  1885. * auditsc_get_stamp - get local copies of audit_context values
  1886. * @ctx: audit_context for the task
  1887. * @t: timespec to store time recorded in the audit_context
  1888. * @serial: serial value that is recorded in the audit_context
  1889. *
  1890. * Also sets the context as auditable.
  1891. */
  1892. int auditsc_get_stamp(struct audit_context *ctx,
  1893. struct timespec *t, unsigned int *serial)
  1894. {
  1895. if (!ctx->in_syscall)
  1896. return 0;
  1897. if (!ctx->serial)
  1898. ctx->serial = audit_serial();
  1899. t->tv_sec = ctx->ctime.tv_sec;
  1900. t->tv_nsec = ctx->ctime.tv_nsec;
  1901. *serial = ctx->serial;
  1902. if (!ctx->prio) {
  1903. ctx->prio = 1;
  1904. ctx->current_state = AUDIT_RECORD_CONTEXT;
  1905. }
  1906. return 1;
  1907. }
  1908. /* global counter which is incremented every time something logs in */
  1909. static atomic_t session_id = ATOMIC_INIT(0);
  1910. /**
  1911. * audit_set_loginuid - set a task's audit_context loginuid
  1912. * @task: task whose audit context is being modified
  1913. * @loginuid: loginuid value
  1914. *
  1915. * Returns 0.
  1916. *
  1917. * Called (set) from fs/proc/base.c::proc_loginuid_write().
  1918. */
  1919. int audit_set_loginuid(struct task_struct *task, uid_t loginuid)
  1920. {
  1921. unsigned int sessionid = atomic_inc_return(&session_id);
  1922. struct audit_context *context = task->audit_context;
  1923. if (context && context->in_syscall) {
  1924. struct audit_buffer *ab;
  1925. ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_LOGIN);
  1926. if (ab) {
  1927. audit_log_format(ab, "login pid=%d uid=%u "
  1928. "old auid=%u new auid=%u"
  1929. " old ses=%u new ses=%u",
  1930. task->pid, task_uid(task),
  1931. task->loginuid, loginuid,
  1932. task->sessionid, sessionid);
  1933. audit_log_end(ab);
  1934. }
  1935. }
  1936. task->sessionid = sessionid;
  1937. task->loginuid = loginuid;
  1938. return 0;
  1939. }
  1940. /**
  1941. * __audit_mq_open - record audit data for a POSIX MQ open
  1942. * @oflag: open flag
  1943. * @mode: mode bits
  1944. * @u_attr: queue attributes
  1945. *
  1946. */
  1947. void __audit_mq_open(int oflag, mode_t mode, struct mq_attr *attr)
  1948. {
  1949. struct audit_context *context = current->audit_context;
  1950. if (attr)
  1951. memcpy(&context->mq_open.attr, attr, sizeof(struct mq_attr));
  1952. else
  1953. memset(&context->mq_open.attr, 0, sizeof(struct mq_attr));
  1954. context->mq_open.oflag = oflag;
  1955. context->mq_open.mode = mode;
  1956. context->type = AUDIT_MQ_OPEN;
  1957. }
  1958. /**
  1959. * __audit_mq_sendrecv - record audit data for a POSIX MQ timed send/receive
  1960. * @mqdes: MQ descriptor
  1961. * @msg_len: Message length
  1962. * @msg_prio: Message priority
  1963. * @abs_timeout: Message timeout in absolute time
  1964. *
  1965. */
  1966. void __audit_mq_sendrecv(mqd_t mqdes, size_t msg_len, unsigned int msg_prio,
  1967. const struct timespec *abs_timeout)
  1968. {
  1969. struct audit_context *context = current->audit_context;
  1970. struct timespec *p = &context->mq_sendrecv.abs_timeout;
  1971. if (abs_timeout)
  1972. memcpy(p, abs_timeout, sizeof(struct timespec));
  1973. else
  1974. memset(p, 0, sizeof(struct timespec));
  1975. context->mq_sendrecv.mqdes = mqdes;
  1976. context->mq_sendrecv.msg_len = msg_len;
  1977. context->mq_sendrecv.msg_prio = msg_prio;
  1978. context->type = AUDIT_MQ_SENDRECV;
  1979. }
  1980. /**
  1981. * __audit_mq_notify - record audit data for a POSIX MQ notify
  1982. * @mqdes: MQ descriptor
  1983. * @u_notification: Notification event
  1984. *
  1985. */
  1986. void __audit_mq_notify(mqd_t mqdes, const struct sigevent *notification)
  1987. {
  1988. struct audit_context *context = current->audit_context;
  1989. if (notification)
  1990. context->mq_notify.sigev_signo = notification->sigev_signo;
  1991. else
  1992. context->mq_notify.sigev_signo = 0;
  1993. context->mq_notify.mqdes = mqdes;
  1994. context->type = AUDIT_MQ_NOTIFY;
  1995. }
  1996. /**
  1997. * __audit_mq_getsetattr - record audit data for a POSIX MQ get/set attribute
  1998. * @mqdes: MQ descriptor
  1999. * @mqstat: MQ flags
  2000. *
  2001. */
  2002. void __audit_mq_getsetattr(mqd_t mqdes, struct mq_attr *mqstat)
  2003. {
  2004. struct audit_context *context = current->audit_context;
  2005. context->mq_getsetattr.mqdes = mqdes;
  2006. context->mq_getsetattr.mqstat = *mqstat;
  2007. context->type = AUDIT_MQ_GETSETATTR;
  2008. }
  2009. /**
  2010. * audit_ipc_obj - record audit data for ipc object
  2011. * @ipcp: ipc permissions
  2012. *
  2013. */
  2014. void __audit_ipc_obj(struct kern_ipc_perm *ipcp)
  2015. {
  2016. struct audit_context *context = current->audit_context;
  2017. context->ipc.uid = ipcp->uid;
  2018. context->ipc.gid = ipcp->gid;
  2019. context->ipc.mode = ipcp->mode;
  2020. context->ipc.has_perm = 0;
  2021. security_ipc_getsecid(ipcp, &context->ipc.osid);
  2022. context->type = AUDIT_IPC;
  2023. }
  2024. /**
  2025. * audit_ipc_set_perm - record audit data for new ipc permissions
  2026. * @qbytes: msgq bytes
  2027. * @uid: msgq user id
  2028. * @gid: msgq group id
  2029. * @mode: msgq mode (permissions)
  2030. *
  2031. * Called only after audit_ipc_obj().
  2032. */
  2033. void __audit_ipc_set_perm(unsigned long qbytes, uid_t uid, gid_t gid, mode_t mode)
  2034. {
  2035. struct audit_context *context = current->audit_context;
  2036. context->ipc.qbytes = qbytes;
  2037. context->ipc.perm_uid = uid;
  2038. context->ipc.perm_gid = gid;
  2039. context->ipc.perm_mode = mode;
  2040. context->ipc.has_perm = 1;
  2041. }
  2042. int audit_bprm(struct linux_binprm *bprm)
  2043. {
  2044. struct audit_aux_data_execve *ax;
  2045. struct audit_context *context = current->audit_context;
  2046. if (likely(!audit_enabled || !context || context->dummy))
  2047. return 0;
  2048. ax = kmalloc(sizeof(*ax), GFP_KERNEL);
  2049. if (!ax)
  2050. return -ENOMEM;
  2051. ax->argc = bprm->argc;
  2052. ax->envc = bprm->envc;
  2053. ax->mm = bprm->mm;
  2054. ax->d.type = AUDIT_EXECVE;
  2055. ax->d.next = context->aux;
  2056. context->aux = (void *)ax;
  2057. return 0;
  2058. }
  2059. /**
  2060. * audit_socketcall - record audit data for sys_socketcall
  2061. * @nargs: number of args
  2062. * @args: args array
  2063. *
  2064. */
  2065. void audit_socketcall(int nargs, unsigned long *args)
  2066. {
  2067. struct audit_context *context = current->audit_context;
  2068. if (likely(!context || context->dummy))
  2069. return;
  2070. context->type = AUDIT_SOCKETCALL;
  2071. context->socketcall.nargs = nargs;
  2072. memcpy(context->socketcall.args, args, nargs * sizeof(unsigned long));
  2073. }
  2074. /**
  2075. * __audit_fd_pair - record audit data for pipe and socketpair
  2076. * @fd1: the first file descriptor
  2077. * @fd2: the second file descriptor
  2078. *
  2079. */
  2080. void __audit_fd_pair(int fd1, int fd2)
  2081. {
  2082. struct audit_context *context = current->audit_context;
  2083. context->fds[0] = fd1;
  2084. context->fds[1] = fd2;
  2085. }
  2086. /**
  2087. * audit_sockaddr - record audit data for sys_bind, sys_connect, sys_sendto
  2088. * @len: data length in user space
  2089. * @a: data address in kernel space
  2090. *
  2091. * Returns 0 for success or NULL context or < 0 on error.
  2092. */
  2093. int audit_sockaddr(int len, void *a)
  2094. {
  2095. struct audit_context *context = current->audit_context;
  2096. if (likely(!context || context->dummy))
  2097. return 0;
  2098. if (!context->sockaddr) {
  2099. void *p = kmalloc(sizeof(struct sockaddr_storage), GFP_KERNEL);
  2100. if (!p)
  2101. return -ENOMEM;
  2102. context->sockaddr = p;
  2103. }
  2104. context->sockaddr_len = len;
  2105. memcpy(context->sockaddr, a, len);
  2106. return 0;
  2107. }
  2108. void __audit_ptrace(struct task_struct *t)
  2109. {
  2110. struct audit_context *context = current->audit_context;
  2111. context->target_pid = t->pid;
  2112. context->target_auid = audit_get_loginuid(t);
  2113. context->target_uid = task_uid(t);
  2114. context->target_sessionid = audit_get_sessionid(t);
  2115. security_task_getsecid(t, &context->target_sid);
  2116. memcpy(context->target_comm, t->comm, TASK_COMM_LEN);
  2117. }
  2118. /**
  2119. * audit_signal_info - record signal info for shutting down audit subsystem
  2120. * @sig: signal value
  2121. * @t: task being signaled
  2122. *
  2123. * If the audit subsystem is being terminated, record the task (pid)
  2124. * and uid that is doing that.
  2125. */
  2126. int __audit_signal_info(int sig, struct task_struct *t)
  2127. {
  2128. struct audit_aux_data_pids *axp;
  2129. struct task_struct *tsk = current;
  2130. struct audit_context *ctx = tsk->audit_context;
  2131. uid_t uid = current_uid(), t_uid = task_uid(t);
  2132. if (audit_pid && t->tgid == audit_pid) {
  2133. if (sig == SIGTERM || sig == SIGHUP || sig == SIGUSR1 || sig == SIGUSR2) {
  2134. audit_sig_pid = tsk->pid;
  2135. if (tsk->loginuid != -1)
  2136. audit_sig_uid = tsk->loginuid;
  2137. else
  2138. audit_sig_uid = uid;
  2139. security_task_getsecid(tsk, &audit_sig_sid);
  2140. }
  2141. if (!audit_signals || audit_dummy_context())
  2142. return 0;
  2143. }
  2144. /* optimize the common case by putting first signal recipient directly
  2145. * in audit_context */
  2146. if (!ctx->target_pid) {
  2147. ctx->target_pid = t->tgid;
  2148. ctx->target_auid = audit_get_loginuid(t);
  2149. ctx->target_uid = t_uid;
  2150. ctx->target_sessionid = audit_get_sessionid(t);
  2151. security_task_getsecid(t, &ctx->target_sid);
  2152. memcpy(ctx->target_comm, t->comm, TASK_COMM_LEN);
  2153. return 0;
  2154. }
  2155. axp = (void *)ctx->aux_pids;
  2156. if (!axp || axp->pid_count == AUDIT_AUX_PIDS) {
  2157. axp = kzalloc(sizeof(*axp), GFP_ATOMIC);
  2158. if (!axp)
  2159. return -ENOMEM;
  2160. axp->d.type = AUDIT_OBJ_PID;
  2161. axp->d.next = ctx->aux_pids;
  2162. ctx->aux_pids = (void *)axp;
  2163. }
  2164. BUG_ON(axp->pid_count >= AUDIT_AUX_PIDS);
  2165. axp->target_pid[axp->pid_count] = t->tgid;
  2166. axp->target_auid[axp->pid_count] = audit_get_loginuid(t);
  2167. axp->target_uid[axp->pid_count] = t_uid;
  2168. axp->target_sessionid[axp->pid_count] = audit_get_sessionid(t);
  2169. security_task_getsecid(t, &axp->target_sid[axp->pid_count]);
  2170. memcpy(axp->target_comm[axp->pid_count], t->comm, TASK_COMM_LEN);
  2171. axp->pid_count++;
  2172. return 0;
  2173. }
  2174. /**
  2175. * __audit_log_bprm_fcaps - store information about a loading bprm and relevant fcaps
  2176. * @bprm: pointer to the bprm being processed
  2177. * @new: the proposed new credentials
  2178. * @old: the old credentials
  2179. *
  2180. * Simply check if the proc already has the caps given by the file and if not
  2181. * store the priv escalation info for later auditing at the end of the syscall
  2182. *
  2183. * -Eric
  2184. */
  2185. int __audit_log_bprm_fcaps(struct linux_binprm *bprm,
  2186. const struct cred *new, const struct cred *old)
  2187. {
  2188. struct audit_aux_data_bprm_fcaps *ax;
  2189. struct audit_context *context = current->audit_context;
  2190. struct cpu_vfs_cap_data vcaps;
  2191. struct dentry *dentry;
  2192. ax = kmalloc(sizeof(*ax), GFP_KERNEL);
  2193. if (!ax)
  2194. return -ENOMEM;
  2195. ax->d.type = AUDIT_BPRM_FCAPS;
  2196. ax->d.next = context->aux;
  2197. context->aux = (void *)ax;
  2198. dentry = dget(bprm->file->f_dentry);
  2199. get_vfs_caps_from_disk(dentry, &vcaps);
  2200. dput(dentry);
  2201. ax->fcap.permitted = vcaps.permitted;
  2202. ax->fcap.inheritable = vcaps.inheritable;
  2203. ax->fcap.fE = !!(vcaps.magic_etc & VFS_CAP_FLAGS_EFFECTIVE);
  2204. ax->fcap_ver = (vcaps.magic_etc & VFS_CAP_REVISION_MASK) >> VFS_CAP_REVISION_SHIFT;
  2205. ax->old_pcap.permitted = old->cap_permitted;
  2206. ax->old_pcap.inheritable = old->cap_inheritable;
  2207. ax->old_pcap.effective = old->cap_effective;
  2208. ax->new_pcap.permitted = new->cap_permitted;
  2209. ax->new_pcap.inheritable = new->cap_inheritable;
  2210. ax->new_pcap.effective = new->cap_effective;
  2211. return 0;
  2212. }
  2213. /**
  2214. * __audit_log_capset - store information about the arguments to the capset syscall
  2215. * @pid: target pid of the capset call
  2216. * @new: the new credentials
  2217. * @old: the old (current) credentials
  2218. *
  2219. * Record the aguments userspace sent to sys_capset for later printing by the
  2220. * audit system if applicable
  2221. */
  2222. void __audit_log_capset(pid_t pid,
  2223. const struct cred *new, const struct cred *old)
  2224. {
  2225. struct audit_context *context = current->audit_context;
  2226. context->capset.pid = pid;
  2227. context->capset.cap.effective = new->cap_effective;
  2228. context->capset.cap.inheritable = new->cap_effective;
  2229. context->capset.cap.permitted = new->cap_permitted;
  2230. context->type = AUDIT_CAPSET;
  2231. }
  2232. /**
  2233. * audit_core_dumps - record information about processes that end abnormally
  2234. * @signr: signal value
  2235. *
  2236. * If a process ends with a core dump, something fishy is going on and we
  2237. * should record the event for investigation.
  2238. */
  2239. void audit_core_dumps(long signr)
  2240. {
  2241. struct audit_buffer *ab;
  2242. u32 sid;
  2243. uid_t auid = audit_get_loginuid(current), uid;
  2244. gid_t gid;
  2245. unsigned int sessionid = audit_get_sessionid(current);
  2246. if (!audit_enabled)
  2247. return;
  2248. if (signr == SIGQUIT) /* don't care for those */
  2249. return;
  2250. ab = audit_log_start(NULL, GFP_KERNEL, AUDIT_ANOM_ABEND);
  2251. current_uid_gid(&uid, &gid);
  2252. audit_log_format(ab, "auid=%u uid=%u gid=%u ses=%u",
  2253. auid, uid, gid, sessionid);
  2254. security_task_getsecid(current, &sid);
  2255. if (sid) {
  2256. char *ctx = NULL;
  2257. u32 len;
  2258. if (security_secid_to_secctx(sid, &ctx, &len))
  2259. audit_log_format(ab, " ssid=%u", sid);
  2260. else {
  2261. audit_log_format(ab, " subj=%s", ctx);
  2262. security_release_secctx(ctx, len);
  2263. }
  2264. }
  2265. audit_log_format(ab, " pid=%d comm=", current->pid);
  2266. audit_log_untrustedstring(ab, current->comm);
  2267. audit_log_format(ab, " sig=%ld", signr);
  2268. audit_log_end(ab);
  2269. }