Skip to content

Commit df4779b

Browse files
LenovoOpenLabpcmoore
authored andcommitted
selinux: remove redundant selinux_nlmsg_perm
selinux_nlmsg_perm is used for only by selinux_netlink_send. Remove the redundant function to simplify the code. Fix a typo by suggestion from Stephen. Signed-off-by: Huaisheng Ye <yehs1@lenovo.com> Acked-by: Stephen Smalley <sds@tycho.nsa.gov> Signed-off-by: Paul Moore <paul@paul-moore.com>
1 parent ae3d8c2 commit df4779b

1 file changed

Lines changed: 34 additions & 39 deletions

File tree

‎security/selinux/hooks.c‎

Lines changed: 34 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5520,44 +5520,6 @@ static int selinux_tun_dev_open(void *security)
55205520
return 0;
55215521
}
55225522

5523-
static int selinux_nlmsg_perm(struct sock *sk, struct sk_buff *skb)
5524-
{
5525-
int err = 0;
5526-
u32 perm;
5527-
struct nlmsghdr *nlh;
5528-
struct sk_security_struct *sksec = sk->sk_security;
5529-
5530-
if (skb->len < NLMSG_HDRLEN) {
5531-
err = -EINVAL;
5532-
goto out;
5533-
}
5534-
nlh = nlmsg_hdr(skb);
5535-
5536-
err = selinux_nlmsg_lookup(sksec->sclass, nlh->nlmsg_type, &perm);
5537-
if (err) {
5538-
if (err == -EINVAL) {
5539-
pr_warn_ratelimited("SELinux: unrecognized netlink"
5540-
" message: protocol=%hu nlmsg_type=%hu sclass=%s"
5541-
" pig=%d comm=%s\n",
5542-
sk->sk_protocol, nlh->nlmsg_type,
5543-
secclass_map[sksec->sclass - 1].name,
5544-
task_pid_nr(current), current->comm);
5545-
if (!enforcing_enabled(&selinux_state) ||
5546-
security_get_allow_unknown(&selinux_state))
5547-
err = 0;
5548-
}
5549-
5550-
/* Ignore */
5551-
if (err == -ENOENT)
5552-
err = 0;
5553-
goto out;
5554-
}
5555-
5556-
err = sock_has_perm(sk, perm);
5557-
out:
5558-
return err;
5559-
}
5560-
55615523
#ifdef CONFIG_NETFILTER
55625524

55635525
static unsigned int selinux_ip_forward(struct sk_buff *skb,
@@ -5886,7 +5848,40 @@ static unsigned int selinux_ipv6_postroute(void *priv,
58865848

58875849
static int selinux_netlink_send(struct sock *sk, struct sk_buff *skb)
58885850
{
5889-
return selinux_nlmsg_perm(sk, skb);
5851+
int err = 0;
5852+
u32 perm;
5853+
struct nlmsghdr *nlh;
5854+
struct sk_security_struct *sksec = sk->sk_security;
5855+
5856+
if (skb->len < NLMSG_HDRLEN) {
5857+
err = -EINVAL;
5858+
goto out;
5859+
}
5860+
nlh = nlmsg_hdr(skb);
5861+
5862+
err = selinux_nlmsg_lookup(sksec->sclass, nlh->nlmsg_type, &perm);
5863+
if (err) {
5864+
if (err == -EINVAL) {
5865+
pr_warn_ratelimited("SELinux: unrecognized netlink"
5866+
" message: protocol=%hu nlmsg_type=%hu sclass=%s"
5867+
" pid=%d comm=%s\n",
5868+
sk->sk_protocol, nlh->nlmsg_type,
5869+
secclass_map[sksec->sclass - 1].name,
5870+
task_pid_nr(current), current->comm);
5871+
if (!enforcing_enabled(&selinux_state) ||
5872+
security_get_allow_unknown(&selinux_state))
5873+
err = 0;
5874+
}
5875+
5876+
/* Ignore */
5877+
if (err == -ENOENT)
5878+
err = 0;
5879+
goto out;
5880+
}
5881+
5882+
err = sock_has_perm(sk, perm);
5883+
out:
5884+
return err;
58905885
}
58915886

58925887
static void ipc_init_security(struct ipc_security_struct *isec, u16 sclass)

0 commit comments

Comments
 (0)