From patchwork Tue Nov 15 21:19:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 20569 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2947467wru; Tue, 15 Nov 2022 13:24:13 -0800 (PST) X-Google-Smtp-Source: AA0mqf50KOFcHGmC6i7U5YICXkRAdyCplpaasR66CQFTcJyOo5hXkZxHEPy84mY0so022X+aI+TZ X-Received: by 2002:a17:903:120b:b0:188:50c2:89fb with SMTP id l11-20020a170903120b00b0018850c289fbmr5768742plh.130.1668547453031; Tue, 15 Nov 2022 13:24:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1668547453; cv=none; d=google.com; s=arc-20160816; b=QPKqu1wBmrtB7M9U+0EakGjKCVo3QKkmLL86qdyLfMqXzv1lzTlxTuemt7kCdRej4G iCXBzFBstbIMplCwnKxD7xGQj+39vGpjKJtCSHHd8AfUis7kFO7Q92m50/yoYeCDaaK5 MA8i3kLW2xToywAvSZPuMLjrk6oCuHApxu5dPKcbgL9mpktrgRN5o3x7TydEL/Z/l3/o XxNFFHVkoO1vHgWVyXTtl052arBqDC4zqDU/1UawizBncjKAoelQx83Vtam5QjLIdx+n JFbrnykFX/PkzThWyxoL/1BvkQIfLq5xzLKFdj3/SLzDtFEQrK+GQ03jcit3/S/inpSm k0pA== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id bk4-20020a056a02028400b00476e63cfd0fsi393448pgb.466.2022.11.15.13.23.55; Tue, 15 Nov 2022 13:24:13 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1749598814505984174?= X-GMAIL-MSGID: =?utf-8?q?1749598814505984174?= 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