Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp7522652rwb; Tue, 15 Nov 2022 13:42:19 -0800 (PST) X-Google-Smtp-Source: AA0mqf7oCmskRlA71Ih5hAGnMwNzSzsaswbVBGD/xV4H5k41GKlUevSP6NG2F4Lvzk8GKDQS1fAQ X-Received: by 2002:a17:906:68c4:b0:7ad:d662:f568 with SMTP id y4-20020a17090668c400b007add662f568mr14830118ejr.616.1668548539684; Tue, 15 Nov 2022 13:42:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668548539; cv=none; d=google.com; s=arc-20160816; b=05zGnDVUMdjZlKdXrc7iF4ra6cfDBpVcun7lXWmXOePVi93P7JCaKj0esVRhYVw4ew 561N8z+MCyL8Gvrr7wZ89qLSOcE84igRtAS40jpoOmvDOL4xrLRuHxBcNsVVIsL4OgiS dH89sWSeJs6f7hguqaQZIw/B933IyidgxI1M1K5ZrlyyWyA3soCpPoUCxR76T9dMmilN YKX7V9doDM0M6uxG3qU55azJEZ16gPkaoEOdJWQGRxBOlWHZOk+RkTwlXyDxHqZu5VoY rUwMvNmG2Ubn5XI9a0xg+jVRZAI0yklHaTqnmIbOyzhJIOMWipnOlTYdOP7AkQhWGFIr 5pVw== 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=O4voqyqcbC1mGHkdqsComHC8t7xgb7NXhy1RVgGBazg=; b=nSvLmWSFeUMs0GDKorLVLp2dmUj0XdviAzSR4pm811y/OiNSK2PfAW6KS8KdzdbmSU o9iP2tIRhs/sF2lKrzwU8Nxc8e5yl4ch6D1yfmmp1jXHh5WEFgkkD35AYFf/kDmBA4Jq JrRtNvJ51PcbzgXtM6TBrQiWQ3K/QPhge5wbReYXJQBXi0CSB90i3xC4BZNQ4J7Kymsz zlIO1YIn176w7JH8onOKsnW07bf3dP1rtzOWw6qVoTEv/Aji5CSKGX6ns+Ea0JrDBNCW StkovtOdtd7k3rt9IgyAqRxKg/UaemVj6z5sEspK1PmuRZEgvlZA1djzvZCWLKF+8nTJ fIhg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@arista.com header.s=google header.b=YwulyWQx; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id js18-20020a17090797d200b007aeed8bdd50si9056920ejc.639.2022.11.15.13.41.58; Tue, 15 Nov 2022 13:42:19 -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=YwulyWQx; 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 S238709AbiKOVUW (ORCPT + 91 others); Tue, 15 Nov 2022 16:20:22 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45288 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbiKOVTz (ORCPT ); Tue, 15 Nov 2022 16:19:55 -0500 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8A85B1D305 for ; Tue, 15 Nov 2022 13:19:46 -0800 (PST) Received: by mail-wm1-x331.google.com with SMTP id m7-20020a05600c090700b003cf8a105d9eso49081wmp.5 for ; Tue, 15 Nov 2022 13:19:46 -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=O4voqyqcbC1mGHkdqsComHC8t7xgb7NXhy1RVgGBazg=; b=YwulyWQxFTlK3VttrI24bnCHMwwrAe/1KahE3WGjJJ8WL+Mn6T6KYdNtBFYzBrXVNe oixrbUxkVsQ8hKzZKAfCUR8e2gU1/zZh4Znnn/m6JVn16jMs4aHIKoN5e+ItM+O/QD5q nwnw6L5a838kRS4xWLMxlqGhgJdX+okXu9G8UHEhOiJP+qOfM6byfBjbj5ON47N2Mb9h OAcL8RGAxgWeGT+AJ2stN7SFs2h1oZIDkT2R0PRD11+TMig1X6O7XBR3fBk2Voggbsa+ uS5HQKa+C2PmcW5c7nbn/q/qnwb2RescA5UjxaKRR3PwsrIxhda1rrCRZpUtpX01nn7+ Bb0w== 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=O4voqyqcbC1mGHkdqsComHC8t7xgb7NXhy1RVgGBazg=; b=Y2aeYuCSD2K4c1syHo8zdThQWY8/PX+pHLvMz+Kt0SO2jN2iKH6p524M4eRdH3t5sV PRTNjfPuEB25tnU2rnAEWZ4YsTURmYtA6HDcQyWptYbrCXVT7eIrg8ME53O6B6zd4Ras 48nbg8B4ioGtEUcjFC7K1+etPlyJL9aq884Mxer+7CvIYIFFRtW6rN+vhk49n/eWo2GL rLAgHeeyESnKbkjfYDB7eKW6ZjbyttCK0QvKo0TCyfJSlbfUgV1nyEnemlPMn/mJqw8Q 5KKVesKXRStO/LpkvLsKxTBjoblfM55MHne5K6AHVpvMs1pzPgDbe5ncihfkurBdXNsF ZuPg== X-Gm-Message-State: ANoB5plcXT+Rya8sglP1JOR82c+FdfIRArJ4eIdzjAV+nXzrw96927hR 9RDuCmhjjUfl7iY3Kdb0aXjr54oxzBr7Mg== X-Received: by 2002:a05:600c:188a:b0:3cf:8e62:f769 with SMTP id x10-20020a05600c188a00b003cf8e62f769mr147561wmp.52.1668547158791; Tue, 15 Nov 2022 13:19:18 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id n41-20020a05600c502900b003c65c9a36dfsm17201487wmr.48.2022.11.15.13.19.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Nov 2022 13:19:18 -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 v4 4/5] net/tcp: Do cleanup on tcp_md5_key_copy() failure Date: Tue, 15 Nov 2022 21:19:04 +0000 Message-Id: <20221115211905.1685426-5-dima@arista.com> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221115211905.1685426-1-dima@arista.com> References: <20221115211905.1685426-1-dima@arista.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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=ham 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 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 --- 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 4bdb6e1ecaf3..deabf3309865 100644 --- a/net/ipv4/tcp_ipv4.c +++ b/net/ipv4/tcp_ipv4.c @@ -1628,13 +1628,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 3e3bdc120fc8..64788cfbefc7 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 -- 2.38.1