Skip to content

Commit 9d44c97

Browse files
Vishal Goelcschaufler
authored andcommitted
Smack: Fix the issue of permission denied error in ipv6 hook
Permission denied error comes when 2 IPv6 servers are running and client tries to connect one of them. Scenario is that both servers are using same IP and port but different protocols(Udp and tcp). They are using different SMACK64IPIN labels.Tcp server is using "test" and udp server is using "test-in". When we try to run tcp client with SMACK64IPOUT label as "test", then connection denied error comes. It should not happen since both tcp server and client labels are same.This happens because there is no check for protocol in smk_ipv6_port_label() function while searching for the earlier port entry. It checks whether there is an existing port entry on the basis of port only. So it updates the earlier port entry in the list. Due to which smack label gets changed for earlier entry in the "smk_ipv6_port_list" list and permission denied error comes. Now a check is added for socket type also.Now if 2 processes use same port but different protocols (tcp or udp), then 2 different port entries will be added in the list. Similarly while checking smack access in smk_ipv6_port_check() function, port entry is searched on the basis of both port and protocol. Signed-off-by: Vishal Goel <vishal.goel@samsung.com> Signed-off-by: Himanshu Shukla <Himanshu.sh@samsung.com> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent 3c7ce34 commit 9d44c97

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎security/smack/smack.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ struct smk_port_label {
173173
unsigned short smk_port; /* the port number */
174174
struct smack_known *smk_in; /* inbound label */
175175
struct smack_known *smk_out; /* outgoing label */
176+
short smk_sock_type; /* Socket type */
176177
};
177178
#endif /* SMACK_IPV6_PORT_LABELING */
178179

‎security/smack/smack_lsm.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2635,7 +2635,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
26352635
*/
26362636
rcu_read_lock();
26372637
list_for_each_entry_rcu(spp, &smk_ipv6_port_list, list) {
2638-
if (spp->smk_port != port)
2638+
if (spp->smk_port != port || spp->smk_sock_type != sock->type)
26392639
continue;
26402640
spp->smk_port = port;
26412641
spp->smk_sock = sk;
@@ -2656,6 +2656,7 @@ static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
26562656
spp->smk_sock = sk;
26572657
spp->smk_in = ssp->smk_in;
26582658
spp->smk_out = ssp->smk_out;
2659+
spp->smk_sock_type = sock->type;
26592660

26602661
mutex_lock(&smack_ipv6_lock);
26612662
list_add_rcu(&spp->list, &smk_ipv6_port_list);
@@ -2712,7 +2713,7 @@ static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
27122713
port = ntohs(address->sin6_port);
27132714
rcu_read_lock();
27142715
list_for_each_entry_rcu(spp, &smk_ipv6_port_list, list) {
2715-
if (spp->smk_port != port)
2716+
if (spp->smk_port != port || spp->smk_sock_type != sk->sk_type)
27162717
continue;
27172718
object = spp->smk_in;
27182719
if (act == SMK_CONNECTING)

0 commit comments

Comments
 (0)