From patchwork Tue Nov 22 18:55:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 24508 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2389262wrr; Tue, 22 Nov 2022 11:03:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5deg5pYR/LG9E97V+3YYYEsRpg7n2bzoUDwVBrKecRUqrcAzVC47rWdBxToo17k1X1b+6x X-Received: by 2002:a63:4703:0:b0:470:27c:54b8 with SMTP id u3-20020a634703000000b00470027c54b8mr4593989pga.578.1669143822566; Tue, 22 Nov 2022 11:03:42 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669143822; cv=none; d=google.com; s=arc-20160816; b=dWBjSKLZMQ8PKRPuyOvJSnPO3Tes/0Jpp+ILbChUzO62yEQ/C5FQjbZGEZn3Or40I/ Ip6JfILQ5evxtARVgcfja9DrdolizqgZ15R8SbxYvUJZnWNymtjNHHoAWcuZGYo6ndA9 oSFruaoFq2kAmzTmNC3L59oOY3LsM1TpDphAUIWYDAfUL1IkPioEtYRh+1T3Qap0h1BT sRccwom6QDcmMXq28xta52mgQ5R78O6yonlSl6Lvwz5HfOHzgDBICymDbaQI1jPGTzkz PENOxg4HH42q+Mi8E0QdFDYUFC2mmpZycAq8EiPXb4A766DyiZvmP02l6nSxQPe8cuwV AW9A== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TjLQXh6CP0bu3ylJVW1lqp0iv9ZGwOCitUmVTWM7f24=; b=NjETkdD/7R5xzSxw/jAifDXxK3bH5uhmVlHgelo4838PtvUAmmIiG471Kj9TZUxyKv XUh53wG3x99/gi3lTmsQ/O3XMlXeSGputbPwrmUlj2bXLZQ7hwCoxHceNlNMzazSNVqT /o38z9/YBo9tH2S7hbOyno+wwyzCgoXlacKapqxSkQGvv3XxN/dbSmDsr1elB/g6V7zG nu6M7Lfj5vjlZ5zzasuu1PpCiT8UPO1oLtVGnYyS/kFKDXuwpcTg5hqC5QA8cxeayfbd GLTHP01YULsa2uesHa29mtMMC4uYA1nHn6iQVqmZ39EllQOM2bAlFMf6Z/OUE3qQKl/s vkYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=asabgvgZ; 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 n38-20020a056a000d6600b0056e6d31b27asi13408398pfv.160.2022.11.22.11.03.25; Tue, 22 Nov 2022 11:03:42 -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=asabgvgZ; 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 S234662AbiKVS4N (ORCPT + 99 others); Tue, 22 Nov 2022 13:56:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54782 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234611AbiKVSzu (ORCPT ); Tue, 22 Nov 2022 13:55:50 -0500 Received: from mail-wm1-x32f.google.com (mail-wm1-x32f.google.com [IPv6:2a00:1450:4864:20::32f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 164348C0B8 for ; Tue, 22 Nov 2022 10:55:49 -0800 (PST) Received: by mail-wm1-x32f.google.com with SMTP id i64-20020a1c3b43000000b003d016c21100so6374707wma.3 for ; Tue, 22 Nov 2022 10:55:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=TjLQXh6CP0bu3ylJVW1lqp0iv9ZGwOCitUmVTWM7f24=; b=asabgvgZjZSEg11xskqHJkg3F5Xt5qAFKTk90VSv7grWhNbP8hGqtDw0UFtYqeZFqB kqVf95FR9eYSguoS+pBS2IeeKZSt+1lpazHQKt7SzCk8+n0ervhX22xnSuAlsN4jQ14s znUZIGo1SS3G23ZS3rnwHqNuDRgzZdfOz2wTkF+jM2kocRzi1pEbeiB6hyEYS9pWHblB QgK0XdYR7s4K0a+xN7xta54ggnCeqAXRHGskijyQjS3k7yCZOinqyO8ghFbnuMNB7OnH uqNJUwWqjkb14X8lx1S0P43uCIfTf+ZGd9RBQOYcGK3sXovfAMJOQNKVcGjPrA+sHAwi rE2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=TjLQXh6CP0bu3ylJVW1lqp0iv9ZGwOCitUmVTWM7f24=; b=vQpipQebn8MaXpXvDz49aW2WcxV44uDJpmIxXJULnCXlKHAcHjKK/h2aEqJrJBV86d xxPhHjZtjO7EaZC6s0nvwS8V/VMOIDWD24T+JzJ27WU/Xps576koJZ8MavBCcJfOW+41 wbQK6WGPCDDqEF3qWAfyYXSL/yLueWwxrZwu+8apWpeVDK8dJAUE4C0fjw1S8brBPdyE u0Mhm/BWCUoku4PwAt7SbxwMo81B3J1C4pcngxc0YTD1Mn8y2u0Lqlwv2Z47QPdXH+zv YwUPVVJJchJ2v+mdczPHCrHEKukO8GMVAr9YgDsbRyMqqzHMXVb2QwzBMbl//8EYR9Qn DZ/w== X-Gm-Message-State: ANoB5plcp2YxMjuFWYidlPaADWw74as3PXCVNg91g87uYAtKulFJBDEY QBXj8qd14Db7ug9Hyer4iHbNBkifFi8rKA== X-Received: by 2002:a05:600c:3108:b0:3c6:bd12:ac68 with SMTP id g8-20020a05600c310800b003c6bd12ac68mr20905077wmo.123.1669143347407; Tue, 22 Nov 2022 10:55:47 -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.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Nov 2022 10:55:47 -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 4/5] net/tcp: Do cleanup on tcp_md5_key_copy() failure Date: Tue, 22 Nov 2022 18:55:33 +0000 Message-Id: <20221122185534.308643-5-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221122185534.308643-1-dima@arista.com> References: <20221122185534.308643-1-dima@arista.com> 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?1750224153111872801?= X-GMAIL-MSGID: =?utf-8?q?1750224153111872801?= If the kernel was short on (atomic) memory and failed to allocate it - don't proceed to creation of request socket. Otherwise the socket would be unsigned and userspace likely doesn't expect that the TCP is not MD5-signed anymore. Signed-off-by: Dmitry Safonov Acked-by: Jakub Kicinski --- net/ipv4/tcp_ipv4.c | 9 ++------- net/ipv6/tcp_ipv6.c | 15 ++++++++------- 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c index 776fbc2451bc..6ddfa8e45d03 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1630,13 +1630,8 @@ struct sock *tcp_v4_syn_recv_sock(const struct sock *sk, struct sk_buff *skb, addr = (union tcp_md5_addr *)&newinet->inet_daddr; key = tcp_md5_do_lookup(sk, l3index, addr, AF_INET); if (key) { - /* - * We're using one, so create a matching key - * on the newsk structure. If we fail to get - * memory, then we end up not copying the key - * across. Shucks. - */ - tcp_md5_key_copy(newsk, addr, AF_INET, 32, l3index, key); + if (tcp_md5_key_copy(newsk, addr, AF_INET, 32, l3index, key)) + goto put_and_exit; sk_gso_disable(newsk); } #endif diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c index 83304d6a6bd0..21486b4a9774 100644 --- a/net/ipv6/tcp_ipv6.c +++ b/net/ipv6/tcp_ipv6.c @@ -1376,13 +1376,14 @@ static struct sock *tcp_v6_syn_recv_sock(const struct sock *sk, struct sk_buff * /* Copy over the MD5 key from the original socket */ key = tcp_v6_md5_do_lookup(sk, &newsk->sk_v6_daddr, l3index); if (key) { - /* We're using one, so create a matching key - * on the newsk structure. If we fail to get - * memory, then we end up not copying the key - * across. Shucks. - */ - tcp_md5_key_copy(newsk, (union tcp_md5_addr *)&newsk->sk_v6_daddr, - AF_INET6, 128, l3index, key); + const union tcp_md5_addr *addr; + + addr = (union tcp_md5_addr *)&newsk->sk_v6_daddr; + if (tcp_md5_key_copy(newsk, addr, AF_INET6, 128, l3index, key)) { + inet_csk_prepare_forced_close(newsk); + tcp_done(newsk); + goto out; + } } #endif