From: Kuniyuki Iwashima <kuniyu@google.com>
To: edumazet@google.com
Cc: davem@davemloft.net, horms@kernel.org, kuba@kernel.org,
kuni1840@gmail.com, kuniyu@google.com, ncardwell@google.com,
netdev@vger.kernel.org, pabeni@redhat.com
Subject: Re: [PATCH v1 net-next] tcp: Initialise ehash secrets during connect() and listen().
Date: Tue, 3 Mar 2026 04:58:29 +0000 [thread overview]
Message-ID: <20260303045843.1732769-1-kuniyu@google.com> (raw)
In-Reply-To: <CANn89i+5gC3Wr2jAOG0=Sp1H2tJ7_ZufHcp1B7t7SdfgY+JmeA@mail.gmail.com>
From: Eric Dumazet <edumazet@google.com>
Date: Tue, 3 Mar 2026 04:42:24 +0100
> On Mon, Mar 2, 2026 at 9:51 PM Kuniyuki Iwashima <kuniyu@google.com> wrote:
> >
> > inet_ehashfn() and inet6_ehashfn() initialise random secrets
> > on the first call by net_get_random_once().
> >
> > While the init part is patched out using static keys, with
> > CONFIG_STACKPROTECTOR_STRONG=y, this causes a compiler to
> > generate a stack canary due to an automatic variable,
> > unsigned long ___flags, in the DO_ONCE() macro being passed
> > to __do_once_start().
> >
> > With FDO, this is visible in __inet_lookup_established() and
> > __inet6_lookup_established() too.
> >
> > Let's move net_get_random_once() to the slow paths: inet_hash()
> > for listen(), and inet_hash_connect() and inet6_hash_connect()
> > for connect().
> >
> > Note that IPv6 listener will initialise both IPv4 & IPv6 secrets
> > in inet_hash() for IPv4-mapped IPv6 address.
> >
> > With the patch, the stack size is reduced by 16 bytes (___flags
> > + a stack canary) and NOPs for the static key go away.
> >
> > Before: __inet6_lookup_established()
> >
> >
> >
> > Suggested-by: Eric Dumazet <edumazet@google.com>
> > Signed-off-by: Kuniyuki Iwashima <kuniyu@google.com>
> > ---
> > include/net/inet6_hashtables.h | 2 ++
> > net/ipv4/inet_hashtables.c | 16 ++++++++++++++--
> > net/ipv6/inet6_hashtables.c | 11 ++++++++---
> > 3 files changed, 24 insertions(+), 5 deletions(-)
> >
> > diff --git a/include/net/inet6_hashtables.h b/include/net/inet6_hashtables.h
> > index 282e29237d93..c17e0d874808 100644
> > --- a/include/net/inet6_hashtables.h
> > +++ b/include/net/inet6_hashtables.h
> > @@ -24,6 +24,8 @@
> >
> > struct inet_hashinfo;
> >
> > +void inet6_init_ehash_secret(void);
> > +
> > static inline unsigned int __inet6_ehashfn(const u32 lhash,
> > const u16 lport,
> > const u32 fhash,
> > diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
> > index fca980772c81..2c2cac5b0f1a 100644
> > --- a/net/ipv4/inet_hashtables.c
> > +++ b/net/ipv4/inet_hashtables.c
> > @@ -30,12 +30,15 @@
> > #include <net/sock_reuseport.h>
> > #include <net/tcp.h>
> >
> > +static void inet_init_ehash_secret(void)
> > +{
> > + net_get_random_once(&inet_ehash_secret, sizeof(inet_ehash_secret));
> > +}
>
> Could this use get_random_sleepable_once()?
> We are running in process context here.
> Same remark for inet6_init_ehash_secret()
Ah that's better !
I'll squash this to v2, thanks !
---8<---
diff --git a/include/linux/net.h b/include/linux/net.h
index f58b38ab37f8..a8e818de95b3 100644
--- a/include/linux/net.h
+++ b/include/linux/net.h
@@ -304,6 +304,8 @@ do { \
#define net_get_random_once(buf, nbytes) \
get_random_once((buf), (nbytes))
+#define net_get_random_sleepable_once(buf, nbytes) \
+ get_random_sleepable_once((buf), (nbytes))
/*
* E.g. XFS meta- & log-data is in slab pages, or bcache meta
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
index 2c2cac5b0f1a..e4c9a1590a74 100644
--- a/net/ipv4/inet_hashtables.c
+++ b/net/ipv4/inet_hashtables.c
@@ -32,7 +32,8 @@
static void inet_init_ehash_secret(void)
{
- net_get_random_once(&inet_ehash_secret, sizeof(inet_ehash_secret));
+ net_get_random_sleepable_once(&inet_ehash_secret,
+ sizeof(inet_ehash_secret));
}
u32 inet_ehashfn(const struct net *net, const __be32 laddr,
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c
index 054f75d32381..a0e5a8812614 100644
--- a/net/ipv6/inet6_hashtables.c
+++ b/net/ipv6/inet6_hashtables.c
@@ -25,8 +25,10 @@
void inet6_init_ehash_secret(void)
{
- net_get_random_once(&inet6_ehash_secret, sizeof(inet6_ehash_secret));
- net_get_random_once(&tcp_ipv6_hash_secret, sizeof(tcp_ipv6_hash_secret));
+ net_get_random_sleepable_once(&inet6_ehash_secret,
+ sizeof(inet6_ehash_secret));
+ net_get_random_sleepable_once(&tcp_ipv6_hash_secret,
+ sizeof(tcp_ipv6_hash_secret));
}
u32 inet6_ehashfn(const struct net *net,
---8<---
prev parent reply other threads:[~2026-03-03 4:58 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-02 20:51 [PATCH v1 net-next] tcp: Initialise ehash secrets during connect() and listen() Kuniyuki Iwashima
2026-03-03 3:42 ` Eric Dumazet
2026-03-03 4:58 ` Kuniyuki Iwashima [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260303045843.1732769-1-kuniyu@google.com \
--to=kuniyu@google.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=kuni1840@gmail.com \
--cc=ncardwell@google.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox