mirror of
https://github.com/torvalds/linux.git
synced 2024-11-21 19:46:16 +00:00
lsm: infrastructure management of the sock security
Move management of the sock->sk_security blob out of the individual security modules and into the security infrastructure. Instead of allocating the blobs from within the modules the modules tell the infrastructure how much space is required, and the space is allocated there. Acked-by: Paul Moore <paul@paul-moore.com> Reviewed-by: Kees Cook <keescook@chromium.org> Reviewed-by: John Johansen <john.johansen@canonical.com> Acked-by: Stephen Smalley <stephen.smalley.work@gmail.com> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com> [PM: subject tweak] Signed-off-by: Paul Moore <paul@paul-moore.com>
This commit is contained in:
parent
8400291e28
commit
2aff9d20d5
@ -73,6 +73,7 @@ struct lsm_blob_sizes {
|
|||||||
int lbs_cred;
|
int lbs_cred;
|
||||||
int lbs_file;
|
int lbs_file;
|
||||||
int lbs_inode;
|
int lbs_inode;
|
||||||
|
int lbs_sock;
|
||||||
int lbs_superblock;
|
int lbs_superblock;
|
||||||
int lbs_ipc;
|
int lbs_ipc;
|
||||||
int lbs_msg_msg;
|
int lbs_msg_msg;
|
||||||
|
@ -51,10 +51,9 @@ struct aa_sk_ctx {
|
|||||||
struct aa_label *peer;
|
struct aa_label *peer;
|
||||||
};
|
};
|
||||||
|
|
||||||
#define SK_CTX(X) ((X)->sk_security)
|
|
||||||
static inline struct aa_sk_ctx *aa_sock(const struct sock *sk)
|
static inline struct aa_sk_ctx *aa_sock(const struct sock *sk)
|
||||||
{
|
{
|
||||||
return sk->sk_security;
|
return sk->sk_security + apparmor_blob_sizes.lbs_sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P) \
|
#define DEFINE_AUDIT_NET(NAME, OP, SK, F, T, P) \
|
||||||
|
@ -1058,27 +1058,12 @@ static int apparmor_userns_create(const struct cred *cred)
|
|||||||
return error;
|
return error;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int apparmor_sk_alloc_security(struct sock *sk, int family, gfp_t flags)
|
|
||||||
{
|
|
||||||
struct aa_sk_ctx *ctx;
|
|
||||||
|
|
||||||
ctx = kzalloc(sizeof(*ctx), flags);
|
|
||||||
if (!ctx)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
sk->sk_security = ctx;
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static void apparmor_sk_free_security(struct sock *sk)
|
static void apparmor_sk_free_security(struct sock *sk)
|
||||||
{
|
{
|
||||||
struct aa_sk_ctx *ctx = aa_sock(sk);
|
struct aa_sk_ctx *ctx = aa_sock(sk);
|
||||||
|
|
||||||
sk->sk_security = NULL;
|
|
||||||
aa_put_label(ctx->label);
|
aa_put_label(ctx->label);
|
||||||
aa_put_label(ctx->peer);
|
aa_put_label(ctx->peer);
|
||||||
kfree(ctx);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -1433,6 +1418,7 @@ struct lsm_blob_sizes apparmor_blob_sizes __ro_after_init = {
|
|||||||
.lbs_cred = sizeof(struct aa_label *),
|
.lbs_cred = sizeof(struct aa_label *),
|
||||||
.lbs_file = sizeof(struct aa_file_ctx),
|
.lbs_file = sizeof(struct aa_file_ctx),
|
||||||
.lbs_task = sizeof(struct aa_task_ctx),
|
.lbs_task = sizeof(struct aa_task_ctx),
|
||||||
|
.lbs_sock = sizeof(struct aa_sk_ctx),
|
||||||
};
|
};
|
||||||
|
|
||||||
static const struct lsm_id apparmor_lsmid = {
|
static const struct lsm_id apparmor_lsmid = {
|
||||||
@ -1478,7 +1464,6 @@ static struct security_hook_list apparmor_hooks[] __ro_after_init = {
|
|||||||
LSM_HOOK_INIT(getprocattr, apparmor_getprocattr),
|
LSM_HOOK_INIT(getprocattr, apparmor_getprocattr),
|
||||||
LSM_HOOK_INIT(setprocattr, apparmor_setprocattr),
|
LSM_HOOK_INIT(setprocattr, apparmor_setprocattr),
|
||||||
|
|
||||||
LSM_HOOK_INIT(sk_alloc_security, apparmor_sk_alloc_security),
|
|
||||||
LSM_HOOK_INIT(sk_free_security, apparmor_sk_free_security),
|
LSM_HOOK_INIT(sk_free_security, apparmor_sk_free_security),
|
||||||
LSM_HOOK_INIT(sk_clone_security, apparmor_sk_clone_security),
|
LSM_HOOK_INIT(sk_clone_security, apparmor_sk_clone_security),
|
||||||
|
|
||||||
|
@ -151,7 +151,7 @@ static int aa_label_sk_perm(const struct cred *subj_cred,
|
|||||||
const char *op, u32 request,
|
const char *op, u32 request,
|
||||||
struct sock *sk)
|
struct sock *sk)
|
||||||
{
|
{
|
||||||
struct aa_sk_ctx *ctx = SK_CTX(sk);
|
struct aa_sk_ctx *ctx = aa_sock(sk);
|
||||||
int error = 0;
|
int error = 0;
|
||||||
|
|
||||||
AA_BUG(!label);
|
AA_BUG(!label);
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
#include <linux/msg.h>
|
#include <linux/msg.h>
|
||||||
#include <linux/overflow.h>
|
#include <linux/overflow.h>
|
||||||
#include <net/flow.h>
|
#include <net/flow.h>
|
||||||
|
#include <net/sock.h>
|
||||||
|
|
||||||
/* How many LSMs were built into the kernel? */
|
/* How many LSMs were built into the kernel? */
|
||||||
#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
|
#define LSM_COUNT (__end_lsm_info - __start_lsm_info)
|
||||||
@ -227,6 +228,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
|
|||||||
lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
|
lsm_set_blob_size(&needed->lbs_inode, &blob_sizes.lbs_inode);
|
||||||
lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
|
lsm_set_blob_size(&needed->lbs_ipc, &blob_sizes.lbs_ipc);
|
||||||
lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
|
lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
|
||||||
|
lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
|
||||||
lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
|
lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
|
||||||
lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
|
lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
|
||||||
lsm_set_blob_size(&needed->lbs_xattr_count,
|
lsm_set_blob_size(&needed->lbs_xattr_count,
|
||||||
@ -401,6 +403,7 @@ static void __init ordered_lsm_init(void)
|
|||||||
init_debug("inode blob size = %d\n", blob_sizes.lbs_inode);
|
init_debug("inode blob size = %d\n", blob_sizes.lbs_inode);
|
||||||
init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc);
|
init_debug("ipc blob size = %d\n", blob_sizes.lbs_ipc);
|
||||||
init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg);
|
init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg);
|
||||||
|
init_debug("sock blob size = %d\n", blob_sizes.lbs_sock);
|
||||||
init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
|
init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
|
||||||
init_debug("task blob size = %d\n", blob_sizes.lbs_task);
|
init_debug("task blob size = %d\n", blob_sizes.lbs_task);
|
||||||
init_debug("xattr slots = %d\n", blob_sizes.lbs_xattr_count);
|
init_debug("xattr slots = %d\n", blob_sizes.lbs_xattr_count);
|
||||||
@ -4673,6 +4676,28 @@ int security_socket_getpeersec_dgram(struct socket *sock,
|
|||||||
}
|
}
|
||||||
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* lsm_sock_alloc - allocate a composite sock blob
|
||||||
|
* @sock: the sock that needs a blob
|
||||||
|
* @priority: allocation mode
|
||||||
|
*
|
||||||
|
* Allocate the sock blob for all the modules
|
||||||
|
*
|
||||||
|
* Returns 0, or -ENOMEM if memory can't be allocated.
|
||||||
|
*/
|
||||||
|
static int lsm_sock_alloc(struct sock *sock, gfp_t priority)
|
||||||
|
{
|
||||||
|
if (blob_sizes.lbs_sock == 0) {
|
||||||
|
sock->sk_security = NULL;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
sock->sk_security = kzalloc(blob_sizes.lbs_sock, priority);
|
||||||
|
if (sock->sk_security == NULL)
|
||||||
|
return -ENOMEM;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* security_sk_alloc() - Allocate and initialize a sock's LSM blob
|
* security_sk_alloc() - Allocate and initialize a sock's LSM blob
|
||||||
* @sk: sock
|
* @sk: sock
|
||||||
@ -4686,7 +4711,14 @@ EXPORT_SYMBOL(security_socket_getpeersec_dgram);
|
|||||||
*/
|
*/
|
||||||
int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
|
int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
|
||||||
{
|
{
|
||||||
return call_int_hook(sk_alloc_security, sk, family, priority);
|
int rc = lsm_sock_alloc(sk, priority);
|
||||||
|
|
||||||
|
if (unlikely(rc))
|
||||||
|
return rc;
|
||||||
|
rc = call_int_hook(sk_alloc_security, sk, family, priority);
|
||||||
|
if (unlikely(rc))
|
||||||
|
security_sk_free(sk);
|
||||||
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -4698,6 +4730,8 @@ int security_sk_alloc(struct sock *sk, int family, gfp_t priority)
|
|||||||
void security_sk_free(struct sock *sk)
|
void security_sk_free(struct sock *sk)
|
||||||
{
|
{
|
||||||
call_void_hook(sk_free_security, sk);
|
call_void_hook(sk_free_security, sk);
|
||||||
|
kfree(sk->sk_security);
|
||||||
|
sk->sk_security = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4584,7 +4584,7 @@ static int socket_sockcreate_sid(const struct task_security_struct *tsec,
|
|||||||
|
|
||||||
static int sock_has_perm(struct sock *sk, u32 perms)
|
static int sock_has_perm(struct sock *sk, u32 perms)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct common_audit_data ad;
|
struct common_audit_data ad;
|
||||||
struct lsm_network_audit net;
|
struct lsm_network_audit net;
|
||||||
|
|
||||||
@ -4652,7 +4652,7 @@ static int selinux_socket_post_create(struct socket *sock, int family,
|
|||||||
isec->initialized = LABEL_INITIALIZED;
|
isec->initialized = LABEL_INITIALIZED;
|
||||||
|
|
||||||
if (sock->sk) {
|
if (sock->sk) {
|
||||||
sksec = sock->sk->sk_security;
|
sksec = selinux_sock(sock->sk);
|
||||||
sksec->sclass = sclass;
|
sksec->sclass = sclass;
|
||||||
sksec->sid = sid;
|
sksec->sid = sid;
|
||||||
/* Allows detection of the first association on this socket */
|
/* Allows detection of the first association on this socket */
|
||||||
@ -4668,8 +4668,8 @@ static int selinux_socket_post_create(struct socket *sock, int family,
|
|||||||
static int selinux_socket_socketpair(struct socket *socka,
|
static int selinux_socket_socketpair(struct socket *socka,
|
||||||
struct socket *sockb)
|
struct socket *sockb)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec_a = socka->sk->sk_security;
|
struct sk_security_struct *sksec_a = selinux_sock(socka->sk);
|
||||||
struct sk_security_struct *sksec_b = sockb->sk->sk_security;
|
struct sk_security_struct *sksec_b = selinux_sock(sockb->sk);
|
||||||
|
|
||||||
sksec_a->peer_sid = sksec_b->sid;
|
sksec_a->peer_sid = sksec_b->sid;
|
||||||
sksec_b->peer_sid = sksec_a->sid;
|
sksec_b->peer_sid = sksec_a->sid;
|
||||||
@ -4684,7 +4684,7 @@ static int selinux_socket_socketpair(struct socket *socka,
|
|||||||
static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
|
static int selinux_socket_bind(struct socket *sock, struct sockaddr *address, int addrlen)
|
||||||
{
|
{
|
||||||
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
u16 family;
|
u16 family;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@ -4824,7 +4824,7 @@ static int selinux_socket_connect_helper(struct socket *sock,
|
|||||||
struct sockaddr *address, int addrlen)
|
struct sockaddr *address, int addrlen)
|
||||||
{
|
{
|
||||||
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
err = sock_has_perm(sk, SOCKET__CONNECT);
|
err = sock_has_perm(sk, SOCKET__CONNECT);
|
||||||
@ -5002,9 +5002,9 @@ static int selinux_socket_unix_stream_connect(struct sock *sock,
|
|||||||
struct sock *other,
|
struct sock *other,
|
||||||
struct sock *newsk)
|
struct sock *newsk)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec_sock = sock->sk_security;
|
struct sk_security_struct *sksec_sock = selinux_sock(sock);
|
||||||
struct sk_security_struct *sksec_other = other->sk_security;
|
struct sk_security_struct *sksec_other = selinux_sock(other);
|
||||||
struct sk_security_struct *sksec_new = newsk->sk_security;
|
struct sk_security_struct *sksec_new = selinux_sock(newsk);
|
||||||
struct common_audit_data ad;
|
struct common_audit_data ad;
|
||||||
struct lsm_network_audit net;
|
struct lsm_network_audit net;
|
||||||
int err;
|
int err;
|
||||||
@ -5033,8 +5033,8 @@ static int selinux_socket_unix_stream_connect(struct sock *sock,
|
|||||||
static int selinux_socket_unix_may_send(struct socket *sock,
|
static int selinux_socket_unix_may_send(struct socket *sock,
|
||||||
struct socket *other)
|
struct socket *other)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *ssec = sock->sk->sk_security;
|
struct sk_security_struct *ssec = selinux_sock(sock->sk);
|
||||||
struct sk_security_struct *osec = other->sk->sk_security;
|
struct sk_security_struct *osec = selinux_sock(other->sk);
|
||||||
struct common_audit_data ad;
|
struct common_audit_data ad;
|
||||||
struct lsm_network_audit net;
|
struct lsm_network_audit net;
|
||||||
|
|
||||||
@ -5071,7 +5071,7 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
|
|||||||
u16 family)
|
u16 family)
|
||||||
{
|
{
|
||||||
int err = 0;
|
int err = 0;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
u32 sk_sid = sksec->sid;
|
u32 sk_sid = sksec->sid;
|
||||||
struct common_audit_data ad;
|
struct common_audit_data ad;
|
||||||
struct lsm_network_audit net;
|
struct lsm_network_audit net;
|
||||||
@ -5100,7 +5100,7 @@ static int selinux_sock_rcv_skb_compat(struct sock *sk, struct sk_buff *skb,
|
|||||||
static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
static int selinux_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
int err, peerlbl_active, secmark_active;
|
int err, peerlbl_active, secmark_active;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
u16 family = sk->sk_family;
|
u16 family = sk->sk_family;
|
||||||
u32 sk_sid = sksec->sid;
|
u32 sk_sid = sksec->sid;
|
||||||
struct common_audit_data ad;
|
struct common_audit_data ad;
|
||||||
@ -5168,7 +5168,7 @@ static int selinux_socket_getpeersec_stream(struct socket *sock,
|
|||||||
int err = 0;
|
int err = 0;
|
||||||
char *scontext = NULL;
|
char *scontext = NULL;
|
||||||
u32 scontext_len;
|
u32 scontext_len;
|
||||||
struct sk_security_struct *sksec = sock->sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sock->sk);
|
||||||
u32 peer_sid = SECSID_NULL;
|
u32 peer_sid = SECSID_NULL;
|
||||||
|
|
||||||
if (sksec->sclass == SECCLASS_UNIX_STREAM_SOCKET ||
|
if (sksec->sclass == SECCLASS_UNIX_STREAM_SOCKET ||
|
||||||
@ -5228,34 +5228,27 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock,
|
|||||||
|
|
||||||
static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority)
|
static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
sksec = kzalloc(sizeof(*sksec), priority);
|
|
||||||
if (!sksec)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
sksec->peer_sid = SECINITSID_UNLABELED;
|
sksec->peer_sid = SECINITSID_UNLABELED;
|
||||||
sksec->sid = SECINITSID_UNLABELED;
|
sksec->sid = SECINITSID_UNLABELED;
|
||||||
sksec->sclass = SECCLASS_SOCKET;
|
sksec->sclass = SECCLASS_SOCKET;
|
||||||
selinux_netlbl_sk_security_reset(sksec);
|
selinux_netlbl_sk_security_reset(sksec);
|
||||||
sk->sk_security = sksec;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void selinux_sk_free_security(struct sock *sk)
|
static void selinux_sk_free_security(struct sock *sk)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
sk->sk_security = NULL;
|
|
||||||
selinux_netlbl_sk_security_free(sksec);
|
selinux_netlbl_sk_security_free(sksec);
|
||||||
kfree(sksec);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)
|
static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct sk_security_struct *newsksec = newsk->sk_security;
|
struct sk_security_struct *newsksec = selinux_sock(newsk);
|
||||||
|
|
||||||
newsksec->sid = sksec->sid;
|
newsksec->sid = sksec->sid;
|
||||||
newsksec->peer_sid = sksec->peer_sid;
|
newsksec->peer_sid = sksec->peer_sid;
|
||||||
@ -5269,7 +5262,7 @@ static void selinux_sk_getsecid(const struct sock *sk, u32 *secid)
|
|||||||
if (!sk)
|
if (!sk)
|
||||||
*secid = SECINITSID_ANY_SOCKET;
|
*secid = SECINITSID_ANY_SOCKET;
|
||||||
else {
|
else {
|
||||||
const struct sk_security_struct *sksec = sk->sk_security;
|
const struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
*secid = sksec->sid;
|
*secid = sksec->sid;
|
||||||
}
|
}
|
||||||
@ -5279,7 +5272,7 @@ static void selinux_sock_graft(struct sock *sk, struct socket *parent)
|
|||||||
{
|
{
|
||||||
struct inode_security_struct *isec =
|
struct inode_security_struct *isec =
|
||||||
inode_security_novalidate(SOCK_INODE(parent));
|
inode_security_novalidate(SOCK_INODE(parent));
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
if (sk->sk_family == PF_INET || sk->sk_family == PF_INET6 ||
|
if (sk->sk_family == PF_INET || sk->sk_family == PF_INET6 ||
|
||||||
sk->sk_family == PF_UNIX)
|
sk->sk_family == PF_UNIX)
|
||||||
@ -5296,7 +5289,7 @@ static int selinux_sctp_process_new_assoc(struct sctp_association *asoc,
|
|||||||
{
|
{
|
||||||
struct sock *sk = asoc->base.sk;
|
struct sock *sk = asoc->base.sk;
|
||||||
u16 family = sk->sk_family;
|
u16 family = sk->sk_family;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct common_audit_data ad;
|
struct common_audit_data ad;
|
||||||
struct lsm_network_audit net;
|
struct lsm_network_audit net;
|
||||||
int err;
|
int err;
|
||||||
@ -5351,7 +5344,7 @@ static int selinux_sctp_process_new_assoc(struct sctp_association *asoc,
|
|||||||
static int selinux_sctp_assoc_request(struct sctp_association *asoc,
|
static int selinux_sctp_assoc_request(struct sctp_association *asoc,
|
||||||
struct sk_buff *skb)
|
struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = asoc->base.sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(asoc->base.sk);
|
||||||
u32 conn_sid;
|
u32 conn_sid;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@ -5384,7 +5377,7 @@ static int selinux_sctp_assoc_request(struct sctp_association *asoc,
|
|||||||
static int selinux_sctp_assoc_established(struct sctp_association *asoc,
|
static int selinux_sctp_assoc_established(struct sctp_association *asoc,
|
||||||
struct sk_buff *skb)
|
struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = asoc->base.sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(asoc->base.sk);
|
||||||
|
|
||||||
if (!selinux_policycap_extsockclass())
|
if (!selinux_policycap_extsockclass())
|
||||||
return 0;
|
return 0;
|
||||||
@ -5483,8 +5476,8 @@ static int selinux_sctp_bind_connect(struct sock *sk, int optname,
|
|||||||
static void selinux_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk,
|
static void selinux_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk,
|
||||||
struct sock *newsk)
|
struct sock *newsk)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct sk_security_struct *newsksec = newsk->sk_security;
|
struct sk_security_struct *newsksec = selinux_sock(newsk);
|
||||||
|
|
||||||
/* If policy does not support SECCLASS_SCTP_SOCKET then call
|
/* If policy does not support SECCLASS_SCTP_SOCKET then call
|
||||||
* the non-sctp clone version.
|
* the non-sctp clone version.
|
||||||
@ -5500,8 +5493,8 @@ static void selinux_sctp_sk_clone(struct sctp_association *asoc, struct sock *sk
|
|||||||
|
|
||||||
static int selinux_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
|
static int selinux_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *ssksec = ssk->sk_security;
|
struct sk_security_struct *ssksec = selinux_sock(ssk);
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
ssksec->sclass = sksec->sclass;
|
ssksec->sclass = sksec->sclass;
|
||||||
ssksec->sid = sksec->sid;
|
ssksec->sid = sksec->sid;
|
||||||
@ -5516,7 +5509,7 @@ static int selinux_mptcp_add_subflow(struct sock *sk, struct sock *ssk)
|
|||||||
static int selinux_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
|
static int selinux_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
|
||||||
struct request_sock *req)
|
struct request_sock *req)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
int err;
|
int err;
|
||||||
u16 family = req->rsk_ops->family;
|
u16 family = req->rsk_ops->family;
|
||||||
u32 connsid;
|
u32 connsid;
|
||||||
@ -5537,7 +5530,7 @@ static int selinux_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
|
|||||||
static void selinux_inet_csk_clone(struct sock *newsk,
|
static void selinux_inet_csk_clone(struct sock *newsk,
|
||||||
const struct request_sock *req)
|
const struct request_sock *req)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *newsksec = newsk->sk_security;
|
struct sk_security_struct *newsksec = selinux_sock(newsk);
|
||||||
|
|
||||||
newsksec->sid = req->secid;
|
newsksec->sid = req->secid;
|
||||||
newsksec->peer_sid = req->peer_secid;
|
newsksec->peer_sid = req->peer_secid;
|
||||||
@ -5554,7 +5547,7 @@ static void selinux_inet_csk_clone(struct sock *newsk,
|
|||||||
static void selinux_inet_conn_established(struct sock *sk, struct sk_buff *skb)
|
static void selinux_inet_conn_established(struct sock *sk, struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
u16 family = sk->sk_family;
|
u16 family = sk->sk_family;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
/* handle mapped IPv4 packets arriving via IPv6 sockets */
|
/* handle mapped IPv4 packets arriving via IPv6 sockets */
|
||||||
if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
|
if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
|
||||||
@ -5629,7 +5622,7 @@ static int selinux_tun_dev_attach_queue(void *security)
|
|||||||
static int selinux_tun_dev_attach(struct sock *sk, void *security)
|
static int selinux_tun_dev_attach(struct sock *sk, void *security)
|
||||||
{
|
{
|
||||||
struct tun_security_struct *tunsec = security;
|
struct tun_security_struct *tunsec = security;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
/* we don't currently perform any NetLabel based labeling here and it
|
/* we don't currently perform any NetLabel based labeling here and it
|
||||||
* isn't clear that we would want to do so anyway; while we could apply
|
* isn't clear that we would want to do so anyway; while we could apply
|
||||||
@ -5752,7 +5745,7 @@ static unsigned int selinux_ip_output(void *priv, struct sk_buff *skb,
|
|||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
|
|
||||||
/* standard practice, label using the parent socket */
|
/* standard practice, label using the parent socket */
|
||||||
sksec = sk->sk_security;
|
sksec = selinux_sock(sk);
|
||||||
sid = sksec->sid;
|
sid = sksec->sid;
|
||||||
} else
|
} else
|
||||||
sid = SECINITSID_KERNEL;
|
sid = SECINITSID_KERNEL;
|
||||||
@ -5775,7 +5768,7 @@ static unsigned int selinux_ip_postroute_compat(struct sk_buff *skb,
|
|||||||
sk = skb_to_full_sk(skb);
|
sk = skb_to_full_sk(skb);
|
||||||
if (sk == NULL)
|
if (sk == NULL)
|
||||||
return NF_ACCEPT;
|
return NF_ACCEPT;
|
||||||
sksec = sk->sk_security;
|
sksec = selinux_sock(sk);
|
||||||
|
|
||||||
ad_net_init_from_iif(&ad, &net, state->out->ifindex, state->pf);
|
ad_net_init_from_iif(&ad, &net, state->out->ifindex, state->pf);
|
||||||
if (selinux_parse_skb(skb, &ad, NULL, 0, &proto))
|
if (selinux_parse_skb(skb, &ad, NULL, 0, &proto))
|
||||||
@ -5864,7 +5857,7 @@ static unsigned int selinux_ip_postroute(void *priv,
|
|||||||
u32 skb_sid;
|
u32 skb_sid;
|
||||||
struct sk_security_struct *sksec;
|
struct sk_security_struct *sksec;
|
||||||
|
|
||||||
sksec = sk->sk_security;
|
sksec = selinux_sock(sk);
|
||||||
if (selinux_skb_peerlbl_sid(skb, family, &skb_sid))
|
if (selinux_skb_peerlbl_sid(skb, family, &skb_sid))
|
||||||
return NF_DROP;
|
return NF_DROP;
|
||||||
/* At this point, if the returned skb peerlbl is SECSID_NULL
|
/* At this point, if the returned skb peerlbl is SECSID_NULL
|
||||||
@ -5893,7 +5886,7 @@ static unsigned int selinux_ip_postroute(void *priv,
|
|||||||
} else {
|
} else {
|
||||||
/* Locally generated packet, fetch the security label from the
|
/* Locally generated packet, fetch the security label from the
|
||||||
* associated socket. */
|
* associated socket. */
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
peer_sid = sksec->sid;
|
peer_sid = sksec->sid;
|
||||||
secmark_perm = PACKET__SEND;
|
secmark_perm = PACKET__SEND;
|
||||||
}
|
}
|
||||||
@ -5936,7 +5929,7 @@ static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)
|
|||||||
unsigned int data_len = skb->len;
|
unsigned int data_len = skb->len;
|
||||||
unsigned char *data = skb->data;
|
unsigned char *data = skb->data;
|
||||||
struct nlmsghdr *nlh;
|
struct nlmsghdr *nlh;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
u16 sclass = sksec->sclass;
|
u16 sclass = sksec->sclass;
|
||||||
u32 perm;
|
u32 perm;
|
||||||
|
|
||||||
@ -6994,6 +6987,7 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
|
|||||||
.lbs_inode = sizeof(struct inode_security_struct),
|
.lbs_inode = sizeof(struct inode_security_struct),
|
||||||
.lbs_ipc = sizeof(struct ipc_security_struct),
|
.lbs_ipc = sizeof(struct ipc_security_struct),
|
||||||
.lbs_msg_msg = sizeof(struct msg_security_struct),
|
.lbs_msg_msg = sizeof(struct msg_security_struct),
|
||||||
|
.lbs_sock = sizeof(struct sk_security_struct),
|
||||||
.lbs_superblock = sizeof(struct superblock_security_struct),
|
.lbs_superblock = sizeof(struct superblock_security_struct),
|
||||||
.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
|
.lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
|
||||||
};
|
};
|
||||||
|
@ -195,4 +195,9 @@ selinux_superblock(const struct super_block *superblock)
|
|||||||
return superblock->s_security + selinux_blob_sizes.lbs_superblock;
|
return superblock->s_security + selinux_blob_sizes.lbs_superblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct sk_security_struct *selinux_sock(const struct sock *sock)
|
||||||
|
{
|
||||||
|
return sock->sk_security + selinux_blob_sizes.lbs_sock;
|
||||||
|
}
|
||||||
|
|
||||||
#endif /* _SELINUX_OBJSEC_H_ */
|
#endif /* _SELINUX_OBJSEC_H_ */
|
||||||
|
@ -17,6 +17,7 @@
|
|||||||
#include <linux/gfp.h>
|
#include <linux/gfp.h>
|
||||||
#include <linux/ip.h>
|
#include <linux/ip.h>
|
||||||
#include <linux/ipv6.h>
|
#include <linux/ipv6.h>
|
||||||
|
#include <linux/lsm_hooks.h>
|
||||||
#include <net/sock.h>
|
#include <net/sock.h>
|
||||||
#include <net/netlabel.h>
|
#include <net/netlabel.h>
|
||||||
#include <net/ip.h>
|
#include <net/ip.h>
|
||||||
@ -68,7 +69,7 @@ static int selinux_netlbl_sidlookup_cached(struct sk_buff *skb,
|
|||||||
static struct netlbl_lsm_secattr *selinux_netlbl_sock_genattr(struct sock *sk)
|
static struct netlbl_lsm_secattr *selinux_netlbl_sock_genattr(struct sock *sk)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct netlbl_lsm_secattr *secattr;
|
struct netlbl_lsm_secattr *secattr;
|
||||||
|
|
||||||
if (sksec->nlbl_secattr != NULL)
|
if (sksec->nlbl_secattr != NULL)
|
||||||
@ -100,7 +101,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr(
|
|||||||
const struct sock *sk,
|
const struct sock *sk,
|
||||||
u32 sid)
|
u32 sid)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct netlbl_lsm_secattr *secattr = sksec->nlbl_secattr;
|
struct netlbl_lsm_secattr *secattr = sksec->nlbl_secattr;
|
||||||
|
|
||||||
if (secattr == NULL)
|
if (secattr == NULL)
|
||||||
@ -240,7 +241,7 @@ int selinux_netlbl_skbuff_setsid(struct sk_buff *skb,
|
|||||||
* being labeled by it's parent socket, if it is just exit */
|
* being labeled by it's parent socket, if it is just exit */
|
||||||
sk = skb_to_full_sk(skb);
|
sk = skb_to_full_sk(skb);
|
||||||
if (sk != NULL) {
|
if (sk != NULL) {
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
if (sksec->nlbl_state != NLBL_REQSKB)
|
if (sksec->nlbl_state != NLBL_REQSKB)
|
||||||
return 0;
|
return 0;
|
||||||
@ -277,7 +278,7 @@ int selinux_netlbl_sctp_assoc_request(struct sctp_association *asoc,
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct netlbl_lsm_secattr secattr;
|
struct netlbl_lsm_secattr secattr;
|
||||||
struct sk_security_struct *sksec = asoc->base.sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(asoc->base.sk);
|
||||||
struct sockaddr_in addr4;
|
struct sockaddr_in addr4;
|
||||||
struct sockaddr_in6 addr6;
|
struct sockaddr_in6 addr6;
|
||||||
|
|
||||||
@ -356,7 +357,7 @@ int selinux_netlbl_inet_conn_request(struct request_sock *req, u16 family)
|
|||||||
*/
|
*/
|
||||||
void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family)
|
void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
if (family == PF_INET)
|
if (family == PF_INET)
|
||||||
sksec->nlbl_state = NLBL_LABELED;
|
sksec->nlbl_state = NLBL_LABELED;
|
||||||
@ -374,8 +375,8 @@ void selinux_netlbl_inet_csk_clone(struct sock *sk, u16 family)
|
|||||||
*/
|
*/
|
||||||
void selinux_netlbl_sctp_sk_clone(struct sock *sk, struct sock *newsk)
|
void selinux_netlbl_sctp_sk_clone(struct sock *sk, struct sock *newsk)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct sk_security_struct *newsksec = newsk->sk_security;
|
struct sk_security_struct *newsksec = selinux_sock(newsk);
|
||||||
|
|
||||||
newsksec->nlbl_state = sksec->nlbl_state;
|
newsksec->nlbl_state = sksec->nlbl_state;
|
||||||
}
|
}
|
||||||
@ -393,7 +394,7 @@ void selinux_netlbl_sctp_sk_clone(struct sock *sk, struct sock *newsk)
|
|||||||
int selinux_netlbl_socket_post_create(struct sock *sk, u16 family)
|
int selinux_netlbl_socket_post_create(struct sock *sk, u16 family)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct netlbl_lsm_secattr *secattr;
|
struct netlbl_lsm_secattr *secattr;
|
||||||
|
|
||||||
if (family != PF_INET && family != PF_INET6)
|
if (family != PF_INET && family != PF_INET6)
|
||||||
@ -510,7 +511,7 @@ int selinux_netlbl_socket_setsockopt(struct socket *sock,
|
|||||||
{
|
{
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct netlbl_lsm_secattr secattr;
|
struct netlbl_lsm_secattr secattr;
|
||||||
|
|
||||||
if (selinux_netlbl_option(level, optname) &&
|
if (selinux_netlbl_option(level, optname) &&
|
||||||
@ -548,7 +549,7 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk,
|
|||||||
struct sockaddr *addr)
|
struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
struct netlbl_lsm_secattr *secattr;
|
struct netlbl_lsm_secattr *secattr;
|
||||||
|
|
||||||
/* connected sockets are allowed to disconnect when the address family
|
/* connected sockets are allowed to disconnect when the address family
|
||||||
@ -587,7 +588,7 @@ static int selinux_netlbl_socket_connect_helper(struct sock *sk,
|
|||||||
int selinux_netlbl_socket_connect_locked(struct sock *sk,
|
int selinux_netlbl_socket_connect_locked(struct sock *sk,
|
||||||
struct sockaddr *addr)
|
struct sockaddr *addr)
|
||||||
{
|
{
|
||||||
struct sk_security_struct *sksec = sk->sk_security;
|
struct sk_security_struct *sksec = selinux_sock(sk);
|
||||||
|
|
||||||
if (sksec->nlbl_state != NLBL_REQSKB &&
|
if (sksec->nlbl_state != NLBL_REQSKB &&
|
||||||
sksec->nlbl_state != NLBL_CONNLABELED)
|
sksec->nlbl_state != NLBL_CONNLABELED)
|
||||||
|
@ -355,6 +355,11 @@ static inline struct superblock_smack *smack_superblock(
|
|||||||
return superblock->s_security + smack_blob_sizes.lbs_superblock;
|
return superblock->s_security + smack_blob_sizes.lbs_superblock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static inline struct socket_smack *smack_sock(const struct sock *sock)
|
||||||
|
{
|
||||||
|
return sock->sk_security + smack_blob_sizes.lbs_sock;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Is the directory transmuting?
|
* Is the directory transmuting?
|
||||||
*/
|
*/
|
||||||
|
@ -1606,7 +1606,7 @@ static int smack_inode_getsecurity(struct mnt_idmap *idmap,
|
|||||||
if (sock == NULL || sock->sk == NULL)
|
if (sock == NULL || sock->sk == NULL)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
ssp = sock->sk->sk_security;
|
ssp = smack_sock(sock->sk);
|
||||||
|
|
||||||
if (strcmp(name, XATTR_SMACK_IPIN) == 0)
|
if (strcmp(name, XATTR_SMACK_IPIN) == 0)
|
||||||
isp = ssp->smk_in;
|
isp = ssp->smk_in;
|
||||||
@ -1994,7 +1994,7 @@ static int smack_file_receive(struct file *file)
|
|||||||
|
|
||||||
if (inode->i_sb->s_magic == SOCKFS_MAGIC) {
|
if (inode->i_sb->s_magic == SOCKFS_MAGIC) {
|
||||||
sock = SOCKET_I(inode);
|
sock = SOCKET_I(inode);
|
||||||
ssp = sock->sk->sk_security;
|
ssp = smack_sock(sock->sk);
|
||||||
tsp = smack_cred(current_cred());
|
tsp = smack_cred(current_cred());
|
||||||
/*
|
/*
|
||||||
* If the receiving process can't write to the
|
* If the receiving process can't write to the
|
||||||
@ -2409,11 +2409,7 @@ static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
|
|||||||
static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
|
static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
|
||||||
{
|
{
|
||||||
struct smack_known *skp = smk_of_current();
|
struct smack_known *skp = smk_of_current();
|
||||||
struct socket_smack *ssp;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
|
|
||||||
ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
|
|
||||||
if (ssp == NULL)
|
|
||||||
return -ENOMEM;
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sockets created by kernel threads receive web label.
|
* Sockets created by kernel threads receive web label.
|
||||||
@ -2427,11 +2423,10 @@ static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
|
|||||||
}
|
}
|
||||||
ssp->smk_packet = NULL;
|
ssp->smk_packet = NULL;
|
||||||
|
|
||||||
sk->sk_security = ssp;
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef SMACK_IPV6_PORT_LABELING
|
||||||
/**
|
/**
|
||||||
* smack_sk_free_security - Free a socket blob
|
* smack_sk_free_security - Free a socket blob
|
||||||
* @sk: the socket
|
* @sk: the socket
|
||||||
@ -2440,7 +2435,6 @@ static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
|
|||||||
*/
|
*/
|
||||||
static void smack_sk_free_security(struct sock *sk)
|
static void smack_sk_free_security(struct sock *sk)
|
||||||
{
|
{
|
||||||
#ifdef SMACK_IPV6_PORT_LABELING
|
|
||||||
struct smk_port_label *spp;
|
struct smk_port_label *spp;
|
||||||
|
|
||||||
if (sk->sk_family == PF_INET6) {
|
if (sk->sk_family == PF_INET6) {
|
||||||
@ -2453,9 +2447,8 @@ static void smack_sk_free_security(struct sock *sk)
|
|||||||
}
|
}
|
||||||
rcu_read_unlock();
|
rcu_read_unlock();
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
kfree(sk->sk_security);
|
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* smack_sk_clone_security - Copy security context
|
* smack_sk_clone_security - Copy security context
|
||||||
@ -2466,8 +2459,8 @@ static void smack_sk_free_security(struct sock *sk)
|
|||||||
*/
|
*/
|
||||||
static void smack_sk_clone_security(const struct sock *sk, struct sock *newsk)
|
static void smack_sk_clone_security(const struct sock *sk, struct sock *newsk)
|
||||||
{
|
{
|
||||||
struct socket_smack *ssp_old = sk->sk_security;
|
struct socket_smack *ssp_old = smack_sock(sk);
|
||||||
struct socket_smack *ssp_new = newsk->sk_security;
|
struct socket_smack *ssp_new = smack_sock(newsk);
|
||||||
|
|
||||||
*ssp_new = *ssp_old;
|
*ssp_new = *ssp_old;
|
||||||
}
|
}
|
||||||
@ -2583,7 +2576,7 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip)
|
|||||||
*/
|
*/
|
||||||
static int smack_netlbl_add(struct sock *sk)
|
static int smack_netlbl_add(struct sock *sk)
|
||||||
{
|
{
|
||||||
struct socket_smack *ssp = sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
struct smack_known *skp = ssp->smk_out;
|
struct smack_known *skp = ssp->smk_out;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -2616,7 +2609,7 @@ static int smack_netlbl_add(struct sock *sk)
|
|||||||
*/
|
*/
|
||||||
static void smack_netlbl_delete(struct sock *sk)
|
static void smack_netlbl_delete(struct sock *sk)
|
||||||
{
|
{
|
||||||
struct socket_smack *ssp = sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Take the label off the socket if one is set.
|
* Take the label off the socket if one is set.
|
||||||
@ -2648,7 +2641,7 @@ static int smk_ipv4_check(struct sock *sk, struct sockaddr_in *sap)
|
|||||||
struct smack_known *skp;
|
struct smack_known *skp;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct smack_known *hkp;
|
struct smack_known *hkp;
|
||||||
struct socket_smack *ssp = sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
struct smk_audit_info ad;
|
struct smk_audit_info ad;
|
||||||
|
|
||||||
rcu_read_lock();
|
rcu_read_lock();
|
||||||
@ -2721,7 +2714,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
|
|||||||
{
|
{
|
||||||
struct sock *sk = sock->sk;
|
struct sock *sk = sock->sk;
|
||||||
struct sockaddr_in6 *addr6;
|
struct sockaddr_in6 *addr6;
|
||||||
struct socket_smack *ssp = sock->sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sock->sk);
|
||||||
struct smk_port_label *spp;
|
struct smk_port_label *spp;
|
||||||
unsigned short port = 0;
|
unsigned short port = 0;
|
||||||
|
|
||||||
@ -2809,7 +2802,7 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
|
|||||||
int act)
|
int act)
|
||||||
{
|
{
|
||||||
struct smk_port_label *spp;
|
struct smk_port_label *spp;
|
||||||
struct socket_smack *ssp = sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
struct smack_known *skp = NULL;
|
struct smack_known *skp = NULL;
|
||||||
unsigned short port;
|
unsigned short port;
|
||||||
struct smack_known *object;
|
struct smack_known *object;
|
||||||
@ -2912,7 +2905,7 @@ static int smack_inode_setsecurity(struct inode *inode, const char *name,
|
|||||||
if (sock == NULL || sock->sk == NULL)
|
if (sock == NULL || sock->sk == NULL)
|
||||||
return -EOPNOTSUPP;
|
return -EOPNOTSUPP;
|
||||||
|
|
||||||
ssp = sock->sk->sk_security;
|
ssp = smack_sock(sock->sk);
|
||||||
|
|
||||||
if (strcmp(name, XATTR_SMACK_IPIN) == 0)
|
if (strcmp(name, XATTR_SMACK_IPIN) == 0)
|
||||||
ssp->smk_in = skp;
|
ssp->smk_in = skp;
|
||||||
@ -2960,7 +2953,7 @@ static int smack_socket_post_create(struct socket *sock, int family,
|
|||||||
* Sockets created by kernel threads receive web label.
|
* Sockets created by kernel threads receive web label.
|
||||||
*/
|
*/
|
||||||
if (unlikely(current->flags & PF_KTHREAD)) {
|
if (unlikely(current->flags & PF_KTHREAD)) {
|
||||||
ssp = sock->sk->sk_security;
|
ssp = smack_sock(sock->sk);
|
||||||
ssp->smk_in = &smack_known_web;
|
ssp->smk_in = &smack_known_web;
|
||||||
ssp->smk_out = &smack_known_web;
|
ssp->smk_out = &smack_known_web;
|
||||||
}
|
}
|
||||||
@ -2985,8 +2978,8 @@ static int smack_socket_post_create(struct socket *sock, int family,
|
|||||||
static int smack_socket_socketpair(struct socket *socka,
|
static int smack_socket_socketpair(struct socket *socka,
|
||||||
struct socket *sockb)
|
struct socket *sockb)
|
||||||
{
|
{
|
||||||
struct socket_smack *asp = socka->sk->sk_security;
|
struct socket_smack *asp = smack_sock(socka->sk);
|
||||||
struct socket_smack *bsp = sockb->sk->sk_security;
|
struct socket_smack *bsp = smack_sock(sockb->sk);
|
||||||
|
|
||||||
asp->smk_packet = bsp->smk_out;
|
asp->smk_packet = bsp->smk_out;
|
||||||
bsp->smk_packet = asp->smk_out;
|
bsp->smk_packet = asp->smk_out;
|
||||||
@ -3049,7 +3042,7 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
|
|||||||
if (__is_defined(SMACK_IPV6_SECMARK_LABELING))
|
if (__is_defined(SMACK_IPV6_SECMARK_LABELING))
|
||||||
rsp = smack_ipv6host_label(sip);
|
rsp = smack_ipv6host_label(sip);
|
||||||
if (rsp != NULL) {
|
if (rsp != NULL) {
|
||||||
struct socket_smack *ssp = sock->sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sock->sk);
|
||||||
|
|
||||||
rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
|
rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
|
||||||
SMK_CONNECTING);
|
SMK_CONNECTING);
|
||||||
@ -3844,9 +3837,9 @@ static int smack_unix_stream_connect(struct sock *sock,
|
|||||||
{
|
{
|
||||||
struct smack_known *skp;
|
struct smack_known *skp;
|
||||||
struct smack_known *okp;
|
struct smack_known *okp;
|
||||||
struct socket_smack *ssp = sock->sk_security;
|
struct socket_smack *ssp = smack_sock(sock);
|
||||||
struct socket_smack *osp = other->sk_security;
|
struct socket_smack *osp = smack_sock(other);
|
||||||
struct socket_smack *nsp = newsk->sk_security;
|
struct socket_smack *nsp = smack_sock(newsk);
|
||||||
struct smk_audit_info ad;
|
struct smk_audit_info ad;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
#ifdef CONFIG_AUDIT
|
#ifdef CONFIG_AUDIT
|
||||||
@ -3898,8 +3891,8 @@ static int smack_unix_stream_connect(struct sock *sock,
|
|||||||
*/
|
*/
|
||||||
static int smack_unix_may_send(struct socket *sock, struct socket *other)
|
static int smack_unix_may_send(struct socket *sock, struct socket *other)
|
||||||
{
|
{
|
||||||
struct socket_smack *ssp = sock->sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sock->sk);
|
||||||
struct socket_smack *osp = other->sk->sk_security;
|
struct socket_smack *osp = smack_sock(other->sk);
|
||||||
struct smk_audit_info ad;
|
struct smk_audit_info ad;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -3936,7 +3929,7 @@ static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
|
|||||||
struct sockaddr_in6 *sap = (struct sockaddr_in6 *) msg->msg_name;
|
struct sockaddr_in6 *sap = (struct sockaddr_in6 *) msg->msg_name;
|
||||||
#endif
|
#endif
|
||||||
#ifdef SMACK_IPV6_SECMARK_LABELING
|
#ifdef SMACK_IPV6_SECMARK_LABELING
|
||||||
struct socket_smack *ssp = sock->sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sock->sk);
|
||||||
struct smack_known *rsp;
|
struct smack_known *rsp;
|
||||||
#endif
|
#endif
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
@ -4148,7 +4141,7 @@ static struct smack_known *smack_from_netlbl(const struct sock *sk, u16 family,
|
|||||||
netlbl_secattr_init(&secattr);
|
netlbl_secattr_init(&secattr);
|
||||||
|
|
||||||
if (sk)
|
if (sk)
|
||||||
ssp = sk->sk_security;
|
ssp = smack_sock(sk);
|
||||||
|
|
||||||
if (netlbl_skbuff_getattr(skb, family, &secattr) == 0) {
|
if (netlbl_skbuff_getattr(skb, family, &secattr) == 0) {
|
||||||
skp = smack_from_secattr(&secattr, ssp);
|
skp = smack_from_secattr(&secattr, ssp);
|
||||||
@ -4170,7 +4163,7 @@ static struct smack_known *smack_from_netlbl(const struct sock *sk, u16 family,
|
|||||||
*/
|
*/
|
||||||
static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
|
||||||
{
|
{
|
||||||
struct socket_smack *ssp = sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
struct smack_known *skp = NULL;
|
struct smack_known *skp = NULL;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
struct smk_audit_info ad;
|
struct smk_audit_info ad;
|
||||||
@ -4274,7 +4267,7 @@ static int smack_socket_getpeersec_stream(struct socket *sock,
|
|||||||
u32 slen = 1;
|
u32 slen = 1;
|
||||||
int rc = 0;
|
int rc = 0;
|
||||||
|
|
||||||
ssp = sock->sk->sk_security;
|
ssp = smack_sock(sock->sk);
|
||||||
if (ssp->smk_packet != NULL) {
|
if (ssp->smk_packet != NULL) {
|
||||||
rcp = ssp->smk_packet->smk_known;
|
rcp = ssp->smk_packet->smk_known;
|
||||||
slen = strlen(rcp) + 1;
|
slen = strlen(rcp) + 1;
|
||||||
@ -4324,7 +4317,7 @@ static int smack_socket_getpeersec_dgram(struct socket *sock,
|
|||||||
|
|
||||||
switch (family) {
|
switch (family) {
|
||||||
case PF_UNIX:
|
case PF_UNIX:
|
||||||
ssp = sock->sk->sk_security;
|
ssp = smack_sock(sock->sk);
|
||||||
s = ssp->smk_out->smk_secid;
|
s = ssp->smk_out->smk_secid;
|
||||||
break;
|
break;
|
||||||
case PF_INET:
|
case PF_INET:
|
||||||
@ -4373,7 +4366,7 @@ static void smack_sock_graft(struct sock *sk, struct socket *parent)
|
|||||||
(sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
|
(sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ssp = sk->sk_security;
|
ssp = smack_sock(sk);
|
||||||
ssp->smk_in = skp;
|
ssp->smk_in = skp;
|
||||||
ssp->smk_out = skp;
|
ssp->smk_out = skp;
|
||||||
/* cssp->smk_packet is already set in smack_inet_csk_clone() */
|
/* cssp->smk_packet is already set in smack_inet_csk_clone() */
|
||||||
@ -4393,7 +4386,7 @@ static int smack_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
|
|||||||
{
|
{
|
||||||
u16 family = sk->sk_family;
|
u16 family = sk->sk_family;
|
||||||
struct smack_known *skp;
|
struct smack_known *skp;
|
||||||
struct socket_smack *ssp = sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
struct sockaddr_in addr;
|
struct sockaddr_in addr;
|
||||||
struct iphdr *hdr;
|
struct iphdr *hdr;
|
||||||
struct smack_known *hskp;
|
struct smack_known *hskp;
|
||||||
@ -4479,7 +4472,7 @@ static int smack_inet_conn_request(const struct sock *sk, struct sk_buff *skb,
|
|||||||
static void smack_inet_csk_clone(struct sock *sk,
|
static void smack_inet_csk_clone(struct sock *sk,
|
||||||
const struct request_sock *req)
|
const struct request_sock *req)
|
||||||
{
|
{
|
||||||
struct socket_smack *ssp = sk->sk_security;
|
struct socket_smack *ssp = smack_sock(sk);
|
||||||
struct smack_known *skp;
|
struct smack_known *skp;
|
||||||
|
|
||||||
if (req->peer_secid != 0) {
|
if (req->peer_secid != 0) {
|
||||||
@ -5049,6 +5042,7 @@ struct lsm_blob_sizes smack_blob_sizes __ro_after_init = {
|
|||||||
.lbs_inode = sizeof(struct inode_smack),
|
.lbs_inode = sizeof(struct inode_smack),
|
||||||
.lbs_ipc = sizeof(struct smack_known *),
|
.lbs_ipc = sizeof(struct smack_known *),
|
||||||
.lbs_msg_msg = sizeof(struct smack_known *),
|
.lbs_msg_msg = sizeof(struct smack_known *),
|
||||||
|
.lbs_sock = sizeof(struct socket_smack),
|
||||||
.lbs_superblock = sizeof(struct superblock_smack),
|
.lbs_superblock = sizeof(struct superblock_smack),
|
||||||
.lbs_xattr_count = SMACK_INODE_INIT_XATTRS,
|
.lbs_xattr_count = SMACK_INODE_INIT_XATTRS,
|
||||||
};
|
};
|
||||||
@ -5173,7 +5167,9 @@ static struct security_hook_list smack_hooks[] __ro_after_init = {
|
|||||||
LSM_HOOK_INIT(socket_getpeersec_stream, smack_socket_getpeersec_stream),
|
LSM_HOOK_INIT(socket_getpeersec_stream, smack_socket_getpeersec_stream),
|
||||||
LSM_HOOK_INIT(socket_getpeersec_dgram, smack_socket_getpeersec_dgram),
|
LSM_HOOK_INIT(socket_getpeersec_dgram, smack_socket_getpeersec_dgram),
|
||||||
LSM_HOOK_INIT(sk_alloc_security, smack_sk_alloc_security),
|
LSM_HOOK_INIT(sk_alloc_security, smack_sk_alloc_security),
|
||||||
|
#ifdef SMACK_IPV6_PORT_LABELING
|
||||||
LSM_HOOK_INIT(sk_free_security, smack_sk_free_security),
|
LSM_HOOK_INIT(sk_free_security, smack_sk_free_security),
|
||||||
|
#endif
|
||||||
LSM_HOOK_INIT(sk_clone_security, smack_sk_clone_security),
|
LSM_HOOK_INIT(sk_clone_security, smack_sk_clone_security),
|
||||||
LSM_HOOK_INIT(sock_graft, smack_sock_graft),
|
LSM_HOOK_INIT(sock_graft, smack_sock_graft),
|
||||||
LSM_HOOK_INIT(inet_conn_request, smack_inet_conn_request),
|
LSM_HOOK_INIT(inet_conn_request, smack_inet_conn_request),
|
||||||
|
@ -26,8 +26,8 @@ static unsigned int smack_ip_output(void *priv,
|
|||||||
struct socket_smack *ssp;
|
struct socket_smack *ssp;
|
||||||
struct smack_known *skp;
|
struct smack_known *skp;
|
||||||
|
|
||||||
if (sk && sk->sk_security) {
|
if (sk) {
|
||||||
ssp = sk->sk_security;
|
ssp = smack_sock(sk);
|
||||||
skp = ssp->smk_out;
|
skp = ssp->smk_out;
|
||||||
skb->secmark = skp->smk_secid;
|
skb->secmark = skp->smk_secid;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user