* [PATCH net] tcp: fix tcp_inet6_sk() for 32bit kernels
@ 2019-04-01 10:09 Eric Dumazet
2019-04-01 17:22 ` David Miller
2019-04-01 21:05 ` Julian Anastasov
0 siblings, 2 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-04-01 10:09 UTC (permalink / raw)
To: David S . Miller; +Cc: netdev, Eric Dumazet, Eric Dumazet, Julian Anastasov
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: 93a77c11ae79 ("tcp: add tcp_inet6_sk() helper")
Signed-off-by: Eric Dumazet <edumazet@google.com>
Bisected-by: Julian Anastasov <ja@ssi.bg>
---
net/ipv6/tcp_ipv6.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
index eec814fe53b817106bc1d1eaa89dadcb96c974fa..82018bdce863165eba72e1ccf0c12ee558042ae8 100644
--- a/net/ipv6/tcp_ipv6.c
+++ b/net/ipv6/tcp_ipv6.c
@@ -93,12 +93,13 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
/* Helper returning the inet6 address from a given tcp socket.
* It can be used in TCP stack instead of inet6_sk(sk).
* This avoids a dereference and allow compiler optimizations.
+ * It is a specialized version of inet6_sk_generic().
*/
static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)
{
- struct tcp6_sock *tcp6 = container_of(tcp_sk(sk), struct tcp6_sock, tcp);
+ unsigned int offset = sizeof(struct tcp6_sock) - sizeof(struct ipv6_pinfo);
- return &tcp6->inet6;
+ return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
}
static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
--
2.21.0.392.gf8f6787159e-goog
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net] tcp: fix tcp_inet6_sk() for 32bit kernels
2019-04-01 10:09 [PATCH net] tcp: fix tcp_inet6_sk() for 32bit kernels Eric Dumazet
@ 2019-04-01 17:22 ` David Miller
2019-04-01 17:28 ` Eric Dumazet
2019-04-01 21:05 ` Julian Anastasov
1 sibling, 1 reply; 4+ messages in thread
From: David Miller @ 2019-04-01 17:22 UTC (permalink / raw)
To: edumazet; +Cc: netdev, eric.dumazet, ja
From: Eric Dumazet <edumazet@google.com>
Date: Mon, 1 Apr 2019 03:09:20 -0700
> 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: 93a77c11ae79 ("tcp: add tcp_inet6_sk() helper")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Bisected-by: Julian Anastasov <ja@ssi.bg>
This looks like a net-next change, because the Fixes tag commit is only
there. So that's where I have applied it.
Maybe we should change the name of the tcp6_sock.inet6 member if it
should never be accessed directly.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] tcp: fix tcp_inet6_sk() for 32bit kernels
2019-04-01 17:22 ` David Miller
@ 2019-04-01 17:28 ` Eric Dumazet
0 siblings, 0 replies; 4+ messages in thread
From: Eric Dumazet @ 2019-04-01 17:28 UTC (permalink / raw)
To: David Miller; +Cc: netdev, Eric Dumazet, Julian Anastasov
On Mon, Apr 1, 2019 at 10:22 AM David Miller <davem@davemloft.net> wrote:
>
>
> This looks like a net-next change, because the Fixes tag commit is only
> there. So that's where I have applied it.
Oops, wrong script, yes this is a net-next change.
>
> Maybe we should change the name of the tcp6_sock.inet6 member if it
> should never be accessed directly.
Or add an __alignof__(u64) if this does not increase memory needs.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net] tcp: fix tcp_inet6_sk() for 32bit kernels
2019-04-01 10:09 [PATCH net] tcp: fix tcp_inet6_sk() for 32bit kernels Eric Dumazet
2019-04-01 17:22 ` David Miller
@ 2019-04-01 21:05 ` Julian Anastasov
1 sibling, 0 replies; 4+ messages in thread
From: Julian Anastasov @ 2019-04-01 21:05 UTC (permalink / raw)
To: Eric Dumazet; +Cc: David S . Miller, netdev, Eric Dumazet
Hello,
On Mon, 1 Apr 2019, Eric Dumazet wrote:
> 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: 93a77c11ae79 ("tcp: add tcp_inet6_sk() helper")
> Signed-off-by: Eric Dumazet <edumazet@google.com>
> Bisected-by: Julian Anastasov <ja@ssi.bg>
> ---
> net/ipv6/tcp_ipv6.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
> index eec814fe53b817106bc1d1eaa89dadcb96c974fa..82018bdce863165eba72e1ccf0c12ee558042ae8 100644
> --- a/net/ipv6/tcp_ipv6.c
> +++ b/net/ipv6/tcp_ipv6.c
> @@ -93,12 +93,13 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(const struct sock *sk,
> /* Helper returning the inet6 address from a given tcp socket.
> * It can be used in TCP stack instead of inet6_sk(sk).
> * This avoids a dereference and allow compiler optimizations.
> + * It is a specialized version of inet6_sk_generic().
> */
> static struct ipv6_pinfo *tcp_inet6_sk(const struct sock *sk)
> {
> - struct tcp6_sock *tcp6 = container_of(tcp_sk(sk), struct tcp6_sock, tcp);
> + unsigned int offset = sizeof(struct tcp6_sock) - sizeof(struct ipv6_pinfo);
>
> - return &tcp6->inet6;
> + return (struct ipv6_pinfo *)(((u8 *)sk) + offset);
> }
>
> static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
Thanks Eric! It is working here.
Regards
--
Julian Anastasov <ja@ssi.bg>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2019-04-01 21:05 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-04-01 10:09 [PATCH net] tcp: fix tcp_inet6_sk() for 32bit kernels Eric Dumazet
2019-04-01 17:22 ` David Miller
2019-04-01 17:28 ` Eric Dumazet
2019-04-01 21:05 ` Julian Anastasov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).