From: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
To: Eric Dumazet <edumazet@google.com>
Cc: Herbert Xu <herbert@gondor.apana.org.au>,
"David S. Miller" <davem@davemloft.net>,
Linus Torvalds <torvalds@linux-foundation.org>,
linux-kernel <linux-kernel@vger.kernel.org>,
netdev <netdev@vger.kernel.org>,
Yuchung Cheng <ycheng@google.com>,
Jonathan Rajotte-Julien <joraj@efficios.com>
Subject: Re: [regression] TCP_MD5SIG on established sockets
Date: Wed, 1 Jul 2020 08:19:42 -0400 (EDT) [thread overview]
Message-ID: <338284155.18826.1593605982156.JavaMail.zimbra@efficios.com> (raw)
In-Reply-To: <CANn89iKnf6=RFd-XRjPv=qaU8P-LGCBcw6JU5Ywwb16gU2iQqQ@mail.gmail.com>
----- On Jun 30, 2020, at 11:36 PM, Eric Dumazet edumazet@google.com wrote:
> On Tue, Jun 30, 2020 at 7:59 PM Herbert Xu <herbert@gondor.apana.org.au> wrote:
>>
>> On Tue, Jun 30, 2020 at 07:30:43PM -0700, Eric Dumazet wrote:
>> >
>> > I made this clear in the changelog, do we want comments all over the places ?
>> > Do not get me wrong, we had this bug for years and suddenly this is a
>> > big deal...
>>
>> I thought you were adding a new pair of smp_rmb/smp_wmb. If they
>> already exist in the code then I agree it's not a big deal. But
>> adding a new pair of bogus smp_Xmb's is bad for maintenance.
>>
>
> If I knew so many people were excited about TCP / MD5, I would have
> posted all my patches on lkml ;)
>
> Without the smp_wmb() we would still need something to prevent KMSAN
> from detecting that we read uninitialized bytes,
> if key->keylen is increased. (initial content of key->key[] is garbage)
>
> Something like this :
The approach below looks good to me, but you'll also need to annotate
both tcp_md5_hash_key and tcp_md5_do_add with __no_kcsan or use
data_race(expr) to let the concurrency sanitizer know that there is
a known data race which is there on purpose (triggered by memcpy in tcp_md5_do_add
and somewhere within crypto_ahash_update). See Documentation/dev-tools/kcsan.rst
for details.
Thanks,
Mathieu
>
> diff --git a/net/ipv4/tcp.c b/net/ipv4/tcp.c
> index
> f111660453241692a17c881dd6dc2910a1236263..c3af8180c7049d5c4987bf5c67e4aff2ed6967c9
> 100644
> --- a/net/ipv4/tcp.c
> +++ b/net/ipv4/tcp.c
> @@ -4033,11 +4033,9 @@ EXPORT_SYMBOL(tcp_md5_hash_skb_data);
>
> int tcp_md5_hash_key(struct tcp_md5sig_pool *hp, const struct
> tcp_md5sig_key *key)
> {
> - u8 keylen = key->keylen;
> + u8 keylen = READ_ONCE(key->keylen); /* paired with
> WRITE_ONCE() in tcp_md5_do_add */
> struct scatterlist sg;
>
> - smp_rmb(); /* paired with smp_wmb() in tcp_md5_do_add() */
> -
> sg_init_one(&sg, key->key, keylen);
> ahash_request_set_crypt(hp->md5_req, &sg, NULL, keylen);
> return crypto_ahash_update(hp->md5_req);
> diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
> index
> 99916fcc15ca0be12c2c133ff40516f79e6fdf7f..0d08e0134335a21d23702e6a5c24a0f2b3c61c6f
> 100644
> --- a/net/ipv4/tcp_ipv4.c
> +++ b/net/ipv4/tcp_ipv4.c
> @@ -1114,9 +1114,13 @@ int tcp_md5_do_add(struct sock *sk, const union
> tcp_md5_addr *addr,
> /* Pre-existing entry - just update that one. */
> memcpy(key->key, newkey, newkeylen);
>
> - smp_wmb(); /* pairs with smp_rmb() in tcp_md5_hash_key() */
> + /* Pairs with READ_ONCE() in tcp_md5_hash_key().
> + * Also note that a reader could catch new key->keylen value
> + * but old key->key[], this is the reason we use __GFP_ZERO
> + * at sock_kmalloc() time below these lines.
> + */
> + WRITE_ONCE(key->keylen, newkeylen);
>
> - key->keylen = newkeylen;
> return 0;
> }
>
> @@ -1132,7 +1136,7 @@ int tcp_md5_do_add(struct sock *sk, const union
> tcp_md5_addr *addr,
> rcu_assign_pointer(tp->md5sig_info, md5sig);
> }
>
> - key = sock_kmalloc(sk, sizeof(*key), gfp);
> + key = sock_kmalloc(sk, sizeof(*key), gfp | __GFP_ZERO);
> if (!key)
> return -ENOMEM;
> if (!tcp_alloc_md5sig_pool()) {
--
Mathieu Desnoyers
EfficiOS Inc.
http://www.efficios.com
next prev parent reply other threads:[~2020-07-01 12:19 UTC|newest]
Thread overview: 32+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-13 19:38 [regression] TC_MD5SIG on established sockets Mathieu Desnoyers
2020-05-13 19:49 ` Eric Dumazet
2020-05-13 19:56 ` Eric Dumazet
2020-06-29 19:43 ` [regression] TCP_MD5SIG " Mathieu Desnoyers
2020-06-29 20:47 ` Eric Dumazet
2020-06-30 19:43 ` Linus Torvalds
2020-06-30 19:52 ` Linus Torvalds
2020-06-30 20:34 ` Mathieu Desnoyers
2020-06-30 20:39 ` Eric Dumazet
2020-06-30 20:44 ` David Miller
2020-06-30 20:56 ` Eric Dumazet
2020-06-30 21:17 ` Mathieu Desnoyers
2020-06-30 21:23 ` Eric Dumazet
2020-06-30 21:54 ` Eric Dumazet
2020-06-30 22:07 ` Eric Dumazet
2020-06-30 22:38 ` Eric Dumazet
2020-06-30 23:44 ` Mathieu Desnoyers
2020-07-01 0:01 ` Eric Dumazet
2020-07-01 2:02 ` Herbert Xu
2020-07-01 2:17 ` Eric Dumazet
2020-07-01 2:22 ` Herbert Xu
2020-07-01 2:30 ` Eric Dumazet
2020-07-01 2:39 ` Joe Perches
2020-07-01 2:58 ` Herbert Xu
2020-07-01 3:36 ` Eric Dumazet
2020-07-01 3:50 ` Herbert Xu
2020-07-01 12:19 ` Mathieu Desnoyers [this message]
2020-07-01 15:15 ` Eric Dumazet
2020-07-01 17:24 ` Eric Dumazet
2020-06-30 20:21 ` David Miller
2020-06-30 20:30 ` Eric Dumazet
2020-06-30 20:39 ` Mathieu Desnoyers
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=338284155.18826.1593605982156.JavaMail.zimbra@efficios.com \
--to=mathieu.desnoyers@efficios.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=herbert@gondor.apana.org.au \
--cc=joraj@efficios.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=torvalds@linux-foundation.org \
--cc=ycheng@google.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.