policy_unpack.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703
  1. /*
  2. * AppArmor security module
  3. *
  4. * This file contains AppArmor functions for unpacking policy loaded from
  5. * userspace.
  6. *
  7. * Copyright (C) 1998-2008 Novell/SUSE
  8. * Copyright 2009-2010 Canonical Ltd.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License as
  12. * published by the Free Software Foundation, version 2 of the
  13. * License.
  14. *
  15. * AppArmor uses a serialized binary format for loading policy.
  16. * To find policy format documentation look in Documentation/apparmor.txt
  17. * All policy is validated before it is used.
  18. */
  19. #include <asm/unaligned.h>
  20. #include <linux/ctype.h>
  21. #include <linux/errno.h>
  22. #include "include/apparmor.h"
  23. #include "include/audit.h"
  24. #include "include/context.h"
  25. #include "include/match.h"
  26. #include "include/policy.h"
  27. #include "include/policy_unpack.h"
  28. #include "include/sid.h"
  29. /*
  30. * The AppArmor interface treats data as a type byte followed by the
  31. * actual data. The interface has the notion of a a named entry
  32. * which has a name (AA_NAME typecode followed by name string) followed by
  33. * the entries typecode and data. Named types allow for optional
  34. * elements and extensions to be added and tested for without breaking
  35. * backwards compatibility.
  36. */
  37. enum aa_code {
  38. AA_U8,
  39. AA_U16,
  40. AA_U32,
  41. AA_U64,
  42. AA_NAME, /* same as string except it is items name */
  43. AA_STRING,
  44. AA_BLOB,
  45. AA_STRUCT,
  46. AA_STRUCTEND,
  47. AA_LIST,
  48. AA_LISTEND,
  49. AA_ARRAY,
  50. AA_ARRAYEND,
  51. };
  52. /*
  53. * aa_ext is the read of the buffer containing the serialized profile. The
  54. * data is copied into a kernel buffer in apparmorfs and then handed off to
  55. * the unpack routines.
  56. */
  57. struct aa_ext {
  58. void *start;
  59. void *end;
  60. void *pos; /* pointer to current position in the buffer */
  61. u32 version;
  62. };
  63. /* audit callback for unpack fields */
  64. static void audit_cb(struct audit_buffer *ab, void *va)
  65. {
  66. struct common_audit_data *sa = va;
  67. if (sa->aad.iface.target) {
  68. struct aa_profile *name = sa->aad.iface.target;
  69. audit_log_format(ab, " name=");
  70. audit_log_untrustedstring(ab, name->base.hname);
  71. }
  72. if (sa->aad.iface.pos)
  73. audit_log_format(ab, " offset=%ld", sa->aad.iface.pos);
  74. }
  75. /**
  76. * audit_iface - do audit message for policy unpacking/load/replace/remove
  77. * @new: profile if it has been allocated (MAYBE NULL)
  78. * @name: name of the profile being manipulated (MAYBE NULL)
  79. * @info: any extra info about the failure (MAYBE NULL)
  80. * @e: buffer position info (NOT NULL)
  81. * @error: error code
  82. *
  83. * Returns: %0 or error
  84. */
  85. static int audit_iface(struct aa_profile *new, const char *name,
  86. const char *info, struct aa_ext *e, int error)
  87. {
  88. struct aa_profile *profile = __aa_current_profile();
  89. struct common_audit_data sa;
  90. COMMON_AUDIT_DATA_INIT(&sa, NONE);
  91. sa.aad.iface.pos = e->pos - e->start;
  92. sa.aad.iface.target = new;
  93. sa.aad.name = name;
  94. sa.aad.info = info;
  95. sa.aad.error = error;
  96. return aa_audit(AUDIT_APPARMOR_STATUS, profile, GFP_KERNEL, &sa,
  97. audit_cb);
  98. }
  99. /* test if read will be in packed data bounds */
  100. static bool inbounds(struct aa_ext *e, size_t size)
  101. {
  102. return (size <= e->end - e->pos);
  103. }
  104. /**
  105. * aa_u16_chunck - test and do bounds checking for a u16 size based chunk
  106. * @e: serialized data read head (NOT NULL)
  107. * @chunk: start address for chunk of data (NOT NULL)
  108. *
  109. * Returns: the size of chunk found with the read head at the end of the chunk.
  110. */
  111. static size_t unpack_u16_chunk(struct aa_ext *e, char **chunk)
  112. {
  113. size_t size = 0;
  114. if (!inbounds(e, sizeof(u16)))
  115. return 0;
  116. size = le16_to_cpu(get_unaligned((u16 *) e->pos));
  117. e->pos += sizeof(u16);
  118. if (!inbounds(e, size))
  119. return 0;
  120. *chunk = e->pos;
  121. e->pos += size;
  122. return size;
  123. }
  124. /* unpack control byte */
  125. static bool unpack_X(struct aa_ext *e, enum aa_code code)
  126. {
  127. if (!inbounds(e, 1))
  128. return 0;
  129. if (*(u8 *) e->pos != code)
  130. return 0;
  131. e->pos++;
  132. return 1;
  133. }
  134. /**
  135. * unpack_nameX - check is the next element is of type X with a name of @name
  136. * @e: serialized data extent information (NOT NULL)
  137. * @code: type code
  138. * @name: name to match to the serialized element. (MAYBE NULL)
  139. *
  140. * check that the next serialized data element is of type X and has a tag
  141. * name @name. If @name is specified then there must be a matching
  142. * name element in the stream. If @name is NULL any name element will be
  143. * skipped and only the typecode will be tested.
  144. *
  145. * Returns 1 on success (both type code and name tests match) and the read
  146. * head is advanced past the headers
  147. *
  148. * Returns: 0 if either match fails, the read head does not move
  149. */
  150. static bool unpack_nameX(struct aa_ext *e, enum aa_code code, const char *name)
  151. {
  152. /*
  153. * May need to reset pos if name or type doesn't match
  154. */
  155. void *pos = e->pos;
  156. /*
  157. * Check for presence of a tagname, and if present name size
  158. * AA_NAME tag value is a u16.
  159. */
  160. if (unpack_X(e, AA_NAME)) {
  161. char *tag = NULL;
  162. size_t size = unpack_u16_chunk(e, &tag);
  163. /* if a name is specified it must match. otherwise skip tag */
  164. if (name && (!size || strcmp(name, tag)))
  165. goto fail;
  166. } else if (name) {
  167. /* if a name is specified and there is no name tag fail */
  168. goto fail;
  169. }
  170. /* now check if type code matches */
  171. if (unpack_X(e, code))
  172. return 1;
  173. fail:
  174. e->pos = pos;
  175. return 0;
  176. }
  177. static bool unpack_u32(struct aa_ext *e, u32 *data, const char *name)
  178. {
  179. if (unpack_nameX(e, AA_U32, name)) {
  180. if (!inbounds(e, sizeof(u32)))
  181. return 0;
  182. if (data)
  183. *data = le32_to_cpu(get_unaligned((u32 *) e->pos));
  184. e->pos += sizeof(u32);
  185. return 1;
  186. }
  187. return 0;
  188. }
  189. static bool unpack_u64(struct aa_ext *e, u64 *data, const char *name)
  190. {
  191. if (unpack_nameX(e, AA_U64, name)) {
  192. if (!inbounds(e, sizeof(u64)))
  193. return 0;
  194. if (data)
  195. *data = le64_to_cpu(get_unaligned((u64 *) e->pos));
  196. e->pos += sizeof(u64);
  197. return 1;
  198. }
  199. return 0;
  200. }
  201. static size_t unpack_array(struct aa_ext *e, const char *name)
  202. {
  203. if (unpack_nameX(e, AA_ARRAY, name)) {
  204. int size;
  205. if (!inbounds(e, sizeof(u16)))
  206. return 0;
  207. size = (int)le16_to_cpu(get_unaligned((u16 *) e->pos));
  208. e->pos += sizeof(u16);
  209. return size;
  210. }
  211. return 0;
  212. }
  213. static size_t unpack_blob(struct aa_ext *e, char **blob, const char *name)
  214. {
  215. if (unpack_nameX(e, AA_BLOB, name)) {
  216. u32 size;
  217. if (!inbounds(e, sizeof(u32)))
  218. return 0;
  219. size = le32_to_cpu(get_unaligned((u32 *) e->pos));
  220. e->pos += sizeof(u32);
  221. if (inbounds(e, (size_t) size)) {
  222. *blob = e->pos;
  223. e->pos += size;
  224. return size;
  225. }
  226. }
  227. return 0;
  228. }
  229. static int unpack_str(struct aa_ext *e, const char **string, const char *name)
  230. {
  231. char *src_str;
  232. size_t size = 0;
  233. void *pos = e->pos;
  234. *string = NULL;
  235. if (unpack_nameX(e, AA_STRING, name)) {
  236. size = unpack_u16_chunk(e, &src_str);
  237. if (size) {
  238. /* strings are null terminated, length is size - 1 */
  239. if (src_str[size - 1] != 0)
  240. goto fail;
  241. *string = src_str;
  242. }
  243. }
  244. return size;
  245. fail:
  246. e->pos = pos;
  247. return 0;
  248. }
  249. static int unpack_strdup(struct aa_ext *e, char **string, const char *name)
  250. {
  251. const char *tmp;
  252. void *pos = e->pos;
  253. int res = unpack_str(e, &tmp, name);
  254. *string = NULL;
  255. if (!res)
  256. return 0;
  257. *string = kmemdup(tmp, res, GFP_KERNEL);
  258. if (!*string) {
  259. e->pos = pos;
  260. return 0;
  261. }
  262. return res;
  263. }
  264. /**
  265. * verify_accept - verify the accept tables of a dfa
  266. * @dfa: dfa to verify accept tables of (NOT NULL)
  267. * @flags: flags governing dfa
  268. *
  269. * Returns: 1 if valid accept tables else 0 if error
  270. */
  271. static bool verify_accept(struct aa_dfa *dfa, int flags)
  272. {
  273. int i;
  274. /* verify accept permissions */
  275. for (i = 0; i < dfa->tables[YYTD_ID_ACCEPT]->td_lolen; i++) {
  276. int mode = ACCEPT_TABLE(dfa)[i];
  277. if (mode & ~DFA_VALID_PERM_MASK)
  278. return 0;
  279. if (ACCEPT_TABLE2(dfa)[i] & ~DFA_VALID_PERM2_MASK)
  280. return 0;
  281. }
  282. return 1;
  283. }
  284. /**
  285. * unpack_dfa - unpack a file rule dfa
  286. * @e: serialized data extent information (NOT NULL)
  287. *
  288. * returns dfa or ERR_PTR or NULL if no dfa
  289. */
  290. static struct aa_dfa *unpack_dfa(struct aa_ext *e)
  291. {
  292. char *blob = NULL;
  293. size_t size;
  294. struct aa_dfa *dfa = NULL;
  295. size = unpack_blob(e, &blob, "aadfa");
  296. if (size) {
  297. /*
  298. * The dfa is aligned with in the blob to 8 bytes
  299. * from the beginning of the stream.
  300. */
  301. size_t sz = blob - (char *)e->start;
  302. size_t pad = ALIGN(sz, 8) - sz;
  303. int flags = TO_ACCEPT1_FLAG(YYTD_DATA32) |
  304. TO_ACCEPT2_FLAG(YYTD_DATA32);
  305. if (aa_g_paranoid_load)
  306. flags |= DFA_FLAG_VERIFY_STATES;
  307. dfa = aa_dfa_unpack(blob + pad, size - pad, flags);
  308. if (IS_ERR(dfa))
  309. return dfa;
  310. if (!verify_accept(dfa, flags))
  311. goto fail;
  312. }
  313. return dfa;
  314. fail:
  315. aa_put_dfa(dfa);
  316. return ERR_PTR(-EPROTO);
  317. }
  318. /**
  319. * unpack_trans_table - unpack a profile transition table
  320. * @e: serialized data extent information (NOT NULL)
  321. * @profile: profile to add the accept table to (NOT NULL)
  322. *
  323. * Returns: 1 if table succesfully unpacked
  324. */
  325. static bool unpack_trans_table(struct aa_ext *e, struct aa_profile *profile)
  326. {
  327. void *pos = e->pos;
  328. /* exec table is optional */
  329. if (unpack_nameX(e, AA_STRUCT, "xtable")) {
  330. int i, size;
  331. size = unpack_array(e, NULL);
  332. /* currently 4 exec bits and entries 0-3 are reserved iupcx */
  333. if (size > 16 - 4)
  334. goto fail;
  335. profile->file.trans.table = kzalloc(sizeof(char *) * size,
  336. GFP_KERNEL);
  337. if (!profile->file.trans.table)
  338. goto fail;
  339. profile->file.trans.size = size;
  340. for (i = 0; i < size; i++) {
  341. char *str;
  342. int c, j, size = unpack_strdup(e, &str, NULL);
  343. /* unpack_strdup verifies that the last character is
  344. * null termination byte.
  345. */
  346. if (!size)
  347. goto fail;
  348. profile->file.trans.table[i] = str;
  349. /* verify that name doesn't start with space */
  350. if (isspace(*str))
  351. goto fail;
  352. /* count internal # of internal \0 */
  353. for (c = j = 0; j < size - 2; j++) {
  354. if (!str[j])
  355. c++;
  356. }
  357. if (*str == ':') {
  358. /* beginning with : requires an embedded \0,
  359. * verify that exactly 1 internal \0 exists
  360. * trailing \0 already verified by unpack_strdup
  361. */
  362. if (c != 1)
  363. goto fail;
  364. /* first character after : must be valid */
  365. if (!str[1])
  366. goto fail;
  367. } else if (c)
  368. /* fail - all other cases with embedded \0 */
  369. goto fail;
  370. }
  371. if (!unpack_nameX(e, AA_ARRAYEND, NULL))
  372. goto fail;
  373. if (!unpack_nameX(e, AA_STRUCTEND, NULL))
  374. goto fail;
  375. }
  376. return 1;
  377. fail:
  378. aa_free_domain_entries(&profile->file.trans);
  379. e->pos = pos;
  380. return 0;
  381. }
  382. static bool unpack_rlimits(struct aa_ext *e, struct aa_profile *profile)
  383. {
  384. void *pos = e->pos;
  385. /* rlimits are optional */
  386. if (unpack_nameX(e, AA_STRUCT, "rlimits")) {
  387. int i, size;
  388. u32 tmp = 0;
  389. if (!unpack_u32(e, &tmp, NULL))
  390. goto fail;
  391. profile->rlimits.mask = tmp;
  392. size = unpack_array(e, NULL);
  393. if (size > RLIM_NLIMITS)
  394. goto fail;
  395. for (i = 0; i < size; i++) {
  396. u64 tmp = 0;
  397. int a = aa_map_resource(i);
  398. if (!unpack_u64(e, &tmp, NULL))
  399. goto fail;
  400. profile->rlimits.limits[a].rlim_max = tmp;
  401. }
  402. if (!unpack_nameX(e, AA_ARRAYEND, NULL))
  403. goto fail;
  404. if (!unpack_nameX(e, AA_STRUCTEND, NULL))
  405. goto fail;
  406. }
  407. return 1;
  408. fail:
  409. e->pos = pos;
  410. return 0;
  411. }
  412. /**
  413. * unpack_profile - unpack a serialized profile
  414. * @e: serialized data extent information (NOT NULL)
  415. *
  416. * NOTE: unpack profile sets audit struct if there is a failure
  417. */
  418. static struct aa_profile *unpack_profile(struct aa_ext *e)
  419. {
  420. struct aa_profile *profile = NULL;
  421. const char *name = NULL;
  422. int error = -EPROTO;
  423. kernel_cap_t tmpcap;
  424. u32 tmp;
  425. /* check that we have the right struct being passed */
  426. if (!unpack_nameX(e, AA_STRUCT, "profile"))
  427. goto fail;
  428. if (!unpack_str(e, &name, NULL))
  429. goto fail;
  430. profile = aa_alloc_profile(name);
  431. if (!profile)
  432. return ERR_PTR(-ENOMEM);
  433. /* profile renaming is optional */
  434. (void) unpack_str(e, &profile->rename, "rename");
  435. /* xmatch is optional and may be NULL */
  436. profile->xmatch = unpack_dfa(e);
  437. if (IS_ERR(profile->xmatch)) {
  438. error = PTR_ERR(profile->xmatch);
  439. profile->xmatch = NULL;
  440. goto fail;
  441. }
  442. /* xmatch_len is not optional if xmatch is set */
  443. if (profile->xmatch) {
  444. if (!unpack_u32(e, &tmp, NULL))
  445. goto fail;
  446. profile->xmatch_len = tmp;
  447. }
  448. /* per profile debug flags (complain, audit) */
  449. if (!unpack_nameX(e, AA_STRUCT, "flags"))
  450. goto fail;
  451. if (!unpack_u32(e, &tmp, NULL))
  452. goto fail;
  453. if (tmp)
  454. profile->flags |= PFLAG_HAT;
  455. if (!unpack_u32(e, &tmp, NULL))
  456. goto fail;
  457. if (tmp)
  458. profile->mode = APPARMOR_COMPLAIN;
  459. if (!unpack_u32(e, &tmp, NULL))
  460. goto fail;
  461. if (tmp)
  462. profile->audit = AUDIT_ALL;
  463. if (!unpack_nameX(e, AA_STRUCTEND, NULL))
  464. goto fail;
  465. /* path_flags is optional */
  466. if (unpack_u32(e, &profile->path_flags, "path_flags"))
  467. profile->path_flags |= profile->flags & PFLAG_MEDIATE_DELETED;
  468. else
  469. /* set a default value if path_flags field is not present */
  470. profile->path_flags = PFLAG_MEDIATE_DELETED;
  471. if (!unpack_u32(e, &(profile->caps.allow.cap[0]), NULL))
  472. goto fail;
  473. if (!unpack_u32(e, &(profile->caps.audit.cap[0]), NULL))
  474. goto fail;
  475. if (!unpack_u32(e, &(profile->caps.quiet.cap[0]), NULL))
  476. goto fail;
  477. if (!unpack_u32(e, &tmpcap.cap[0], NULL))
  478. goto fail;
  479. if (unpack_nameX(e, AA_STRUCT, "caps64")) {
  480. /* optional upper half of 64 bit caps */
  481. if (!unpack_u32(e, &(profile->caps.allow.cap[1]), NULL))
  482. goto fail;
  483. if (!unpack_u32(e, &(profile->caps.audit.cap[1]), NULL))
  484. goto fail;
  485. if (!unpack_u32(e, &(profile->caps.quiet.cap[1]), NULL))
  486. goto fail;
  487. if (!unpack_u32(e, &(tmpcap.cap[1]), NULL))
  488. goto fail;
  489. if (!unpack_nameX(e, AA_STRUCTEND, NULL))
  490. goto fail;
  491. }
  492. if (unpack_nameX(e, AA_STRUCT, "capsx")) {
  493. /* optional extended caps mediation mask */
  494. if (!unpack_u32(e, &(profile->caps.extended.cap[0]), NULL))
  495. goto fail;
  496. if (!unpack_u32(e, &(profile->caps.extended.cap[1]), NULL))
  497. goto fail;
  498. }
  499. if (!unpack_rlimits(e, profile))
  500. goto fail;
  501. /* get file rules */
  502. profile->file.dfa = unpack_dfa(e);
  503. if (IS_ERR(profile->file.dfa)) {
  504. error = PTR_ERR(profile->file.dfa);
  505. profile->file.dfa = NULL;
  506. goto fail;
  507. }
  508. if (!unpack_u32(e, &profile->file.start, "dfa_start"))
  509. /* default start state */
  510. profile->file.start = DFA_START;
  511. if (!unpack_trans_table(e, profile))
  512. goto fail;
  513. if (!unpack_nameX(e, AA_STRUCTEND, NULL))
  514. goto fail;
  515. return profile;
  516. fail:
  517. if (profile)
  518. name = NULL;
  519. else if (!name)
  520. name = "unknown";
  521. audit_iface(profile, name, "failed to unpack profile", e, error);
  522. aa_put_profile(profile);
  523. return ERR_PTR(error);
  524. }
  525. /**
  526. * verify_head - unpack serialized stream header
  527. * @e: serialized data read head (NOT NULL)
  528. * @ns: Returns - namespace if one is specified else NULL (NOT NULL)
  529. *
  530. * Returns: error or 0 if header is good
  531. */
  532. static int verify_header(struct aa_ext *e, const char **ns)
  533. {
  534. int error = -EPROTONOSUPPORT;
  535. /* get the interface version */
  536. if (!unpack_u32(e, &e->version, "version")) {
  537. audit_iface(NULL, NULL, "invalid profile format", e, error);
  538. return error;
  539. }
  540. /* check that the interface version is currently supported */
  541. if (e->version != 5) {
  542. audit_iface(NULL, NULL, "unsupported interface version", e,
  543. error);
  544. return error;
  545. }
  546. /* read the namespace if present */
  547. if (!unpack_str(e, ns, "namespace"))
  548. *ns = NULL;
  549. return 0;
  550. }
  551. static bool verify_xindex(int xindex, int table_size)
  552. {
  553. int index, xtype;
  554. xtype = xindex & AA_X_TYPE_MASK;
  555. index = xindex & AA_X_INDEX_MASK;
  556. if (xtype == AA_X_TABLE && index > table_size)
  557. return 0;
  558. return 1;
  559. }
  560. /* verify dfa xindexes are in range of transition tables */
  561. static bool verify_dfa_xindex(struct aa_dfa *dfa, int table_size)
  562. {
  563. int i;
  564. for (i = 0; i < dfa->tables[YYTD_ID_ACCEPT]->td_lolen; i++) {
  565. if (!verify_xindex(dfa_user_xindex(dfa, i), table_size))
  566. return 0;
  567. if (!verify_xindex(dfa_other_xindex(dfa, i), table_size))
  568. return 0;
  569. }
  570. return 1;
  571. }
  572. /**
  573. * verify_profile - Do post unpack analysis to verify profile consistency
  574. * @profile: profile to verify (NOT NULL)
  575. *
  576. * Returns: 0 if passes verification else error
  577. */
  578. static int verify_profile(struct aa_profile *profile)
  579. {
  580. if (aa_g_paranoid_load) {
  581. if (profile->file.dfa &&
  582. !verify_dfa_xindex(profile->file.dfa,
  583. profile->file.trans.size)) {
  584. audit_iface(profile, NULL, "Invalid named transition",
  585. NULL, -EPROTO);
  586. return -EPROTO;
  587. }
  588. }
  589. return 0;
  590. }
  591. /**
  592. * aa_unpack - unpack packed binary profile data loaded from user space
  593. * @udata: user data copied to kmem (NOT NULL)
  594. * @size: the size of the user data
  595. * @ns: Returns namespace profile is in if specified else NULL (NOT NULL)
  596. *
  597. * Unpack user data and return refcounted allocated profile or ERR_PTR
  598. *
  599. * Returns: profile else error pointer if fails to unpack
  600. */
  601. struct aa_profile *aa_unpack(void *udata, size_t size, const char **ns)
  602. {
  603. struct aa_profile *profile = NULL;
  604. int error;
  605. struct aa_ext e = {
  606. .start = udata,
  607. .end = udata + size,
  608. .pos = udata,
  609. };
  610. error = verify_header(&e, ns);
  611. if (error)
  612. return ERR_PTR(error);
  613. profile = unpack_profile(&e);
  614. if (IS_ERR(profile))
  615. return profile;
  616. error = verify_profile(profile);
  617. if (error) {
  618. aa_put_profile(profile);
  619. profile = ERR_PTR(error);
  620. }
  621. /* return refcount */
  622. return profile;
  623. }