Commit 06a1c40a authored by Mickaël Salaün's avatar Mickaël Salaün

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/20220506160513.523257-3-mic@digikod.net
Cc: stable@vger.kernel.org
Signed-off-by: default avatarMickaël Salaün <mic@digikod.net>
parent 6cc2df8e
...@@ -20,8 +20,8 @@ struct landlock_cred_security { ...@@ -20,8 +20,8 @@ struct landlock_cred_security {
struct landlock_ruleset *domain; struct landlock_ruleset *domain;
}; };
static inline struct landlock_cred_security *landlock_cred( static inline struct landlock_cred_security *
const struct cred *cred) landlock_cred(const struct cred *cred)
{ {
return cred->security + landlock_blob_sizes.lbs_cred; return cred->security + landlock_blob_sizes.lbs_cred;
} }
...@@ -34,8 +34,8 @@ static inline const struct landlock_ruleset *landlock_get_current_domain(void) ...@@ -34,8 +34,8 @@ static inline const struct landlock_ruleset *landlock_get_current_domain(void)
/* /*
* The call needs to come from an RCU read-side critical section. * The call needs to come from an RCU read-side critical section.
*/ */
static inline const struct landlock_ruleset *landlock_get_task_domain( static inline const struct landlock_ruleset *
const struct task_struct *const task) landlock_get_task_domain(const struct task_struct *const task)
{ {
return landlock_cred(__task_cred(task))->domain; return landlock_cred(__task_cred(task))->domain;
} }
......
...@@ -158,8 +158,8 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset, ...@@ -158,8 +158,8 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
struct landlock_object *object; struct landlock_object *object;
/* Files only get access rights that make sense. */ /* Files only get access rights that make sense. */
if (!d_is_dir(path->dentry) && (access_rights | ACCESS_FILE) != if (!d_is_dir(path->dentry) &&
ACCESS_FILE) (access_rights | ACCESS_FILE) != ACCESS_FILE)
return -EINVAL; return -EINVAL;
if (WARN_ON_ONCE(ruleset->num_layers != 1)) if (WARN_ON_ONCE(ruleset->num_layers != 1))
return -EINVAL; return -EINVAL;
...@@ -182,10 +182,9 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset, ...@@ -182,10 +182,9 @@ int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
/* Access-control management */ /* Access-control management */
static inline u64 unmask_layers( static inline u64 unmask_layers(const struct landlock_ruleset *const domain,
const struct landlock_ruleset *const domain, const struct path *const path,
const struct path *const path, const u32 access_request, const u32 access_request, u64 layer_mask)
u64 layer_mask)
{ {
const struct landlock_rule *rule; const struct landlock_rule *rule;
const struct inode *inode; const struct inode *inode;
...@@ -196,8 +195,8 @@ static inline u64 unmask_layers( ...@@ -196,8 +195,8 @@ static inline u64 unmask_layers(
return layer_mask; return layer_mask;
inode = d_backing_inode(path->dentry); inode = d_backing_inode(path->dentry);
rcu_read_lock(); rcu_read_lock();
rule = landlock_find_rule(domain, rule = landlock_find_rule(
rcu_dereference(landlock_inode(inode)->object)); domain, rcu_dereference(landlock_inode(inode)->object));
rcu_read_unlock(); rcu_read_unlock();
if (!rule) if (!rule)
return layer_mask; return layer_mask;
...@@ -270,8 +269,8 @@ static int check_access_path(const struct landlock_ruleset *const domain, ...@@ -270,8 +269,8 @@ static int check_access_path(const struct landlock_ruleset *const domain,
while (true) { while (true) {
struct dentry *parent_dentry; struct dentry *parent_dentry;
layer_mask = unmask_layers(domain, &walker_path, layer_mask = unmask_layers(domain, &walker_path, access_request,
access_request, layer_mask); layer_mask);
if (layer_mask == 0) { if (layer_mask == 0) {
/* Stops when a rule from each layer grants access. */ /* Stops when a rule from each layer grants access. */
allowed = true; allowed = true;
...@@ -438,8 +437,8 @@ static void hook_sb_delete(struct super_block *const sb) ...@@ -438,8 +437,8 @@ static void hook_sb_delete(struct super_block *const sb)
if (prev_inode) if (prev_inode)
iput(prev_inode); iput(prev_inode);
/* Waits for pending iput() in release_inode(). */ /* Waits for pending iput() in release_inode(). */
wait_var_event(&landlock_superblock(sb)->inode_refs, !atomic_long_read( wait_var_event(&landlock_superblock(sb)->inode_refs,
&landlock_superblock(sb)->inode_refs)); !atomic_long_read(&landlock_superblock(sb)->inode_refs));
} }
/* /*
...@@ -561,7 +560,8 @@ static int hook_path_link(struct dentry *const old_dentry, ...@@ -561,7 +560,8 @@ static int hook_path_link(struct dentry *const old_dentry,
return -EXDEV; return -EXDEV;
if (unlikely(d_is_negative(old_dentry))) if (unlikely(d_is_negative(old_dentry)))
return -ENOENT; return -ENOENT;
return check_access_path(dom, new_dir, return check_access_path(
dom, new_dir,
get_mode_access(d_backing_inode(old_dentry)->i_mode)); get_mode_access(d_backing_inode(old_dentry)->i_mode));
} }
...@@ -590,8 +590,9 @@ static int hook_path_rename(const struct path *const old_dir, ...@@ -590,8 +590,9 @@ static int hook_path_rename(const struct path *const old_dir,
if (unlikely(d_is_negative(old_dentry))) if (unlikely(d_is_negative(old_dentry)))
return -ENOENT; return -ENOENT;
/* RENAME_EXCHANGE is handled because directories are the same. */ /* RENAME_EXCHANGE is handled because directories are the same. */
return check_access_path(dom, old_dir, maybe_remove(old_dentry) | return check_access_path(
maybe_remove(new_dentry) | dom, old_dir,
maybe_remove(old_dentry) | maybe_remove(new_dentry) |
get_mode_access(d_backing_inode(old_dentry)->i_mode)); get_mode_access(d_backing_inode(old_dentry)->i_mode));
} }
...@@ -614,7 +615,8 @@ static int hook_path_mknod(const struct path *const dir, ...@@ -614,7 +615,8 @@ static int hook_path_mknod(const struct path *const dir,
} }
static int hook_path_symlink(const struct path *const dir, static int hook_path_symlink(const struct path *const dir,
struct dentry *const dentry, const char *const old_name) struct dentry *const dentry,
const char *const old_name)
{ {
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_MAKE_SYM); return current_check_access_path(dir, LANDLOCK_ACCESS_FS_MAKE_SYM);
} }
......
...@@ -50,14 +50,14 @@ struct landlock_superblock_security { ...@@ -50,14 +50,14 @@ struct landlock_superblock_security {
atomic_long_t inode_refs; atomic_long_t inode_refs;
}; };
static inline struct landlock_inode_security *landlock_inode( static inline struct landlock_inode_security *
const struct inode *const inode) landlock_inode(const struct inode *const inode)
{ {
return inode->i_security + landlock_blob_sizes.lbs_inode; return inode->i_security + landlock_blob_sizes.lbs_inode;
} }
static inline struct landlock_superblock_security *landlock_superblock( static inline struct landlock_superblock_security *
const struct super_block *const superblock) landlock_superblock(const struct super_block *const superblock)
{ {
return superblock->s_security + landlock_blob_sizes.lbs_superblock; return superblock->s_security + landlock_blob_sizes.lbs_superblock;
} }
...@@ -65,6 +65,7 @@ static inline struct landlock_superblock_security *landlock_superblock( ...@@ -65,6 +65,7 @@ static inline struct landlock_superblock_security *landlock_superblock(
__init void landlock_add_fs_hooks(void); __init void landlock_add_fs_hooks(void);
int landlock_append_fs_rule(struct landlock_ruleset *const ruleset, int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
const struct path *const path, u32 access_hierarchy); const struct path *const path,
u32 access_hierarchy);
#endif /* _SECURITY_LANDLOCK_FS_H */ #endif /* _SECURITY_LANDLOCK_FS_H */
...@@ -17,8 +17,8 @@ ...@@ -17,8 +17,8 @@
#include "object.h" #include "object.h"
struct landlock_object *landlock_create_object( struct landlock_object *
const struct landlock_object_underops *const underops, landlock_create_object(const struct landlock_object_underops *const underops,
void *const underobj) void *const underobj)
{ {
struct landlock_object *new_object; struct landlock_object *new_object;
......
...@@ -76,8 +76,8 @@ struct landlock_object { ...@@ -76,8 +76,8 @@ struct landlock_object {
}; };
}; };
struct landlock_object *landlock_create_object( struct landlock_object *
const struct landlock_object_underops *const underops, landlock_create_object(const struct landlock_object_underops *const underops,
void *const underobj); void *const underobj);
void landlock_put_object(struct landlock_object *const object); void landlock_put_object(struct landlock_object *const object);
......
...@@ -28,8 +28,9 @@ static struct landlock_ruleset *create_ruleset(const u32 num_layers) ...@@ -28,8 +28,9 @@ static struct landlock_ruleset *create_ruleset(const u32 num_layers)
{ {
struct landlock_ruleset *new_ruleset; struct landlock_ruleset *new_ruleset;
new_ruleset = kzalloc(struct_size(new_ruleset, fs_access_masks, new_ruleset =
num_layers), GFP_KERNEL_ACCOUNT); kzalloc(struct_size(new_ruleset, fs_access_masks, num_layers),
GFP_KERNEL_ACCOUNT);
if (!new_ruleset) if (!new_ruleset)
return ERR_PTR(-ENOMEM); return ERR_PTR(-ENOMEM);
refcount_set(&new_ruleset->usage, 1); refcount_set(&new_ruleset->usage, 1);
...@@ -66,10 +67,9 @@ static void build_check_rule(void) ...@@ -66,10 +67,9 @@ static void build_check_rule(void)
BUILD_BUG_ON(rule.num_layers < LANDLOCK_MAX_NUM_LAYERS); BUILD_BUG_ON(rule.num_layers < LANDLOCK_MAX_NUM_LAYERS);
} }
static struct landlock_rule *create_rule( static struct landlock_rule *
struct landlock_object *const object, create_rule(struct landlock_object *const object,
const struct landlock_layer (*const layers)[], const struct landlock_layer (*const layers)[], const u32 num_layers,
const u32 num_layers,
const struct landlock_layer *const new_layer) const struct landlock_layer *const new_layer)
{ {
struct landlock_rule *new_rule; struct landlock_rule *new_rule;
...@@ -156,8 +156,8 @@ static int insert_rule(struct landlock_ruleset *const ruleset, ...@@ -156,8 +156,8 @@ static int insert_rule(struct landlock_ruleset *const ruleset,
return -ENOENT; return -ENOENT;
walker_node = &(ruleset->root.rb_node); walker_node = &(ruleset->root.rb_node);
while (*walker_node) { while (*walker_node) {
struct landlock_rule *const this = rb_entry(*walker_node, struct landlock_rule *const this =
struct landlock_rule, node); rb_entry(*walker_node, struct landlock_rule, node);
if (this->object != object) { if (this->object != object) {
parent_node = *walker_node; parent_node = *walker_node;
...@@ -230,11 +230,11 @@ static void build_check_layer(void) ...@@ -230,11 +230,11 @@ static void build_check_layer(void)
int landlock_insert_rule(struct landlock_ruleset *const ruleset, int landlock_insert_rule(struct landlock_ruleset *const ruleset,
struct landlock_object *const object, const u32 access) struct landlock_object *const object, const u32 access)
{ {
struct landlock_layer layers[] = {{ struct landlock_layer layers[] = { {
.access = access, .access = access,
/* When @level is zero, insert_rule() extends @ruleset. */ /* When @level is zero, insert_rule() extends @ruleset. */
.level = 0, .level = 0,
}}; } };
build_check_layer(); build_check_layer();
return insert_rule(ruleset, object, &layers, ARRAY_SIZE(layers)); return insert_rule(ruleset, object, &layers, ARRAY_SIZE(layers));
...@@ -282,11 +282,11 @@ static int merge_ruleset(struct landlock_ruleset *const dst, ...@@ -282,11 +282,11 @@ static int merge_ruleset(struct landlock_ruleset *const dst,
dst->fs_access_masks[dst->num_layers - 1] = src->fs_access_masks[0]; dst->fs_access_masks[dst->num_layers - 1] = src->fs_access_masks[0];
/* Merges the @src tree. */ /* Merges the @src tree. */
rbtree_postorder_for_each_entry_safe(walker_rule, next_rule, rbtree_postorder_for_each_entry_safe(walker_rule, next_rule, &src->root,
&src->root, node) { node) {
struct landlock_layer layers[] = {{ struct landlock_layer layers[] = { {
.level = dst->num_layers, .level = dst->num_layers,
}}; } };
if (WARN_ON_ONCE(walker_rule->num_layers != 1)) { if (WARN_ON_ONCE(walker_rule->num_layers != 1)) {
err = -EINVAL; err = -EINVAL;
...@@ -327,7 +327,8 @@ static int inherit_ruleset(struct landlock_ruleset *const parent, ...@@ -327,7 +327,8 @@ static int inherit_ruleset(struct landlock_ruleset *const parent,
rbtree_postorder_for_each_entry_safe(walker_rule, next_rule, rbtree_postorder_for_each_entry_safe(walker_rule, next_rule,
&parent->root, node) { &parent->root, node) {
err = insert_rule(child, walker_rule->object, err = insert_rule(child, walker_rule->object,
&walker_rule->layers, walker_rule->num_layers); &walker_rule->layers,
walker_rule->num_layers);
if (err) if (err)
goto out_unlock; goto out_unlock;
} }
...@@ -358,8 +359,7 @@ static void free_ruleset(struct landlock_ruleset *const ruleset) ...@@ -358,8 +359,7 @@ static void free_ruleset(struct landlock_ruleset *const ruleset)
struct landlock_rule *freeme, *next; struct landlock_rule *freeme, *next;
might_sleep(); might_sleep();
rbtree_postorder_for_each_entry_safe(freeme, next, &ruleset->root, rbtree_postorder_for_each_entry_safe(freeme, next, &ruleset->root, node)
node)
free_rule(freeme); free_rule(freeme);
put_hierarchy(ruleset->hierarchy); put_hierarchy(ruleset->hierarchy);
kfree(ruleset); kfree(ruleset);
...@@ -397,8 +397,8 @@ void landlock_put_ruleset_deferred(struct landlock_ruleset *const ruleset) ...@@ -397,8 +397,8 @@ void landlock_put_ruleset_deferred(struct landlock_ruleset *const ruleset)
* Returns the intersection of @parent and @ruleset, or returns @parent if * Returns the intersection of @parent and @ruleset, or returns @parent if
* @ruleset is empty, or returns a duplicate of @ruleset if @parent is empty. * @ruleset is empty, or returns a duplicate of @ruleset if @parent is empty.
*/ */
struct landlock_ruleset *landlock_merge_ruleset( struct landlock_ruleset *
struct landlock_ruleset *const parent, landlock_merge_ruleset(struct landlock_ruleset *const parent,
struct landlock_ruleset *const ruleset) struct landlock_ruleset *const ruleset)
{ {
struct landlock_ruleset *new_dom; struct landlock_ruleset *new_dom;
...@@ -421,8 +421,8 @@ struct landlock_ruleset *landlock_merge_ruleset( ...@@ -421,8 +421,8 @@ struct landlock_ruleset *landlock_merge_ruleset(
new_dom = create_ruleset(num_layers); new_dom = create_ruleset(num_layers);
if (IS_ERR(new_dom)) if (IS_ERR(new_dom))
return new_dom; return new_dom;
new_dom->hierarchy = kzalloc(sizeof(*new_dom->hierarchy), new_dom->hierarchy =
GFP_KERNEL_ACCOUNT); kzalloc(sizeof(*new_dom->hierarchy), GFP_KERNEL_ACCOUNT);
if (!new_dom->hierarchy) { if (!new_dom->hierarchy) {
err = -ENOMEM; err = -ENOMEM;
goto out_put_dom; goto out_put_dom;
...@@ -449,8 +449,8 @@ struct landlock_ruleset *landlock_merge_ruleset( ...@@ -449,8 +449,8 @@ struct landlock_ruleset *landlock_merge_ruleset(
/* /*
* The returned access has the same lifetime as @ruleset. * The returned access has the same lifetime as @ruleset.
*/ */
const struct landlock_rule *landlock_find_rule( const struct landlock_rule *
const struct landlock_ruleset *const ruleset, landlock_find_rule(const struct landlock_ruleset *const ruleset,
const struct landlock_object *const object) const struct landlock_object *const object)
{ {
const struct rb_node *node; const struct rb_node *node;
...@@ -459,8 +459,8 @@ const struct landlock_rule *landlock_find_rule( ...@@ -459,8 +459,8 @@ const struct landlock_rule *landlock_find_rule(
return NULL; return NULL;
node = ruleset->root.rb_node; node = ruleset->root.rb_node;
while (node) { while (node) {
struct landlock_rule *this = rb_entry(node, struct landlock_rule *this =
struct landlock_rule, node); rb_entry(node, struct landlock_rule, node);
if (this->object == object) if (this->object == object)
return this; return this;
......
...@@ -146,14 +146,15 @@ void landlock_put_ruleset(struct landlock_ruleset *const ruleset); ...@@ -146,14 +146,15 @@ void landlock_put_ruleset(struct landlock_ruleset *const ruleset);
void landlock_put_ruleset_deferred(struct landlock_ruleset *const ruleset); void landlock_put_ruleset_deferred(struct landlock_ruleset *const ruleset);
int landlock_insert_rule(struct landlock_ruleset *const ruleset, int landlock_insert_rule(struct landlock_ruleset *const ruleset,
struct landlock_object *const object, const u32 access); struct landlock_object *const object,
const u32 access);
struct landlock_ruleset *landlock_merge_ruleset( struct landlock_ruleset *
struct landlock_ruleset *const parent, landlock_merge_ruleset(struct landlock_ruleset *const parent,
struct landlock_ruleset *const ruleset); struct landlock_ruleset *const ruleset);
const struct landlock_rule *landlock_find_rule( const struct landlock_rule *
const struct landlock_ruleset *const ruleset, landlock_find_rule(const struct landlock_ruleset *const ruleset,
const struct landlock_object *const object); const struct landlock_object *const object);
static inline void landlock_get_ruleset(struct landlock_ruleset *const ruleset) static inline void landlock_get_ruleset(struct landlock_ruleset *const ruleset)
......
...@@ -43,9 +43,10 @@ ...@@ -43,9 +43,10 @@
* @src: User space pointer or NULL. * @src: User space pointer or NULL.
* @usize: (Alleged) size of the data pointed to by @src. * @usize: (Alleged) size of the data pointed to by @src.
*/ */
static __always_inline int copy_min_struct_from_user(void *const dst, static __always_inline int
const size_t ksize, const size_t ksize_min, copy_min_struct_from_user(void *const dst, const size_t ksize,
const void __user *const src, const size_t usize) const size_t ksize_min, const void __user *const src,
const size_t usize)
{ {
/* Checks buffer inconsistencies. */ /* Checks buffer inconsistencies. */
BUILD_BUG_ON(!dst); BUILD_BUG_ON(!dst);
...@@ -168,15 +169,16 @@ SYSCALL_DEFINE3(landlock_create_ruleset, ...@@ -168,15 +169,16 @@ SYSCALL_DEFINE3(landlock_create_ruleset,
return -EOPNOTSUPP; return -EOPNOTSUPP;
if (flags) { if (flags) {
if ((flags == LANDLOCK_CREATE_RULESET_VERSION) if ((flags == LANDLOCK_CREATE_RULESET_VERSION) && !attr &&
&& !attr && !size) !size)
return LANDLOCK_ABI_VERSION; return LANDLOCK_ABI_VERSION;
return -EINVAL; return -EINVAL;
} }
/* Copies raw user space buffer. */ /* Copies raw user space buffer. */
err = copy_min_struct_from_user(&ruleset_attr, sizeof(ruleset_attr), err = copy_min_struct_from_user(&ruleset_attr, sizeof(ruleset_attr),
offsetofend(typeof(ruleset_attr), handled_access_fs), offsetofend(typeof(ruleset_attr),
handled_access_fs),
attr, size); attr, size);
if (err) if (err)
return err; return err;
...@@ -244,8 +246,8 @@ static int get_path_from_fd(const s32 fd, struct path *const path) ...@@ -244,8 +246,8 @@ static int get_path_from_fd(const s32 fd, struct path *const path)
struct fd f; struct fd f;
int err = 0; int err = 0;
BUILD_BUG_ON(!__same_type(fd, BUILD_BUG_ON(!__same_type(
((struct landlock_path_beneath_attr *)NULL)->parent_fd)); fd, ((struct landlock_path_beneath_attr *)NULL)->parent_fd));
/* Handles O_PATH. */ /* Handles O_PATH. */
f = fdget_raw(fd); f = fdget_raw(fd);
...@@ -301,8 +303,8 @@ static int get_path_from_fd(const s32 fd, struct path *const path) ...@@ -301,8 +303,8 @@ static int get_path_from_fd(const s32 fd, struct path *const path)
* - EPERM: @ruleset_fd has no write access to the underlying ruleset; * - EPERM: @ruleset_fd has no write access to the underlying ruleset;
* - EFAULT: @rule_attr inconsistency. * - EFAULT: @rule_attr inconsistency.
*/ */
SYSCALL_DEFINE4(landlock_add_rule, SYSCALL_DEFINE4(landlock_add_rule, const int, ruleset_fd,
const int, ruleset_fd, const enum landlock_rule_type, rule_type, const enum landlock_rule_type, rule_type,
const void __user *const, rule_attr, const __u32, flags) const void __user *const, rule_attr, const __u32, flags)
{ {
struct landlock_path_beneath_attr path_beneath_attr; struct landlock_path_beneath_attr path_beneath_attr;
...@@ -389,8 +391,8 @@ SYSCALL_DEFINE4(landlock_add_rule, ...@@ -389,8 +391,8 @@ SYSCALL_DEFINE4(landlock_add_rule,
* - E2BIG: The maximum number of stacked rulesets is reached for the current * - E2BIG: The maximum number of stacked rulesets is reached for the current
* thread. * thread.
*/ */
SYSCALL_DEFINE2(landlock_restrict_self, SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32,
const int, ruleset_fd, const __u32, flags) flags)
{ {
struct landlock_ruleset *new_dom, *ruleset; struct landlock_ruleset *new_dom, *ruleset;
struct cred *new_cred; struct cred *new_cred;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment