posix_acl.c 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2002,2003 by Andreas Gruenbacher <[email protected]>
  4. *
  5. * Fixes from William Schumacher incorporated on 15 March 2001.
  6. * (Reported by Charles Bertsch, <[email protected]>).
  7. */
  8. /*
  9. * This file contains generic functions for manipulating
  10. * POSIX 1003.1e draft standard 17 ACLs.
  11. */
  12. #include <linux/kernel.h>
  13. #include <linux/slab.h>
  14. #include <linux/atomic.h>
  15. #include <linux/fs.h>
  16. #include <linux/sched.h>
  17. #include <linux/cred.h>
  18. #include <linux/posix_acl.h>
  19. #include <linux/posix_acl_xattr.h>
  20. #include <linux/xattr.h>
  21. #include <linux/export.h>
  22. #include <linux/user_namespace.h>
  23. #include <linux/namei.h>
  24. #include <linux/mnt_idmapping.h>
  25. #include <linux/iversion.h>
  26. static struct posix_acl **acl_by_type(struct inode *inode, int type)
  27. {
  28. switch (type) {
  29. case ACL_TYPE_ACCESS:
  30. return &inode->i_acl;
  31. case ACL_TYPE_DEFAULT:
  32. return &inode->i_default_acl;
  33. default:
  34. BUG();
  35. }
  36. }
  37. struct posix_acl *get_cached_acl(struct inode *inode, int type)
  38. {
  39. struct posix_acl **p = acl_by_type(inode, type);
  40. struct posix_acl *acl;
  41. for (;;) {
  42. rcu_read_lock();
  43. acl = rcu_dereference(*p);
  44. if (!acl || is_uncached_acl(acl) ||
  45. refcount_inc_not_zero(&acl->a_refcount))
  46. break;
  47. rcu_read_unlock();
  48. cpu_relax();
  49. }
  50. rcu_read_unlock();
  51. return acl;
  52. }
  53. EXPORT_SYMBOL(get_cached_acl);
  54. struct posix_acl *get_cached_acl_rcu(struct inode *inode, int type)
  55. {
  56. struct posix_acl *acl = rcu_dereference(*acl_by_type(inode, type));
  57. if (acl == ACL_DONT_CACHE) {
  58. struct posix_acl *ret;
  59. ret = inode->i_op->get_acl(inode, type, LOOKUP_RCU);
  60. if (!IS_ERR(ret))
  61. acl = ret;
  62. }
  63. return acl;
  64. }
  65. EXPORT_SYMBOL(get_cached_acl_rcu);
  66. void set_cached_acl(struct inode *inode, int type, struct posix_acl *acl)
  67. {
  68. struct posix_acl **p = acl_by_type(inode, type);
  69. struct posix_acl *old;
  70. old = xchg(p, posix_acl_dup(acl));
  71. if (!is_uncached_acl(old))
  72. posix_acl_release(old);
  73. }
  74. EXPORT_SYMBOL(set_cached_acl);
  75. static void __forget_cached_acl(struct posix_acl **p)
  76. {
  77. struct posix_acl *old;
  78. old = xchg(p, ACL_NOT_CACHED);
  79. if (!is_uncached_acl(old))
  80. posix_acl_release(old);
  81. }
  82. void forget_cached_acl(struct inode *inode, int type)
  83. {
  84. __forget_cached_acl(acl_by_type(inode, type));
  85. }
  86. EXPORT_SYMBOL(forget_cached_acl);
  87. void forget_all_cached_acls(struct inode *inode)
  88. {
  89. __forget_cached_acl(&inode->i_acl);
  90. __forget_cached_acl(&inode->i_default_acl);
  91. }
  92. EXPORT_SYMBOL(forget_all_cached_acls);
  93. struct posix_acl *get_acl(struct inode *inode, int type)
  94. {
  95. void *sentinel;
  96. struct posix_acl **p;
  97. struct posix_acl *acl;
  98. /*
  99. * The sentinel is used to detect when another operation like
  100. * set_cached_acl() or forget_cached_acl() races with get_acl().
  101. * It is guaranteed that is_uncached_acl(sentinel) is true.
  102. */
  103. acl = get_cached_acl(inode, type);
  104. if (!is_uncached_acl(acl))
  105. return acl;
  106. if (!IS_POSIXACL(inode))
  107. return NULL;
  108. sentinel = uncached_acl_sentinel(current);
  109. p = acl_by_type(inode, type);
  110. /*
  111. * If the ACL isn't being read yet, set our sentinel. Otherwise, the
  112. * current value of the ACL will not be ACL_NOT_CACHED and so our own
  113. * sentinel will not be set; another task will update the cache. We
  114. * could wait for that other task to complete its job, but it's easier
  115. * to just call ->get_acl to fetch the ACL ourself. (This is going to
  116. * be an unlikely race.)
  117. */
  118. cmpxchg(p, ACL_NOT_CACHED, sentinel);
  119. /*
  120. * Normally, the ACL returned by ->get_acl will be cached.
  121. * A filesystem can prevent that by calling
  122. * forget_cached_acl(inode, type) in ->get_acl.
  123. *
  124. * If the filesystem doesn't have a get_acl() function at all, we'll
  125. * just create the negative cache entry.
  126. */
  127. if (!inode->i_op->get_acl) {
  128. set_cached_acl(inode, type, NULL);
  129. return NULL;
  130. }
  131. acl = inode->i_op->get_acl(inode, type, false);
  132. if (IS_ERR(acl)) {
  133. /*
  134. * Remove our sentinel so that we don't block future attempts
  135. * to cache the ACL.
  136. */
  137. cmpxchg(p, sentinel, ACL_NOT_CACHED);
  138. return acl;
  139. }
  140. /*
  141. * Cache the result, but only if our sentinel is still in place.
  142. */
  143. posix_acl_dup(acl);
  144. if (unlikely(cmpxchg(p, sentinel, acl) != sentinel))
  145. posix_acl_release(acl);
  146. return acl;
  147. }
  148. EXPORT_SYMBOL(get_acl);
  149. /*
  150. * Init a fresh posix_acl
  151. */
  152. void
  153. posix_acl_init(struct posix_acl *acl, int count)
  154. {
  155. refcount_set(&acl->a_refcount, 1);
  156. acl->a_count = count;
  157. }
  158. EXPORT_SYMBOL(posix_acl_init);
  159. /*
  160. * Allocate a new ACL with the specified number of entries.
  161. */
  162. struct posix_acl *
  163. posix_acl_alloc(int count, gfp_t flags)
  164. {
  165. const size_t size = sizeof(struct posix_acl) +
  166. count * sizeof(struct posix_acl_entry);
  167. struct posix_acl *acl = kmalloc(size, flags);
  168. if (acl)
  169. posix_acl_init(acl, count);
  170. return acl;
  171. }
  172. EXPORT_SYMBOL(posix_acl_alloc);
  173. /*
  174. * Clone an ACL.
  175. */
  176. struct posix_acl *
  177. posix_acl_clone(const struct posix_acl *acl, gfp_t flags)
  178. {
  179. struct posix_acl *clone = NULL;
  180. if (acl) {
  181. int size = sizeof(struct posix_acl) + acl->a_count *
  182. sizeof(struct posix_acl_entry);
  183. clone = kmemdup(acl, size, flags);
  184. if (clone)
  185. refcount_set(&clone->a_refcount, 1);
  186. }
  187. return clone;
  188. }
  189. EXPORT_SYMBOL_GPL(posix_acl_clone);
  190. /*
  191. * Check if an acl is valid. Returns 0 if it is, or -E... otherwise.
  192. */
  193. int
  194. posix_acl_valid(struct user_namespace *user_ns, const struct posix_acl *acl)
  195. {
  196. const struct posix_acl_entry *pa, *pe;
  197. int state = ACL_USER_OBJ;
  198. int needs_mask = 0;
  199. FOREACH_ACL_ENTRY(pa, acl, pe) {
  200. if (pa->e_perm & ~(ACL_READ|ACL_WRITE|ACL_EXECUTE))
  201. return -EINVAL;
  202. switch (pa->e_tag) {
  203. case ACL_USER_OBJ:
  204. if (state == ACL_USER_OBJ) {
  205. state = ACL_USER;
  206. break;
  207. }
  208. return -EINVAL;
  209. case ACL_USER:
  210. if (state != ACL_USER)
  211. return -EINVAL;
  212. if (!kuid_has_mapping(user_ns, pa->e_uid))
  213. return -EINVAL;
  214. needs_mask = 1;
  215. break;
  216. case ACL_GROUP_OBJ:
  217. if (state == ACL_USER) {
  218. state = ACL_GROUP;
  219. break;
  220. }
  221. return -EINVAL;
  222. case ACL_GROUP:
  223. if (state != ACL_GROUP)
  224. return -EINVAL;
  225. if (!kgid_has_mapping(user_ns, pa->e_gid))
  226. return -EINVAL;
  227. needs_mask = 1;
  228. break;
  229. case ACL_MASK:
  230. if (state != ACL_GROUP)
  231. return -EINVAL;
  232. state = ACL_OTHER;
  233. break;
  234. case ACL_OTHER:
  235. if (state == ACL_OTHER ||
  236. (state == ACL_GROUP && !needs_mask)) {
  237. state = 0;
  238. break;
  239. }
  240. return -EINVAL;
  241. default:
  242. return -EINVAL;
  243. }
  244. }
  245. if (state == 0)
  246. return 0;
  247. return -EINVAL;
  248. }
  249. EXPORT_SYMBOL(posix_acl_valid);
  250. /*
  251. * Returns 0 if the acl can be exactly represented in the traditional
  252. * file mode permission bits, or else 1. Returns -E... on error.
  253. */
  254. int
  255. posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
  256. {
  257. const struct posix_acl_entry *pa, *pe;
  258. umode_t mode = 0;
  259. int not_equiv = 0;
  260. /*
  261. * A null ACL can always be presented as mode bits.
  262. */
  263. if (!acl)
  264. return 0;
  265. FOREACH_ACL_ENTRY(pa, acl, pe) {
  266. switch (pa->e_tag) {
  267. case ACL_USER_OBJ:
  268. mode |= (pa->e_perm & S_IRWXO) << 6;
  269. break;
  270. case ACL_GROUP_OBJ:
  271. mode |= (pa->e_perm & S_IRWXO) << 3;
  272. break;
  273. case ACL_OTHER:
  274. mode |= pa->e_perm & S_IRWXO;
  275. break;
  276. case ACL_MASK:
  277. mode = (mode & ~S_IRWXG) |
  278. ((pa->e_perm & S_IRWXO) << 3);
  279. not_equiv = 1;
  280. break;
  281. case ACL_USER:
  282. case ACL_GROUP:
  283. not_equiv = 1;
  284. break;
  285. default:
  286. return -EINVAL;
  287. }
  288. }
  289. if (mode_p)
  290. *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
  291. return not_equiv;
  292. }
  293. EXPORT_SYMBOL(posix_acl_equiv_mode);
  294. /*
  295. * Create an ACL representing the file mode permission bits of an inode.
  296. */
  297. struct posix_acl *
  298. posix_acl_from_mode(umode_t mode, gfp_t flags)
  299. {
  300. struct posix_acl *acl = posix_acl_alloc(3, flags);
  301. if (!acl)
  302. return ERR_PTR(-ENOMEM);
  303. acl->a_entries[0].e_tag = ACL_USER_OBJ;
  304. acl->a_entries[0].e_perm = (mode & S_IRWXU) >> 6;
  305. acl->a_entries[1].e_tag = ACL_GROUP_OBJ;
  306. acl->a_entries[1].e_perm = (mode & S_IRWXG) >> 3;
  307. acl->a_entries[2].e_tag = ACL_OTHER;
  308. acl->a_entries[2].e_perm = (mode & S_IRWXO);
  309. return acl;
  310. }
  311. EXPORT_SYMBOL(posix_acl_from_mode);
  312. /*
  313. * Return 0 if current is granted want access to the inode
  314. * by the acl. Returns -E... otherwise.
  315. */
  316. int
  317. posix_acl_permission(struct user_namespace *mnt_userns, struct inode *inode,
  318. const struct posix_acl *acl, int want)
  319. {
  320. const struct posix_acl_entry *pa, *pe, *mask_obj;
  321. struct user_namespace *fs_userns = i_user_ns(inode);
  322. int found = 0;
  323. vfsuid_t vfsuid;
  324. vfsgid_t vfsgid;
  325. want &= MAY_READ | MAY_WRITE | MAY_EXEC;
  326. FOREACH_ACL_ENTRY(pa, acl, pe) {
  327. switch(pa->e_tag) {
  328. case ACL_USER_OBJ:
  329. /* (May have been checked already) */
  330. vfsuid = i_uid_into_vfsuid(mnt_userns, inode);
  331. if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
  332. goto check_perm;
  333. break;
  334. case ACL_USER:
  335. vfsuid = make_vfsuid(mnt_userns, fs_userns,
  336. pa->e_uid);
  337. if (vfsuid_eq_kuid(vfsuid, current_fsuid()))
  338. goto mask;
  339. break;
  340. case ACL_GROUP_OBJ:
  341. vfsgid = i_gid_into_vfsgid(mnt_userns, inode);
  342. if (vfsgid_in_group_p(vfsgid)) {
  343. found = 1;
  344. if ((pa->e_perm & want) == want)
  345. goto mask;
  346. }
  347. break;
  348. case ACL_GROUP:
  349. vfsgid = make_vfsgid(mnt_userns, fs_userns,
  350. pa->e_gid);
  351. if (vfsgid_in_group_p(vfsgid)) {
  352. found = 1;
  353. if ((pa->e_perm & want) == want)
  354. goto mask;
  355. }
  356. break;
  357. case ACL_MASK:
  358. break;
  359. case ACL_OTHER:
  360. if (found)
  361. return -EACCES;
  362. else
  363. goto check_perm;
  364. default:
  365. return -EIO;
  366. }
  367. }
  368. return -EIO;
  369. mask:
  370. for (mask_obj = pa+1; mask_obj != pe; mask_obj++) {
  371. if (mask_obj->e_tag == ACL_MASK) {
  372. if ((pa->e_perm & mask_obj->e_perm & want) == want)
  373. return 0;
  374. return -EACCES;
  375. }
  376. }
  377. check_perm:
  378. if ((pa->e_perm & want) == want)
  379. return 0;
  380. return -EACCES;
  381. }
  382. /*
  383. * Modify acl when creating a new inode. The caller must ensure the acl is
  384. * only referenced once.
  385. *
  386. * mode_p initially must contain the mode parameter to the open() / creat()
  387. * system calls. All permissions that are not granted by the acl are removed.
  388. * The permissions in the acl are changed to reflect the mode_p parameter.
  389. */
  390. static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
  391. {
  392. struct posix_acl_entry *pa, *pe;
  393. struct posix_acl_entry *group_obj = NULL, *mask_obj = NULL;
  394. umode_t mode = *mode_p;
  395. int not_equiv = 0;
  396. /* assert(atomic_read(acl->a_refcount) == 1); */
  397. FOREACH_ACL_ENTRY(pa, acl, pe) {
  398. switch(pa->e_tag) {
  399. case ACL_USER_OBJ:
  400. pa->e_perm &= (mode >> 6) | ~S_IRWXO;
  401. mode &= (pa->e_perm << 6) | ~S_IRWXU;
  402. break;
  403. case ACL_USER:
  404. case ACL_GROUP:
  405. not_equiv = 1;
  406. break;
  407. case ACL_GROUP_OBJ:
  408. group_obj = pa;
  409. break;
  410. case ACL_OTHER:
  411. pa->e_perm &= mode | ~S_IRWXO;
  412. mode &= pa->e_perm | ~S_IRWXO;
  413. break;
  414. case ACL_MASK:
  415. mask_obj = pa;
  416. not_equiv = 1;
  417. break;
  418. default:
  419. return -EIO;
  420. }
  421. }
  422. if (mask_obj) {
  423. mask_obj->e_perm &= (mode >> 3) | ~S_IRWXO;
  424. mode &= (mask_obj->e_perm << 3) | ~S_IRWXG;
  425. } else {
  426. if (!group_obj)
  427. return -EIO;
  428. group_obj->e_perm &= (mode >> 3) | ~S_IRWXO;
  429. mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
  430. }
  431. *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
  432. return not_equiv;
  433. }
  434. /*
  435. * Modify the ACL for the chmod syscall.
  436. */
  437. static int __posix_acl_chmod_masq(struct posix_acl *acl, umode_t mode)
  438. {
  439. struct posix_acl_entry *group_obj = NULL, *mask_obj = NULL;
  440. struct posix_acl_entry *pa, *pe;
  441. /* assert(atomic_read(acl->a_refcount) == 1); */
  442. FOREACH_ACL_ENTRY(pa, acl, pe) {
  443. switch(pa->e_tag) {
  444. case ACL_USER_OBJ:
  445. pa->e_perm = (mode & S_IRWXU) >> 6;
  446. break;
  447. case ACL_USER:
  448. case ACL_GROUP:
  449. break;
  450. case ACL_GROUP_OBJ:
  451. group_obj = pa;
  452. break;
  453. case ACL_MASK:
  454. mask_obj = pa;
  455. break;
  456. case ACL_OTHER:
  457. pa->e_perm = (mode & S_IRWXO);
  458. break;
  459. default:
  460. return -EIO;
  461. }
  462. }
  463. if (mask_obj) {
  464. mask_obj->e_perm = (mode & S_IRWXG) >> 3;
  465. } else {
  466. if (!group_obj)
  467. return -EIO;
  468. group_obj->e_perm = (mode & S_IRWXG) >> 3;
  469. }
  470. return 0;
  471. }
  472. int
  473. __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
  474. {
  475. struct posix_acl *clone = posix_acl_clone(*acl, gfp);
  476. int err = -ENOMEM;
  477. if (clone) {
  478. err = posix_acl_create_masq(clone, mode_p);
  479. if (err < 0) {
  480. posix_acl_release(clone);
  481. clone = NULL;
  482. }
  483. }
  484. posix_acl_release(*acl);
  485. *acl = clone;
  486. return err;
  487. }
  488. EXPORT_SYMBOL(__posix_acl_create);
  489. int
  490. __posix_acl_chmod(struct posix_acl **acl, gfp_t gfp, umode_t mode)
  491. {
  492. struct posix_acl *clone = posix_acl_clone(*acl, gfp);
  493. int err = -ENOMEM;
  494. if (clone) {
  495. err = __posix_acl_chmod_masq(clone, mode);
  496. if (err) {
  497. posix_acl_release(clone);
  498. clone = NULL;
  499. }
  500. }
  501. posix_acl_release(*acl);
  502. *acl = clone;
  503. return err;
  504. }
  505. EXPORT_SYMBOL(__posix_acl_chmod);
  506. /**
  507. * posix_acl_chmod - chmod a posix acl
  508. *
  509. * @mnt_userns: user namespace of the mount @inode was found from
  510. * @inode: inode to check permissions on
  511. * @mode: the new mode of @inode
  512. *
  513. * If the inode has been found through an idmapped mount the user namespace of
  514. * the vfsmount must be passed through @mnt_userns. This function will then
  515. * take care to map the inode according to @mnt_userns before checking
  516. * permissions. On non-idmapped mounts or if permission checking is to be
  517. * performed on the raw inode simply passs init_user_ns.
  518. */
  519. int
  520. posix_acl_chmod(struct user_namespace *mnt_userns, struct inode *inode,
  521. umode_t mode)
  522. {
  523. struct posix_acl *acl;
  524. int ret = 0;
  525. if (!IS_POSIXACL(inode))
  526. return 0;
  527. if (!inode->i_op->set_acl)
  528. return -EOPNOTSUPP;
  529. acl = get_acl(inode, ACL_TYPE_ACCESS);
  530. if (IS_ERR_OR_NULL(acl)) {
  531. if (acl == ERR_PTR(-EOPNOTSUPP))
  532. return 0;
  533. return PTR_ERR(acl);
  534. }
  535. ret = __posix_acl_chmod(&acl, GFP_KERNEL, mode);
  536. if (ret)
  537. return ret;
  538. ret = inode->i_op->set_acl(mnt_userns, inode, acl, ACL_TYPE_ACCESS);
  539. posix_acl_release(acl);
  540. return ret;
  541. }
  542. EXPORT_SYMBOL(posix_acl_chmod);
  543. int
  544. posix_acl_create(struct inode *dir, umode_t *mode,
  545. struct posix_acl **default_acl, struct posix_acl **acl)
  546. {
  547. struct posix_acl *p;
  548. struct posix_acl *clone;
  549. int ret;
  550. *acl = NULL;
  551. *default_acl = NULL;
  552. if (S_ISLNK(*mode) || !IS_POSIXACL(dir))
  553. return 0;
  554. p = get_acl(dir, ACL_TYPE_DEFAULT);
  555. if (!p || p == ERR_PTR(-EOPNOTSUPP)) {
  556. *mode &= ~current_umask();
  557. return 0;
  558. }
  559. if (IS_ERR(p))
  560. return PTR_ERR(p);
  561. ret = -ENOMEM;
  562. clone = posix_acl_clone(p, GFP_NOFS);
  563. if (!clone)
  564. goto err_release;
  565. ret = posix_acl_create_masq(clone, mode);
  566. if (ret < 0)
  567. goto err_release_clone;
  568. if (ret == 0)
  569. posix_acl_release(clone);
  570. else
  571. *acl = clone;
  572. if (!S_ISDIR(*mode))
  573. posix_acl_release(p);
  574. else
  575. *default_acl = p;
  576. return 0;
  577. err_release_clone:
  578. posix_acl_release(clone);
  579. err_release:
  580. posix_acl_release(p);
  581. return ret;
  582. }
  583. EXPORT_SYMBOL_GPL(posix_acl_create);
  584. /**
  585. * posix_acl_update_mode - update mode in set_acl
  586. * @mnt_userns: user namespace of the mount @inode was found from
  587. * @inode: target inode
  588. * @mode_p: mode (pointer) for update
  589. * @acl: acl pointer
  590. *
  591. * Update the file mode when setting an ACL: compute the new file permission
  592. * bits based on the ACL. In addition, if the ACL is equivalent to the new
  593. * file mode, set *@acl to NULL to indicate that no ACL should be set.
  594. *
  595. * As with chmod, clear the setgid bit if the caller is not in the owning group
  596. * or capable of CAP_FSETID (see inode_change_ok).
  597. *
  598. * If the inode has been found through an idmapped mount the user namespace of
  599. * the vfsmount must be passed through @mnt_userns. This function will then
  600. * take care to map the inode according to @mnt_userns before checking
  601. * permissions. On non-idmapped mounts or if permission checking is to be
  602. * performed on the raw inode simply passs init_user_ns.
  603. *
  604. * Called from set_acl inode operations.
  605. */
  606. int posix_acl_update_mode(struct user_namespace *mnt_userns,
  607. struct inode *inode, umode_t *mode_p,
  608. struct posix_acl **acl)
  609. {
  610. umode_t mode = inode->i_mode;
  611. int error;
  612. error = posix_acl_equiv_mode(*acl, &mode);
  613. if (error < 0)
  614. return error;
  615. if (error == 0)
  616. *acl = NULL;
  617. if (!vfsgid_in_group_p(i_gid_into_vfsgid(mnt_userns, inode)) &&
  618. !capable_wrt_inode_uidgid(mnt_userns, inode, CAP_FSETID))
  619. mode &= ~S_ISGID;
  620. *mode_p = mode;
  621. return 0;
  622. }
  623. EXPORT_SYMBOL(posix_acl_update_mode);
  624. /*
  625. * Fix up the uids and gids in posix acl extended attributes in place.
  626. */
  627. static int posix_acl_fix_xattr_common(const void *value, size_t size)
  628. {
  629. const struct posix_acl_xattr_header *header = value;
  630. int count;
  631. if (!header)
  632. return -EINVAL;
  633. if (size < sizeof(struct posix_acl_xattr_header))
  634. return -EINVAL;
  635. if (header->a_version != cpu_to_le32(POSIX_ACL_XATTR_VERSION))
  636. return -EOPNOTSUPP;
  637. count = posix_acl_xattr_count(size);
  638. if (count < 0)
  639. return -EINVAL;
  640. if (count == 0)
  641. return 0;
  642. return count;
  643. }
  644. void posix_acl_getxattr_idmapped_mnt(struct user_namespace *mnt_userns,
  645. const struct inode *inode,
  646. void *value, size_t size)
  647. {
  648. struct posix_acl_xattr_header *header = value;
  649. struct posix_acl_xattr_entry *entry = (void *)(header + 1), *end;
  650. struct user_namespace *fs_userns = i_user_ns(inode);
  651. int count;
  652. vfsuid_t vfsuid;
  653. vfsgid_t vfsgid;
  654. kuid_t uid;
  655. kgid_t gid;
  656. if (no_idmapping(mnt_userns, i_user_ns(inode)))
  657. return;
  658. count = posix_acl_fix_xattr_common(value, size);
  659. if (count <= 0)
  660. return;
  661. for (end = entry + count; entry != end; entry++) {
  662. switch (le16_to_cpu(entry->e_tag)) {
  663. case ACL_USER:
  664. uid = make_kuid(&init_user_ns, le32_to_cpu(entry->e_id));
  665. vfsuid = make_vfsuid(mnt_userns, fs_userns, uid);
  666. entry->e_id = cpu_to_le32(from_kuid(&init_user_ns,
  667. vfsuid_into_kuid(vfsuid)));
  668. break;
  669. case ACL_GROUP:
  670. gid = make_kgid(&init_user_ns, le32_to_cpu(entry->e_id));
  671. vfsgid = make_vfsgid(mnt_userns, fs_userns, gid);
  672. entry->e_id = cpu_to_le32(from_kgid(&init_user_ns,
  673. vfsgid_into_kgid(vfsgid)));
  674. break;
  675. default:
  676. break;
  677. }
  678. }
  679. }
  680. static void posix_acl_fix_xattr_userns(
  681. struct user_namespace *to, struct user_namespace *from,
  682. void *value, size_t size)
  683. {
  684. struct posix_acl_xattr_header *header = value;
  685. struct posix_acl_xattr_entry *entry = (void *)(header + 1), *end;
  686. int count;
  687. kuid_t uid;
  688. kgid_t gid;
  689. count = posix_acl_fix_xattr_common(value, size);
  690. if (count <= 0)
  691. return;
  692. for (end = entry + count; entry != end; entry++) {
  693. switch(le16_to_cpu(entry->e_tag)) {
  694. case ACL_USER:
  695. uid = make_kuid(from, le32_to_cpu(entry->e_id));
  696. entry->e_id = cpu_to_le32(from_kuid(to, uid));
  697. break;
  698. case ACL_GROUP:
  699. gid = make_kgid(from, le32_to_cpu(entry->e_id));
  700. entry->e_id = cpu_to_le32(from_kgid(to, gid));
  701. break;
  702. default:
  703. break;
  704. }
  705. }
  706. }
  707. void posix_acl_fix_xattr_from_user(void *value, size_t size)
  708. {
  709. struct user_namespace *user_ns = current_user_ns();
  710. if (user_ns == &init_user_ns)
  711. return;
  712. posix_acl_fix_xattr_userns(&init_user_ns, user_ns, value, size);
  713. }
  714. void posix_acl_fix_xattr_to_user(void *value, size_t size)
  715. {
  716. struct user_namespace *user_ns = current_user_ns();
  717. if (user_ns == &init_user_ns)
  718. return;
  719. posix_acl_fix_xattr_userns(user_ns, &init_user_ns, value, size);
  720. }
  721. /**
  722. * make_posix_acl - convert POSIX ACLs from uapi to VFS format using the
  723. * provided callbacks to map ACL_{GROUP,USER} entries into the
  724. * appropriate format
  725. * @mnt_userns: the mount's idmapping
  726. * @fs_userns: the filesystem's idmapping
  727. * @value: the uapi representation of POSIX ACLs
  728. * @size: the size of @void
  729. * @uid_cb: callback to use for mapping the uid stored in ACL_USER entries
  730. * @gid_cb: callback to use for mapping the gid stored in ACL_GROUP entries
  731. *
  732. * The make_posix_acl() helper is an abstraction to translate from uapi format
  733. * into the VFS format allowing the caller to specific callbacks to map
  734. * ACL_{GROUP,USER} entries into the expected format. This is used in
  735. * posix_acl_from_xattr() and vfs_set_acl_prepare() and avoids pointless code
  736. * duplication.
  737. *
  738. * Return: Allocated struct posix_acl on success, NULL for a valid header but
  739. * without actual POSIX ACL entries, or ERR_PTR() encoded error code.
  740. */
  741. static struct posix_acl *make_posix_acl(struct user_namespace *mnt_userns,
  742. struct user_namespace *fs_userns, const void *value, size_t size,
  743. kuid_t (*uid_cb)(struct user_namespace *, struct user_namespace *,
  744. const struct posix_acl_xattr_entry *),
  745. kgid_t (*gid_cb)(struct user_namespace *, struct user_namespace *,
  746. const struct posix_acl_xattr_entry *))
  747. {
  748. const struct posix_acl_xattr_header *header = value;
  749. const struct posix_acl_xattr_entry *entry = (const void *)(header + 1), *end;
  750. int count;
  751. struct posix_acl *acl;
  752. struct posix_acl_entry *acl_e;
  753. count = posix_acl_fix_xattr_common(value, size);
  754. if (count < 0)
  755. return ERR_PTR(count);
  756. if (count == 0)
  757. return NULL;
  758. acl = posix_acl_alloc(count, GFP_NOFS);
  759. if (!acl)
  760. return ERR_PTR(-ENOMEM);
  761. acl_e = acl->a_entries;
  762. for (end = entry + count; entry != end; acl_e++, entry++) {
  763. acl_e->e_tag = le16_to_cpu(entry->e_tag);
  764. acl_e->e_perm = le16_to_cpu(entry->e_perm);
  765. switch(acl_e->e_tag) {
  766. case ACL_USER_OBJ:
  767. case ACL_GROUP_OBJ:
  768. case ACL_MASK:
  769. case ACL_OTHER:
  770. break;
  771. case ACL_USER:
  772. acl_e->e_uid = uid_cb(mnt_userns, fs_userns, entry);
  773. if (!uid_valid(acl_e->e_uid))
  774. goto fail;
  775. break;
  776. case ACL_GROUP:
  777. acl_e->e_gid = gid_cb(mnt_userns, fs_userns, entry);
  778. if (!gid_valid(acl_e->e_gid))
  779. goto fail;
  780. break;
  781. default:
  782. goto fail;
  783. }
  784. }
  785. return acl;
  786. fail:
  787. posix_acl_release(acl);
  788. return ERR_PTR(-EINVAL);
  789. }
  790. /**
  791. * vfs_set_acl_prepare_kuid - map ACL_USER uid according to mount- and
  792. * filesystem idmapping
  793. * @mnt_userns: the mount's idmapping
  794. * @fs_userns: the filesystem's idmapping
  795. * @e: a ACL_USER entry in POSIX ACL uapi format
  796. *
  797. * The uid stored as ACL_USER entry in @e is a kuid_t stored as a raw {g,u}id
  798. * value. The vfs_set_acl_prepare_kuid() will recover the kuid_t through
  799. * KUIDT_INIT() and then map it according to the idmapped mount. The resulting
  800. * kuid_t is the value which the filesystem can map up into a raw backing store
  801. * id in the filesystem's idmapping.
  802. *
  803. * This is used in vfs_set_acl_prepare() to generate the proper VFS
  804. * representation of POSIX ACLs with ACL_USER entries during setxattr().
  805. *
  806. * Return: A kuid in @fs_userns for the uid stored in @e.
  807. */
  808. static inline kuid_t
  809. vfs_set_acl_prepare_kuid(struct user_namespace *mnt_userns,
  810. struct user_namespace *fs_userns,
  811. const struct posix_acl_xattr_entry *e)
  812. {
  813. kuid_t kuid = KUIDT_INIT(le32_to_cpu(e->e_id));
  814. return from_vfsuid(mnt_userns, fs_userns, VFSUIDT_INIT(kuid));
  815. }
  816. /**
  817. * vfs_set_acl_prepare_kgid - map ACL_GROUP gid according to mount- and
  818. * filesystem idmapping
  819. * @mnt_userns: the mount's idmapping
  820. * @fs_userns: the filesystem's idmapping
  821. * @e: a ACL_GROUP entry in POSIX ACL uapi format
  822. *
  823. * The gid stored as ACL_GROUP entry in @e is a kgid_t stored as a raw {g,u}id
  824. * value. The vfs_set_acl_prepare_kgid() will recover the kgid_t through
  825. * KGIDT_INIT() and then map it according to the idmapped mount. The resulting
  826. * kgid_t is the value which the filesystem can map up into a raw backing store
  827. * id in the filesystem's idmapping.
  828. *
  829. * This is used in vfs_set_acl_prepare() to generate the proper VFS
  830. * representation of POSIX ACLs with ACL_GROUP entries during setxattr().
  831. *
  832. * Return: A kgid in @fs_userns for the gid stored in @e.
  833. */
  834. static inline kgid_t
  835. vfs_set_acl_prepare_kgid(struct user_namespace *mnt_userns,
  836. struct user_namespace *fs_userns,
  837. const struct posix_acl_xattr_entry *e)
  838. {
  839. kgid_t kgid = KGIDT_INIT(le32_to_cpu(e->e_id));
  840. return from_vfsgid(mnt_userns, fs_userns, VFSGIDT_INIT(kgid));
  841. }
  842. /**
  843. * vfs_set_acl_prepare - convert POSIX ACLs from uapi to VFS format taking
  844. * mount and filesystem idmappings into account
  845. * @mnt_userns: the mount's idmapping
  846. * @fs_userns: the filesystem's idmapping
  847. * @value: the uapi representation of POSIX ACLs
  848. * @size: the size of @void
  849. *
  850. * When setting POSIX ACLs with ACL_{GROUP,USER} entries they need to be
  851. * mapped according to the relevant mount- and filesystem idmapping. It is
  852. * important that the ACL_{GROUP,USER} entries in struct posix_acl will be
  853. * mapped into k{g,u}id_t that are supposed to be mapped up in the filesystem
  854. * idmapping. This is crucial since the resulting struct posix_acl might be
  855. * cached filesystem wide. The vfs_set_acl_prepare() function will take care to
  856. * perform all necessary idmappings.
  857. *
  858. * Note, that since basically forever the {g,u}id values encoded as
  859. * ACL_{GROUP,USER} entries in the uapi POSIX ACLs passed via @value contain
  860. * values that have been mapped according to the caller's idmapping. In other
  861. * words, POSIX ACLs passed in uapi format as @value during setxattr() contain
  862. * {g,u}id values in their ACL_{GROUP,USER} entries that should actually have
  863. * been stored as k{g,u}id_t.
  864. *
  865. * This means, vfs_set_acl_prepare() needs to first recover the k{g,u}id_t by
  866. * calling K{G,U}IDT_INIT(). Afterwards they can be interpreted as vfs{g,u}id_t
  867. * through from_vfs{g,u}id() to account for any idmapped mounts. The
  868. * vfs_set_acl_prepare_k{g,u}id() helpers will take care to generate the
  869. * correct k{g,u}id_t.
  870. *
  871. * The filesystem will then receive the POSIX ACLs ready to be cached
  872. * filesystem wide and ready to be written to the backing store taking the
  873. * filesystem's idmapping into account.
  874. *
  875. * Return: Allocated struct posix_acl on success, NULL for a valid header but
  876. * without actual POSIX ACL entries, or ERR_PTR() encoded error code.
  877. */
  878. struct posix_acl *vfs_set_acl_prepare(struct user_namespace *mnt_userns,
  879. struct user_namespace *fs_userns,
  880. const void *value, size_t size)
  881. {
  882. return make_posix_acl(mnt_userns, fs_userns, value, size,
  883. vfs_set_acl_prepare_kuid,
  884. vfs_set_acl_prepare_kgid);
  885. }
  886. EXPORT_SYMBOL(vfs_set_acl_prepare);
  887. /**
  888. * posix_acl_from_xattr_kuid - map ACL_USER uid into filesystem idmapping
  889. * @mnt_userns: unused
  890. * @fs_userns: the filesystem's idmapping
  891. * @e: a ACL_USER entry in POSIX ACL uapi format
  892. *
  893. * Map the uid stored as ACL_USER entry in @e into the filesystem's idmapping.
  894. * This is used in posix_acl_from_xattr() to generate the proper VFS
  895. * representation of POSIX ACLs with ACL_USER entries.
  896. *
  897. * Return: A kuid in @fs_userns for the uid stored in @e.
  898. */
  899. static inline kuid_t
  900. posix_acl_from_xattr_kuid(struct user_namespace *mnt_userns,
  901. struct user_namespace *fs_userns,
  902. const struct posix_acl_xattr_entry *e)
  903. {
  904. return make_kuid(fs_userns, le32_to_cpu(e->e_id));
  905. }
  906. /**
  907. * posix_acl_from_xattr_kgid - map ACL_GROUP gid into filesystem idmapping
  908. * @mnt_userns: unused
  909. * @fs_userns: the filesystem's idmapping
  910. * @e: a ACL_GROUP entry in POSIX ACL uapi format
  911. *
  912. * Map the gid stored as ACL_GROUP entry in @e into the filesystem's idmapping.
  913. * This is used in posix_acl_from_xattr() to generate the proper VFS
  914. * representation of POSIX ACLs with ACL_GROUP entries.
  915. *
  916. * Return: A kgid in @fs_userns for the gid stored in @e.
  917. */
  918. static inline kgid_t
  919. posix_acl_from_xattr_kgid(struct user_namespace *mnt_userns,
  920. struct user_namespace *fs_userns,
  921. const struct posix_acl_xattr_entry *e)
  922. {
  923. return make_kgid(fs_userns, le32_to_cpu(e->e_id));
  924. }
  925. /**
  926. * posix_acl_from_xattr - convert POSIX ACLs from backing store to VFS format
  927. * @fs_userns: the filesystem's idmapping
  928. * @value: the uapi representation of POSIX ACLs
  929. * @size: the size of @void
  930. *
  931. * Filesystems that store POSIX ACLs in the unaltered uapi format should use
  932. * posix_acl_from_xattr() when reading them from the backing store and
  933. * converting them into the struct posix_acl VFS format. The helper is
  934. * specifically intended to be called from the ->get_acl() inode operation.
  935. *
  936. * The posix_acl_from_xattr() function will map the raw {g,u}id values stored
  937. * in ACL_{GROUP,USER} entries into the filesystem idmapping in @fs_userns. The
  938. * posix_acl_from_xattr_k{g,u}id() helpers will take care to generate the
  939. * correct k{g,u}id_t. The returned struct posix_acl can be cached.
  940. *
  941. * Note that posix_acl_from_xattr() does not take idmapped mounts into account.
  942. * If it did it calling is from the ->get_acl() inode operation would return
  943. * POSIX ACLs mapped according to an idmapped mount which would mean that the
  944. * value couldn't be cached for the filesystem. Idmapped mounts are taken into
  945. * account on the fly during permission checking or right at the VFS -
  946. * userspace boundary before reporting them to the user.
  947. *
  948. * Return: Allocated struct posix_acl on success, NULL for a valid header but
  949. * without actual POSIX ACL entries, or ERR_PTR() encoded error code.
  950. */
  951. struct posix_acl *
  952. posix_acl_from_xattr(struct user_namespace *fs_userns,
  953. const void *value, size_t size)
  954. {
  955. return make_posix_acl(&init_user_ns, fs_userns, value, size,
  956. posix_acl_from_xattr_kuid,
  957. posix_acl_from_xattr_kgid);
  958. }
  959. EXPORT_SYMBOL (posix_acl_from_xattr);
  960. /*
  961. * Convert from in-memory to extended attribute representation.
  962. */
  963. int
  964. posix_acl_to_xattr(struct user_namespace *user_ns, const struct posix_acl *acl,
  965. void *buffer, size_t size)
  966. {
  967. struct posix_acl_xattr_header *ext_acl = buffer;
  968. struct posix_acl_xattr_entry *ext_entry;
  969. int real_size, n;
  970. real_size = posix_acl_xattr_size(acl->a_count);
  971. if (!buffer)
  972. return real_size;
  973. if (real_size > size)
  974. return -ERANGE;
  975. ext_entry = (void *)(ext_acl + 1);
  976. ext_acl->a_version = cpu_to_le32(POSIX_ACL_XATTR_VERSION);
  977. for (n=0; n < acl->a_count; n++, ext_entry++) {
  978. const struct posix_acl_entry *acl_e = &acl->a_entries[n];
  979. ext_entry->e_tag = cpu_to_le16(acl_e->e_tag);
  980. ext_entry->e_perm = cpu_to_le16(acl_e->e_perm);
  981. switch(acl_e->e_tag) {
  982. case ACL_USER:
  983. ext_entry->e_id =
  984. cpu_to_le32(from_kuid(user_ns, acl_e->e_uid));
  985. break;
  986. case ACL_GROUP:
  987. ext_entry->e_id =
  988. cpu_to_le32(from_kgid(user_ns, acl_e->e_gid));
  989. break;
  990. default:
  991. ext_entry->e_id = cpu_to_le32(ACL_UNDEFINED_ID);
  992. break;
  993. }
  994. }
  995. return real_size;
  996. }
  997. EXPORT_SYMBOL (posix_acl_to_xattr);
  998. static int
  999. posix_acl_xattr_get(const struct xattr_handler *handler,
  1000. struct dentry *unused, struct inode *inode,
  1001. const char *name, void *value, size_t size)
  1002. {
  1003. struct posix_acl *acl;
  1004. int error;
  1005. if (!IS_POSIXACL(inode))
  1006. return -EOPNOTSUPP;
  1007. if (S_ISLNK(inode->i_mode))
  1008. return -EOPNOTSUPP;
  1009. acl = get_acl(inode, handler->flags);
  1010. if (IS_ERR(acl))
  1011. return PTR_ERR(acl);
  1012. if (acl == NULL)
  1013. return -ENODATA;
  1014. error = posix_acl_to_xattr(&init_user_ns, acl, value, size);
  1015. posix_acl_release(acl);
  1016. return error;
  1017. }
  1018. int
  1019. set_posix_acl(struct user_namespace *mnt_userns, struct inode *inode,
  1020. int type, struct posix_acl *acl)
  1021. {
  1022. if (!IS_POSIXACL(inode))
  1023. return -EOPNOTSUPP;
  1024. if (!inode->i_op->set_acl)
  1025. return -EOPNOTSUPP;
  1026. if (type == ACL_TYPE_DEFAULT && !S_ISDIR(inode->i_mode))
  1027. return acl ? -EACCES : 0;
  1028. if (!inode_owner_or_capable(mnt_userns, inode))
  1029. return -EPERM;
  1030. if (acl) {
  1031. int ret = posix_acl_valid(inode->i_sb->s_user_ns, acl);
  1032. if (ret)
  1033. return ret;
  1034. }
  1035. return inode->i_op->set_acl(mnt_userns, inode, acl, type);
  1036. }
  1037. EXPORT_SYMBOL(set_posix_acl);
  1038. static int
  1039. posix_acl_xattr_set(const struct xattr_handler *handler,
  1040. struct user_namespace *mnt_userns,
  1041. struct dentry *unused, struct inode *inode,
  1042. const char *name, const void *value, size_t size,
  1043. int flags)
  1044. {
  1045. struct posix_acl *acl = NULL;
  1046. int ret;
  1047. if (value) {
  1048. /*
  1049. * By the time we end up here the {g,u}ids stored in
  1050. * ACL_{GROUP,USER} have already been mapped according to the
  1051. * caller's idmapping. The vfs_set_acl_prepare() helper will
  1052. * recover them and take idmapped mounts into account. The
  1053. * filesystem will receive the POSIX ACLs in the correct
  1054. * format ready to be cached or written to the backing store
  1055. * taking the filesystem idmapping into account.
  1056. */
  1057. acl = vfs_set_acl_prepare(mnt_userns, i_user_ns(inode),
  1058. value, size);
  1059. if (IS_ERR(acl))
  1060. return PTR_ERR(acl);
  1061. }
  1062. ret = set_posix_acl(mnt_userns, inode, handler->flags, acl);
  1063. posix_acl_release(acl);
  1064. return ret;
  1065. }
  1066. static bool
  1067. posix_acl_xattr_list(struct dentry *dentry)
  1068. {
  1069. return IS_POSIXACL(d_backing_inode(dentry));
  1070. }
  1071. const struct xattr_handler posix_acl_access_xattr_handler = {
  1072. .name = XATTR_NAME_POSIX_ACL_ACCESS,
  1073. .flags = ACL_TYPE_ACCESS,
  1074. .list = posix_acl_xattr_list,
  1075. .get = posix_acl_xattr_get,
  1076. .set = posix_acl_xattr_set,
  1077. };
  1078. EXPORT_SYMBOL_GPL(posix_acl_access_xattr_handler);
  1079. const struct xattr_handler posix_acl_default_xattr_handler = {
  1080. .name = XATTR_NAME_POSIX_ACL_DEFAULT,
  1081. .flags = ACL_TYPE_DEFAULT,
  1082. .list = posix_acl_xattr_list,
  1083. .get = posix_acl_xattr_get,
  1084. .set = posix_acl_xattr_set,
  1085. };
  1086. EXPORT_SYMBOL_GPL(posix_acl_default_xattr_handler);
  1087. int simple_set_acl(struct user_namespace *mnt_userns, struct inode *inode,
  1088. struct posix_acl *acl, int type)
  1089. {
  1090. int error;
  1091. if (type == ACL_TYPE_ACCESS) {
  1092. error = posix_acl_update_mode(mnt_userns, inode,
  1093. &inode->i_mode, &acl);
  1094. if (error)
  1095. return error;
  1096. }
  1097. inode->i_ctime = current_time(inode);
  1098. if (IS_I_VERSION(inode))
  1099. inode_inc_iversion(inode);
  1100. set_cached_acl(inode, type, acl);
  1101. return 0;
  1102. }
  1103. int simple_acl_create(struct inode *dir, struct inode *inode)
  1104. {
  1105. struct posix_acl *default_acl, *acl;
  1106. int error;
  1107. error = posix_acl_create(dir, &inode->i_mode, &default_acl, &acl);
  1108. if (error)
  1109. return error;
  1110. set_cached_acl(inode, ACL_TYPE_DEFAULT, default_acl);
  1111. set_cached_acl(inode, ACL_TYPE_ACCESS, acl);
  1112. if (default_acl)
  1113. posix_acl_release(default_acl);
  1114. if (acl)
  1115. posix_acl_release(acl);
  1116. return 0;
  1117. }