Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp711582ybt; Wed, 1 Jul 2020 08:17:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxiVrxhTxkS4pDSiTMunkUmUu3HgUstN2TFf8Mj7+8eHrXyKBrZngAUwvivXHmWH1Xawrha X-Received: by 2002:a17:906:c04d:: with SMTP id bm13mr15134942ejb.321.1593616677217; Wed, 01 Jul 2020 08:17:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593616677; cv=none; d=google.com; s=arc-20160816; b=TCzzLVVeJo7CW2Rb3bshmlIZGf6hLmfdzHbnR/FWzItrs/EVnn9q55LaRqm0LLW/A1 NeK+Xl8nTJ9UWJ6hlvWc58hns0GMdQPoiIKKj0AnA8xOZpUUvm1Xpcj4TKttLZsjfuxQ nbamuEEeiXbZ32c0Qicx80xMfxJna58eC/GWApdzL4JKacp0A1HeyZS5H2NQTNwOKa9t pPxza2pWXDtWD/grYOvzzgU++Uz0FW1L4+ZwXg6gmnvCgXG4x7eIWYszEIDmzlF0ksn6 PWB1MV+nytG5M0ryvgK7aG20LLdEnM8M8wPsAVmxXW9LuUHSE4V2Df4wx/SrCWcVlTGE LP5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=1OXCzKlm/ajG5X9F9mYOppVckbS/UtVwRERIIxYgAF0=; b=Wg/S4OfbickuZiCL6VYGHyh1Gc9sm+Rzz6yclk/iS0fXpX6CP9e3gWM0m1iuDPjhk2 i3/iGZ8iF6pQh7DnP6QDD55iGybHevFQj8oYYYsd1NUJw7/CegUqV1xFEDK+CLggo3KQ PqKXf19eQpQNwhihFOH5F0Bsab9+8MEb5p4IeGkrh70VVqP25PjFHCPvm9FUY8tadRyr E3F6+HyT8aifMYACHRMevn53FDINIbgezlOAcpAWk+cnSPDecZNRmXYDKHoC46Fs5WCN eFZ2dhIhA2QbK29E6acOPULLI9V3G0JmRuJ79Q9uOxpIL1+4LiLJQsH1NPODW+B3oYxo 1wxQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gm7DKZnd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id 8si3661257ejx.659.2020.07.01.08.17.33; Wed, 01 Jul 2020 08:17:57 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=gm7DKZnd; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731850AbgGAPPX (ORCPT + 99 others); Wed, 1 Jul 2020 11:15:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727887AbgGAPPX (ORCPT ); Wed, 1 Jul 2020 11:15:23 -0400 Received: from mail-yb1-xb2e.google.com (mail-yb1-xb2e.google.com [IPv6:2607:f8b0:4864:20::b2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0410C08C5C1 for ; Wed, 1 Jul 2020 08:15:22 -0700 (PDT) Received: by mail-yb1-xb2e.google.com with SMTP id k18so12122588ybm.13 for ; Wed, 01 Jul 2020 08:15:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=1OXCzKlm/ajG5X9F9mYOppVckbS/UtVwRERIIxYgAF0=; b=gm7DKZndG5xIUYp+pckIqDJmVIxEdJ7mokqKBpWulCAJXdFJpoRETrlva80b8BWqri JfzgfjH1Wfp5e4nkEu/uKtEzZtsWfbvgyKfIbpucXnVhHTqsEePdXkjcdheSmeC2udk9 bJcg4gANj48YwTwHPaWhoC3J8VsheYwWi0m1XwNuIGnKdeMOy0OsWOFK/w/sRiLEDHe0 vcdWjg8T7zs4KZFrKCnyiVRl7fRxYbIA7pWPSRoYp6i93GCrQ92p0mNitS70hGi4Q0ip 9iUrnQttT1sBktCWpJzmQ7Ay+LfJI4YBNXkzUaAQiHpqn5F13JgJaofExLIp+GFKGtEa spTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=1OXCzKlm/ajG5X9F9mYOppVckbS/UtVwRERIIxYgAF0=; b=H3TZWyg9mfah5CgYiAszgnOIWHPUI2qLhDrdYzB6thyIMLgTcAoWzIQN8xhhrpW7m/ ehA3JZjZ8JQFIbGLV1XDwOM2z9GHSrTPdLChtGNQur/ztVdrz0fKcphrzNC49FMFQX+g hYwslSx3lqKrJyP4ZVBNT8Pt/AsS0/srSf949FTfVm7yMC5H2T3WCsrWZVHIL2lDxsgS oP4T0XUauYpPx+Acj22lzRaTZ8Dzw1MrSDDh7croPDEDJI0fDT7OYki+SzsTZc0tT6Ij CrP5ItUBwW6IHBPK3vlV7xwcNJ3Ct1fEmhf2o3xXOQZ8eFHjJCI/r4J8eqTGtYDO8KA7 3PXg== X-Gm-Message-State: AOAM532amGjH+QZ5FpAWpVZnALfkKztSi42jfTbFqGyAnPSfZoiz4KLG LjsUW5K46GG9LDZvUFwNZHq8qbJU0/2/q/a2XHli8A== X-Received: by 2002:a25:b7cc:: with SMTP id u12mr27806815ybj.173.1593616521698; Wed, 01 Jul 2020 08:15:21 -0700 (PDT) MIME-Version: 1.0 References: <20200701020211.GA6875@gondor.apana.org.au> <20200701022241.GA7167@gondor.apana.org.au> <20200701025843.GA7254@gondor.apana.org.au> <338284155.18826.1593605982156.JavaMail.zimbra@efficios.com> In-Reply-To: <338284155.18826.1593605982156.JavaMail.zimbra@efficios.com> From: Eric Dumazet Date: Wed, 1 Jul 2020 08:15:10 -0700 Message-ID: Subject: Re: [regression] TCP_MD5SIG on established sockets To: Mathieu Desnoyers Cc: Herbert Xu , "David S. Miller" , Linus Torvalds , linux-kernel , netdev , Yuchung Cheng , Jonathan Rajotte-Julien Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 1, 2020 at 5:19 AM Mathieu Desnoyers wrote: > 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. Sure, I can add a data_race() and let stable teams handle the backports without it ;) > > 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