Skip to content

Commit d0c294c

Browse files
mkubecekdavem330
authored andcommitted
tcp: prevent fetching dst twice in early demux code
On s390x, gcc 4.8 compiles this part of tcp_v6_early_demux() struct dst_entry *dst = sk->sk_rx_dst; if (dst) dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie); to code reading sk->sk_rx_dst twice, once for the test and once for the argument of ip6_dst_check() (dst_check() is inline). This allows ip6_dst_check() to be called with null first argument, causing a crash. Protect sk->sk_rx_dst access by READ_ONCE() both in IPv4 and IPv6 TCP early demux code. Fixes: 41063e9 ("ipv4: Early TCP socket demux.") Fixes: c710998 ("ipv6: Early TCP socket demux") Signed-off-by: Michal Kubecek <[email protected]> Acked-by: Eric Dumazet <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent dff173d commit d0c294c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

net/ipv4/tcp_ipv4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1518,7 +1518,7 @@ void tcp_v4_early_demux(struct sk_buff *skb)
15181518
skb->sk = sk;
15191519
skb->destructor = sock_edemux;
15201520
if (sk->sk_state != TCP_TIME_WAIT) {
1521-
struct dst_entry *dst = sk->sk_rx_dst;
1521+
struct dst_entry *dst = READ_ONCE(sk->sk_rx_dst);
15221522

15231523
if (dst)
15241524
dst = dst_check(dst, 0);

net/ipv6/tcp_ipv6.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ static void tcp_v6_early_demux(struct sk_buff *skb)
15851585
skb->sk = sk;
15861586
skb->destructor = sock_edemux;
15871587
if (sk->sk_state != TCP_TIME_WAIT) {
1588-
struct dst_entry *dst = sk->sk_rx_dst;
1588+
struct dst_entry *dst = READ_ONCE(sk->sk_rx_dst);
15891589

15901590
if (dst)
15911591
dst = dst_check(dst, inet6_sk(sk)->rx_dst_cookie);

0 commit comments

Comments
 (0)