auditsc.c 66 KB

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