Skip to content

Commit

Permalink
Revert "sock: Inline SELinux's sk_security to struct sock"
Browse files Browse the repository at this point in the history
This reverts commit 7a53a63.

Signed-off-by: Forenche <[email protected]>
  • Loading branch information
Forenche committed Apr 19, 2021
1 parent d1fbe1b commit 5a3597b
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 27 deletions.
18 changes: 1 addition & 17 deletions include/net/sock.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,22 +231,6 @@ struct sock_common {
/* public: */
};

struct sk_security_struct {
#ifdef CONFIG_NETLABEL
enum { /* NetLabel state */
NLBL_UNSET = 0,
NLBL_REQUIRE,
NLBL_LABELED,
NLBL_REQSKB,
NLBL_CONNLABELED,
} nlbl_state;
struct netlbl_lsm_secattr *nlbl_secattr; /* NetLabel sec attributes */
#endif
u32 sid; /* SID of this object */
u32 peer_sid; /* SID of peer */
u16 sclass; /* sock security class */
};

/**
* struct sock - network layer representation of sockets
* @__sk_common: shared layout with inet_timewait_sock
Expand Down Expand Up @@ -486,7 +470,7 @@ struct sock {
struct socket *sk_socket;
void *sk_user_data;
#ifdef CONFIG_SECURITY
struct sk_security_struct sk_security[1];
void *sk_security;
#endif
struct sock_cgroup_data sk_cgrp_data;
struct mem_cgroup *sk_memcg;
Expand Down
6 changes: 2 additions & 4 deletions net/core/sock.c
Original file line number Diff line number Diff line change
Expand Up @@ -1441,17 +1441,15 @@ static inline void sock_lock_init(struct sock *sk)
static void sock_copy(struct sock *nsk, const struct sock *osk)
{
#ifdef CONFIG_SECURITY_NETWORK
struct sk_security_struct sksec;
memcpy(&sksec, nsk->sk_security, sizeof(sksec));
void *sptr = nsk->sk_security;
#endif

memcpy(nsk, osk, offsetof(struct sock, sk_dontcopy_begin));

memcpy(&nsk->sk_dontcopy_end, &osk->sk_dontcopy_end,
osk->sk_prot->obj_size - offsetof(struct sock, sk_dontcopy_end));

#ifdef CONFIG_SECURITY_NETWORK
memcpy(nsk->sk_security, &sksec, sizeof(sksec));
nsk->sk_security = sptr;
security_sk_clone(osk, nsk);
#endif
}
Expand Down
14 changes: 9 additions & 5 deletions security/selinux/hooks.c
Original file line number Diff line number Diff line change
Expand Up @@ -5063,15 +5063,17 @@ static int selinux_socket_getpeersec_dgram(struct socket *sock, struct sk_buff *

static int selinux_sk_alloc_security(struct sock *sk, int family, gfp_t priority)
{
struct sk_security_struct *sksec = sk->sk_security;
struct sk_security_struct *sksec;

sksec = kzalloc(sizeof(*sksec), priority);
if (!sksec)
return -ENOMEM;

#ifdef CONFIG_NETLABEL
memset(sksec, 0, offsetof(struct sk_security_struct, sid));
#endif
sksec->peer_sid = SECINITSID_UNLABELED;
sksec->sid = SECINITSID_UNLABELED;
sksec->sclass = SECCLASS_SOCKET;
selinux_netlbl_sk_security_reset(sksec);
sk->sk_security = sksec;

return 0;
}
Expand All @@ -5080,12 +5082,14 @@ static void selinux_sk_free_security(struct sock *sk)
{
struct sk_security_struct *sksec = sk->sk_security;

sk->sk_security = NULL;
selinux_netlbl_sk_security_free(sksec);
kfree(sksec);
}

static void selinux_sk_clone_security(const struct sock *sk, struct sock *newsk)
{
const struct sk_security_struct *sksec = sk->sk_security;
struct sk_security_struct *sksec = sk->sk_security;
struct sk_security_struct *newsksec = newsk->sk_security;

newsksec->sid = sksec->sid;
Expand Down
16 changes: 16 additions & 0 deletions security/selinux/include/objsec.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,22 @@ struct netport_security_struct {
u8 protocol; /* transport protocol */
};

struct sk_security_struct {
#ifdef CONFIG_NETLABEL
enum { /* NetLabel state */
NLBL_UNSET = 0,
NLBL_REQUIRE,
NLBL_LABELED,
NLBL_REQSKB,
NLBL_CONNLABELED,
} nlbl_state;
struct netlbl_lsm_secattr *nlbl_secattr; /* NetLabel sec attributes */
#endif
u32 sid; /* SID of this object */
u32 peer_sid; /* SID of peer */
u16 sclass; /* sock security class */
};

struct tun_security_struct {
u32 sid; /* SID for the tun device sockets */
};
Expand Down
2 changes: 1 addition & 1 deletion security/selinux/netlabel.c
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ static struct netlbl_lsm_secattr *selinux_netlbl_sock_getattr(
const struct sock *sk,
u32 sid)
{
const struct sk_security_struct *sksec = sk->sk_security;
struct sk_security_struct *sksec = sk->sk_security;
struct netlbl_lsm_secattr *secattr = sksec->nlbl_secattr;

if (secattr == NULL)
Expand Down

0 comments on commit 5a3597b

Please sign in to comment.