Received: by 2002:aa6:c429:0:b029:98:93ff:f56f with SMTP id g9csp3395886lkq; Mon, 23 Nov 2020 04:45:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwKLjs0A/M6/HqO1eDBI8MsWcVkXjdVKOdm3cEEsE0sEFdQbWaISHGlNkqScPtGd7oabNqI X-Received: by 2002:a17:906:50e:: with SMTP id j14mr43291037eja.403.1606135543796; Mon, 23 Nov 2020 04:45:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606135543; cv=none; d=google.com; s=arc-20160816; b=oVMe4znxCgxdsERT8dI6t3F9bTf9ctKv7coGOK7A8Hs68xRFsgmxXevK2jgyeQLLCV 4rLHuOjLPByQYIaf85NMQnrPTlzqKPrbfyAJMzoTq6t9Bx89OLNaYaGv3Q5wOP/jC2Ff vE6VsXNkp/jy1Ov6WJV9FzfptZBYLz4lELhTLyn4L5vNZW7F8Zv7wWPCEZURFOOZ3Zf1 mu6wYaHi8aNpxa/EcMenxcDsIZ3DLsjbhh+RJNA9a+RRrYRzGcHXWZ94F7xtSAGbLkan g+MXCM/6QegQLgHPRepkh0CXzd0GuMNitjvM889ocKxFc3+oPf8CYu38P4ZpdMFToxQR T8dQ== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7wVp9KSLZSX91HxuS/nMJk79FeTH7v6pyF9UZhEEj2Y=; b=LZ4EuYHsQkDAnX0ziHCbnL/kKysezfEfWmaMEA5hvQsH7AiTPSfrRQbU2nfVh5H/bv pFRtMneEtTTOSEI87Qzzzu/OW/T2KKB9/L8y6GZI4RWSZhV+O5fsaJGe++xkcK7ecctR vjoCARZIXWELRarq9pa401udI6CYPY4Poc71p0Mea1Sxm1gneyeeYu/KrBszJWcifFoY T7SkFYP6pkI4t9lJFWueaDvTnTxJrSn4tnzra1AAJa6jCBAKqbz+7MkPot6mCDgo0Ruk SwlWArsck6xNgts6IWilOrWdFVGFt9ZaZPT92SdrbbQM57O6AJEvmWssCTla2ErJH+LD 3TJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=DUD1T1cG; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u4si6577169ejm.412.2020.11.23.04.45.19; Mon, 23 Nov 2020 04:45:43 -0800 (PST) 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=@linuxfoundation.org header.s=korg header.b=DUD1T1cG; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732178AbgKWMjJ (ORCPT + 99 others); Mon, 23 Nov 2020 07:39:09 -0500 Received: from mail.kernel.org ([198.145.29.99]:50996 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732099AbgKWMia (ORCPT ); Mon, 23 Nov 2020 07:38:30 -0500 Received: from localhost (83-86-74-64.cable.dynamic.v4.ziggo.nl [83.86.74.64]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 48CE520732; Mon, 23 Nov 2020 12:38:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1606135109; bh=g6Feh2htxV7HMEZau/zqSu7cLlyR+IG7c0WryBTjzGg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=DUD1T1cGIUOBR8vqvBw2sFhr2KuZIAb/CE0Iv4BpwhgFfaWlAdckBhXVWmWZLyytF 3hrbiAZwG/9WWHxZJI5tFJMhYMDRo8InEaFDMC45O+OY/BDhj+gjUIV6HTe9kRHvl0 yGRMGbAK+OC9lUUNYRqIoiaLKEZwV8glIvY7Vc/Y= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Fastabend , Alexei Starovoitov , Sasha Levin Subject: [PATCH 5.4 107/158] bpf, sockmap: Skb verdict SK_PASS to self already checked rmem limits Date: Mon, 23 Nov 2020 13:22:15 +0100 Message-Id: <20201123121825.102685070@linuxfoundation.org> X-Mailer: git-send-email 2.29.2 In-Reply-To: <20201123121819.943135899@linuxfoundation.org> References: <20201123121819.943135899@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Fastabend [ Upstream commit cfea28f890cf292d5fe90680db64b68086ef25ba ] For sk_skb case where skb_verdict program returns SK_PASS to continue to pass packet up the stack, the memory limits were already checked before enqueuing in skb_queue_tail from TCP side. So, lets remove the extra checks here. The theory is if the TCP stack believes we have memory to receive the packet then lets trust the stack and not double check the limits. In fact the accounting here can cause a drop if sk_rmem_alloc has increased after the stack accepted this packet, but before the duplicate check here. And worse if this happens because TCP stack already believes the data has been received there is no retransmit. Fixes: 51199405f9672 ("bpf: skb_verdict, support SK_PASS on RX BPF path") Signed-off-by: John Fastabend Signed-off-by: Alexei Starovoitov Link: https://lore.kernel.org/bpf/160226857664.5692.668205469388498375.stgit@john-Precision-5820-Tower Signed-off-by: Sasha Levin --- net/core/skmsg.c | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 1f8e3445cd2f0..605c48df7eb68 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -765,6 +765,7 @@ EXPORT_SYMBOL_GPL(sk_psock_tls_strp_read); static void sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb, int verdict) { + struct tcp_skb_cb *tcp; struct sock *sk_other; switch (verdict) { @@ -774,16 +775,12 @@ static void sk_psock_verdict_apply(struct sk_psock *psock, !sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED)) { goto out_free; } - if (atomic_read(&sk_other->sk_rmem_alloc) <= - sk_other->sk_rcvbuf) { - struct tcp_skb_cb *tcp = TCP_SKB_CB(skb); - tcp->bpf.flags |= BPF_F_INGRESS; - skb_queue_tail(&psock->ingress_skb, skb); - schedule_work(&psock->work); - break; - } - goto out_free; + tcp = TCP_SKB_CB(skb); + tcp->bpf.flags |= BPF_F_INGRESS; + skb_queue_tail(&psock->ingress_skb, skb); + schedule_work(&psock->work); + break; case __SK_REDIRECT: sk_psock_skb_redirect(skb); break; -- 2.27.0