Skip to content

Commit acf25aa

Browse files
committed
Merge tag 'Smack-for-5.8' of git://github.com/cschaufler/smack-next
Pull smack updates from Casey Schaufler: "Clean out dead code and repair an out-of-bounds warning" * tag 'Smack-for-5.8' of git://github.com/cschaufler/smack-next: Smack: Remove unused inline function smk_ad_setfield_u_fs_path_mnt Smack:- Remove redundant inode_smack cache Smack:- Remove mutex lock "smk_lock" from inode_smack Smack: slab-out-of-bounds in vsscanf smack: remove redundant structure variable from header. smack: avoid unused 'sip' variable warning
2 parents a484a49 + ef26650 commit acf25aa

File tree

3 files changed

+21
-43
lines changed

3 files changed

+21
-43
lines changed

security/smack/smack.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,7 @@ struct inode_smack {
109109
struct smack_known *smk_inode; /* label of the fso */
110110
struct smack_known *smk_task; /* label of the task */
111111
struct smack_known *smk_mmap; /* label of the mmap domain */
112-
struct mutex smk_lock; /* initialization lock */
113112
int smk_flags; /* smack inode flags */
114-
struct rcu_head smk_rcu; /* for freeing inode_smack */
115113
};
116114

117115
struct task_smack {
@@ -148,7 +146,6 @@ struct smk_net4addr {
148146
struct smack_known *smk_label; /* label */
149147
};
150148

151-
#if IS_ENABLED(CONFIG_IPV6)
152149
/*
153150
* An entry in the table identifying IPv6 hosts.
154151
*/
@@ -159,9 +156,7 @@ struct smk_net6addr {
159156
int smk_masks; /* mask size */
160157
struct smack_known *smk_label; /* label */
161158
};
162-
#endif /* CONFIG_IPV6 */
163159

164-
#ifdef SMACK_IPV6_PORT_LABELING
165160
/*
166161
* An entry in the table identifying ports.
167162
*/
@@ -174,7 +169,6 @@ struct smk_port_label {
174169
short smk_sock_type; /* Socket type */
175170
short smk_can_reuse;
176171
};
177-
#endif /* SMACK_IPV6_PORT_LABELING */
178172

179173
struct smack_known_list_elem {
180174
struct list_head list;
@@ -335,9 +329,7 @@ extern struct smack_known smack_known_web;
335329
extern struct mutex smack_known_lock;
336330
extern struct list_head smack_known_list;
337331
extern struct list_head smk_net4addr_list;
338-
#if IS_ENABLED(CONFIG_IPV6)
339332
extern struct list_head smk_net6addr_list;
340-
#endif /* CONFIG_IPV6 */
341333

342334
extern struct mutex smack_onlycap_lock;
343335
extern struct list_head smack_onlycap_list;
@@ -505,10 +497,6 @@ static inline void smk_ad_setfield_u_fs_path_dentry(struct smk_audit_info *a,
505497
struct dentry *d)
506498
{
507499
}
508-
static inline void smk_ad_setfield_u_fs_path_mnt(struct smk_audit_info *a,
509-
struct vfsmount *m)
510-
{
511-
}
512500
static inline void smk_ad_setfield_u_fs_inode(struct smk_audit_info *a,
513501
struct inode *i)
514502
{

security/smack/smack_lsm.c

Lines changed: 11 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,8 @@
5050
#define SMK_RECEIVING 1
5151
#define SMK_SENDING 2
5252

53-
#ifdef SMACK_IPV6_PORT_LABELING
54-
DEFINE_MUTEX(smack_ipv6_lock);
53+
static DEFINE_MUTEX(smack_ipv6_lock);
5554
static LIST_HEAD(smk_ipv6_port_list);
56-
#endif
57-
static struct kmem_cache *smack_inode_cache;
5855
struct kmem_cache *smack_rule_cache;
5956
int smack_enabled;
6057

@@ -316,7 +313,6 @@ static void init_inode_smack(struct inode *inode, struct smack_known *skp)
316313

317314
isp->smk_inode = skp;
318315
isp->smk_flags = 0;
319-
mutex_init(&isp->smk_lock);
320316
}
321317

322318
/**
@@ -2320,7 +2316,6 @@ static struct smack_known *smack_ipv4host_label(struct sockaddr_in *sip)
23202316
return NULL;
23212317
}
23222318

2323-
#if IS_ENABLED(CONFIG_IPV6)
23242319
/*
23252320
* smk_ipv6_localhost - Check for local ipv6 host address
23262321
* @sip: the address
@@ -2388,7 +2383,6 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip)
23882383

23892384
return NULL;
23902385
}
2391-
#endif /* CONFIG_IPV6 */
23922386

23932387
/**
23942388
* smack_netlabel - Set the secattr on a socket
@@ -2477,7 +2471,6 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
24772471
return smack_netlabel(sk, sk_lbl);
24782472
}
24792473

2480-
#if IS_ENABLED(CONFIG_IPV6)
24812474
/**
24822475
* smk_ipv6_check - check Smack access
24832476
* @subject: subject Smack label
@@ -2510,7 +2503,6 @@ static int smk_ipv6_check(struct smack_known *subject,
25102503
rc = smk_bu_note("IPv6 check", subject, object, MAY_WRITE, rc);
25112504
return rc;
25122505
}
2513-
#endif /* CONFIG_IPV6 */
25142506

25152507
#ifdef SMACK_IPV6_PORT_LABELING
25162508
/**
@@ -2599,6 +2591,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
25992591
mutex_unlock(&smack_ipv6_lock);
26002592
return;
26012593
}
2594+
#endif
26022595

26032596
/**
26042597
* smk_ipv6_port_check - check Smack port access
@@ -2661,7 +2654,6 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
26612654

26622655
return smk_ipv6_check(skp, object, address, act);
26632656
}
2664-
#endif /* SMACK_IPV6_PORT_LABELING */
26652657

26662658
/**
26672659
* smack_inode_setsecurity - set smack xattrs
@@ -2836,24 +2828,21 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
28362828
return 0;
28372829
if (IS_ENABLED(CONFIG_IPV6) && sap->sa_family == AF_INET6) {
28382830
struct sockaddr_in6 *sip = (struct sockaddr_in6 *)sap;
2839-
#ifdef SMACK_IPV6_SECMARK_LABELING
2840-
struct smack_known *rsp;
2841-
#endif
2831+
struct smack_known *rsp = NULL;
28422832

28432833
if (addrlen < SIN6_LEN_RFC2133)
28442834
return 0;
2845-
#ifdef SMACK_IPV6_SECMARK_LABELING
2846-
rsp = smack_ipv6host_label(sip);
2835+
if (__is_defined(SMACK_IPV6_SECMARK_LABELING))
2836+
rsp = smack_ipv6host_label(sip);
28472837
if (rsp != NULL) {
28482838
struct socket_smack *ssp = sock->sk->sk_security;
28492839

28502840
rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
28512841
SMK_CONNECTING);
28522842
}
2853-
#endif
2854-
#ifdef SMACK_IPV6_PORT_LABELING
2855-
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2856-
#endif
2843+
if (__is_defined(SMACK_IPV6_PORT_LABELING))
2844+
rc = smk_ipv6_port_check(sock->sk, sip, SMK_CONNECTING);
2845+
28572846
return rc;
28582847
}
28592848
if (sap->sa_family != AF_INET || addrlen < sizeof(struct sockaddr_in))
@@ -3273,13 +3262,12 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
32733262

32743263
isp = smack_inode(inode);
32753264

3276-
mutex_lock(&isp->smk_lock);
32773265
/*
32783266
* If the inode is already instantiated
32793267
* take the quick way out
32803268
*/
32813269
if (isp->smk_flags & SMK_INODE_INSTANT)
3282-
goto unlockandout;
3270+
return;
32833271

32843272
sbp = inode->i_sb;
32853273
sbsp = sbp->s_security;
@@ -3330,7 +3318,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
33303318
break;
33313319
}
33323320
isp->smk_flags |= SMK_INODE_INSTANT;
3333-
goto unlockandout;
3321+
return;
33343322
}
33353323

33363324
/*
@@ -3465,8 +3453,6 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
34653453

34663454
isp->smk_flags |= (SMK_INODE_INSTANT | transflag);
34673455

3468-
unlockandout:
3469-
mutex_unlock(&isp->smk_lock);
34703456
return;
34713457
}
34723458

@@ -4760,15 +4746,9 @@ static __init int smack_init(void)
47604746
struct cred *cred = (struct cred *) current->cred;
47614747
struct task_smack *tsp;
47624748

4763-
smack_inode_cache = KMEM_CACHE(inode_smack, 0);
4764-
if (!smack_inode_cache)
4765-
return -ENOMEM;
4766-
47674749
smack_rule_cache = KMEM_CACHE(smack_rule, 0);
4768-
if (!smack_rule_cache) {
4769-
kmem_cache_destroy(smack_inode_cache);
4750+
if (!smack_rule_cache)
47704751
return -ENOMEM;
4771-
}
47724752

47734753
/*
47744754
* Set the security state for the initial task.

security/smack/smackfs.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -878,11 +878,21 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
878878
else
879879
rule += strlen(skp->smk_known) + 1;
880880

881+
if (rule > data + count) {
882+
rc = -EOVERFLOW;
883+
goto out;
884+
}
885+
881886
ret = sscanf(rule, "%d", &maplevel);
882887
if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
883888
goto out;
884889

885890
rule += SMK_DIGITLEN;
891+
if (rule > data + count) {
892+
rc = -EOVERFLOW;
893+
goto out;
894+
}
895+
886896
ret = sscanf(rule, "%d", &catlen);
887897
if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
888898
goto out;

0 commit comments

Comments
 (0)