Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 06a1c40

Browse files
committed
landlock: Format with clang-format
Let's follow a consistent and documented coding style. Everything may not be to our liking but it is better than tacit knowledge. Moreover, this will help maintain style consistency between different developers. This contains only whitespace changes. Automatically formatted with: clang-format-14 -i security/landlock/*.[ch] include/uapi/linux/landlock.h Link: https://lore.kernel.org/r/[email protected] Cc: [email protected] Signed-off-by: Mickaël Salaün <[email protected]>
1 parent 6cc2df8 commit 06a1c40

File tree

10 files changed

+142
-136
lines changed

10 files changed

+142
-136
lines changed

security/landlock/cred.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include "setup.h"
1616

1717
static int hook_cred_prepare(struct cred *const new,
18-
const struct cred *const old, const gfp_t gfp)
18+
const struct cred *const old, const gfp_t gfp)
1919
{
2020
struct landlock_ruleset *const old_dom = landlock_cred(old)->domain;
2121

@@ -42,5 +42,5 @@ static struct security_hook_list landlock_hooks[] __lsm_ro_after_init = {
4242
__init void landlock_add_cred_hooks(void)
4343
{
4444
security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
45-
LANDLOCK_NAME);
45+
LANDLOCK_NAME);
4646
}

security/landlock/cred.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ struct landlock_cred_security {
2020
struct landlock_ruleset *domain;
2121
};
2222

23-
static inline struct landlock_cred_security *landlock_cred(
24-
const struct cred *cred)
23+
static inline struct landlock_cred_security *
24+
landlock_cred(const struct cred *cred)
2525
{
2626
return cred->security + landlock_blob_sizes.lbs_cred;
2727
}
@@ -34,8 +34,8 @@ static inline const struct landlock_ruleset *landlock_get_current_domain(void)
3434
/*
3535
* The call needs to come from an RCU read-side critical section.
3636
*/
37-
static inline const struct landlock_ruleset *landlock_get_task_domain(
38-
const struct task_struct *const task)
37+
static inline const struct landlock_ruleset *
38+
landlock_get_task_domain(const struct task_struct *const task)
3939
{
4040
return landlock_cred(__task_cred(task))->domain;
4141
}

security/landlock/fs.c

Lines changed: 40 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ static struct landlock_object *get_inode_object(struct inode *const inode)
152152
* @path: Should have been checked by get_path_from_fd().
153153
*/
154154
int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
155-
const struct path *const path, u32 access_rights)
155+
const struct path *const path, u32 access_rights)
156156
{
157157
int err;
158158
struct landlock_object *object;
159159

160160
/* Files only get access rights that make sense. */
161-
if (!d_is_dir(path->dentry) && (access_rights | ACCESS_FILE) !=
162-
ACCESS_FILE)
161+
if (!d_is_dir(path->dentry) &&
162+
(access_rights | ACCESS_FILE) != ACCESS_FILE)
163163
return -EINVAL;
164164
if (WARN_ON_ONCE(ruleset->num_layers != 1))
165165
return -EINVAL;
@@ -182,10 +182,9 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
182182

183183
/* Access-control management */
184184

185-
static inline u64 unmask_layers(
186-
const struct landlock_ruleset *const domain,
187-
const struct path *const path, const u32 access_request,
188-
u64 layer_mask)
185+
static inline u64 unmask_layers(const struct landlock_ruleset *const domain,
186+
const struct path *const path,
187+
const u32 access_request, u64 layer_mask)
189188
{
190189
const struct landlock_rule *rule;
191190
const struct inode *inode;
@@ -196,8 +195,8 @@ static inline u64 unmask_layers(
196195
return layer_mask;
197196
inode = d_backing_inode(path->dentry);
198197
rcu_read_lock();
199-
rule = landlock_find_rule(domain,
200-
rcu_dereference(landlock_inode(inode)->object));
198+
rule = landlock_find_rule(
199+
domain, rcu_dereference(landlock_inode(inode)->object));
201200
rcu_read_unlock();
202201
if (!rule)
203202
return layer_mask;
@@ -225,7 +224,7 @@ static inline u64 unmask_layers(
225224
}
226225

227226
static int check_access_path(const struct landlock_ruleset *const domain,
228-
const struct path *const path, u32 access_request)
227+
const struct path *const path, u32 access_request)
229228
{
230229
bool allowed = false;
231230
struct path walker_path;
@@ -245,8 +244,8 @@ static int check_access_path(const struct landlock_ruleset *const domain,
245244
* /proc/<pid>/fd/<file-descriptor> .
246245
*/
247246
if ((path->dentry->d_sb->s_flags & SB_NOUSER) ||
248-
(d_is_positive(path->dentry) &&
249-
unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))))
247+
(d_is_positive(path->dentry) &&
248+
unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))))
250249
return 0;
251250
if (WARN_ON_ONCE(domain->num_layers < 1))
252251
return -EACCES;
@@ -270,8 +269,8 @@ static int check_access_path(const struct landlock_ruleset *const domain,
270269
while (true) {
271270
struct dentry *parent_dentry;
272271

273-
layer_mask = unmask_layers(domain, &walker_path,
274-
access_request, layer_mask);
272+
layer_mask = unmask_layers(domain, &walker_path, access_request,
273+
layer_mask);
275274
if (layer_mask == 0) {
276275
/* Stops when a rule from each layer grants access. */
277276
allowed = true;
@@ -310,7 +309,7 @@ static int check_access_path(const struct landlock_ruleset *const domain,
310309
}
311310

312311
static inline int current_check_access_path(const struct path *const path,
313-
const u32 access_request)
312+
const u32 access_request)
314313
{
315314
const struct landlock_ruleset *const dom =
316315
landlock_get_current_domain();
@@ -438,8 +437,8 @@ static void hook_sb_delete(struct super_block *const sb)
438437
if (prev_inode)
439438
iput(prev_inode);
440439
/* Waits for pending iput() in release_inode(). */
441-
wait_var_event(&landlock_superblock(sb)->inode_refs, !atomic_long_read(
442-
&landlock_superblock(sb)->inode_refs));
440+
wait_var_event(&landlock_superblock(sb)->inode_refs,
441+
!atomic_long_read(&landlock_superblock(sb)->inode_refs));
443442
}
444443

445444
/*
@@ -461,16 +460,16 @@ static void hook_sb_delete(struct super_block *const sb)
461460
* a dedicated user space option would be required (e.g. as a ruleset flag).
462461
*/
463462
static int hook_sb_mount(const char *const dev_name,
464-
const struct path *const path, const char *const type,
465-
const unsigned long flags, void *const data)
463+
const struct path *const path, const char *const type,
464+
const unsigned long flags, void *const data)
466465
{
467466
if (!landlock_get_current_domain())
468467
return 0;
469468
return -EPERM;
470469
}
471470

472471
static int hook_move_mount(const struct path *const from_path,
473-
const struct path *const to_path)
472+
const struct path *const to_path)
474473
{
475474
if (!landlock_get_current_domain())
476475
return 0;
@@ -504,7 +503,7 @@ static int hook_sb_remount(struct super_block *const sb, void *const mnt_opts)
504503
* view of the filesystem.
505504
*/
506505
static int hook_sb_pivotroot(const struct path *const old_path,
507-
const struct path *const new_path)
506+
const struct path *const new_path)
508507
{
509508
if (!landlock_get_current_domain())
510509
return 0;
@@ -547,8 +546,8 @@ static inline u32 get_mode_access(const umode_t mode)
547546
* deal with that.
548547
*/
549548
static int hook_path_link(struct dentry *const old_dentry,
550-
const struct path *const new_dir,
551-
struct dentry *const new_dentry)
549+
const struct path *const new_dir,
550+
struct dentry *const new_dentry)
552551
{
553552
const struct landlock_ruleset *const dom =
554553
landlock_get_current_domain();
@@ -561,22 +560,23 @@ static int hook_path_link(struct dentry *const old_dentry,
561560
return -EXDEV;
562561
if (unlikely(d_is_negative(old_dentry)))
563562
return -ENOENT;
564-
return check_access_path(dom, new_dir,
565-
get_mode_access(d_backing_inode(old_dentry)->i_mode));
563+
return check_access_path(
564+
dom, new_dir,
565+
get_mode_access(d_backing_inode(old_dentry)->i_mode));
566566
}
567567

568568
static inline u32 maybe_remove(const struct dentry *const dentry)
569569
{
570570
if (d_is_negative(dentry))
571571
return 0;
572572
return d_is_dir(dentry) ? LANDLOCK_ACCESS_FS_REMOVE_DIR :
573-
LANDLOCK_ACCESS_FS_REMOVE_FILE;
573+
LANDLOCK_ACCESS_FS_REMOVE_FILE;
574574
}
575575

576576
static int hook_path_rename(const struct path *const old_dir,
577-
struct dentry *const old_dentry,
578-
const struct path *const new_dir,
579-
struct dentry *const new_dentry)
577+
struct dentry *const old_dentry,
578+
const struct path *const new_dir,
579+
struct dentry *const new_dentry)
580580
{
581581
const struct landlock_ruleset *const dom =
582582
landlock_get_current_domain();
@@ -590,20 +590,21 @@ static int hook_path_rename(const struct path *const old_dir,
590590
if (unlikely(d_is_negative(old_dentry)))
591591
return -ENOENT;
592592
/* RENAME_EXCHANGE is handled because directories are the same. */
593-
return check_access_path(dom, old_dir, maybe_remove(old_dentry) |
594-
maybe_remove(new_dentry) |
593+
return check_access_path(
594+
dom, old_dir,
595+
maybe_remove(old_dentry) | maybe_remove(new_dentry) |
595596
get_mode_access(d_backing_inode(old_dentry)->i_mode));
596597
}
597598

598599
static int hook_path_mkdir(const struct path *const dir,
599-
struct dentry *const dentry, const umode_t mode)
600+
struct dentry *const dentry, const umode_t mode)
600601
{
601602
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_MAKE_DIR);
602603
}
603604

604605
static int hook_path_mknod(const struct path *const dir,
605-
struct dentry *const dentry, const umode_t mode,
606-
const unsigned int dev)
606+
struct dentry *const dentry, const umode_t mode,
607+
const unsigned int dev)
607608
{
608609
const struct landlock_ruleset *const dom =
609610
landlock_get_current_domain();
@@ -614,19 +615,20 @@ static int hook_path_mknod(const struct path *const dir,
614615
}
615616

616617
static int hook_path_symlink(const struct path *const dir,
617-
struct dentry *const dentry, const char *const old_name)
618+
struct dentry *const dentry,
619+
const char *const old_name)
618620
{
619621
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_MAKE_SYM);
620622
}
621623

622624
static int hook_path_unlink(const struct path *const dir,
623-
struct dentry *const dentry)
625+
struct dentry *const dentry)
624626
{
625627
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_REMOVE_FILE);
626628
}
627629

628630
static int hook_path_rmdir(const struct path *const dir,
629-
struct dentry *const dentry)
631+
struct dentry *const dentry)
630632
{
631633
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_REMOVE_DIR);
632634
}
@@ -690,5 +692,5 @@ static struct security_hook_list landlock_hooks[] __lsm_ro_after_init = {
690692
__init void landlock_add_fs_hooks(void)
691693
{
692694
security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
693-
LANDLOCK_NAME);
695+
LANDLOCK_NAME);
694696
}

security/landlock/fs.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,21 +50,22 @@ struct landlock_superblock_security {
5050
atomic_long_t inode_refs;
5151
};
5252

53-
static inline struct landlock_inode_security *landlock_inode(
54-
const struct inode *const inode)
53+
static inline struct landlock_inode_security *
54+
landlock_inode(const struct inode *const inode)
5555
{
5656
return inode->i_security + landlock_blob_sizes.lbs_inode;
5757
}
5858

59-
static inline struct landlock_superblock_security *landlock_superblock(
60-
const struct super_block *const superblock)
59+
static inline struct landlock_superblock_security *
60+
landlock_superblock(const struct super_block *const superblock)
6161
{
6262
return superblock->s_security + landlock_blob_sizes.lbs_superblock;
6363
}
6464

6565
__init void landlock_add_fs_hooks(void);
6666

6767
int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
68-
const struct path *const path, u32 access_hierarchy);
68+
const struct path *const path,
69+
u32 access_hierarchy);
6970

7071
#endif /* _SECURITY_LANDLOCK_FS_H */

security/landlock/object.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@
1717

1818
#include "object.h"
1919

20-
struct landlock_object *landlock_create_object(
21-
const struct landlock_object_underops *const underops,
22-
void *const underobj)
20+
struct landlock_object *
21+
landlock_create_object(const struct landlock_object_underops *const underops,
22+
void *const underobj)
2323
{
2424
struct landlock_object *new_object;
2525

security/landlock/object.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,9 @@ struct landlock_object {
7676
};
7777
};
7878

79-
struct landlock_object *landlock_create_object(
80-
const struct landlock_object_underops *const underops,
81-
void *const underobj);
79+
struct landlock_object *
80+
landlock_create_object(const struct landlock_object_underops *const underops,
81+
void *const underobj);
8282

8383
void landlock_put_object(struct landlock_object *const object);
8484

security/landlock/ptrace.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
* means a subset of) the @child domain.
3131
*/
3232
static bool domain_scope_le(const struct landlock_ruleset *const parent,
33-
const struct landlock_ruleset *const child)
33+
const struct landlock_ruleset *const child)
3434
{
3535
const struct landlock_hierarchy *walker;
3636

@@ -48,7 +48,7 @@ static bool domain_scope_le(const struct landlock_ruleset *const parent,
4848
}
4949

5050
static bool task_is_scoped(const struct task_struct *const parent,
51-
const struct task_struct *const child)
51+
const struct task_struct *const child)
5252
{
5353
bool is_scoped;
5454
const struct landlock_ruleset *dom_parent, *dom_child;
@@ -62,7 +62,7 @@ static bool task_is_scoped(const struct task_struct *const parent,
6262
}
6363

6464
static int task_ptrace(const struct task_struct *const parent,
65-
const struct task_struct *const child)
65+
const struct task_struct *const child)
6666
{
6767
/* Quick return for non-landlocked tasks. */
6868
if (!landlocked(parent))
@@ -86,7 +86,7 @@ static int task_ptrace(const struct task_struct *const parent,
8686
* granted, -errno if denied.
8787
*/
8888
static int hook_ptrace_access_check(struct task_struct *const child,
89-
const unsigned int mode)
89+
const unsigned int mode)
9090
{
9191
return task_ptrace(current, child);
9292
}
@@ -116,5 +116,5 @@ static struct security_hook_list landlock_hooks[] __lsm_ro_after_init = {
116116
__init void landlock_add_ptrace_hooks(void)
117117
{
118118
security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
119-
LANDLOCK_NAME);
119+
LANDLOCK_NAME);
120120
}

0 commit comments

Comments
 (0)