Skip to content

Commit f5d5476

Browse files
edumazetdavem330
authored andcommitted
tcp: fix tcp_inet6_sk() for 32bit kernels
It turns out that struct ipv6_pinfo is not located as we think. inet6_sk_generic() and tcp_inet6_sk() disagree on 32bit kernels by 4-bytes, because struct tcp_sock has 8-bytes alignment, but ipv6_pinfo size is not a multiple of 8. sizeof(struct ipv6_pinfo): 116 (not padded to 8) I actually first coded tcp_inet6_sk() as this patch does, but thought that "container_of(tcp_sk(sk), struct tcp6_sock, tcp)" was cleaner. As Julian told me : Nobody should use tcp6_sock.inet6 directly, it should be accessed via tcp_inet6_sk() or inet6_sk(). This happened when we added the first u64 field in struct tcp_sock. Fixes: 93a77c1 ("tcp: add tcp_inet6_sk() helper") Signed-off-by: Eric Dumazet <[email protected]> Bisected-by: Julian Anastasov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6578229 commit f5d5476

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

net/ipv6/tcp_ipv6.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,12 +93,13 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
9393
/* Helper returning the inet6 address from a given tcp socket.
9494
* It can be used in TCP stack instead of inet6_sk(sk).
9595
* This avoids a dereference and allow compiler optimizations.
96+
* It is a specialized version of inet6_sk_generic().
9697
*/
9798
static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)
9899
{
99-
struct tcp6_sock *tcp6 = container_of(tcp_sk(sk), struct tcp6_sock, tcp);
100+
unsigned int offset = sizeof(struct tcp6_sock) - sizeof(struct ipv6_pinfo);
100101

101-
return &tcp6->inet6;
102+
return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
102103
}
103104

104105
static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)

0 commit comments

Comments
 (0)