Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp152879ybt; Tue, 30 Jun 2020 17:02:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJSkvDHjhaOzzQ8PQsueQ/L3r0FM9GyB7MK5saEq+/cLryr/HhYWqpoNLSB1S8pcepTGjI X-Received: by 2002:a17:906:c40d:: with SMTP id u13mr19688722ejz.519.1593561749255; Tue, 30 Jun 2020 17:02:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1593561749; cv=none; d=google.com; s=arc-20160816; b=TxW6skyXK5TE/bULzdN9N6He6Px92WQhfav/i8TU5B7y3TLwbRHzp5hGy73JcOJVRD yMWiOO2Y8V67m/+vGyKZ96VYIAGEn6bayZ+1EQQaIXjeev2MyCOWNp5VOEzp/PEmUFNa yNd62qBoL9aFiCGR9OIiJzbS+0g5JkUFmLSlYrHzYdKtbBECoPwLes3DwDLmVbeQqJ1U r+5wzgaRwI8PChOfryH2Vty+gOMZTDfxl2ptjIOs+gEMutDhst2lEneOHkI4xHxppwp5 OTvlNBznqHIL1SkISKihXrMGmVFZ9MQUIM8eopyklX9tbXaqwL+q39puxYiesL0V8nvP 2zVg== 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=XKc0i29ur8bZ3QP5tHtJmPHNVBdp2DJUaH455nkGk4s=; b=B8FAWPgzDjg3PSO3rTtGkVmU1u/ysLqGREjCKXmzHh4zhADU3MTflgRC4CfFs0buO9 +LHHeUAJbStCQ2E0bXx6EN3OOWaVvZtyYlh1XOQkMOJuz3cUwLeX6Be0In3M+VGbsE0v +ZgE2ceK6r/pk/baTMZbZq31MjkeiJ24TAZWYSmA5Taw825M5pz2Q+ivxERfmC5dO5oB zpUf3TTWxFA8ssVtH/+LFByS4e/05UMhMtufFfuc7TizlFnr4kmxLwpCHx8Qi5+/y4kr sHfEZD9H6pJDmAGXvqymJVCZnzNIIfdRynNABOngiqtv9rrcHPx7p707KzQZP7bHyDhX +EJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=GDMwtKQ+; 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 qk3si2780394ejb.323.2020.06.30.17.01.54; Tue, 30 Jun 2020 17:02:29 -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=GDMwtKQ+; 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 S1726084AbgGAABe (ORCPT + 99 others); Tue, 30 Jun 2020 20:01:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725862AbgGAABd (ORCPT ); Tue, 30 Jun 2020 20:01:33 -0400 Received: from mail-yb1-xb2d.google.com (mail-yb1-xb2d.google.com [IPv6:2607:f8b0:4864:20::b2d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86A71C061755 for ; Tue, 30 Jun 2020 17:01:33 -0700 (PDT) Received: by mail-yb1-xb2d.google.com with SMTP id j19so8010684ybj.1 for ; Tue, 30 Jun 2020 17:01:33 -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=XKc0i29ur8bZ3QP5tHtJmPHNVBdp2DJUaH455nkGk4s=; b=GDMwtKQ+H/jIvrSzz12y4L6SpqnTjq6z16AaR9iUU/G80hyILg7zCLy8m/9ECUJPcz /Jr4LSIFh0xiTXtiH4+dzVwzmNoC2mNW0f2ZwiHzBYeN2rnNPDFeVd7Q0cSynOMxPaar p64b73DOlTJf8SxO5xsnR9UsOUJVdYJQLM9yWP1WUZvCylChUXX67KJ8dKVtufyzq9rb 5/N0moL9Yhk8Vh9rqWTyIHh9k+2jKEEByttbH1Ww166ld0CzLMdNTXHMobgYIA96gJOJ BT3GHsN0NTZS8qQONc/Z4oEU2ifY8LDigwIzT+wanKzBSNKD7DbZyIRT0Oy9FpFqJnBr Xjng== 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=XKc0i29ur8bZ3QP5tHtJmPHNVBdp2DJUaH455nkGk4s=; b=VMAHR8653SuLjuex/oP+9Xf8wLKA5QFRTNtQjUdP/F29Kk1CoYf38OghX7DV+5myQl Tph5vfLom+54Jjy3deInk8DN3GMUgWPOrQ1ukbb1nF4n5abgkLzFrIRI741hmDzK4jbT ymS/7F9beDCo0INZ3Hd/GR6iPtbXe/TsoCDpo83BxeOJASC88qwFk9SCpBhW1aWP6tC4 +E8F6YFyzVczOgJoGpyGvnaRiLiiVb+QvPlov5k1D+bJfwElouYzq7ab2Q67rgLi3chx mD8XBXEyOTTZ863rB54i7zRsyMhENde/C/5SPSaHveHbTlADB2aH0dmjG1B0deZVlVwl wsDQ== X-Gm-Message-State: AOAM532xFS1RJCDtP2UKn+gQxk48SDcdkxmqO9yl1xtQklDevwDsnAlH FCFGr2S5rAHtCKDAKYnmL0hhMZjVwXDg0KaPsCk1LyW3ip8= X-Received: by 2002:a25:b7cc:: with SMTP id u12mr22675401ybj.173.1593561692346; Tue, 30 Jun 2020 17:01:32 -0700 (PDT) MIME-Version: 1.0 References: <20200630.134429.1590957032456466647.davem@davemloft.net> <474095696.17969.1593551866537.JavaMail.zimbra@efficios.com> <416125262.18159.1593560661355.JavaMail.zimbra@efficios.com> In-Reply-To: <416125262.18159.1593560661355.JavaMail.zimbra@efficios.com> From: Eric Dumazet Date: Tue, 30 Jun 2020 17:01:20 -0700 Message-ID: Subject: Re: [regression] TCP_MD5SIG on established sockets To: Mathieu Desnoyers Cc: paulmck , "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 Tue, Jun 30, 2020 at 4:44 PM Mathieu Desnoyers wrote: > > ----- On Jun 30, 2020, at 6:38 PM, Eric Dumazet edumazet@google.com wrote: > [...] > > > > For updates of keys, it seems existing code lacks some RCU care. > > > > MD5 keys use RCU for lookups/hashes, but the replacement of a key does > > not allocate a new piece of memory. > > How is that RCU-safe ? > > Based on what I see here: > > tcp_md5_do_add() has a comment stating: > > "/* This can be called on a newly created socket, from other files */" > > which appears to be untrue if this can indeed be called on a live socket. "This can be called" is not the same than "this is always called for newly created socket" > > The path for pre-existing keys does: > > key = tcp_md5_do_lookup_exact(sk, addr, family, prefixlen, l3index); > if (key) { > /* Pre-existing entry - just update that one. */ > memcpy(key->key, newkey, newkeylen); > key->keylen = newkeylen; > return 0; > } > > AFAIU, this works only if you assume there are no concurrent readers > accessing key->key, else they can see a corrupted key. This is fine. > > The change you are proposing adds smp_wmb/smp_rmb to pair stores > to key before key_len with loads of key_len before key. I'm not sure > what this is trying to achieve, and how it prevents the readers from > observing a corrupted state if the key is updated on a live socket ? By definition if you change the MD5 key on a socket while packets are flying, the incoming packet could either 1) See old key (packet is dropped) 2) See new key. So any other decision (catching intermediate state) is really not an issue, since you already accepted the fact that a packet could be dropped, and TCP will retransmit. TCP MD5 implementation does not support multiple keys for one flow, you can not have both old and new keys being checked. > > Based on my understanding, this path which deals with pre-existing keys > in-place should only ever be used when there are no concurrent readers, > else a new memory allocation would be needed to guarantee that readers > always observe a valid copy. This is not _needed,_ and since memory allocations can fail, we would potentially break applications assuming that changing MD5 key would never fail. Patch has been sent for review on netdev@ ( https://patchwork.ozlabs.org/project/netdev/patch/20200630234101.3259179-1-edumazet@google.com/ )