fs.c 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Landlock LSM - Filesystem management and hooks
  4. *
  5. * Copyright © 2016-2020 Mickaël Salaün <[email protected]>
  6. * Copyright © 2018-2020 ANSSI
  7. * Copyright © 2021-2022 Microsoft Corporation
  8. */
  9. #include <linux/atomic.h>
  10. #include <linux/bitops.h>
  11. #include <linux/bits.h>
  12. #include <linux/compiler_types.h>
  13. #include <linux/dcache.h>
  14. #include <linux/err.h>
  15. #include <linux/fs.h>
  16. #include <linux/init.h>
  17. #include <linux/kernel.h>
  18. #include <linux/limits.h>
  19. #include <linux/list.h>
  20. #include <linux/lsm_hooks.h>
  21. #include <linux/mount.h>
  22. #include <linux/namei.h>
  23. #include <linux/path.h>
  24. #include <linux/rcupdate.h>
  25. #include <linux/spinlock.h>
  26. #include <linux/stat.h>
  27. #include <linux/types.h>
  28. #include <linux/wait_bit.h>
  29. #include <linux/workqueue.h>
  30. #include <uapi/linux/landlock.h>
  31. #include "common.h"
  32. #include "cred.h"
  33. #include "fs.h"
  34. #include "limits.h"
  35. #include "object.h"
  36. #include "ruleset.h"
  37. #include "setup.h"
  38. /* Underlying object management */
  39. static void release_inode(struct landlock_object *const object)
  40. __releases(object->lock)
  41. {
  42. struct inode *const inode = object->underobj;
  43. struct super_block *sb;
  44. if (!inode) {
  45. spin_unlock(&object->lock);
  46. return;
  47. }
  48. /*
  49. * Protects against concurrent use by hook_sb_delete() of the reference
  50. * to the underlying inode.
  51. */
  52. object->underobj = NULL;
  53. /*
  54. * Makes sure that if the filesystem is concurrently unmounted,
  55. * hook_sb_delete() will wait for us to finish iput().
  56. */
  57. sb = inode->i_sb;
  58. atomic_long_inc(&landlock_superblock(sb)->inode_refs);
  59. spin_unlock(&object->lock);
  60. /*
  61. * Because object->underobj was not NULL, hook_sb_delete() and
  62. * get_inode_object() guarantee that it is safe to reset
  63. * landlock_inode(inode)->object while it is not NULL. It is therefore
  64. * not necessary to lock inode->i_lock.
  65. */
  66. rcu_assign_pointer(landlock_inode(inode)->object, NULL);
  67. /*
  68. * Now, new rules can safely be tied to @inode with get_inode_object().
  69. */
  70. iput(inode);
  71. if (atomic_long_dec_and_test(&landlock_superblock(sb)->inode_refs))
  72. wake_up_var(&landlock_superblock(sb)->inode_refs);
  73. }
  74. static const struct landlock_object_underops landlock_fs_underops = {
  75. .release = release_inode
  76. };
  77. /* Ruleset management */
  78. static struct landlock_object *get_inode_object(struct inode *const inode)
  79. {
  80. struct landlock_object *object, *new_object;
  81. struct landlock_inode_security *inode_sec = landlock_inode(inode);
  82. rcu_read_lock();
  83. retry:
  84. object = rcu_dereference(inode_sec->object);
  85. if (object) {
  86. if (likely(refcount_inc_not_zero(&object->usage))) {
  87. rcu_read_unlock();
  88. return object;
  89. }
  90. /*
  91. * We are racing with release_inode(), the object is going
  92. * away. Wait for release_inode(), then retry.
  93. */
  94. spin_lock(&object->lock);
  95. spin_unlock(&object->lock);
  96. goto retry;
  97. }
  98. rcu_read_unlock();
  99. /*
  100. * If there is no object tied to @inode, then create a new one (without
  101. * holding any locks).
  102. */
  103. new_object = landlock_create_object(&landlock_fs_underops, inode);
  104. if (IS_ERR(new_object))
  105. return new_object;
  106. /*
  107. * Protects against concurrent calls to get_inode_object() or
  108. * hook_sb_delete().
  109. */
  110. spin_lock(&inode->i_lock);
  111. if (unlikely(rcu_access_pointer(inode_sec->object))) {
  112. /* Someone else just created the object, bail out and retry. */
  113. spin_unlock(&inode->i_lock);
  114. kfree(new_object);
  115. rcu_read_lock();
  116. goto retry;
  117. }
  118. /*
  119. * @inode will be released by hook_sb_delete() on its superblock
  120. * shutdown, or by release_inode() when no more ruleset references the
  121. * related object.
  122. */
  123. ihold(inode);
  124. rcu_assign_pointer(inode_sec->object, new_object);
  125. spin_unlock(&inode->i_lock);
  126. return new_object;
  127. }
  128. /* All access rights that can be tied to files. */
  129. /* clang-format off */
  130. #define ACCESS_FILE ( \
  131. LANDLOCK_ACCESS_FS_EXECUTE | \
  132. LANDLOCK_ACCESS_FS_WRITE_FILE | \
  133. LANDLOCK_ACCESS_FS_READ_FILE)
  134. /* clang-format on */
  135. /*
  136. * All access rights that are denied by default whether they are handled or not
  137. * by a ruleset/layer. This must be ORed with all ruleset->fs_access_masks[]
  138. * entries when we need to get the absolute handled access masks.
  139. */
  140. /* clang-format off */
  141. #define ACCESS_INITIALLY_DENIED ( \
  142. LANDLOCK_ACCESS_FS_REFER)
  143. /* clang-format on */
  144. /*
  145. * @path: Should have been checked by get_path_from_fd().
  146. */
  147. int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
  148. const struct path *const path,
  149. access_mask_t access_rights)
  150. {
  151. int err;
  152. struct landlock_object *object;
  153. /* Files only get access rights that make sense. */
  154. if (!d_is_dir(path->dentry) &&
  155. (access_rights | ACCESS_FILE) != ACCESS_FILE)
  156. return -EINVAL;
  157. if (WARN_ON_ONCE(ruleset->num_layers != 1))
  158. return -EINVAL;
  159. /* Transforms relative access rights to absolute ones. */
  160. access_rights |=
  161. LANDLOCK_MASK_ACCESS_FS &
  162. ~(ruleset->fs_access_masks[0] | ACCESS_INITIALLY_DENIED);
  163. object = get_inode_object(d_backing_inode(path->dentry));
  164. if (IS_ERR(object))
  165. return PTR_ERR(object);
  166. mutex_lock(&ruleset->lock);
  167. err = landlock_insert_rule(ruleset, object, access_rights);
  168. mutex_unlock(&ruleset->lock);
  169. /*
  170. * No need to check for an error because landlock_insert_rule()
  171. * increments the refcount for the new object if needed.
  172. */
  173. landlock_put_object(object);
  174. return err;
  175. }
  176. /* Access-control management */
  177. /*
  178. * The lifetime of the returned rule is tied to @domain.
  179. *
  180. * Returns NULL if no rule is found or if @dentry is negative.
  181. */
  182. static inline const struct landlock_rule *
  183. find_rule(const struct landlock_ruleset *const domain,
  184. const struct dentry *const dentry)
  185. {
  186. const struct landlock_rule *rule;
  187. const struct inode *inode;
  188. /* Ignores nonexistent leafs. */
  189. if (d_is_negative(dentry))
  190. return NULL;
  191. inode = d_backing_inode(dentry);
  192. rcu_read_lock();
  193. rule = landlock_find_rule(
  194. domain, rcu_dereference(landlock_inode(inode)->object));
  195. rcu_read_unlock();
  196. return rule;
  197. }
  198. /*
  199. * @layer_masks is read and may be updated according to the access request and
  200. * the matching rule.
  201. *
  202. * Returns true if the request is allowed (i.e. relevant layer masks for the
  203. * request are empty).
  204. */
  205. static inline bool
  206. unmask_layers(const struct landlock_rule *const rule,
  207. const access_mask_t access_request,
  208. layer_mask_t (*const layer_masks)[LANDLOCK_NUM_ACCESS_FS])
  209. {
  210. size_t layer_level;
  211. if (!access_request || !layer_masks)
  212. return true;
  213. if (!rule)
  214. return false;
  215. /*
  216. * An access is granted if, for each policy layer, at least one rule
  217. * encountered on the pathwalk grants the requested access,
  218. * regardless of its position in the layer stack. We must then check
  219. * the remaining layers for each inode, from the first added layer to
  220. * the last one. When there is multiple requested accesses, for each
  221. * policy layer, the full set of requested accesses may not be granted
  222. * by only one rule, but by the union (binary OR) of multiple rules.
  223. * E.g. /a/b <execute> + /a <read> => /a/b <execute + read>
  224. */
  225. for (layer_level = 0; layer_level < rule->num_layers; layer_level++) {
  226. const struct landlock_layer *const layer =
  227. &rule->layers[layer_level];
  228. const layer_mask_t layer_bit = BIT_ULL(layer->level - 1);
  229. const unsigned long access_req = access_request;
  230. unsigned long access_bit;
  231. bool is_empty;
  232. /*
  233. * Records in @layer_masks which layer grants access to each
  234. * requested access.
  235. */
  236. is_empty = true;
  237. for_each_set_bit(access_bit, &access_req,
  238. ARRAY_SIZE(*layer_masks)) {
  239. if (layer->access & BIT_ULL(access_bit))
  240. (*layer_masks)[access_bit] &= ~layer_bit;
  241. is_empty = is_empty && !(*layer_masks)[access_bit];
  242. }
  243. if (is_empty)
  244. return true;
  245. }
  246. return false;
  247. }
  248. /*
  249. * Allows access to pseudo filesystems that will never be mountable (e.g.
  250. * sockfs, pipefs), but can still be reachable through
  251. * /proc/<pid>/fd/<file-descriptor>
  252. */
  253. static inline bool is_nouser_or_private(const struct dentry *dentry)
  254. {
  255. return (dentry->d_sb->s_flags & SB_NOUSER) ||
  256. (d_is_positive(dentry) &&
  257. unlikely(IS_PRIVATE(d_backing_inode(dentry))));
  258. }
  259. static inline access_mask_t
  260. get_handled_accesses(const struct landlock_ruleset *const domain)
  261. {
  262. access_mask_t access_dom = ACCESS_INITIALLY_DENIED;
  263. size_t layer_level;
  264. for (layer_level = 0; layer_level < domain->num_layers; layer_level++)
  265. access_dom |= domain->fs_access_masks[layer_level];
  266. return access_dom & LANDLOCK_MASK_ACCESS_FS;
  267. }
  268. static inline access_mask_t
  269. init_layer_masks(const struct landlock_ruleset *const domain,
  270. const access_mask_t access_request,
  271. layer_mask_t (*const layer_masks)[LANDLOCK_NUM_ACCESS_FS])
  272. {
  273. access_mask_t handled_accesses = 0;
  274. size_t layer_level;
  275. memset(layer_masks, 0, sizeof(*layer_masks));
  276. /* An empty access request can happen because of O_WRONLY | O_RDWR. */
  277. if (!access_request)
  278. return 0;
  279. /* Saves all handled accesses per layer. */
  280. for (layer_level = 0; layer_level < domain->num_layers; layer_level++) {
  281. const unsigned long access_req = access_request;
  282. unsigned long access_bit;
  283. for_each_set_bit(access_bit, &access_req,
  284. ARRAY_SIZE(*layer_masks)) {
  285. /*
  286. * Artificially handles all initially denied by default
  287. * access rights.
  288. */
  289. if (BIT_ULL(access_bit) &
  290. (domain->fs_access_masks[layer_level] |
  291. ACCESS_INITIALLY_DENIED)) {
  292. (*layer_masks)[access_bit] |=
  293. BIT_ULL(layer_level);
  294. handled_accesses |= BIT_ULL(access_bit);
  295. }
  296. }
  297. }
  298. return handled_accesses;
  299. }
  300. /*
  301. * Check that a destination file hierarchy has more restrictions than a source
  302. * file hierarchy. This is only used for link and rename actions.
  303. *
  304. * @layer_masks_child2: Optional child masks.
  305. */
  306. static inline bool no_more_access(
  307. const layer_mask_t (*const layer_masks_parent1)[LANDLOCK_NUM_ACCESS_FS],
  308. const layer_mask_t (*const layer_masks_child1)[LANDLOCK_NUM_ACCESS_FS],
  309. const bool child1_is_directory,
  310. const layer_mask_t (*const layer_masks_parent2)[LANDLOCK_NUM_ACCESS_FS],
  311. const layer_mask_t (*const layer_masks_child2)[LANDLOCK_NUM_ACCESS_FS],
  312. const bool child2_is_directory)
  313. {
  314. unsigned long access_bit;
  315. for (access_bit = 0; access_bit < ARRAY_SIZE(*layer_masks_parent2);
  316. access_bit++) {
  317. /* Ignores accesses that only make sense for directories. */
  318. const bool is_file_access =
  319. !!(BIT_ULL(access_bit) & ACCESS_FILE);
  320. if (child1_is_directory || is_file_access) {
  321. /*
  322. * Checks if the destination restrictions are a
  323. * superset of the source ones (i.e. inherited access
  324. * rights without child exceptions):
  325. * restrictions(parent2) >= restrictions(child1)
  326. */
  327. if ((((*layer_masks_parent1)[access_bit] &
  328. (*layer_masks_child1)[access_bit]) |
  329. (*layer_masks_parent2)[access_bit]) !=
  330. (*layer_masks_parent2)[access_bit])
  331. return false;
  332. }
  333. if (!layer_masks_child2)
  334. continue;
  335. if (child2_is_directory || is_file_access) {
  336. /*
  337. * Checks inverted restrictions for RENAME_EXCHANGE:
  338. * restrictions(parent1) >= restrictions(child2)
  339. */
  340. if ((((*layer_masks_parent2)[access_bit] &
  341. (*layer_masks_child2)[access_bit]) |
  342. (*layer_masks_parent1)[access_bit]) !=
  343. (*layer_masks_parent1)[access_bit])
  344. return false;
  345. }
  346. }
  347. return true;
  348. }
  349. /*
  350. * Removes @layer_masks accesses that are not requested.
  351. *
  352. * Returns true if the request is allowed, false otherwise.
  353. */
  354. static inline bool
  355. scope_to_request(const access_mask_t access_request,
  356. layer_mask_t (*const layer_masks)[LANDLOCK_NUM_ACCESS_FS])
  357. {
  358. const unsigned long access_req = access_request;
  359. unsigned long access_bit;
  360. if (WARN_ON_ONCE(!layer_masks))
  361. return true;
  362. for_each_clear_bit(access_bit, &access_req, ARRAY_SIZE(*layer_masks))
  363. (*layer_masks)[access_bit] = 0;
  364. return !memchr_inv(layer_masks, 0, sizeof(*layer_masks));
  365. }
  366. /*
  367. * Returns true if there is at least one access right different than
  368. * LANDLOCK_ACCESS_FS_REFER.
  369. */
  370. static inline bool
  371. is_eacces(const layer_mask_t (*const layer_masks)[LANDLOCK_NUM_ACCESS_FS],
  372. const access_mask_t access_request)
  373. {
  374. unsigned long access_bit;
  375. /* LANDLOCK_ACCESS_FS_REFER alone must return -EXDEV. */
  376. const unsigned long access_check = access_request &
  377. ~LANDLOCK_ACCESS_FS_REFER;
  378. if (!layer_masks)
  379. return false;
  380. for_each_set_bit(access_bit, &access_check, ARRAY_SIZE(*layer_masks)) {
  381. if ((*layer_masks)[access_bit])
  382. return true;
  383. }
  384. return false;
  385. }
  386. /**
  387. * check_access_path_dual - Check accesses for requests with a common path
  388. *
  389. * @domain: Domain to check against.
  390. * @path: File hierarchy to walk through.
  391. * @access_request_parent1: Accesses to check, once @layer_masks_parent1 is
  392. * equal to @layer_masks_parent2 (if any). This is tied to the unique
  393. * requested path for most actions, or the source in case of a refer action
  394. * (i.e. rename or link), or the source and destination in case of
  395. * RENAME_EXCHANGE.
  396. * @layer_masks_parent1: Pointer to a matrix of layer masks per access
  397. * masks, identifying the layers that forbid a specific access. Bits from
  398. * this matrix can be unset according to the @path walk. An empty matrix
  399. * means that @domain allows all possible Landlock accesses (i.e. not only
  400. * those identified by @access_request_parent1). This matrix can
  401. * initially refer to domain layer masks and, when the accesses for the
  402. * destination and source are the same, to requested layer masks.
  403. * @dentry_child1: Dentry to the initial child of the parent1 path. This
  404. * pointer must be NULL for non-refer actions (i.e. not link nor rename).
  405. * @access_request_parent2: Similar to @access_request_parent1 but for a
  406. * request involving a source and a destination. This refers to the
  407. * destination, except in case of RENAME_EXCHANGE where it also refers to
  408. * the source. Must be set to 0 when using a simple path request.
  409. * @layer_masks_parent2: Similar to @layer_masks_parent1 but for a refer
  410. * action. This must be NULL otherwise.
  411. * @dentry_child2: Dentry to the initial child of the parent2 path. This
  412. * pointer is only set for RENAME_EXCHANGE actions and must be NULL
  413. * otherwise.
  414. *
  415. * This helper first checks that the destination has a superset of restrictions
  416. * compared to the source (if any) for a common path. Because of
  417. * RENAME_EXCHANGE actions, source and destinations may be swapped. It then
  418. * checks that the collected accesses and the remaining ones are enough to
  419. * allow the request.
  420. *
  421. * Returns:
  422. * - 0 if the access request is granted;
  423. * - -EACCES if it is denied because of access right other than
  424. * LANDLOCK_ACCESS_FS_REFER;
  425. * - -EXDEV if the renaming or linking would be a privileged escalation
  426. * (according to each layered policies), or if LANDLOCK_ACCESS_FS_REFER is
  427. * not allowed by the source or the destination.
  428. */
  429. static int check_access_path_dual(
  430. const struct landlock_ruleset *const domain,
  431. const struct path *const path,
  432. const access_mask_t access_request_parent1,
  433. layer_mask_t (*const layer_masks_parent1)[LANDLOCK_NUM_ACCESS_FS],
  434. const struct dentry *const dentry_child1,
  435. const access_mask_t access_request_parent2,
  436. layer_mask_t (*const layer_masks_parent2)[LANDLOCK_NUM_ACCESS_FS],
  437. const struct dentry *const dentry_child2)
  438. {
  439. bool allowed_parent1 = false, allowed_parent2 = false, is_dom_check,
  440. child1_is_directory = true, child2_is_directory = true;
  441. struct path walker_path;
  442. access_mask_t access_masked_parent1, access_masked_parent2;
  443. layer_mask_t _layer_masks_child1[LANDLOCK_NUM_ACCESS_FS],
  444. _layer_masks_child2[LANDLOCK_NUM_ACCESS_FS];
  445. layer_mask_t(*layer_masks_child1)[LANDLOCK_NUM_ACCESS_FS] = NULL,
  446. (*layer_masks_child2)[LANDLOCK_NUM_ACCESS_FS] = NULL;
  447. if (!access_request_parent1 && !access_request_parent2)
  448. return 0;
  449. if (WARN_ON_ONCE(!domain || !path))
  450. return 0;
  451. if (is_nouser_or_private(path->dentry))
  452. return 0;
  453. if (WARN_ON_ONCE(domain->num_layers < 1 || !layer_masks_parent1))
  454. return -EACCES;
  455. if (unlikely(layer_masks_parent2)) {
  456. if (WARN_ON_ONCE(!dentry_child1))
  457. return -EACCES;
  458. /*
  459. * For a double request, first check for potential privilege
  460. * escalation by looking at domain handled accesses (which are
  461. * a superset of the meaningful requested accesses).
  462. */
  463. access_masked_parent1 = access_masked_parent2 =
  464. get_handled_accesses(domain);
  465. is_dom_check = true;
  466. } else {
  467. if (WARN_ON_ONCE(dentry_child1 || dentry_child2))
  468. return -EACCES;
  469. /* For a simple request, only check for requested accesses. */
  470. access_masked_parent1 = access_request_parent1;
  471. access_masked_parent2 = access_request_parent2;
  472. is_dom_check = false;
  473. }
  474. if (unlikely(dentry_child1)) {
  475. unmask_layers(find_rule(domain, dentry_child1),
  476. init_layer_masks(domain, LANDLOCK_MASK_ACCESS_FS,
  477. &_layer_masks_child1),
  478. &_layer_masks_child1);
  479. layer_masks_child1 = &_layer_masks_child1;
  480. child1_is_directory = d_is_dir(dentry_child1);
  481. }
  482. if (unlikely(dentry_child2)) {
  483. unmask_layers(find_rule(domain, dentry_child2),
  484. init_layer_masks(domain, LANDLOCK_MASK_ACCESS_FS,
  485. &_layer_masks_child2),
  486. &_layer_masks_child2);
  487. layer_masks_child2 = &_layer_masks_child2;
  488. child2_is_directory = d_is_dir(dentry_child2);
  489. }
  490. walker_path = *path;
  491. path_get(&walker_path);
  492. /*
  493. * We need to walk through all the hierarchy to not miss any relevant
  494. * restriction.
  495. */
  496. while (true) {
  497. struct dentry *parent_dentry;
  498. const struct landlock_rule *rule;
  499. /*
  500. * If at least all accesses allowed on the destination are
  501. * already allowed on the source, respectively if there is at
  502. * least as much as restrictions on the destination than on the
  503. * source, then we can safely refer files from the source to
  504. * the destination without risking a privilege escalation.
  505. * This also applies in the case of RENAME_EXCHANGE, which
  506. * implies checks on both direction. This is crucial for
  507. * standalone multilayered security policies. Furthermore,
  508. * this helps avoid policy writers to shoot themselves in the
  509. * foot.
  510. */
  511. if (unlikely(is_dom_check &&
  512. no_more_access(
  513. layer_masks_parent1, layer_masks_child1,
  514. child1_is_directory, layer_masks_parent2,
  515. layer_masks_child2,
  516. child2_is_directory))) {
  517. allowed_parent1 = scope_to_request(
  518. access_request_parent1, layer_masks_parent1);
  519. allowed_parent2 = scope_to_request(
  520. access_request_parent2, layer_masks_parent2);
  521. /* Stops when all accesses are granted. */
  522. if (allowed_parent1 && allowed_parent2)
  523. break;
  524. /*
  525. * Now, downgrades the remaining checks from domain
  526. * handled accesses to requested accesses.
  527. */
  528. is_dom_check = false;
  529. access_masked_parent1 = access_request_parent1;
  530. access_masked_parent2 = access_request_parent2;
  531. }
  532. rule = find_rule(domain, walker_path.dentry);
  533. allowed_parent1 = unmask_layers(rule, access_masked_parent1,
  534. layer_masks_parent1);
  535. allowed_parent2 = unmask_layers(rule, access_masked_parent2,
  536. layer_masks_parent2);
  537. /* Stops when a rule from each layer grants access. */
  538. if (allowed_parent1 && allowed_parent2)
  539. break;
  540. jump_up:
  541. if (walker_path.dentry == walker_path.mnt->mnt_root) {
  542. if (follow_up(&walker_path)) {
  543. /* Ignores hidden mount points. */
  544. goto jump_up;
  545. } else {
  546. /*
  547. * Stops at the real root. Denies access
  548. * because not all layers have granted access.
  549. */
  550. break;
  551. }
  552. }
  553. if (unlikely(IS_ROOT(walker_path.dentry))) {
  554. /*
  555. * Stops at disconnected root directories. Only allows
  556. * access to internal filesystems (e.g. nsfs, which is
  557. * reachable through /proc/<pid>/ns/<namespace>).
  558. */
  559. allowed_parent1 = allowed_parent2 =
  560. !!(walker_path.mnt->mnt_flags & MNT_INTERNAL);
  561. break;
  562. }
  563. parent_dentry = dget_parent(walker_path.dentry);
  564. dput(walker_path.dentry);
  565. walker_path.dentry = parent_dentry;
  566. }
  567. path_put(&walker_path);
  568. if (allowed_parent1 && allowed_parent2)
  569. return 0;
  570. /*
  571. * This prioritizes EACCES over EXDEV for all actions, including
  572. * renames with RENAME_EXCHANGE.
  573. */
  574. if (likely(is_eacces(layer_masks_parent1, access_request_parent1) ||
  575. is_eacces(layer_masks_parent2, access_request_parent2)))
  576. return -EACCES;
  577. /*
  578. * Gracefully forbids reparenting if the destination directory
  579. * hierarchy is not a superset of restrictions of the source directory
  580. * hierarchy, or if LANDLOCK_ACCESS_FS_REFER is not allowed by the
  581. * source or the destination.
  582. */
  583. return -EXDEV;
  584. }
  585. static inline int check_access_path(const struct landlock_ruleset *const domain,
  586. const struct path *const path,
  587. access_mask_t access_request)
  588. {
  589. layer_mask_t layer_masks[LANDLOCK_NUM_ACCESS_FS] = {};
  590. access_request = init_layer_masks(domain, access_request, &layer_masks);
  591. return check_access_path_dual(domain, path, access_request,
  592. &layer_masks, NULL, 0, NULL, NULL);
  593. }
  594. static inline int current_check_access_path(const struct path *const path,
  595. const access_mask_t access_request)
  596. {
  597. const struct landlock_ruleset *const dom =
  598. landlock_get_current_domain();
  599. if (!dom)
  600. return 0;
  601. return check_access_path(dom, path, access_request);
  602. }
  603. static inline access_mask_t get_mode_access(const umode_t mode)
  604. {
  605. switch (mode & S_IFMT) {
  606. case S_IFLNK:
  607. return LANDLOCK_ACCESS_FS_MAKE_SYM;
  608. case 0:
  609. /* A zero mode translates to S_IFREG. */
  610. case S_IFREG:
  611. return LANDLOCK_ACCESS_FS_MAKE_REG;
  612. case S_IFDIR:
  613. return LANDLOCK_ACCESS_FS_MAKE_DIR;
  614. case S_IFCHR:
  615. return LANDLOCK_ACCESS_FS_MAKE_CHAR;
  616. case S_IFBLK:
  617. return LANDLOCK_ACCESS_FS_MAKE_BLOCK;
  618. case S_IFIFO:
  619. return LANDLOCK_ACCESS_FS_MAKE_FIFO;
  620. case S_IFSOCK:
  621. return LANDLOCK_ACCESS_FS_MAKE_SOCK;
  622. default:
  623. WARN_ON_ONCE(1);
  624. return 0;
  625. }
  626. }
  627. static inline access_mask_t maybe_remove(const struct dentry *const dentry)
  628. {
  629. if (d_is_negative(dentry))
  630. return 0;
  631. return d_is_dir(dentry) ? LANDLOCK_ACCESS_FS_REMOVE_DIR :
  632. LANDLOCK_ACCESS_FS_REMOVE_FILE;
  633. }
  634. /**
  635. * collect_domain_accesses - Walk through a file path and collect accesses
  636. *
  637. * @domain: Domain to check against.
  638. * @mnt_root: Last directory to check.
  639. * @dir: Directory to start the walk from.
  640. * @layer_masks_dom: Where to store the collected accesses.
  641. *
  642. * This helper is useful to begin a path walk from the @dir directory to a
  643. * @mnt_root directory used as a mount point. This mount point is the common
  644. * ancestor between the source and the destination of a renamed and linked
  645. * file. While walking from @dir to @mnt_root, we record all the domain's
  646. * allowed accesses in @layer_masks_dom.
  647. *
  648. * This is similar to check_access_path_dual() but much simpler because it only
  649. * handles walking on the same mount point and only checks one set of accesses.
  650. *
  651. * Returns:
  652. * - true if all the domain access rights are allowed for @dir;
  653. * - false if the walk reached @mnt_root.
  654. */
  655. static bool collect_domain_accesses(
  656. const struct landlock_ruleset *const domain,
  657. const struct dentry *const mnt_root, struct dentry *dir,
  658. layer_mask_t (*const layer_masks_dom)[LANDLOCK_NUM_ACCESS_FS])
  659. {
  660. unsigned long access_dom;
  661. bool ret = false;
  662. if (WARN_ON_ONCE(!domain || !mnt_root || !dir || !layer_masks_dom))
  663. return true;
  664. if (is_nouser_or_private(dir))
  665. return true;
  666. access_dom = init_layer_masks(domain, LANDLOCK_MASK_ACCESS_FS,
  667. layer_masks_dom);
  668. dget(dir);
  669. while (true) {
  670. struct dentry *parent_dentry;
  671. /* Gets all layers allowing all domain accesses. */
  672. if (unmask_layers(find_rule(domain, dir), access_dom,
  673. layer_masks_dom)) {
  674. /*
  675. * Stops when all handled accesses are allowed by at
  676. * least one rule in each layer.
  677. */
  678. ret = true;
  679. break;
  680. }
  681. /* We should not reach a root other than @mnt_root. */
  682. if (dir == mnt_root || WARN_ON_ONCE(IS_ROOT(dir)))
  683. break;
  684. parent_dentry = dget_parent(dir);
  685. dput(dir);
  686. dir = parent_dentry;
  687. }
  688. dput(dir);
  689. return ret;
  690. }
  691. /**
  692. * current_check_refer_path - Check if a rename or link action is allowed
  693. *
  694. * @old_dentry: File or directory requested to be moved or linked.
  695. * @new_dir: Destination parent directory.
  696. * @new_dentry: Destination file or directory.
  697. * @removable: Sets to true if it is a rename operation.
  698. * @exchange: Sets to true if it is a rename operation with RENAME_EXCHANGE.
  699. *
  700. * Because of its unprivileged constraints, Landlock relies on file hierarchies
  701. * (and not only inodes) to tie access rights to files. Being able to link or
  702. * rename a file hierarchy brings some challenges. Indeed, moving or linking a
  703. * file (i.e. creating a new reference to an inode) can have an impact on the
  704. * actions allowed for a set of files if it would change its parent directory
  705. * (i.e. reparenting).
  706. *
  707. * To avoid trivial access right bypasses, Landlock first checks if the file or
  708. * directory requested to be moved would gain new access rights inherited from
  709. * its new hierarchy. Before returning any error, Landlock then checks that
  710. * the parent source hierarchy and the destination hierarchy would allow the
  711. * link or rename action. If it is not the case, an error with EACCES is
  712. * returned to inform user space that there is no way to remove or create the
  713. * requested source file type. If it should be allowed but the new inherited
  714. * access rights would be greater than the source access rights, then the
  715. * kernel returns an error with EXDEV. Prioritizing EACCES over EXDEV enables
  716. * user space to abort the whole operation if there is no way to do it, or to
  717. * manually copy the source to the destination if this remains allowed, e.g.
  718. * because file creation is allowed on the destination directory but not direct
  719. * linking.
  720. *
  721. * To achieve this goal, the kernel needs to compare two file hierarchies: the
  722. * one identifying the source file or directory (including itself), and the
  723. * destination one. This can be seen as a multilayer partial ordering problem.
  724. * The kernel walks through these paths and collects in a matrix the access
  725. * rights that are denied per layer. These matrices are then compared to see
  726. * if the destination one has more (or the same) restrictions as the source
  727. * one. If this is the case, the requested action will not return EXDEV, which
  728. * doesn't mean the action is allowed. The parent hierarchy of the source
  729. * (i.e. parent directory), and the destination hierarchy must also be checked
  730. * to verify that they explicitly allow such action (i.e. referencing,
  731. * creation and potentially removal rights). The kernel implementation is then
  732. * required to rely on potentially four matrices of access rights: one for the
  733. * source file or directory (i.e. the child), a potentially other one for the
  734. * other source/destination (in case of RENAME_EXCHANGE), one for the source
  735. * parent hierarchy and a last one for the destination hierarchy. These
  736. * ephemeral matrices take some space on the stack, which limits the number of
  737. * layers to a deemed reasonable number: 16.
  738. *
  739. * Returns:
  740. * - 0 if access is allowed;
  741. * - -EXDEV if @old_dentry would inherit new access rights from @new_dir;
  742. * - -EACCES if file removal or creation is denied.
  743. */
  744. static int current_check_refer_path(struct dentry *const old_dentry,
  745. const struct path *const new_dir,
  746. struct dentry *const new_dentry,
  747. const bool removable, const bool exchange)
  748. {
  749. const struct landlock_ruleset *const dom =
  750. landlock_get_current_domain();
  751. bool allow_parent1, allow_parent2;
  752. access_mask_t access_request_parent1, access_request_parent2;
  753. struct path mnt_dir;
  754. layer_mask_t layer_masks_parent1[LANDLOCK_NUM_ACCESS_FS],
  755. layer_masks_parent2[LANDLOCK_NUM_ACCESS_FS];
  756. if (!dom)
  757. return 0;
  758. if (WARN_ON_ONCE(dom->num_layers < 1))
  759. return -EACCES;
  760. if (unlikely(d_is_negative(old_dentry)))
  761. return -ENOENT;
  762. if (exchange) {
  763. if (unlikely(d_is_negative(new_dentry)))
  764. return -ENOENT;
  765. access_request_parent1 =
  766. get_mode_access(d_backing_inode(new_dentry)->i_mode);
  767. } else {
  768. access_request_parent1 = 0;
  769. }
  770. access_request_parent2 =
  771. get_mode_access(d_backing_inode(old_dentry)->i_mode);
  772. if (removable) {
  773. access_request_parent1 |= maybe_remove(old_dentry);
  774. access_request_parent2 |= maybe_remove(new_dentry);
  775. }
  776. /* The mount points are the same for old and new paths, cf. EXDEV. */
  777. if (old_dentry->d_parent == new_dir->dentry) {
  778. /*
  779. * The LANDLOCK_ACCESS_FS_REFER access right is not required
  780. * for same-directory referer (i.e. no reparenting).
  781. */
  782. access_request_parent1 = init_layer_masks(
  783. dom, access_request_parent1 | access_request_parent2,
  784. &layer_masks_parent1);
  785. return check_access_path_dual(dom, new_dir,
  786. access_request_parent1,
  787. &layer_masks_parent1, NULL, 0,
  788. NULL, NULL);
  789. }
  790. access_request_parent1 |= LANDLOCK_ACCESS_FS_REFER;
  791. access_request_parent2 |= LANDLOCK_ACCESS_FS_REFER;
  792. /* Saves the common mount point. */
  793. mnt_dir.mnt = new_dir->mnt;
  794. mnt_dir.dentry = new_dir->mnt->mnt_root;
  795. /* new_dir->dentry is equal to new_dentry->d_parent */
  796. allow_parent1 = collect_domain_accesses(dom, mnt_dir.dentry,
  797. old_dentry->d_parent,
  798. &layer_masks_parent1);
  799. allow_parent2 = collect_domain_accesses(
  800. dom, mnt_dir.dentry, new_dir->dentry, &layer_masks_parent2);
  801. if (allow_parent1 && allow_parent2)
  802. return 0;
  803. /*
  804. * To be able to compare source and destination domain access rights,
  805. * take into account the @old_dentry access rights aggregated with its
  806. * parent access rights. This will be useful to compare with the
  807. * destination parent access rights.
  808. */
  809. return check_access_path_dual(dom, &mnt_dir, access_request_parent1,
  810. &layer_masks_parent1, old_dentry,
  811. access_request_parent2,
  812. &layer_masks_parent2,
  813. exchange ? new_dentry : NULL);
  814. }
  815. /* Inode hooks */
  816. static void hook_inode_free_security(struct inode *const inode)
  817. {
  818. /*
  819. * All inodes must already have been untied from their object by
  820. * release_inode() or hook_sb_delete().
  821. */
  822. WARN_ON_ONCE(landlock_inode(inode)->object);
  823. }
  824. /* Super-block hooks */
  825. /*
  826. * Release the inodes used in a security policy.
  827. *
  828. * Cf. fsnotify_unmount_inodes() and invalidate_inodes()
  829. */
  830. static void hook_sb_delete(struct super_block *const sb)
  831. {
  832. struct inode *inode, *prev_inode = NULL;
  833. if (!landlock_initialized)
  834. return;
  835. spin_lock(&sb->s_inode_list_lock);
  836. list_for_each_entry(inode, &sb->s_inodes, i_sb_list) {
  837. struct landlock_object *object;
  838. /* Only handles referenced inodes. */
  839. if (!atomic_read(&inode->i_count))
  840. continue;
  841. /*
  842. * Protects against concurrent modification of inode (e.g.
  843. * from get_inode_object()).
  844. */
  845. spin_lock(&inode->i_lock);
  846. /*
  847. * Checks I_FREEING and I_WILL_FREE to protect against a race
  848. * condition when release_inode() just called iput(), which
  849. * could lead to a NULL dereference of inode->security or a
  850. * second call to iput() for the same Landlock object. Also
  851. * checks I_NEW because such inode cannot be tied to an object.
  852. */
  853. if (inode->i_state & (I_FREEING | I_WILL_FREE | I_NEW)) {
  854. spin_unlock(&inode->i_lock);
  855. continue;
  856. }
  857. rcu_read_lock();
  858. object = rcu_dereference(landlock_inode(inode)->object);
  859. if (!object) {
  860. rcu_read_unlock();
  861. spin_unlock(&inode->i_lock);
  862. continue;
  863. }
  864. /* Keeps a reference to this inode until the next loop walk. */
  865. __iget(inode);
  866. spin_unlock(&inode->i_lock);
  867. /*
  868. * If there is no concurrent release_inode() ongoing, then we
  869. * are in charge of calling iput() on this inode, otherwise we
  870. * will just wait for it to finish.
  871. */
  872. spin_lock(&object->lock);
  873. if (object->underobj == inode) {
  874. object->underobj = NULL;
  875. spin_unlock(&object->lock);
  876. rcu_read_unlock();
  877. /*
  878. * Because object->underobj was not NULL,
  879. * release_inode() and get_inode_object() guarantee
  880. * that it is safe to reset
  881. * landlock_inode(inode)->object while it is not NULL.
  882. * It is therefore not necessary to lock inode->i_lock.
  883. */
  884. rcu_assign_pointer(landlock_inode(inode)->object, NULL);
  885. /*
  886. * At this point, we own the ihold() reference that was
  887. * originally set up by get_inode_object() and the
  888. * __iget() reference that we just set in this loop
  889. * walk. Therefore the following call to iput() will
  890. * not sleep nor drop the inode because there is now at
  891. * least two references to it.
  892. */
  893. iput(inode);
  894. } else {
  895. spin_unlock(&object->lock);
  896. rcu_read_unlock();
  897. }
  898. if (prev_inode) {
  899. /*
  900. * At this point, we still own the __iget() reference
  901. * that we just set in this loop walk. Therefore we
  902. * can drop the list lock and know that the inode won't
  903. * disappear from under us until the next loop walk.
  904. */
  905. spin_unlock(&sb->s_inode_list_lock);
  906. /*
  907. * We can now actually put the inode reference from the
  908. * previous loop walk, which is not needed anymore.
  909. */
  910. iput(prev_inode);
  911. cond_resched();
  912. spin_lock(&sb->s_inode_list_lock);
  913. }
  914. prev_inode = inode;
  915. }
  916. spin_unlock(&sb->s_inode_list_lock);
  917. /* Puts the inode reference from the last loop walk, if any. */
  918. if (prev_inode)
  919. iput(prev_inode);
  920. /* Waits for pending iput() in release_inode(). */
  921. wait_var_event(&landlock_superblock(sb)->inode_refs,
  922. !atomic_long_read(&landlock_superblock(sb)->inode_refs));
  923. }
  924. /*
  925. * Because a Landlock security policy is defined according to the filesystem
  926. * topology (i.e. the mount namespace), changing it may grant access to files
  927. * not previously allowed.
  928. *
  929. * To make it simple, deny any filesystem topology modification by landlocked
  930. * processes. Non-landlocked processes may still change the namespace of a
  931. * landlocked process, but this kind of threat must be handled by a system-wide
  932. * access-control security policy.
  933. *
  934. * This could be lifted in the future if Landlock can safely handle mount
  935. * namespace updates requested by a landlocked process. Indeed, we could
  936. * update the current domain (which is currently read-only) by taking into
  937. * account the accesses of the source and the destination of a new mount point.
  938. * However, it would also require to make all the child domains dynamically
  939. * inherit these new constraints. Anyway, for backward compatibility reasons,
  940. * a dedicated user space option would be required (e.g. as a ruleset flag).
  941. */
  942. static int hook_sb_mount(const char *const dev_name,
  943. const struct path *const path, const char *const type,
  944. const unsigned long flags, void *const data)
  945. {
  946. if (!landlock_get_current_domain())
  947. return 0;
  948. return -EPERM;
  949. }
  950. static int hook_move_mount(const struct path *const from_path,
  951. const struct path *const to_path)
  952. {
  953. if (!landlock_get_current_domain())
  954. return 0;
  955. return -EPERM;
  956. }
  957. /*
  958. * Removing a mount point may reveal a previously hidden file hierarchy, which
  959. * may then grant access to files, which may have previously been forbidden.
  960. */
  961. static int hook_sb_umount(struct vfsmount *const mnt, const int flags)
  962. {
  963. if (!landlock_get_current_domain())
  964. return 0;
  965. return -EPERM;
  966. }
  967. static int hook_sb_remount(struct super_block *const sb, void *const mnt_opts)
  968. {
  969. if (!landlock_get_current_domain())
  970. return 0;
  971. return -EPERM;
  972. }
  973. /*
  974. * pivot_root(2), like mount(2), changes the current mount namespace. It must
  975. * then be forbidden for a landlocked process.
  976. *
  977. * However, chroot(2) may be allowed because it only changes the relative root
  978. * directory of the current process. Moreover, it can be used to restrict the
  979. * view of the filesystem.
  980. */
  981. static int hook_sb_pivotroot(const struct path *const old_path,
  982. const struct path *const new_path)
  983. {
  984. if (!landlock_get_current_domain())
  985. return 0;
  986. return -EPERM;
  987. }
  988. /* Path hooks */
  989. static int hook_path_link(struct dentry *const old_dentry,
  990. const struct path *const new_dir,
  991. struct dentry *const new_dentry)
  992. {
  993. return current_check_refer_path(old_dentry, new_dir, new_dentry, false,
  994. false);
  995. }
  996. static int hook_path_rename(const struct path *const old_dir,
  997. struct dentry *const old_dentry,
  998. const struct path *const new_dir,
  999. struct dentry *const new_dentry,
  1000. const unsigned int flags)
  1001. {
  1002. /* old_dir refers to old_dentry->d_parent and new_dir->mnt */
  1003. return current_check_refer_path(old_dentry, new_dir, new_dentry, true,
  1004. !!(flags & RENAME_EXCHANGE));
  1005. }
  1006. static int hook_path_mkdir(const struct path *const dir,
  1007. struct dentry *const dentry, const umode_t mode)
  1008. {
  1009. return current_check_access_path(dir, LANDLOCK_ACCESS_FS_MAKE_DIR);
  1010. }
  1011. static int hook_path_mknod(const struct path *const dir,
  1012. struct dentry *const dentry, const umode_t mode,
  1013. const unsigned int dev)
  1014. {
  1015. const struct landlock_ruleset *const dom =
  1016. landlock_get_current_domain();
  1017. if (!dom)
  1018. return 0;
  1019. return check_access_path(dom, dir, get_mode_access(mode));
  1020. }
  1021. static int hook_path_symlink(const struct path *const dir,
  1022. struct dentry *const dentry,
  1023. const char *const old_name)
  1024. {
  1025. return current_check_access_path(dir, LANDLOCK_ACCESS_FS_MAKE_SYM);
  1026. }
  1027. static int hook_path_unlink(const struct path *const dir,
  1028. struct dentry *const dentry)
  1029. {
  1030. return current_check_access_path(dir, LANDLOCK_ACCESS_FS_REMOVE_FILE);
  1031. }
  1032. static int hook_path_rmdir(const struct path *const dir,
  1033. struct dentry *const dentry)
  1034. {
  1035. return current_check_access_path(dir, LANDLOCK_ACCESS_FS_REMOVE_DIR);
  1036. }
  1037. /* File hooks */
  1038. static inline access_mask_t get_file_access(const struct file *const file)
  1039. {
  1040. access_mask_t access = 0;
  1041. if (file->f_mode & FMODE_READ) {
  1042. /* A directory can only be opened in read mode. */
  1043. if (S_ISDIR(file_inode(file)->i_mode))
  1044. return LANDLOCK_ACCESS_FS_READ_DIR;
  1045. access = LANDLOCK_ACCESS_FS_READ_FILE;
  1046. }
  1047. if (file->f_mode & FMODE_WRITE)
  1048. access |= LANDLOCK_ACCESS_FS_WRITE_FILE;
  1049. /* __FMODE_EXEC is indeed part of f_flags, not f_mode. */
  1050. if (file->f_flags & __FMODE_EXEC)
  1051. access |= LANDLOCK_ACCESS_FS_EXECUTE;
  1052. return access;
  1053. }
  1054. static int hook_file_open(struct file *const file)
  1055. {
  1056. const struct landlock_ruleset *const dom =
  1057. landlock_get_current_domain();
  1058. if (!dom)
  1059. return 0;
  1060. /*
  1061. * Because a file may be opened with O_PATH, get_file_access() may
  1062. * return 0. This case will be handled with a future Landlock
  1063. * evolution.
  1064. */
  1065. return check_access_path(dom, &file->f_path, get_file_access(file));
  1066. }
  1067. static struct security_hook_list landlock_hooks[] __lsm_ro_after_init = {
  1068. LSM_HOOK_INIT(inode_free_security, hook_inode_free_security),
  1069. LSM_HOOK_INIT(sb_delete, hook_sb_delete),
  1070. LSM_HOOK_INIT(sb_mount, hook_sb_mount),
  1071. LSM_HOOK_INIT(move_mount, hook_move_mount),
  1072. LSM_HOOK_INIT(sb_umount, hook_sb_umount),
  1073. LSM_HOOK_INIT(sb_remount, hook_sb_remount),
  1074. LSM_HOOK_INIT(sb_pivotroot, hook_sb_pivotroot),
  1075. LSM_HOOK_INIT(path_link, hook_path_link),
  1076. LSM_HOOK_INIT(path_rename, hook_path_rename),
  1077. LSM_HOOK_INIT(path_mkdir, hook_path_mkdir),
  1078. LSM_HOOK_INIT(path_mknod, hook_path_mknod),
  1079. LSM_HOOK_INIT(path_symlink, hook_path_symlink),
  1080. LSM_HOOK_INIT(path_unlink, hook_path_unlink),
  1081. LSM_HOOK_INIT(path_rmdir, hook_path_rmdir),
  1082. LSM_HOOK_INIT(file_open, hook_file_open),
  1083. };
  1084. __init void landlock_add_fs_hooks(void)
  1085. {
  1086. security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
  1087. LANDLOCK_NAME);
  1088. }