Skip to content

Commit 6f2b76a

Browse files
committed
Merge tag 'Smack-for-5.16' of https://github.com/cschaufler/smack-next
Pull smack updates from Casey Schaufler: "Multiple corrections to smackfs: - a change for overlayfs support that corrects the initial attributes on created files - code clean-up for netlabel processing - several fixes in smackfs for a variety of reasons - Errors reported by W=1 have been addressed All told, nothing challenging" * tag 'Smack-for-5.16' of https://github.com/cschaufler/smack-next: smackfs: use netlbl_cfg_cipsov4_del() for deleting cipso_v4_doi smackfs: use __GFP_NOFAIL for smk_cipso_doi() Smack: fix W=1 build warnings smack: remove duplicated hook function Smack:- Use overlay inode label in smack_inode_copy_up() smack: Guard smack_ipv6_lock definition within a SMACK_IPV6_PORT_LABELING block smackfs: Fix use-after-free in netlbl_catmap_walk()
2 parents f2786f4 + 0934ad4 commit 6f2b76a

File tree

3 files changed

+34
-44
lines changed

3 files changed

+34
-44
lines changed

security/smack/smack_lsm.c

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,10 @@
5151
#define SMK_RECEIVING 1
5252
#define SMK_SENDING 2
5353

54+
#ifdef SMACK_IPV6_PORT_LABELING
5455
static DEFINE_MUTEX(smack_ipv6_lock);
5556
static LIST_HEAD(smk_ipv6_port_list);
57+
#endif
5658
struct kmem_cache *smack_rule_cache;
5759
int smack_enabled __initdata;
5860

@@ -389,7 +391,7 @@ static int smk_copy_relabel(struct list_head *nhead, struct list_head *ohead,
389391

390392
/**
391393
* smk_ptrace_mode - helper function for converting PTRACE_MODE_* into MAY_*
392-
* @mode - input mode in form of PTRACE_MODE_*
394+
* @mode: input mode in form of PTRACE_MODE_*
393395
*
394396
* Returns a converted MAY_* mode usable by smack rules
395397
*/
@@ -1213,6 +1215,7 @@ static int smack_inode_getattr(const struct path *path)
12131215

12141216
/**
12151217
* smack_inode_setxattr - Smack check for setting xattrs
1218+
* @mnt_userns: active user namespace
12161219
* @dentry: the object
12171220
* @name: name of the attribute
12181221
* @value: value of the attribute
@@ -1339,6 +1342,7 @@ static int smack_inode_getxattr(struct dentry *dentry, const char *name)
13391342

13401343
/**
13411344
* smack_inode_removexattr - Smack check on removexattr
1345+
* @mnt_userns: active user namespace
13421346
* @dentry: the object
13431347
* @name: name of the attribute
13441348
*
@@ -1398,6 +1402,7 @@ static int smack_inode_removexattr(struct user_namespace *mnt_userns,
13981402

13991403
/**
14001404
* smack_inode_getsecurity - get smack xattrs
1405+
* @mnt_userns: active user namespace
14011406
* @inode: the object
14021407
* @name: attribute name
14031408
* @buffer: where to put the result
@@ -1619,13 +1624,14 @@ static int smack_file_fcntl(struct file *file, unsigned int cmd,
16191624
}
16201625

16211626
/**
1622-
* smack_mmap_file :
1623-
* Check permissions for a mmap operation. The @file may be NULL, e.g.
1624-
* if mapping anonymous memory.
1625-
* @file contains the file structure for file to map (may be NULL).
1626-
* @reqprot contains the protection requested by the application.
1627-
* @prot contains the protection that will be applied by the kernel.
1628-
* @flags contains the operational flags.
1627+
* smack_mmap_file - Check permissions for a mmap operation.
1628+
* @file: contains the file structure for file to map (may be NULL).
1629+
* @reqprot: contains the protection requested by the application.
1630+
* @prot: contains the protection that will be applied by the kernel.
1631+
* @flags: contains the operational flags.
1632+
*
1633+
* The @file may be NULL, e.g. if mapping anonymous memory.
1634+
*
16291635
* Return 0 if permission is granted.
16301636
*/
16311637
static int smack_mmap_file(struct file *file,
@@ -2603,7 +2609,6 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
26032609
mutex_unlock(&smack_ipv6_lock);
26042610
return;
26052611
}
2606-
#endif
26072612

26082613
/**
26092614
* smk_ipv6_port_check - check Smack port access
@@ -2666,6 +2671,7 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
26662671

26672672
return smk_ipv6_check(skp, object, address, act);
26682673
}
2674+
#endif
26692675

26702676
/**
26712677
* smack_inode_setsecurity - set smack xattrs
@@ -2852,8 +2858,9 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
28522858
rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
28532859
SMK_CONNECTING);
28542860
}
2855-
if (__is_defined(SMACK_IPV6_PORT_LABELING))
2856-
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2861+
#ifdef SMACK_IPV6_PORT_LABELING
2862+
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2863+
#endif
28572864

28582865
return rc;
28592866
}
@@ -3051,7 +3058,7 @@ static int smack_sem_associate(struct kern_ipc_perm *isp, int semflg)
30513058
}
30523059

30533060
/**
3054-
* smack_sem_shmctl - Smack access check for sem
3061+
* smack_sem_semctl - Smack access check for sem
30553062
* @isp: the object
30563063
* @cmd: what it wants to do
30573064
*
@@ -3197,7 +3204,7 @@ static int smack_msg_queue_msgsnd(struct kern_ipc_perm *isp, struct msg_msg *msg
31973204
}
31983205

31993206
/**
3200-
* smack_msg_queue_msgsnd - Smack access check for msg_queue
3207+
* smack_msg_queue_msgrcv - Smack access check for msg_queue
32013208
* @isp: the object
32023209
* @msg: unused
32033210
* @target: unused
@@ -3206,8 +3213,10 @@ static int smack_msg_queue_msgsnd(struct kern_ipc_perm *isp, struct msg_msg *msg
32063213
*
32073214
* Returns 0 if current has read and write access, error code otherwise
32083215
*/
3209-
static int smack_msg_queue_msgrcv(struct kern_ipc_perm *isp, struct msg_msg *msg,
3210-
struct task_struct *target, long type, int mode)
3216+
static int smack_msg_queue_msgrcv(struct kern_ipc_perm *isp,
3217+
struct msg_msg *msg,
3218+
struct task_struct *target, long type,
3219+
int mode)
32113220
{
32123221
return smk_curacc_msq(isp, MAY_READWRITE);
32133222
}
@@ -4634,7 +4643,7 @@ static int smack_inode_copy_up(struct dentry *dentry, struct cred **new)
46344643
/*
46354644
* Get label from overlay inode and set it in create_sid
46364645
*/
4637-
isp = smack_inode(d_inode(dentry->d_parent));
4646+
isp = smack_inode(d_inode(dentry));
46384647
skp = isp->smk_inode;
46394648
tsp->smk_task = skp;
46404649
*new = new_creds;

security/smack/smack_netfilter.c

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -18,27 +18,7 @@
1818
#include <net/net_namespace.h>
1919
#include "smack.h"
2020

21-
#if IS_ENABLED(CONFIG_IPV6)
22-
23-
static unsigned int smack_ipv6_output(void *priv,
24-
struct sk_buff *skb,
25-
const struct nf_hook_state *state)
26-
{
27-
struct sock *sk = skb_to_full_sk(skb);
28-
struct socket_smack *ssp;
29-
struct smack_known *skp;
30-
31-
if (sk && sk->sk_security) {
32-
ssp = sk->sk_security;
33-
skp = ssp->smk_out;
34-
skb->secmark = skp->smk_secid;
35-
}
36-
37-
return NF_ACCEPT;
38-
}
39-
#endif /* IPV6 */
40-
41-
static unsigned int smack_ipv4_output(void *priv,
21+
static unsigned int smack_ip_output(void *priv,
4222
struct sk_buff *skb,
4323
const struct nf_hook_state *state)
4424
{
@@ -57,14 +37,14 @@ static unsigned int smack_ipv4_output(void *priv,
5737

5838
static const struct nf_hook_ops smack_nf_ops[] = {
5939
{
60-
.hook = smack_ipv4_output,
40+
.hook = smack_ip_output,
6141
.pf = NFPROTO_IPV4,
6242
.hooknum = NF_INET_LOCAL_OUT,
6343
.priority = NF_IP_PRI_SELINUX_FIRST,
6444
},
6545
#if IS_ENABLED(CONFIG_IPV6)
6646
{
67-
.hook = smack_ipv6_output,
47+
.hook = smack_ip_output,
6848
.pf = NFPROTO_IPV6,
6949
.hooknum = NF_INET_LOCAL_OUT,
7050
.priority = NF_IP6_PRI_SELINUX_FIRST,

security/smack/smackfs.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -693,9 +693,7 @@ static void smk_cipso_doi(void)
693693
printk(KERN_WARNING "%s:%d remove rc = %d\n",
694694
__func__, __LINE__, rc);
695695

696-
doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL);
697-
if (doip == NULL)
698-
panic("smack: Failed to initialize cipso DOI.\n");
696+
doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL | __GFP_NOFAIL);
699697
doip->map.std = NULL;
700698
doip->doi = smk_cipso_doi_value;
701699
doip->type = CIPSO_V4_MAP_PASS;
@@ -714,7 +712,7 @@ static void smk_cipso_doi(void)
714712
if (rc != 0) {
715713
printk(KERN_WARNING "%s:%d map add rc = %d\n",
716714
__func__, __LINE__, rc);
717-
kfree(doip);
715+
netlbl_cfg_cipsov4_del(doip->doi, &nai);
718716
return;
719717
}
720718
}
@@ -831,6 +829,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file)
831829
static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
832830
size_t count, loff_t *ppos, int format)
833831
{
832+
struct netlbl_lsm_catmap *old_cat;
834833
struct smack_known *skp;
835834
struct netlbl_lsm_secattr ncats;
836835
char mapcatset[SMK_CIPSOLEN];
@@ -920,9 +919,11 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
920919

921920
rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
922921
if (rc >= 0) {
923-
netlbl_catmap_free(skp->smk_netlabel.attr.mls.cat);
922+
old_cat = skp->smk_netlabel.attr.mls.cat;
924923
skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
925924
skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
925+
synchronize_rcu();
926+
netlbl_catmap_free(old_cat);
926927
rc = count;
927928
/*
928929
* This mapping may have been cached, so clear the cache.

0 commit comments

Comments
 (0)