Skip to content

Commit 284904a

Browse files
pcmooreJames Morris
authored andcommitted
lsm: Relocate the IPv4 security_inet_conn_request() hooks
The current placement of the security_inet_conn_request() hooks do not allow individual LSMs to override the IP options of the connection's request_sock. This is a problem as both SELinux and Smack have the ability to use labeled networking protocols which make use of IP options to carry security attributes and the inability to set the IP options at the start of the TCP handshake is problematic. This patch moves the IPv4 security_inet_conn_request() hooks past the code where the request_sock's IP options are set/reset so that the LSM can safely manipulate the IP options as needed. This patch intentionally does not change the related IPv6 hooks as IPv6 based labeling protocols which use IPv6 options are not currently implemented, once they are we will have a better idea of the correct placement for the IPv6 hooks. Signed-off-by: Paul Moore <paul.moore@hp.com> Acked-by: David S. Miller <davem@davemloft.net> Signed-off-by: James Morris <jmorris@namei.org>
1 parent bb79816 commit 284904a

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

net/ipv4/syncookies.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -288,10 +288,6 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
288288
if (!req)
289289
goto out;
290290

291-
if (security_inet_conn_request(sk, skb, req)) {
292-
reqsk_free(req);
293-
goto out;
294-
}
295291
ireq = inet_rsk(req);
296292
treq = tcp_rsk(req);
297293
treq->rcv_isn = ntohl(th->seq) - 1;
@@ -322,6 +318,11 @@ struct sock *cookie_v4_check(struct sock *sk, struct sk_buff *skb,
322318
}
323319
}
324320

321+
if (security_inet_conn_request(sk, skb, req)) {
322+
reqsk_free(req);
323+
goto out;
324+
}
325+
325326
req->expires = 0UL;
326327
req->retrans = 0;
327328

net/ipv4/tcp_ipv4.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1230,14 +1230,15 @@ int tcp_v4_conn_request(struct sock *sk, struct sk_buff *skb)
12301230

12311231
tcp_openreq_init(req, &tmp_opt, skb);
12321232

1233-
if (security_inet_conn_request(sk, skb, req))
1234-
goto drop_and_free;
1235-
12361233
ireq = inet_rsk(req);
12371234
ireq->loc_addr = daddr;
12381235
ireq->rmt_addr = saddr;
12391236
ireq->no_srccheck = inet_sk(sk)->transparent;
12401237
ireq->opt = tcp_v4_save_options(sk, skb);
1238+
1239+
if (security_inet_conn_request(sk, skb, req))
1240+
goto drop_and_free;
1241+
12411242
if (!want_cookie)
12421243
TCP_ECN_create_request(req, tcp_hdr(skb));
12431244

0 commit comments

Comments
 (0)