mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2025-01-16 18:26:42 +00:00
a04a119808
Create a system call lsm_get_self_attr() to provide the security module maintained attributes of the current process. Create a system call lsm_set_self_attr() to set a security module maintained attribute of the current process. Historically these attributes have been exposed to user space via entries in procfs under /proc/self/attr. The attribute value is provided in a lsm_ctx structure. The structure identifies the size of the attribute, and the attribute value. The format of the attribute value is defined by the security module. A flags field is included for LSM specific information. It is currently unused and must be 0. The total size of the data, including the lsm_ctx structure and any padding, is maintained as well. struct lsm_ctx { __u64 id; __u64 flags; __u64 len; __u64 ctx_len; __u8 ctx[]; }; Two new LSM hooks are used to interface with the LSMs. security_getselfattr() collects the lsm_ctx values from the LSMs that support the hook, accounting for space requirements. security_setselfattr() identifies which LSM the attribute is intended for and passes it along. Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: Serge Hallyn <serge@hallyn.com> Reviewed-by: John Johansen <john.johansen@canonical.com> Signed-off-by: Paul Moore <paul@paul-moore.com>
156 lines
4.6 KiB
C
156 lines
4.6 KiB
C
/*
|
|
* Linux Security Module interfaces
|
|
*
|
|
* Copyright (C) 2001 WireX Communications, Inc <chris@wirex.com>
|
|
* Copyright (C) 2001 Greg Kroah-Hartman <greg@kroah.com>
|
|
* Copyright (C) 2001 Networks Associates Technology, Inc <ssmalley@nai.com>
|
|
* Copyright (C) 2001 James Morris <jmorris@intercode.com.au>
|
|
* Copyright (C) 2001 Silicon Graphics, Inc. (Trust Technology Group)
|
|
* Copyright (C) 2015 Intel Corporation.
|
|
* Copyright (C) 2015 Casey Schaufler <casey@schaufler-ca.com>
|
|
* Copyright (C) 2016 Mellanox Techonologies
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License as published by
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
* (at your option) any later version.
|
|
*
|
|
* Due to this file being licensed under the GPL there is controversy over
|
|
* whether this permits you to write a module that #includes this file
|
|
* without placing your module under the GPL. Please consult a lawyer for
|
|
* advice before doing this.
|
|
*
|
|
*/
|
|
|
|
#ifndef __LINUX_LSM_HOOKS_H
|
|
#define __LINUX_LSM_HOOKS_H
|
|
|
|
#include <uapi/linux/lsm.h>
|
|
#include <linux/security.h>
|
|
#include <linux/init.h>
|
|
#include <linux/rculist.h>
|
|
#include <linux/xattr.h>
|
|
|
|
union security_list_options {
|
|
#define LSM_HOOK(RET, DEFAULT, NAME, ...) RET (*NAME)(__VA_ARGS__);
|
|
#include "lsm_hook_defs.h"
|
|
#undef LSM_HOOK
|
|
};
|
|
|
|
struct security_hook_heads {
|
|
#define LSM_HOOK(RET, DEFAULT, NAME, ...) struct hlist_head NAME;
|
|
#include "lsm_hook_defs.h"
|
|
#undef LSM_HOOK
|
|
} __randomize_layout;
|
|
|
|
/**
|
|
* struct lsm_id - Identify a Linux Security Module.
|
|
* @lsm: name of the LSM, must be approved by the LSM maintainers
|
|
* @id: LSM ID number from uapi/linux/lsm.h
|
|
*
|
|
* Contains the information that identifies the LSM.
|
|
*/
|
|
struct lsm_id {
|
|
const char *name;
|
|
u64 id;
|
|
};
|
|
|
|
/*
|
|
* Security module hook list structure.
|
|
* For use with generic list macros for common operations.
|
|
*/
|
|
struct security_hook_list {
|
|
struct hlist_node list;
|
|
struct hlist_head *head;
|
|
union security_list_options hook;
|
|
const struct lsm_id *lsmid;
|
|
} __randomize_layout;
|
|
|
|
/*
|
|
* Security blob size or offset data.
|
|
*/
|
|
struct lsm_blob_sizes {
|
|
int lbs_cred;
|
|
int lbs_file;
|
|
int lbs_inode;
|
|
int lbs_superblock;
|
|
int lbs_ipc;
|
|
int lbs_msg_msg;
|
|
int lbs_task;
|
|
int lbs_xattr_count; /* number of xattr slots in new_xattrs array */
|
|
};
|
|
|
|
/**
|
|
* lsm_get_xattr_slot - Return the next available slot and increment the index
|
|
* @xattrs: array storing LSM-provided xattrs
|
|
* @xattr_count: number of already stored xattrs (updated)
|
|
*
|
|
* Retrieve the first available slot in the @xattrs array to fill with an xattr,
|
|
* and increment @xattr_count.
|
|
*
|
|
* Return: The slot to fill in @xattrs if non-NULL, NULL otherwise.
|
|
*/
|
|
static inline struct xattr *lsm_get_xattr_slot(struct xattr *xattrs,
|
|
int *xattr_count)
|
|
{
|
|
if (unlikely(!xattrs))
|
|
return NULL;
|
|
return &xattrs[(*xattr_count)++];
|
|
}
|
|
|
|
/*
|
|
* LSM_RET_VOID is used as the default value in LSM_HOOK definitions for void
|
|
* LSM hooks (in include/linux/lsm_hook_defs.h).
|
|
*/
|
|
#define LSM_RET_VOID ((void) 0)
|
|
|
|
/*
|
|
* Initializing a security_hook_list structure takes
|
|
* up a lot of space in a source file. This macro takes
|
|
* care of the common case and reduces the amount of
|
|
* text involved.
|
|
*/
|
|
#define LSM_HOOK_INIT(HEAD, HOOK) \
|
|
{ .head = &security_hook_heads.HEAD, .hook = { .HEAD = HOOK } }
|
|
|
|
extern struct security_hook_heads security_hook_heads;
|
|
extern char *lsm_names;
|
|
|
|
extern void security_add_hooks(struct security_hook_list *hooks, int count,
|
|
const struct lsm_id *lsmid);
|
|
|
|
#define LSM_FLAG_LEGACY_MAJOR BIT(0)
|
|
#define LSM_FLAG_EXCLUSIVE BIT(1)
|
|
|
|
enum lsm_order {
|
|
LSM_ORDER_FIRST = -1, /* This is only for capabilities. */
|
|
LSM_ORDER_MUTABLE = 0,
|
|
LSM_ORDER_LAST = 1, /* This is only for integrity. */
|
|
};
|
|
|
|
struct lsm_info {
|
|
const char *name; /* Required. */
|
|
enum lsm_order order; /* Optional: default is LSM_ORDER_MUTABLE */
|
|
unsigned long flags; /* Optional: flags describing LSM */
|
|
int *enabled; /* Optional: controlled by CONFIG_LSM */
|
|
int (*init)(void); /* Required. */
|
|
struct lsm_blob_sizes *blobs; /* Optional: for blob sharing. */
|
|
};
|
|
|
|
extern struct lsm_info __start_lsm_info[], __end_lsm_info[];
|
|
extern struct lsm_info __start_early_lsm_info[], __end_early_lsm_info[];
|
|
|
|
#define DEFINE_LSM(lsm) \
|
|
static struct lsm_info __lsm_##lsm \
|
|
__used __section(".lsm_info.init") \
|
|
__aligned(sizeof(unsigned long))
|
|
|
|
#define DEFINE_EARLY_LSM(lsm) \
|
|
static struct lsm_info __early_lsm_##lsm \
|
|
__used __section(".early_lsm_info.init") \
|
|
__aligned(sizeof(unsigned long))
|
|
|
|
extern int lsm_inode_alloc(struct inode *inode);
|
|
|
|
#endif /* ! __LINUX_LSM_HOOKS_H */
|