Skip to content

Commit

Permalink
landlock: Format with clang-format
Browse files Browse the repository at this point in the history
commit 06a1c40 upstream.

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: Mickaël Salaün <mic@digikod.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
l0kod authored and gregkh committed Jun 9, 2022
1 parent ac09fcf commit 522ac03
Show file tree
Hide file tree
Showing 10 changed files with 142 additions and 136 deletions.
4 changes: 2 additions & 2 deletions security/landlock/cred.c
Expand Up @@ -15,7 +15,7 @@
#include "setup.h"

static int hook_cred_prepare(struct cred *const new,
const struct cred *const old, const gfp_t gfp)
const struct cred *const old, const gfp_t gfp)
{
struct landlock_ruleset *const old_dom = landlock_cred(old)->domain;

Expand All @@ -42,5 +42,5 @@ static struct security_hook_list landlock_hooks[] __lsm_ro_after_init = {
__init void landlock_add_cred_hooks(void)
{
security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
LANDLOCK_NAME);
LANDLOCK_NAME);
}
8 changes: 4 additions & 4 deletions security/landlock/cred.h
Expand Up @@ -20,8 +20,8 @@ struct landlock_cred_security {
struct landlock_ruleset *domain;
};

static inline struct landlock_cred_security *landlock_cred(
const struct cred *cred)
static inline struct landlock_cred_security *
landlock_cred(const struct cred *cred)
{
return cred->security + landlock_blob_sizes.lbs_cred;
}
Expand All @@ -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.
*/
static inline const struct landlock_ruleset *landlock_get_task_domain(
const struct task_struct *const task)
static inline const struct landlock_ruleset *
landlock_get_task_domain(const struct task_struct *const task)
{
return landlock_cred(__task_cred(task))->domain;
}
Expand Down
78 changes: 40 additions & 38 deletions security/landlock/fs.c
Expand Up @@ -152,14 +152,14 @@ static struct landlock_object *get_inode_object(struct inode *const inode)
* @path: Should have been checked by get_path_from_fd().
*/
int landlock_append_fs_rule(struct landlock_ruleset *const ruleset,
const struct path *const path, u32 access_rights)
const struct path *const path, u32 access_rights)
{
int err;
struct landlock_object *object;

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

/* Access-control management */

static inline u64 unmask_layers(
const struct landlock_ruleset *const domain,
const struct path *const path, const u32 access_request,
u64 layer_mask)
static inline u64 unmask_layers(const struct landlock_ruleset *const domain,
const struct path *const path,
const u32 access_request, u64 layer_mask)
{
const struct landlock_rule *rule;
const struct inode *inode;
Expand All @@ -196,8 +195,8 @@ static inline u64 unmask_layers(
return layer_mask;
inode = d_backing_inode(path->dentry);
rcu_read_lock();
rule = landlock_find_rule(domain,
rcu_dereference(landlock_inode(inode)->object));
rule = landlock_find_rule(
domain, rcu_dereference(landlock_inode(inode)->object));
rcu_read_unlock();
if (!rule)
return layer_mask;
Expand Down Expand Up @@ -225,7 +224,7 @@ static inline u64 unmask_layers(
}

static int check_access_path(const struct landlock_ruleset *const domain,
const struct path *const path, u32 access_request)
const struct path *const path, u32 access_request)
{
bool allowed = false;
struct path walker_path;
Expand All @@ -245,8 +244,8 @@ static int check_access_path(const struct landlock_ruleset *const domain,
* /proc/<pid>/fd/<file-descriptor> .
*/
if ((path->dentry->d_sb->s_flags & SB_NOUSER) ||
(d_is_positive(path->dentry) &&
unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))))
(d_is_positive(path->dentry) &&
unlikely(IS_PRIVATE(d_backing_inode(path->dentry)))))
return 0;
if (WARN_ON_ONCE(domain->num_layers < 1))
return -EACCES;
Expand All @@ -270,8 +269,8 @@ static int check_access_path(const struct landlock_ruleset *const domain,
while (true) {
struct dentry *parent_dentry;

layer_mask = unmask_layers(domain, &walker_path,
access_request, layer_mask);
layer_mask = unmask_layers(domain, &walker_path, access_request,
layer_mask);
if (layer_mask == 0) {
/* Stops when a rule from each layer grants access. */
allowed = true;
Expand Down Expand Up @@ -310,7 +309,7 @@ static int check_access_path(const struct landlock_ruleset *const domain,
}

static inline int current_check_access_path(const struct path *const path,
const u32 access_request)
const u32 access_request)
{
const struct landlock_ruleset *const dom =
landlock_get_current_domain();
Expand Down Expand Up @@ -438,8 +437,8 @@ static void hook_sb_delete(struct super_block *const sb)
if (prev_inode)
iput(prev_inode);
/* Waits for pending iput() in release_inode(). */
wait_var_event(&landlock_superblock(sb)->inode_refs, !atomic_long_read(
&landlock_superblock(sb)->inode_refs));
wait_var_event(&landlock_superblock(sb)->inode_refs,
!atomic_long_read(&landlock_superblock(sb)->inode_refs));
}

/*
Expand All @@ -461,16 +460,16 @@ static void hook_sb_delete(struct super_block *const sb)
* a dedicated user space option would be required (e.g. as a ruleset flag).
*/
static int hook_sb_mount(const char *const dev_name,
const struct path *const path, const char *const type,
const unsigned long flags, void *const data)
const struct path *const path, const char *const type,
const unsigned long flags, void *const data)
{
if (!landlock_get_current_domain())
return 0;
return -EPERM;
}

static int hook_move_mount(const struct path *const from_path,
const struct path *const to_path)
const struct path *const to_path)
{
if (!landlock_get_current_domain())
return 0;
Expand Down Expand Up @@ -504,7 +503,7 @@ static int hook_sb_remount(struct super_block *const sb, void *const mnt_opts)
* view of the filesystem.
*/
static int hook_sb_pivotroot(const struct path *const old_path,
const struct path *const new_path)
const struct path *const new_path)
{
if (!landlock_get_current_domain())
return 0;
Expand Down Expand Up @@ -547,8 +546,8 @@ static inline u32 get_mode_access(const umode_t mode)
* deal with that.
*/
static int hook_path_link(struct dentry *const old_dentry,
const struct path *const new_dir,
struct dentry *const new_dentry)
const struct path *const new_dir,
struct dentry *const new_dentry)
{
const struct landlock_ruleset *const dom =
landlock_get_current_domain();
Expand All @@ -561,22 +560,23 @@ static int hook_path_link(struct dentry *const old_dentry,
return -EXDEV;
if (unlikely(d_is_negative(old_dentry)))
return -ENOENT;
return check_access_path(dom, new_dir,
get_mode_access(d_backing_inode(old_dentry)->i_mode));
return check_access_path(
dom, new_dir,
get_mode_access(d_backing_inode(old_dentry)->i_mode));
}

static inline u32 maybe_remove(const struct dentry *const dentry)
{
if (d_is_negative(dentry))
return 0;
return d_is_dir(dentry) ? LANDLOCK_ACCESS_FS_REMOVE_DIR :
LANDLOCK_ACCESS_FS_REMOVE_FILE;
LANDLOCK_ACCESS_FS_REMOVE_FILE;
}

static int hook_path_rename(const struct path *const old_dir,
struct dentry *const old_dentry,
const struct path *const new_dir,
struct dentry *const new_dentry)
struct dentry *const old_dentry,
const struct path *const new_dir,
struct dentry *const new_dentry)
{
const struct landlock_ruleset *const dom =
landlock_get_current_domain();
Expand All @@ -590,20 +590,21 @@ static int hook_path_rename(const struct path *const old_dir,
if (unlikely(d_is_negative(old_dentry)))
return -ENOENT;
/* RENAME_EXCHANGE is handled because directories are the same. */
return check_access_path(dom, old_dir, maybe_remove(old_dentry) |
maybe_remove(new_dentry) |
return check_access_path(
dom, old_dir,
maybe_remove(old_dentry) | maybe_remove(new_dentry) |
get_mode_access(d_backing_inode(old_dentry)->i_mode));
}

static int hook_path_mkdir(const struct path *const dir,
struct dentry *const dentry, const umode_t mode)
struct dentry *const dentry, const umode_t mode)
{
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_MAKE_DIR);
}

static int hook_path_mknod(const struct path *const dir,
struct dentry *const dentry, const umode_t mode,
const unsigned int dev)
struct dentry *const dentry, const umode_t mode,
const unsigned int dev)
{
const struct landlock_ruleset *const dom =
landlock_get_current_domain();
Expand All @@ -614,19 +615,20 @@ static int hook_path_mknod(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);
}

static int hook_path_unlink(const struct path *const dir,
struct dentry *const dentry)
struct dentry *const dentry)
{
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_REMOVE_FILE);
}

static int hook_path_rmdir(const struct path *const dir,
struct dentry *const dentry)
struct dentry *const dentry)
{
return current_check_access_path(dir, LANDLOCK_ACCESS_FS_REMOVE_DIR);
}
Expand Down Expand Up @@ -690,5 +692,5 @@ static struct security_hook_list landlock_hooks[] __lsm_ro_after_init = {
__init void landlock_add_fs_hooks(void)
{
security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
LANDLOCK_NAME);
LANDLOCK_NAME);
}
11 changes: 6 additions & 5 deletions security/landlock/fs.h
Expand Up @@ -50,21 +50,22 @@ struct landlock_superblock_security {
atomic_long_t inode_refs;
};

static inline struct landlock_inode_security *landlock_inode(
const struct inode *const inode)
static inline struct landlock_inode_security *
landlock_inode(const struct inode *const inode)
{
return inode->i_security + landlock_blob_sizes.lbs_inode;
}

static inline struct landlock_superblock_security *landlock_superblock(
const struct super_block *const superblock)
static inline struct landlock_superblock_security *
landlock_superblock(const struct super_block *const superblock)
{
return superblock->s_security + landlock_blob_sizes.lbs_superblock;
}

__init void landlock_add_fs_hooks(void);

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 */
6 changes: 3 additions & 3 deletions security/landlock/object.c
Expand Up @@ -17,9 +17,9 @@

#include "object.h"

struct landlock_object *landlock_create_object(
const struct landlock_object_underops *const underops,
void *const underobj)
struct landlock_object *
landlock_create_object(const struct landlock_object_underops *const underops,
void *const underobj)
{
struct landlock_object *new_object;

Expand Down
6 changes: 3 additions & 3 deletions security/landlock/object.h
Expand Up @@ -76,9 +76,9 @@ struct landlock_object {
};
};

struct landlock_object *landlock_create_object(
const struct landlock_object_underops *const underops,
void *const underobj);
struct landlock_object *
landlock_create_object(const struct landlock_object_underops *const underops,
void *const underobj);

void landlock_put_object(struct landlock_object *const object);

Expand Down
10 changes: 5 additions & 5 deletions security/landlock/ptrace.c
Expand Up @@ -30,7 +30,7 @@
* means a subset of) the @child domain.
*/
static bool domain_scope_le(const struct landlock_ruleset *const parent,
const struct landlock_ruleset *const child)
const struct landlock_ruleset *const child)
{
const struct landlock_hierarchy *walker;

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

static bool task_is_scoped(const struct task_struct *const parent,
const struct task_struct *const child)
const struct task_struct *const child)
{
bool is_scoped;
const struct landlock_ruleset *dom_parent, *dom_child;
Expand All @@ -62,7 +62,7 @@ static bool task_is_scoped(const struct task_struct *const parent,
}

static int task_ptrace(const struct task_struct *const parent,
const struct task_struct *const child)
const struct task_struct *const child)
{
/* Quick return for non-landlocked tasks. */
if (!landlocked(parent))
Expand All @@ -86,7 +86,7 @@ static int task_ptrace(const struct task_struct *const parent,
* granted, -errno if denied.
*/
static int hook_ptrace_access_check(struct task_struct *const child,
const unsigned int mode)
const unsigned int mode)
{
return task_ptrace(current, child);
}
Expand Down Expand Up @@ -116,5 +116,5 @@ static struct security_hook_list landlock_hooks[] __lsm_ro_after_init = {
__init void landlock_add_ptrace_hooks(void)
{
security_add_hooks(landlock_hooks, ARRAY_SIZE(landlock_hooks),
LANDLOCK_NAME);
LANDLOCK_NAME);
}

0 comments on commit 522ac03

Please sign in to comment.