|
50 | 50 | #define SMK_RECEIVING 1
|
51 | 51 | #define SMK_SENDING 2
|
52 | 52 |
|
53 |
| -#ifdef SMACK_IPV6_PORT_LABELING |
54 |
| -DEFINE_MUTEX(smack_ipv6_lock); |
| 53 | +static DEFINE_MUTEX(smack_ipv6_lock); |
55 | 54 | static LIST_HEAD(smk_ipv6_port_list);
|
56 |
| -#endif |
57 |
| -static struct kmem_cache *smack_inode_cache; |
58 | 55 | struct kmem_cache *smack_rule_cache;
|
59 | 56 | int smack_enabled;
|
60 | 57 |
|
@@ -316,7 +313,6 @@ static void init_inode_smack(struct inode *inode, struct smack_known *skp)
|
316 | 313 |
|
317 | 314 | isp->smk_inode = skp;
|
318 | 315 | isp->smk_flags = 0;
|
319 |
| - mutex_init(&isp->smk_lock); |
320 | 316 | }
|
321 | 317 |
|
322 | 318 | /**
|
@@ -2320,7 +2316,6 @@ static struct smack_known *smack_ipv4host_label(struct sockaddr_in *sip)
|
2320 | 2316 | return NULL;
|
2321 | 2317 | }
|
2322 | 2318 |
|
2323 |
| -#if IS_ENABLED(CONFIG_IPV6) |
2324 | 2319 | /*
|
2325 | 2320 | * smk_ipv6_localhost - Check for local ipv6 host address
|
2326 | 2321 | * @sip: the address
|
@@ -2388,7 +2383,6 @@ static struct smack_known *smack_ipv6host_label(struct sockaddr_in6 *sip)
|
2388 | 2383 |
|
2389 | 2384 | return NULL;
|
2390 | 2385 | }
|
2391 |
| -#endif /* CONFIG_IPV6 */ |
2392 | 2386 |
|
2393 | 2387 | /**
|
2394 | 2388 | * smack_netlabel - Set the secattr on a socket
|
@@ -2477,7 +2471,6 @@ static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
|
2477 | 2471 | return smack_netlabel(sk, sk_lbl);
|
2478 | 2472 | }
|
2479 | 2473 |
|
2480 |
| -#if IS_ENABLED(CONFIG_IPV6) |
2481 | 2474 | /**
|
2482 | 2475 | * smk_ipv6_check - check Smack access
|
2483 | 2476 | * @subject: subject Smack label
|
@@ -2510,7 +2503,6 @@ static int smk_ipv6_check(struct smack_known *subject,
|
2510 | 2503 | rc = smk_bu_note("IPv6 check", subject, object, MAY_WRITE, rc);
|
2511 | 2504 | return rc;
|
2512 | 2505 | }
|
2513 |
| -#endif /* CONFIG_IPV6 */ |
2514 | 2506 |
|
2515 | 2507 | #ifdef SMACK_IPV6_PORT_LABELING
|
2516 | 2508 | /**
|
@@ -2599,6 +2591,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
|
2599 | 2591 | mutex_unlock(&smack_ipv6_lock);
|
2600 | 2592 | return;
|
2601 | 2593 | }
|
| 2594 | +#endif |
2602 | 2595 |
|
2603 | 2596 | /**
|
2604 | 2597 | * 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,
|
2661 | 2654 |
|
2662 | 2655 | return smk_ipv6_check(skp, object, address, act);
|
2663 | 2656 | }
|
2664 |
| -#endif /* SMACK_IPV6_PORT_LABELING */ |
2665 | 2657 |
|
2666 | 2658 | /**
|
2667 | 2659 | * smack_inode_setsecurity - set smack xattrs
|
@@ -2836,24 +2828,21 @@ static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
|
2836 | 2828 | return 0;
|
2837 | 2829 | if (IS_ENABLED(CONFIG_IPV6) && sap->sa_family == AF_INET6) {
|
2838 | 2830 | 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; |
2842 | 2832 |
|
2843 | 2833 | if (addrlen < SIN6_LEN_RFC2133)
|
2844 | 2834 | 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); |
2847 | 2837 | if (rsp != NULL) {
|
2848 | 2838 | struct socket_smack *ssp = sock->sk->sk_security;
|
2849 | 2839 |
|
2850 | 2840 | rc = smk_ipv6_check(ssp->smk_out, rsp, sip,
|
2851 | 2841 | SMK_CONNECTING);
|
2852 | 2842 | }
|
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 | + |
2857 | 2846 | return rc;
|
2858 | 2847 | }
|
2859 | 2848 | 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)
|
3273 | 3262 |
|
3274 | 3263 | isp = smack_inode(inode);
|
3275 | 3264 |
|
3276 |
| - mutex_lock(&isp->smk_lock); |
3277 | 3265 | /*
|
3278 | 3266 | * If the inode is already instantiated
|
3279 | 3267 | * take the quick way out
|
3280 | 3268 | */
|
3281 | 3269 | if (isp->smk_flags & SMK_INODE_INSTANT)
|
3282 |
| - goto unlockandout; |
| 3270 | + return; |
3283 | 3271 |
|
3284 | 3272 | sbp = inode->i_sb;
|
3285 | 3273 | sbsp = sbp->s_security;
|
@@ -3330,7 +3318,7 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
|
3330 | 3318 | break;
|
3331 | 3319 | }
|
3332 | 3320 | isp->smk_flags |= SMK_INODE_INSTANT;
|
3333 |
| - goto unlockandout; |
| 3321 | + return; |
3334 | 3322 | }
|
3335 | 3323 |
|
3336 | 3324 | /*
|
@@ -3465,8 +3453,6 @@ static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
|
3465 | 3453 |
|
3466 | 3454 | isp->smk_flags |= (SMK_INODE_INSTANT | transflag);
|
3467 | 3455 |
|
3468 |
| -unlockandout: |
3469 |
| - mutex_unlock(&isp->smk_lock); |
3470 | 3456 | return;
|
3471 | 3457 | }
|
3472 | 3458 |
|
@@ -4760,15 +4746,9 @@ static __init int smack_init(void)
|
4760 | 4746 | struct cred *cred = (struct cred *) current->cred;
|
4761 | 4747 | struct task_smack *tsp;
|
4762 | 4748 |
|
4763 |
| - smack_inode_cache = KMEM_CACHE(inode_smack, 0); |
4764 |
| - if (!smack_inode_cache) |
4765 |
| - return -ENOMEM; |
4766 |
| - |
4767 | 4749 | 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) |
4770 | 4751 | return -ENOMEM;
|
4771 |
| - } |
4772 | 4752 |
|
4773 | 4753 | /*
|
4774 | 4754 | * Set the security state for the initial task.
|
|
0 commit comments