From patchwork Tue Nov 22 18:55:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 2066 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2388157wrr; Tue, 22 Nov 2022 11:02:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf5rYJxMJvPbqHlZUwYf6GP+u6eme3BLbPmjilpVx2JiMab0/5w3PxGZYJ8/hI92syshuVtM X-Received: by 2002:a17:90a:ab84:b0:213:343:9873 with SMTP id n4-20020a17090aab8400b0021303439873mr32900476pjq.102.1669143734275; Tue, 22 Nov 2022 11:02:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669143734; cv=none; d=google.com; s=arc-20160816; b=LoomyiHzcGjVTwfR/9z0DOMeQ9Pq57pSBqCuBNknMk3ZfpPdu9cF/R1vgWAtup78Da +jB1cIwutEfO8eFJanKhH1fcqGUeXj/N+mxLedjrdBourOY+I+o5KABo01ABUSdlAswl Z6e6xfKXS5Eo1hCnwhikyeSpcGmUmhvfaXdgfTlUTZj1Ef89qJAwrxov1AQpdKJTu7vW JsI0Sg/HYn7kdBdAxkcTKIRsPE6Fv7+IukoSFks0ywK66+8E/hgGdPDfAvKh49q0Mu9E ATY7z42V6Ss33fc+HjMCy8mYTm10NekwlIdRJ1ug+qtHH7IE1zUL3lPaFQsK9zTxIQn7 Vjfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zTBORMVN8Ms/JVLz5RLeY+CtQ5QsJjxcwcBxY+FPoWs=; b=B4qNXj1QnS4svrRgd1PN7jb0mkZMn9uJG0s2f9AREC8Jam2Ubv0c3hizlXVZocG+9x lQ+WnsZbJDnrlPTxo6710+yeN3N8rh1RTQyTqbYWpfj4Uz3KauqQwyH27qqNcyI4534X 1/3XA71xMwaKBrkZ9aZrpgV+qct0iti9WFikc49rEgTLnb8iMzfKadVb76zbsFNCpTD2 hIKVSzkYKaRiFWTAoIV/azjpjyuE/D+uEGlW2yUQEpxPFMHMWDPi3lYXIYxnV336MttY AVUV9LPdRKQNAhMuPa7sRUfBQYwhGQxY1Iu+oNZecLvTrzAA4kNCNa/Q+hhYRdzLc6Xt fdOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=aVVvjmTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 4-20020a631144000000b004700d8ddfc4si15350163pgr.646.2022.11.22.11.01.52; Tue, 22 Nov 2022 11:02:14 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=aVVvjmTf; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=arista.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234571AbiKVSzs (ORCPT + 99 others); Tue, 22 Nov 2022 13:55:48 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234338AbiKVSzo (ORCPT ); Tue, 22 Nov 2022 13:55:44 -0500 Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A3BD97FF07 for ; Tue, 22 Nov 2022 10:55:43 -0800 (PST) Received: by mail-wm1-x333.google.com with SMTP id l39-20020a05600c1d2700b003cf93c8156dso11984684wms.4 for ; Tue, 22 Nov 2022 10:55:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zTBORMVN8Ms/JVLz5RLeY+CtQ5QsJjxcwcBxY+FPoWs=; b=aVVvjmTfNNSKHAt9Gh1wtxRPrigAIiPMVVI1C0x+Cdm8rVZxq/jVw7PBENK0t28HdY OCI99YZuRU1N1l1o3wkcdIepfKqAdnTUTPrGR9T486NxtUEW2IUQIB0U8oNv1XvXJMjg Bld/9Cv3l0kPVtvuYFAYEOLOD53wR/O2ZdSOEUQYNzFwMGsEa0Q2XLw66DUD+bIUO2WL TREsecDqOVP28OMBaVgEzmZcbBM5f5c1NEY9qL1idxrvibDciHg/AZ96fmWmh5ggPkXV PFIH41L1u8V3+9Oi8KgftVHTSKX+JOmCHUHuTswHNCHHj/AUWnfd6n8uSvJVHYf42SLr psXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zTBORMVN8Ms/JVLz5RLeY+CtQ5QsJjxcwcBxY+FPoWs=; b=khuKQZBThVwdKJugZyVxYA2FIgl0pcZm2S0sonk9LHg9xprBCAkHJHENf20N4AMJJm RFO7UyGSRoj/WfLFcq0Lf9RO1w3P48dp44QIIr5L1B8JxAs/nmkWouDnfRMvikVN8M1I ZddXmhd05meEBeWG4kegwmfUEvq5pd5aT0TL1hTGFB/OReyvsQnMlZDOymouE5e5XK0i YOnOjfyKdZkH/QIXzjkyqNGPYDAzgQpiIJCU71ZV8TKommm2x7g10Emr88TeIr3o8c9O 9QS5bcrqxZ8KcZgewjOGlH/312aanYREwljWKZjmAt7nT5Ua0D2bEkTRWGfF2iVLHT/7 V9ZQ== X-Gm-Message-State: ANoB5pmuTu6I6rYIuAJqZiHKoAYRVM1EM8VZuASBXfVUd7y7iucRjvKG YqGOhfOAYXbiZdme2sM0nGMGpngW56i0SA== X-Received: by 2002:a1c:4b0f:0:b0:3cf:735c:9d5a with SMTP id y15-20020a1c4b0f000000b003cf735c9d5amr10880872wma.113.1669143341798; Tue, 22 Nov 2022 10:55:41 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id c18-20020adffb12000000b002365730eae8sm14478044wrr.55.2022.11.22.10.55.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 10:55:41 -0800 (PST) From: Dmitry Safonov To: linux-kernel@vger.kernel.org, David Ahern , Eric Dumazet , Peter Zijlstra Cc: Dmitry Safonov , Ard Biesheuvel , Bob Gilligan , "David S. Miller" , Dmitry Safonov <0x7f454c46@gmail.com>, Francesco Ruggeri , Hideaki YOSHIFUJI , Jakub Kicinski , Jason Baron , Josh Poimboeuf , Paolo Abeni , Salam Noureddine , Steven Rostedt , netdev@vger.kernel.org Subject: [PATCH v5 0/5] net/tcp: Dynamically disable TCP-MD5 static key Date: Tue, 22 Nov 2022 18:55:29 +0000 Message-Id: <20221122185534.308643-1-dima@arista.com> X-Mailer: git-send-email 2.38.1 MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_NONE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750224060057084183?= X-GMAIL-MSGID: =?utf-8?q?1750224060057084183?= Changes from v4: - Used rcu_dereference_protected() for tp->md5sig_info in tcp_md5_do_add() and tcp_md5_key_copy() fail paths to make sure there won't be false-positives from sparse (Jakub) - Added Acked-by: Jakub Kicinski Changes from v3: - Used atomic_try_cmpxchg() as suggested by Peter Zijlstra - Renamed static_key_fast_inc() => static_key_fast_inc_not_negative() (addressing Peter Zijlstra's review) - Based on linux-tip/master - tcp_md5_key_copy() now does net_warn_ratelimited() (addressing Peter Zijlstra's review) tcp_md5_do_add() does not as it returns -EUSERS from setsockopt() syscall back to the userspace - Corrected WARN_ON_ONCE(!static_key_fast_inc(key)) (Spotted by Jason Baron) - Moved declaration of static_key_fast_inc_not_negative() and its EXPORT_SYMBOL_GPL() to the patch 3 that uses it, "net/tcp: Disable TCP-MD5 static key on tcp_md5sig_info destruction" (addressing Peter Zijlstra's review) - Added patch 4 that destroys the newly created request socket if md5 info allocation or static_key increment was unsuccessful. Instead of proceeding to add a socket without TCP-MD5 keys. - Added patch 5 that separates helper tcp_time_wait_init() and converts BUG_ON() to WARN_ON_ONCE(). Changes from v2: - Prevent key->enabled from turning negative by overflow from static_key_slow_inc() or static_key_fast_inc() (addressing Peter Zijlstra's review) - Added checks if static_branch_inc() and static_key_fast_int() were successful to TCP-MD5 code. Changes from v1: - Add static_key_fast_inc() helper rather than open-coded atomic_inc() (as suggested by Eric Dumazet) Version 4: https://lore.kernel.org/all/20221115211905.1685426-1-dima@arista.com/T/#u Version 3: https://lore.kernel.org/all/20221111212320.1386566-1-dima@arista.com/T/#u Version 2: https://lore.kernel.org/all/20221103212524.865762-1-dima@arista.com/T/#u Version 1: https://lore.kernel.org/all/20221102211350.625011-1-dima@arista.com/T/#u The static key introduced by commit 6015c71e656b ("tcp: md5: add tcp_md5_needed jump label") is a fast-path optimization aimed at avoiding a cache line miss. Once an MD5 key is introduced in the system the static key is enabled and never disabled. Address this by disabling the static key when the last tcp_md5sig_info in system is destroyed. Previously it was submitted as a part of TCP-AO patches set [1]. Now in attempt to split 36 patches submission, I send this independently. Cc: Ard Biesheuvel Cc: Bob Gilligan Cc: David Ahern Cc: "David S. Miller" Cc: Dmitry Safonov <0x7f454c46@gmail.com> Cc: Eric Dumazet Cc: Francesco Ruggeri Cc: Hideaki YOSHIFUJI Cc: Jakub Kicinski Cc: Jason Baron Cc: Josh Poimboeuf Cc: Paolo Abeni Cc: Peter Zijlstra Cc: Salam Noureddine Cc: Steven Rostedt Cc: netdev@vger.kernel.org Cc: linux-kernel@vger.kernel.org [1]: https://lore.kernel.org/all/20221027204347.529913-1-dima@arista.com/T/#u Thanks, Dmitry Dmitry Safonov (5): jump_label: Prevent key->enabled int overflow net/tcp: Separate tcp_md5sig_info allocation into tcp_md5sig_info_add() net/tcp: Disable TCP-MD5 static key on tcp_md5sig_info destruction net/tcp: Do cleanup on tcp_md5_key_copy() failure net/tcp: Separate initialization of twsk include/linux/jump_label.h | 21 +++++++-- include/net/tcp.h | 10 ++-- kernel/jump_label.c | 55 +++++++++++++++++----- net/ipv4/tcp.c | 5 +- net/ipv4/tcp_ipv4.c | 96 +++++++++++++++++++++++++++++--------- net/ipv4/tcp_minisocks.c | 61 +++++++++++++++--------- net/ipv4/tcp_output.c | 4 +- net/ipv6/tcp_ipv6.c | 21 ++++----- 8 files changed, 193 insertions(+), 80 deletions(-) base-commit: 771a207d1ee9f38da8c0cee1412228f18b900bac