aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2015-03-24 18:58:54 -0400
committerDavid S. Miller <davem@davemloft.net>2015-03-24 21:16:29 -0400
commitff74e23f7edb3759d1290b10f80222e3bbb6304b (patch)
tree72cb9b6121234d31fc179bf9d780c51f3c3a6e85
parent0980c1e3084572b1d6c35ace5d795cf68b7ae409 (diff)
tcp: md5: input path is run under rcu protected sections
It is guaranteed that both tcp_v4_rcv() and tcp_v6_rcv() run from rcu read locked sections : ip_local_deliver_finish() and ip6_input_finish() both use rcu_read_lock() Also align tcp_v6_inbound_md5_hash() on tcp_v4_inbound_md5_hash() by returning a boolean. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--net/ipv4/tcp_ipv4.c17
-rw-r--r--net/ipv6/tcp_ipv6.c25
2 files changed, 9 insertions, 33 deletions
diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
index 4e90217003e8..d339a0488f51 100644
--- a/net/ipv4/tcp_ipv4.c
+++ b/net/ipv4/tcp_ipv4.c
@@ -1153,8 +1153,9 @@ clear_hash_noput:
1153} 1153}
1154EXPORT_SYMBOL(tcp_v4_md5_hash_skb); 1154EXPORT_SYMBOL(tcp_v4_md5_hash_skb);
1155 1155
1156static bool __tcp_v4_inbound_md5_hash(struct sock *sk, 1156/* Called with rcu_read_lock() */
1157 const struct sk_buff *skb) 1157static bool tcp_v4_inbound_md5_hash(struct sock *sk,
1158 const struct sk_buff *skb)
1158{ 1159{
1159 /* 1160 /*
1160 * This gets called for each TCP segment that arrives 1161 * This gets called for each TCP segment that arrives
@@ -1206,18 +1207,6 @@ static bool __tcp_v4_inbound_md5_hash(struct sock *sk,
1206 } 1207 }
1207 return false; 1208 return false;
1208} 1209}
1209
1210static bool tcp_v4_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
1211{
1212 bool ret;
1213
1214 rcu_read_lock();
1215 ret = __tcp_v4_inbound_md5_hash(sk, skb);
1216 rcu_read_unlock();
1217
1218 return ret;
1219}
1220
1221#endif 1210#endif
1222 1211
1223static void tcp_v4_init_req(struct request_sock *req, struct sock *sk_listener, 1212static void tcp_v4_init_req(struct request_sock *req, struct sock *sk_listener,
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index 4a4e6d30c448..078e7d0f4cd8 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -633,8 +633,7 @@ clear_hash_noput:
633 return 1; 633 return 1;
634} 634}
635 635
636static int __tcp_v6_inbound_md5_hash(struct sock *sk, 636static bool tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
637 const struct sk_buff *skb)
638{ 637{
639 const __u8 *hash_location = NULL; 638 const __u8 *hash_location = NULL;
640 struct tcp_md5sig_key *hash_expected; 639 struct tcp_md5sig_key *hash_expected;
@@ -648,16 +647,16 @@ static int __tcp_v6_inbound_md5_hash(struct sock *sk,
648 647
649 /* We've parsed the options - do we have a hash? */ 648 /* We've parsed the options - do we have a hash? */
650 if (!hash_expected && !hash_location) 649 if (!hash_expected && !hash_location)
651 return 0; 650 return false;
652 651
653 if (hash_expected && !hash_location) { 652 if (hash_expected && !hash_location) {
654 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND); 653 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5NOTFOUND);
655 return 1; 654 return true;
656 } 655 }
657 656
658 if (!hash_expected && hash_location) { 657 if (!hash_expected && hash_location) {
659 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED); 658 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_TCPMD5UNEXPECTED);
660 return 1; 659 return true;
661 } 660 }
662 661
663 /* check the signature */ 662 /* check the signature */
@@ -670,22 +669,10 @@ static int __tcp_v6_inbound_md5_hash(struct sock *sk,
670 genhash ? "failed" : "mismatch", 669 genhash ? "failed" : "mismatch",
671 &ip6h->saddr, ntohs(th->source), 670 &ip6h->saddr, ntohs(th->source),
672 &ip6h->daddr, ntohs(th->dest)); 671 &ip6h->daddr, ntohs(th->dest));
673 return 1; 672 return true;
674 } 673 }
675 return 0; 674 return false;
676}
677
678static int tcp_v6_inbound_md5_hash(struct sock *sk, const struct sk_buff *skb)
679{
680 int ret;
681
682 rcu_read_lock();
683 ret = __tcp_v6_inbound_md5_hash(sk, skb);
684 rcu_read_unlock();
685
686 return ret;
687} 675}
688
689#endif 676#endif
690 677
691static void tcp_v6_init_req(struct request_sock *req, struct sock *sk, 678static void tcp_v6_init_req(struct request_sock *req, struct sock *sk,