From: Eric Dumazet <eric.dumazet@gmail.com>
To: Dmitry Safonov <dima@arista.com>, linux-kernel@vger.kernel.org
Cc: Dmitry Safonov <0x7f454c46@gmail.com>,
Andy Lutomirski <luto@amacapital.net>,
David Ahern <dsahern@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Francesco Ruggeri <fruggeri@arista.com>,
Jakub Kicinski <kuba@kernel.org>,
Herbert Xu <herbert@gondor.apana.org.au>,
Hideaki YOSHIFUJI <yoshfuji@linux-ipv6.org>,
Leonard Crestez <cdleonard@gmail.com>,
linux-crypto@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [PATCH 1/5] tcp/md5: Don't BUG_ON() failed kmemdup()
Date: Thu, 4 Nov 2021 19:55:19 -0700 [thread overview]
Message-ID: <15c0469e-9433-0a8d-50f0-de6517365464@gmail.com> (raw)
In-Reply-To: <20211105014953.972946-2-dima@arista.com>
On 11/4/21 6:49 PM, Dmitry Safonov wrote:
> static_branch_unlikely(&tcp_md5_needed) is enabled by
> tcp_alloc_md5sig_pool(), so as long as the code doesn't change
> tcp_md5sig_pool has been already populated if this code is being
> executed.
>
> In case tcptw->tw_md5_key allocaion failed - no reason to crash kernel:
> tcp_{v4,v6}_send_ack() will send unsigned segment, the connection won't be
> established, which is bad enough, but in OOM situation totally
> acceptable and better than kernel crash.
>
> Introduce tcp_md5sig_pool_ready() helper.
> tcp_alloc_md5sig_pool() usage is intentionally avoided here as it's
> fast-path here and it's check for sanity rather than point of actual
> pool allocation. That will allow to have generic slow-path allocator
> for tcp crypto pool.
>
> Signed-off-by: Dmitry Safonov <dima@arista.com>
> ---
> include/net/tcp.h | 1 +
> net/ipv4/tcp.c | 5 +++++
> net/ipv4/tcp_minisocks.c | 5 +++--
> 3 files changed, 9 insertions(+), 2 deletions(-)
>
> diff --git a/include/net/tcp.h b/include/net/tcp.h
> index 4da22b41bde6..3e5423a10a74 100644
> --- a/include/net/tcp.h
> +++ b/include/net/tcp.h
> @@ -1672,6 +1672,7 @@ tcp_md5_do_lookup(const struct sock *sk, int l3index,
> #endif
>
> bool tcp_alloc_md5sig_pool(void);
> +bool tcp_md5sig_pool_ready(void);
>
> struct tcp_md5sig_pool *tcp_get_md5sig_pool(void);
> static inline void tcp_put_md5sig_pool(void)
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index b7796b4cf0a0..c0856a6af9f5 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -4314,6 +4314,11 @@ bool tcp_alloc_md5sig_pool(void)
> }
> EXPORT_SYMBOL(tcp_alloc_md5sig_pool);
>
> +bool tcp_md5sig_pool_ready(void)
> +{
> + return tcp_md5sig_pool_populated;
> +}
> +EXPORT_SYMBOL(tcp_md5sig_pool_ready);
>
> /**
> * tcp_get_md5sig_pool - get md5sig_pool for this user
> diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
> index cf913a66df17..c99cdb529902 100644
> --- a/net/ipv4/tcp_minisocks.c
> +++ b/net/ipv4/tcp_minisocks.c
> @@ -293,11 +293,12 @@ void tcp_time_wait(struct sock *sk, int state, int timeo)
> tcptw->tw_md5_key = NULL;
> if (static_branch_unlikely(&tcp_md5_needed)) {
> struct tcp_md5sig_key *key;
> + bool err = WARN_ON(!tcp_md5sig_pool_ready());
>
> key = tp->af_specific->md5_lookup(sk, sk);
> - if (key) {
> + if (key && !err) {
> tcptw->tw_md5_key = kmemdup(key, sizeof(*key), GFP_ATOMIC);
> - BUG_ON(tcptw->tw_md5_key && !tcp_alloc_md5sig_pool());
> + WARN_ON_ONCE(tcptw->tw_md5_key == NULL);
> }
> }
> } while (0);
>
Hmmm.... how this BUG_ON() could trigger exactly ?
tcp_md5_needed can only be enabled after __tcp_alloc_md5sig_pool has succeeded.
This patch, sent during merge-window, is a distraction, sorry.
About renaming : It looks nice, but is a disaster for backports
done for stable releases. Please refrain from doing this.
next prev parent reply other threads:[~2021-11-05 2:55 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-05 1:49 [PATCH 0/5] tcp/md5: Generic tcp_sig_pool Dmitry Safonov
2021-11-05 1:49 ` [PATCH 1/5] tcp/md5: Don't BUG_ON() failed kmemdup() Dmitry Safonov
2021-11-05 2:55 ` Eric Dumazet [this message]
2021-11-05 9:16 ` Leonard Crestez
2021-11-05 13:31 ` Dmitry Safonov
2021-11-05 1:49 ` [PATCH 2/5] tcp/md5: Don't leak ahash in OOM Dmitry Safonov
2021-11-05 2:24 ` Eric Dumazet
2021-11-05 1:49 ` [PATCH 3/5] tcp/md5: Alloc tcp_md5sig_pool only in setsockopt() Dmitry Safonov
2021-11-05 1:49 ` [PATCH 4/5] tcp/md5: Use tcp_md5sig_pool_* naming scheme Dmitry Safonov
2021-11-05 1:49 ` [PATCH 5/5] tcp/md5: Make more generic tcp_sig_pool Dmitry Safonov
2021-11-05 9:54 ` Leonard Crestez
2021-11-05 13:59 ` Dmitry Safonov
2021-11-05 16:53 ` Leonard Crestez
2021-11-06 3:43 ` Herbert Xu
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=15c0469e-9433-0a8d-50f0-de6517365464@gmail.com \
--to=eric.dumazet@gmail.com \
--cc=0x7f454c46@gmail.com \
--cc=cdleonard@gmail.com \
--cc=davem@davemloft.net \
--cc=dima@arista.com \
--cc=dsahern@kernel.org \
--cc=edumazet@google.com \
--cc=fruggeri@arista.com \
--cc=herbert@gondor.apana.org.au \
--cc=kuba@kernel.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=luto@amacapital.net \
--cc=netdev@vger.kernel.org \
--cc=yoshfuji@linux-ipv6.org \
/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;
as well as URLs for NNTP newsgroup(s).