From patchwork Tue Jun 15 02:13:35 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320395 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B4230C48BE8 for ; Tue, 15 Jun 2021 02:23:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 99026613F5 for ; Tue, 15 Jun 2021 02:23:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229743AbhFOCZW (ORCPT ); Mon, 14 Jun 2021 22:25:22 -0400 Received: from mail-qk1-f179.google.com ([209.85.222.179]:36698 "EHLO mail-qk1-f179.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229689AbhFOCZW (ORCPT ); Mon, 14 Jun 2021 22:25:22 -0400 Received: by mail-qk1-f179.google.com with SMTP id i68so36960365qke.3; Mon, 14 Jun 2021 19:23:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=utSDi74JoxgeFkn6+VzF9KRMzUGip+skVUxRXuPWjX0=; b=I5MKGwIiqyzjIfqJa0sA7eJ9/pLktaqzVsh5G6k6BX/pJGIJKjyy05IFd8TpJLa5MA pXVcT1zjFGmXQ/m4EcTpgsuOy4uwuIX7pHde7HQEmAmTdvKogrOGmcpWh9gWK4zb7f5S xvAqt94OQqYWg9jdo14jKMlgcwJ8vs355aYUVHFSGqQ/FOPSdXZOc7XBT4znoCd97s93 oRGejrt0m4i/9UedHt9CnpmZWYJhGzCSTKP80WTSDzZcdYCPKfgNsTAw8VimNyvY5pxm nl+vfR7rsrII0EvWhyCzwh/LMsAcYd71pzKfMUTHHOhrsRnnBcv2bWIqM7MdMDe20Lsr GUUw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=utSDi74JoxgeFkn6+VzF9KRMzUGip+skVUxRXuPWjX0=; b=p+sZPti+0p3OS9SiE7csyIyefutOhNmKwk1E9U4H3spJVVEqwelmwgHdvYn2m3ahVW xqUJyQV+kYV34iYS1VjaH+jau0Wfg7OYygoYUGwNwSiA/pFdxC0TXd5MHqtTY0VJqXKe 1wceWw0H4fTgjIymgP2pES/CknYC/D6djdswjIL6znRQjQbd3sjhG6zHu9oBU4sFIzqT b75KVaq0y2szYCH0dXCF02301SFG4WIpIEAut4nj4uN8dLCPSATmOPVxaV75eHonglPW 7daL0PjBfijARzh9xiakIgKGVgv2qe1JCeNxKbbbZF/qShyPOg2goW47MVlDO+PbKI4u g1Bg== X-Gm-Message-State: AOAM531nkUFz56LuyLMDnGe0lKi+qC87vPoAwBGqLQp3k5XKlUfMwtqk fd0FbgLOFVTB0/bQYrRF/GjYHfEinsBOzg== X-Google-Smtp-Source: ABdhPJxAYSngxxAksyB+vc/nTlMLwXTToT29novZ9PebuWBhrwfpN8fee14VyMKUkrqEqqDe9gAn+g== X-Received: by 2002:a37:8345:: with SMTP id f66mr19165442qkd.396.1623723236367; Mon, 14 Jun 2021 19:13:56 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.13.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:13:55 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 1/8] skmsg: improve udp_bpf_recvmsg() accuracy Date: Mon, 14 Jun 2021 19:13:35 -0700 Message-Id: <20210615021342.7416-2-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang I tried to reuse sk_msg_wait_data() for different protocols, but it turns out it can not be simply reused. For example, UDP actually uses two queues to receive skb: udp_sk(sk)->reader_queue and sk->sk_receive_queue. So we have to check both of them to know whether we have received any packet. Also, UDP does not lock the sock during BH Rx path, it makes no sense for its ->recvmsg() to lock the sock. It is always possible for ->recvmsg() to be called before packets actually arrive in the receive queue, we just use best effort to make it accurate here. Fixes: 1f5be6b3b063 ("udp: Implement udp_bpf_recvmsg() for sockmap") Cc: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- include/linux/skmsg.h | 2 -- net/core/skmsg.c | 23 --------------------- net/ipv4/tcp_bpf.c | 24 +++++++++++++++++++++- net/ipv4/udp_bpf.c | 47 ++++++++++++++++++++++++++++++++++++++----- 4 files changed, 65 insertions(+), 31 deletions(-) diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h index aba0f0f429be..e3d080c299f6 100644 --- a/include/linux/skmsg.h +++ b/include/linux/skmsg.h @@ -126,8 +126,6 @@ int sk_msg_zerocopy_from_iter(struct sock *sk, struct iov_iter *from, struct sk_msg *msg, u32 bytes); int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from, struct sk_msg *msg, u32 bytes); -int sk_msg_wait_data(struct sock *sk, struct sk_psock *psock, int flags, - long timeo, int *err); int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, int len, int flags); diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 43ce17a6a585..f9a81b314e4c 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -399,29 +399,6 @@ int sk_msg_memcopy_from_iter(struct sock *sk, struct iov_iter *from, } EXPORT_SYMBOL_GPL(sk_msg_memcopy_from_iter); -int sk_msg_wait_data(struct sock *sk, struct sk_psock *psock, int flags, - long timeo, int *err) -{ - DEFINE_WAIT_FUNC(wait, woken_wake_function); - int ret = 0; - - if (sk->sk_shutdown & RCV_SHUTDOWN) - return 1; - - if (!timeo) - return ret; - - add_wait_queue(sk_sleep(sk), &wait); - sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); - ret = sk_wait_event(sk, &timeo, - !list_empty(&psock->ingress_msg) || - !skb_queue_empty(&sk->sk_receive_queue), &wait); - sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); - remove_wait_queue(sk_sleep(sk), &wait); - return ret; -} -EXPORT_SYMBOL_GPL(sk_msg_wait_data); - /* Receive sk_msg from psock->ingress_msg to @msg. */ int sk_msg_recvmsg(struct sock *sk, struct sk_psock *psock, struct msghdr *msg, int len, int flags) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index ad9d17923fc5..bb49b52d7be8 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -163,6 +163,28 @@ static bool tcp_bpf_stream_read(const struct sock *sk) return !empty; } +static int tcp_msg_wait_data(struct sock *sk, struct sk_psock *psock, int flags, + long timeo, int *err) +{ + DEFINE_WAIT_FUNC(wait, woken_wake_function); + int ret = 0; + + if (sk->sk_shutdown & RCV_SHUTDOWN) + return 1; + + if (!timeo) + return ret; + + add_wait_queue(sk_sleep(sk), &wait); + sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); + ret = sk_wait_event(sk, &timeo, + !list_empty(&psock->ingress_msg) || + !skb_queue_empty(&sk->sk_receive_queue), &wait); + sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); + remove_wait_queue(sk_sleep(sk), &wait); + return ret; +} + static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, int flags, int *addr_len) { @@ -188,7 +210,7 @@ static int tcp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, long timeo; timeo = sock_rcvtimeo(sk, nonblock); - data = sk_msg_wait_data(sk, psock, flags, timeo, &err); + data = tcp_msg_wait_data(sk, psock, flags, timeo, &err); if (data) { if (!sk_psock_queue_empty(psock)) goto msg_bytes_ready; diff --git a/net/ipv4/udp_bpf.c b/net/ipv4/udp_bpf.c index 954c4591a6fd..565a70040c57 100644 --- a/net/ipv4/udp_bpf.c +++ b/net/ipv4/udp_bpf.c @@ -21,6 +21,45 @@ static int sk_udp_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, return udp_prot.recvmsg(sk, msg, len, noblock, flags, addr_len); } +static bool udp_sk_has_data(struct sock *sk) +{ + return !skb_queue_empty(&udp_sk(sk)->reader_queue) || + !skb_queue_empty(&sk->sk_receive_queue); +} + +static bool psock_has_data(struct sk_psock *psock) +{ + return !skb_queue_empty(&psock->ingress_skb) || + !sk_psock_queue_empty(psock); +} + +#define udp_msg_has_data(__sk, __psock) \ + ({ udp_sk_has_data(__sk) || psock_has_data(__psock); }) + +static int udp_msg_wait_data(struct sock *sk, struct sk_psock *psock, int flags, + long timeo, int *err) +{ + DEFINE_WAIT_FUNC(wait, woken_wake_function); + int ret = 0; + + if (sk->sk_shutdown & RCV_SHUTDOWN) + return 1; + + if (!timeo) + return ret; + + add_wait_queue(sk_sleep(sk), &wait); + sk_set_bit(SOCKWQ_ASYNC_WAITDATA, sk); + ret = udp_msg_has_data(sk, psock); + if (!ret) { + wait_woken(&wait, TASK_INTERRUPTIBLE, timeo); + ret = udp_msg_has_data(sk, psock); + } + sk_clear_bit(SOCKWQ_ASYNC_WAITDATA, sk); + remove_wait_queue(sk_sleep(sk), &wait); + return ret; +} + static int udp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, int nonblock, int flags, int *addr_len) { @@ -34,8 +73,7 @@ static int udp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, if (unlikely(!psock)) return sk_udp_recvmsg(sk, msg, len, nonblock, flags, addr_len); - lock_sock(sk); - if (sk_psock_queue_empty(psock)) { + if (!psock_has_data(psock)) { ret = sk_udp_recvmsg(sk, msg, len, nonblock, flags, addr_len); goto out; } @@ -47,9 +85,9 @@ static int udp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, long timeo; timeo = sock_rcvtimeo(sk, nonblock); - data = sk_msg_wait_data(sk, psock, flags, timeo, &err); + data = udp_msg_wait_data(sk, psock, flags, timeo, &err); if (data) { - if (!sk_psock_queue_empty(psock)) + if (psock_has_data(psock)) goto msg_bytes_ready; ret = sk_udp_recvmsg(sk, msg, len, nonblock, flags, addr_len); goto out; @@ -62,7 +100,6 @@ static int udp_bpf_recvmsg(struct sock *sk, struct msghdr *msg, size_t len, } ret = copied; out: - release_sock(sk); sk_psock_put(sk, psock); return ret; } From patchwork Tue Jun 15 02:13:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320449 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 641E7C48BE8 for ; Tue, 15 Jun 2021 02:36:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 501B0613F5 for ; Tue, 15 Jun 2021 02:36:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229649AbhFOCif (ORCPT ); Mon, 14 Jun 2021 22:38:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229829AbhFOCie (ORCPT ); Mon, 14 Jun 2021 22:38:34 -0400 Received: from mail-vs1-xe36.google.com (mail-vs1-xe36.google.com [IPv6:2607:f8b0:4864:20::e36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB307C061574; Mon, 14 Jun 2021 19:36:29 -0700 (PDT) Received: by mail-vs1-xe36.google.com with SMTP id z7so8986061vso.3; Mon, 14 Jun 2021 19:36:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=2SXBq0RQ1G77Xbs0xalfygk3bDY+dvdl+rT4iV6EI+0=; b=bxVDKKcXNafEjM4mLf7H3nuwdyzdavUzpqZjeLaXS5m2kYa3bcwr7elPIXYY38MjDa lNddy/t5+cjgoFAd3x6EtatKTSaGmGDLoafCvakRSgGltJy1O1hvu2T64YhvjfpsR2FQ hFnUhmiVsJQG9NFP9AFLU7vGEbI02oBjhNECbkRKo9VQs03o04+xyhlbKG1/IIJjVMm9 M95+7N0dPiNsi+H9DNKZtLjUJ+9UPdyyrmuPk88wtzSFEMjFO0l7d0UeHwgKSjCfg9gQ W8nvWo+6kGhiSlN+h6nUjEJNV2qKc6QZJqvg90D1eAvzPRJuQUcFtpnQDlZMo0IBqfbR /BVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=2SXBq0RQ1G77Xbs0xalfygk3bDY+dvdl+rT4iV6EI+0=; b=tKmH5r+q9bE2RinbT8uoEcIbbDEI0OUzv8ExPRPkfMVMrVYDmichyxKRvHLuqeB6aR pNj+QlqiQEgNxM4+2DDuACfe4fhLuT9HRmQeZXC3oiK3JnYeXs8IaKP6qX8JzVSyOEG1 oKtwU2BCc4Y5xTi4rV3oLN/D/lHnLangnjyyn7kDDZ6HmAnBapqJ/gpjdQEu61qtrZCB Q97H8UKO8RaVWjZhHYQY6VxyxYJs5PpyUoC8kEyCVSZk3k0FSuE7DAjZlM/1/Y8siy3/ +fqj02e52QnmhtepVpJGrDbdWR1Bb9iriHpzBgECLFxpVeP0d4Xc5CPsVwXIm/OgPzKI Pf/Q== X-Gm-Message-State: AOAM5335MkRwmFzI+bhrRGZJ0gjMPh7W1XGGc0QviZ4ImEjDxXJiZUcn X2JPSkc+fDfVzPDuk5PAaxCtBeEoz0lPeA== X-Google-Smtp-Source: ABdhPJxDDTdlywr/kBTcgM2ePG32jKdGTzVkMGbYphir8fgFGZRXEUdtvc8rk8sQrv8/COrfFvZgSw== X-Received: by 2002:a05:6214:20e3:: with SMTP id 3mr2458849qvk.53.1623723237701; Mon, 14 Jun 2021 19:13:57 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:13:57 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , Jiang Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 2/8] selftests/bpf: Retry for EAGAIN in udp_redir_to_connected() Date: Mon, 14 Jun 2021 19:13:36 -0700 Message-Id: <20210615021342.7416-3-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang We use non-blocking sockets for testing sockmap redirections, and got some random EAGAIN errors from UDP tests. There is no guarantee the packet would be immediately available to receive as soon as it is sent out, even on the local host. For UDP, this is especially true because it does not lock the sock during BH (unlike the TCP path). This is probably why we only saw this error in UDP cases. No matter how hard we try to make the queue empty check accurate, it is always possible for recvmsg() to beat ->sk_data_ready(). Therefore, we should just retry in case of EAGAIN. Fixes: d6378af615275 ("selftests/bpf: Add a test case for udp sockmap") Reported-by: Jiang Wang Cc: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- tools/testing/selftests/bpf/prog_tests/sockmap_listen.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c index 648d9ae898d2..01ab11259809 100644 --- a/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c +++ b/tools/testing/selftests/bpf/prog_tests/sockmap_listen.c @@ -1610,6 +1610,7 @@ static void udp_redir_to_connected(int family, int sotype, int sock_mapfd, struct sockaddr_storage addr; int c0, c1, p0, p1; unsigned int pass; + int retries = 100; socklen_t len; int err, n; u64 value; @@ -1686,9 +1687,13 @@ static void udp_redir_to_connected(int family, int sotype, int sock_mapfd, if (pass != 1) FAIL("%s: want pass count 1, have %d", log_prefix, pass); +again: n = read(mode == REDIR_INGRESS ? p0 : c0, &b, 1); - if (n < 0) + if (n < 0) { + if (errno == EAGAIN && retries--) + goto again; FAIL_ERRNO("%s: read", log_prefix); + } if (n == 0) FAIL("%s: incomplete read", log_prefix); From patchwork Tue Jun 15 02:13:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320461 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E016C2B9F4 for ; Tue, 15 Jun 2021 02:46:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 571D3613C2 for ; Tue, 15 Jun 2021 02:46:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229781AbhFOCsS (ORCPT ); Mon, 14 Jun 2021 22:48:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48722 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229609AbhFOCsR (ORCPT ); Mon, 14 Jun 2021 22:48:17 -0400 Received: from mail-qk1-x733.google.com (mail-qk1-x733.google.com [IPv6:2607:f8b0:4864:20::733]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0DA54C061574; Mon, 14 Jun 2021 19:46:13 -0700 (PDT) Received: by mail-qk1-x733.google.com with SMTP id g19so7806971qkk.2; Mon, 14 Jun 2021 19:46:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DV0T/Qr/nJx8jfvW3ukFjANC4TKgQt+cqMliLspYgy0=; b=TyvUdaj9mu/Y8GbmB/A7t1MkJtCWQoLM+uRbnlvtl3gMyN9GNAdWipqQbd5OVKbMG7 zZhfDxTRtTiGUzxSO9WeC+khEg6MEiipckMc5J2EkoCngtfi4DTe46QPE4qNjeQJhOFg /h2AK7Z3O+XJtLbuVGbrY5aXkB43tV/Jb9D4nnQcftVgiKx8VyvlsUjsxkuZvk9gMdAK ntoRAAa+K/aoMWtOOEkLsVeL3l03Vl+x0mobo/LGay/id1IW4F3aXQUd6RSAuUtgpzIQ Rk8a2jrU37qJ7cX7IJUkpTeqfTn88Dnj1yfuLOX9y9lwPsPmsITMFAXv87miX77VWCEg 1UsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DV0T/Qr/nJx8jfvW3ukFjANC4TKgQt+cqMliLspYgy0=; b=Uf7O6paWpyLG2LxaJA5BMYE93QkDQY7s9ROl0Ia9pC/QzgbYVXK1OraeEjWy66WZB9 QkAQvaEisRlIY3XYCL754aCyXgi3MNJjiiz2Bq4Va419y+whBsc0NhYiWnp0RGzccwed RDVhNBSl/ppwtsWddrH8Fuxa/0EIBTx3G0K9ujGfIUTSxA078DDLVZCVJVjeKWw9cr0a HURo28Py3nhhAC6YLoU73C9p2rKu7xPIXJuEt2oTykqWbuQhru6FO7v7TSzoRFsbMmt0 ReD/BTQMDKpUX8OecyTrF319U8BvRQ/kHMaHnD9RDMxiXDO82ZZxSt5njlWvxz07DUZo AXLQ== X-Gm-Message-State: AOAM5331IILs1nKbJT7kao8aFaWnB3+OtZK3RjdbXdvWr/mrLfxdywzy 35JjTNX3tNu8hpgDJZzZnK4vibIvybLQHQ== X-Google-Smtp-Source: ABdhPJxROlCDb5f3PnQDmV9B3n+h8p2HvhvOQerLQxiDh0rQ0hA+6AV6bfJSrAWvrK9zRwDXV3jquQ== X-Received: by 2002:a37:89c5:: with SMTP id l188mr19739046qkd.27.1623723239038; Mon, 14 Jun 2021 19:13:59 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.13.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:13:58 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 3/8] udp: fix a memory leak in udp_read_sock() Date: Mon, 14 Jun 2021 19:13:37 -0700 Message-Id: <20210615021342.7416-4-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang sk_psock_verdict_recv() clones the skb and uses the clone afterward, so udp_read_sock() should free the skb after using it, regardless of error or not. This fixes a real kmemleak. Fixes: d7f571188ecf ("udp: Implement ->read_sock() for sockmap") Cc: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- net/ipv4/udp.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 15f5504adf5b..e31d67fd5183 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c @@ -1798,11 +1798,13 @@ int udp_read_sock(struct sock *sk, read_descriptor_t *desc, if (used <= 0) { if (!copied) copied = used; + kfree_skb(skb); break; } else if (used <= skb->len) { copied += used; } + kfree_skb(skb); if (!desc->count) break; } From patchwork Tue Jun 15 02:13:38 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320401 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2A028C49361 for ; Tue, 15 Jun 2021 02:23:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 15122613F5 for ; Tue, 15 Jun 2021 02:23:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231283AbhFOCZd (ORCPT ); Mon, 14 Jun 2021 22:25:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231483AbhFOCZa (ORCPT ); Mon, 14 Jun 2021 22:25:30 -0400 Received: from mail-qk1-x734.google.com (mail-qk1-x734.google.com [IPv6:2607:f8b0:4864:20::734]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C9CB8C0613A2; Mon, 14 Jun 2021 19:23:25 -0700 (PDT) Received: by mail-qk1-x734.google.com with SMTP id 5so2526854qkc.8; Mon, 14 Jun 2021 19:23:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+UdaHYvUCGtywdH+/61KW/Rjo4BNhU+1cStUbcIix1E=; b=ZNvnigzBKsLC/rUhO5wakJH3YNjwWixQA7eU+sE4SkVL/OuBYvsTHJNO3pkuP8kXlH f/nu3OgPFgbs3HmKzE6UyxaCduDSLGbqwqY5AWdIZlnoEGEMa1zBSgrz+APwu4G082mC Mn7PAjFvlxyRh8Tiy0eu264HSwp4XcVpLd5yFQNX9uzFSTVnOVJLexzIdwkeoCCT9oOv FNPLk6zlBnudePUtSFAugLKvqAiYVssaoxPWhO058r3J3c1ly83BaZvvqRXShWya1HT7 goPStDkt9TrI/H4mgWHhfwnRatQxm7mm6jyPG4DOO9ywMY1nLIHYLhjSDqTY6KEk36jz l3pA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+UdaHYvUCGtywdH+/61KW/Rjo4BNhU+1cStUbcIix1E=; b=WKVXoyPV8d8QZIbQdJa+Ppo0uB3sJs84LSuz5vtu4Qj2WGOvnV3CLymQWcJGXM3Ssg BAd8adtxr+BbzsnGtqjl5td9LPpIt6ySHnVUKkhWwRu+PTrlNE001k2WnLQmTAvO1AJr czfUEk/mOWq4FVfe+AsILUor8noSeoxxdU2IlB8MjUmMwcXrCAWO4Y/HaXCxGDLgSxcJ FpJm9bSyoaIhSXSry4kxtm8tpdaeFeLNwctvhB8ftuc1S3/N2a4w7S7FVHUPBsYRvB2b zuq2GnoNiOA+mlotokwtTEwNshDJg8omiLSbfu7WZPlXt1g4vrmSFcX1wb8oPnvzkINd pfaw== X-Gm-Message-State: AOAM5330JPivvZIX3IFy00YOF1JufaBcFw8ANZlr3lxNkEQ0IF2hzkT2 8pZpInpv0/+YX+ja2FVQV72Guwh2svHtgQ== X-Google-Smtp-Source: ABdhPJyCdV3nNzXXHRgjB6Y6pCSwBbefB9bH8FqYGc2gsiIiuC0EQpkFUTRDnbJSTDCylrgGPEtpwA== X-Received: by 2002:ae9:ed96:: with SMTP id c144mr19104878qkg.401.1623723240386; Mon, 14 Jun 2021 19:14:00 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.13.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:14:00 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , Jiang Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 4/8] skmsg: clear skb redirect pointer before dropping it Date: Mon, 14 Jun 2021 19:13:38 -0700 Message-Id: <20210615021342.7416-5-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang When we drop skb inside sk_psock_skb_redirect(), we have to clear its skb->_sk_redir pointer too, otherwise kfree_skb() would misinterpret it as a valid skb->_skb_refdst and dst_release() would eventually complain. Fixes: e3526bb92a20 ("skmsg: Move sk_redir from TCP_SKB_CB to skb") Reported-by: Jiang Wang Cc: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- net/core/skmsg.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index f9a81b314e4c..4334720e2a04 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -843,12 +843,14 @@ static void sk_psock_skb_redirect(struct sk_buff *skb) * a socket that is in this state so we drop the skb. */ if (!psock_other || sock_flag(sk_other, SOCK_DEAD)) { + skb_bpf_redirect_clear(skb); kfree_skb(skb); return; } spin_lock_bh(&psock_other->ingress_lock); if (!sk_psock_test_state(psock_other, SK_PSOCK_TX_ENABLED)) { spin_unlock_bh(&psock_other->ingress_lock); + skb_bpf_redirect_clear(skb); kfree_skb(skb); return; } From patchwork Tue Jun 15 02:13:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320403 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1C121C49EA3 for ; Tue, 15 Jun 2021 02:23:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 068B56128B for ; Tue, 15 Jun 2021 02:23:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231845AbhFOCZp (ORCPT ); Mon, 14 Jun 2021 22:25:45 -0400 Received: from mail-qt1-f181.google.com ([209.85.160.181]:33499 "EHLO mail-qt1-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231365AbhFOCZi (ORCPT ); Mon, 14 Jun 2021 22:25:38 -0400 Received: by mail-qt1-f181.google.com with SMTP id e3so10191215qte.0; Mon, 14 Jun 2021 19:23:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Z52yKO5K3X5Hvoq0tYlNwZhMPzpoNySZf4mcZZAiaZU=; b=vN5+Wa+lJHNtFFHVR5feQYsws83JHCxtaSuRqWSqaTNwHQaD4RzcseqFUtJNCZ7U3s dZK1UmSg+dmv5gHARFTZoSaYJZMQvezr/cYkC2ooKdJsuR5m0Yjdnv5SwOLNnvCG4RHg 9ekfBi4xRyoNQnyV5uyU3X8M4auqIDwCGGMp6Fzqx5/FjG5hiZ+EIfFWyUSTE1hQjghW pvZisqijUYmGZomY24jpcPq/lBvrX2O7MOjlOyHPeEbewqV3gmDvbu2zM5y2jWYSLPPG el1c0LcDJf/TPbNWglMejgWuSoa6VBlucKb0sMhYhcu1UJMtaa0UgXepz9oxvfwIOxiR zdxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z52yKO5K3X5Hvoq0tYlNwZhMPzpoNySZf4mcZZAiaZU=; b=Eir+9Qly9T7lC4WO3s382bqdhHpKMGT3lakMdq4q+jWBXNQbp6EzutwIU+qbo/k0Eu DGbnSgDP5O8xOaCQDMbiXnZKDfgZbAjsSDrEcxqPTmEU1gOXneMZ48Mwcx+IrFu75DDv G79pfv0uH5C0fIQT6C99RwZa4fw8gueZnDWdiwrWIWbFsSBHCBwx/lnoQq6jCnBZNqVT 8KInqVBMhcqao2d3/ZioWvOtMuX2ex6GNDxyJasYDK4Tcn9R5UWHmalg2NFq4QX7p8+E XZzGgBWtW87YVwyR6boC7YsLxbB0MpTqOPwdAJSNd5V138GsjwyWlkZcyUlbu8fWIG7w G13w== X-Gm-Message-State: AOAM533xcgnwxDLzKzluWkVhl0UYLPwgcZg5mH+y6YwgKnqllfAwCLnc Cs3d+s/4+KxjQteUAars4Bfvtu/usX4Iwg== X-Google-Smtp-Source: ABdhPJxR6w1DdVT90D/Rp7NsKchb++POdLW4kgPio3Fljc270AHLvsqVOuJ6Z8EfWpYSl+nWg2jaWw== X-Received: by 2002:aed:3071:: with SMTP id 104mr19587096qte.119.1623723241624; Mon, 14 Jun 2021 19:14:01 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.14.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:14:01 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 5/8] skmsg: fix a memory leak in sk_psock_verdict_apply() Date: Mon, 14 Jun 2021 19:13:39 -0700 Message-Id: <20210615021342.7416-6-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang If the dest psock does not set SK_PSOCK_TX_ENABLED, the skb can't be queued anywhere so must be dropped. This one is found during code review. Fixes: 799aa7f98d53 ("skmsg: Avoid lock_sock() in sk_psock_backlog()") Cc: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- net/core/skmsg.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 4334720e2a04..5464477e2d3d 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -924,8 +924,13 @@ static void sk_psock_verdict_apply(struct sk_psock *psock, if (sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED)) { skb_queue_tail(&psock->ingress_skb, skb); schedule_work(&psock->work); + err = 0; } spin_unlock_bh(&psock->ingress_lock); + if (err < 0) { + skb_bpf_redirect_clear(skb); + goto out_free; + } } break; case __SK_REDIRECT: From patchwork Tue Jun 15 02:13:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320397 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1887FC49EA4 for ; Tue, 15 Jun 2021 02:23:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 022A9613F5 for ; Tue, 15 Jun 2021 02:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231577AbhFOCZ1 (ORCPT ); Mon, 14 Jun 2021 22:25:27 -0400 Received: from mail-io1-f45.google.com ([209.85.166.45]:33712 "EHLO mail-io1-f45.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231365AbhFOCZ0 (ORCPT ); Mon, 14 Jun 2021 22:25:26 -0400 Received: by mail-io1-f45.google.com with SMTP id a6so41817328ioe.0; Mon, 14 Jun 2021 19:23:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zc+SAKDfiUE8ujVoPqGDWH3VJtOwCIGiCCnmCpsCpfc=; b=dVGM0bDLhrQqlEsU0Vvq9ZU/am7mJjIhmwt7cKtV2gs/gkIlIbZfMe1BgggrQSwwyR cE76D0xZhOE3YCRSFt+PXVDAPaY7sOh20pb4dKyablg3H4cBrQz10OwdaQjsdz4cKIws vCWekgqeeLvTNZUfkPZGfegCUAXLq6MQRXMOh2uRWhl5FeOwSiKR9CmjjoyidLQ55dEz Go0wpWC1f9uNyTV5NphlQrl8o1k/8C7qBesA8e7n7aINCMLe8JKdCSUMl1JmPkDO6U0q YsE5NavHTHmnVVM1svQV7grqPrcuZ2lIiB0qy3JsyLKFe3Q6XcG68SxxHXY9ly9II28r bLVg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zc+SAKDfiUE8ujVoPqGDWH3VJtOwCIGiCCnmCpsCpfc=; b=SiSlKsXK4j40ed8jaFtIQ7eMO6qKIItG6Q+alpxESUEN15VVc5scVqJrKJYUugitDt Z+gH3tzwx9NBtzBopuGuBxVrzlw64OXNOdJ6B5qqN5AzkkjZ5gN4U/0/oQIEshfDkXCK 1LLVclEiL6SFHsd8wdcPOxY+r3FNEqgShm3N13oyGjhgPzIGP8AwoJbwt+paNxYayHsp 38Tsd6hantlQKb9l3Egz8iKkcyH9cDZ0Uq2ZTmtsQjnUGS0i2zYd8m4Y8prqWdcPak/g SIR8asTx9nPDnLr7hw1BpiwBydTYRTBtjOW8I2AX8P3lJOxYQ1CanWP57vfJ7SvRYsLX ZBQA== X-Gm-Message-State: AOAM531bRwApUwFZL+2rT2EvtvMzYQ7zvKtDhFW9uNNrS0O3sG/Cu/D8 K074FRqldYb/TZZ8BkU3GyFyWMHmOO97hA== X-Google-Smtp-Source: ABdhPJyVA3km6pZC37OohV8kORsf3gk+TV/KSkokzOsVl14JwD9Hvl1v8PZFvZPI9T1IuwzjSWGjKg== X-Received: by 2002:a37:468b:: with SMTP id t133mr3001938qka.244.1623723242905; Mon, 14 Jun 2021 19:14:02 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.14.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:14:02 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 6/8] skmsg: teach sk_psock_verdict_apply() to return errors Date: Mon, 14 Jun 2021 19:13:40 -0700 Message-Id: <20210615021342.7416-7-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang Currently sk_psock_verdict_apply() is void, but it handles some error conditions too. Its caller is impossible to learn whether it succeeds or fails, especially sk_psock_verdict_recv(). Make it return int to indicate error cases and propagate errors to callers properly. Fixes: ef5659280eb1 ("bpf, sockmap: Allow skipping sk_skb parser program") Cc: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- net/core/skmsg.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 5464477e2d3d..e3d210811db4 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -824,7 +824,7 @@ int sk_psock_msg_verdict(struct sock *sk, struct sk_psock *psock, } EXPORT_SYMBOL_GPL(sk_psock_msg_verdict); -static void sk_psock_skb_redirect(struct sk_buff *skb) +static int sk_psock_skb_redirect(struct sk_buff *skb) { struct sk_psock *psock_other; struct sock *sk_other; @@ -835,7 +835,7 @@ static void sk_psock_skb_redirect(struct sk_buff *skb) */ if (unlikely(!sk_other)) { kfree_skb(skb); - return; + return -EIO; } psock_other = sk_psock(sk_other); /* This error indicates the socket is being torn down or had another @@ -845,19 +845,20 @@ static void sk_psock_skb_redirect(struct sk_buff *skb) if (!psock_other || sock_flag(sk_other, SOCK_DEAD)) { skb_bpf_redirect_clear(skb); kfree_skb(skb); - return; + return -EIO; } spin_lock_bh(&psock_other->ingress_lock); if (!sk_psock_test_state(psock_other, SK_PSOCK_TX_ENABLED)) { spin_unlock_bh(&psock_other->ingress_lock); skb_bpf_redirect_clear(skb); kfree_skb(skb); - return; + return -EIO; } skb_queue_tail(&psock_other->ingress_skb, skb); schedule_work(&psock_other->work); spin_unlock_bh(&psock_other->ingress_lock); + return 0; } static void sk_psock_tls_verdict_apply(struct sk_buff *skb, struct sock *sk, int verdict) @@ -894,14 +895,15 @@ int sk_psock_tls_strp_read(struct sk_psock *psock, struct sk_buff *skb) } EXPORT_SYMBOL_GPL(sk_psock_tls_strp_read); -static void sk_psock_verdict_apply(struct sk_psock *psock, - struct sk_buff *skb, int verdict) +static int sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb, + int verdict) { struct sock *sk_other; - int err = -EIO; + int err = 0; switch (verdict) { case __SK_PASS: + err = -EIO; sk_other = psock->sk; if (sock_flag(sk_other, SOCK_DEAD) || !sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED)) { @@ -934,13 +936,15 @@ static void sk_psock_verdict_apply(struct sk_psock *psock, } break; case __SK_REDIRECT: - sk_psock_skb_redirect(skb); + err = sk_psock_skb_redirect(skb); break; case __SK_DROP: default: out_free: kfree_skb(skb); } + + return err; } static void sk_psock_write_space(struct sock *sk) @@ -1107,7 +1111,8 @@ static int sk_psock_verdict_recv(read_descriptor_t *desc, struct sk_buff *skb, ret = sk_psock_map_verd(ret, skb_bpf_redirect_fetch(skb)); skb->sk = NULL; } - sk_psock_verdict_apply(psock, skb, ret); + if (sk_psock_verdict_apply(psock, skb, ret) < 0) + len = 0; out: rcu_read_unlock(); return len; From patchwork Tue Jun 15 02:13:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320405 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 67941C49EA2 for ; Tue, 15 Jun 2021 02:24:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54F8961434 for ; Tue, 15 Jun 2021 02:24:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231715AbhFOC0G (ORCPT ); Mon, 14 Jun 2021 22:26:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231753AbhFOC0A (ORCPT ); Mon, 14 Jun 2021 22:26:00 -0400 Received: from mail-io1-xd2c.google.com (mail-io1-xd2c.google.com [IPv6:2607:f8b0:4864:20::d2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 26AEBC061574; Mon, 14 Jun 2021 19:23:56 -0700 (PDT) Received: by mail-io1-xd2c.google.com with SMTP id h5so5068022iok.5; Mon, 14 Jun 2021 19:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Li7iIK9O8bheMw2lclanyfnMSKgSW79Xj968UPC+rYs=; b=fZki6ssOlB+VxyfcAnV58alC1PcfzefwADuEnz6mbAO92jBi8Kcx7hMrNR+qCzArt2 L87xwldgoJqlFDoRElkm8PpClfMIoqVsJyfzfXXE8NPl7OSN5MNT28Zh3YFs8ldW1XWs 5QPetvSCQvO+6mvoQbm0GbALj4ZigR4xCEnR5rh9N4B2fzeDbUItLZl+yGFy39Yx22md Dqz0yjzmbu3oFi8fotj4lP/xMFxDnAlgZQajKjDDsuoGSQtGHoyQnUTU+kLX0SxSlCyq XmNoPYLeNhmhnuRFIQBpbZJT7qfCoyZpo2MjIhdIrUzAoIuVM20RTeSI3nXtkSdxd4jU MRIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Li7iIK9O8bheMw2lclanyfnMSKgSW79Xj968UPC+rYs=; b=lZSwCdlOQOwvWBgbD3W7MHjK6CZkQuIOymoGZmJ/DHW6MsXCSLx2TVTqzhEkcj8L81 uHBt7wJiQRniTXQV2DxIew52ieK2peH0L1Lm44fhpQo42r7xxVlmJS1kvk72sse6c7lY abPM/D33BzRVqefPoxIqxmThl2NmxrHnTrm5GW1jnqPzSFlqxISGI0BsTLn+KJS/42r2 +UFXDkAJ45J3Itwsg2Kc45rM4BubXYccCZMwE0HrJINbEbwAk6mYg1V3RbVJI9sae39p zPt0fYaF36fHZco+zE/UkjSNh5rz07d1JPhXdCT1XO8bBlS8QKgz+P30eWoU755lZm74 nxcw== X-Gm-Message-State: AOAM533kHZZkGd+ca1S03m+n04xrD90924kDxZDwNM7KA4JxF5hieVKP ZHZOWwVVqh+p9FI5too3a0X2yGVr8F7tVw== X-Google-Smtp-Source: ABdhPJyBDpKGYzy1QdSgYN1+LUQ2WQjOJBtCkZBYaLxqGUQo4yOcWw+TKPfPbOI2t/fKEN7Q6EmLkw== X-Received: by 2002:a05:620a:29d4:: with SMTP id s20mr19323986qkp.287.1623723244147; Mon, 14 Jun 2021 19:14:04 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:14:03 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 7/8] skmsg: pass source psock to sk_psock_skb_redirect() Date: Mon, 14 Jun 2021 19:13:41 -0700 Message-Id: <20210615021342.7416-8-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang sk_psock_skb_redirect() only takes skb as a parameter, we will need to know where this skb is from, so just pass the source psock to this function as a new parameter. This patch prepares for the next one. Cc: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- net/core/skmsg.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index e3d210811db4..3aa9065811ad 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -824,7 +824,7 @@ int sk_psock_msg_verdict(struct sock *sk, struct sk_psock *psock, } EXPORT_SYMBOL_GPL(sk_psock_msg_verdict); -static int sk_psock_skb_redirect(struct sk_buff *skb) +static int sk_psock_skb_redirect(struct sk_psock *from, struct sk_buff *skb) { struct sk_psock *psock_other; struct sock *sk_other; @@ -861,11 +861,12 @@ static int sk_psock_skb_redirect(struct sk_buff *skb) return 0; } -static void sk_psock_tls_verdict_apply(struct sk_buff *skb, struct sock *sk, int verdict) +static void sk_psock_tls_verdict_apply(struct sk_buff *skb, + struct sk_psock *from, int verdict) { switch (verdict) { case __SK_REDIRECT: - sk_psock_skb_redirect(skb); + sk_psock_skb_redirect(from, skb); break; case __SK_PASS: case __SK_DROP: @@ -889,7 +890,7 @@ int sk_psock_tls_strp_read(struct sk_psock *psock, struct sk_buff *skb) ret = sk_psock_map_verd(ret, skb_bpf_redirect_fetch(skb)); skb->sk = NULL; } - sk_psock_tls_verdict_apply(skb, psock->sk, ret); + sk_psock_tls_verdict_apply(skb, psock, ret); rcu_read_unlock(); return ret; } @@ -936,7 +937,7 @@ static int sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb, } break; case __SK_REDIRECT: - err = sk_psock_skb_redirect(skb); + err = sk_psock_skb_redirect(psock, skb); break; case __SK_DROP: default: From patchwork Tue Jun 15 02:13:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cong Wang X-Patchwork-Id: 12320457 X-Patchwork-Delegate: bpf@iogearbox.net Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 44DA1C48BE6 for ; Tue, 15 Jun 2021 02:41:30 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id F109F61428 for ; Tue, 15 Jun 2021 02:41:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231393AbhFOCnc (ORCPT ); Mon, 14 Jun 2021 22:43:32 -0400 Received: from mail-qk1-f171.google.com ([209.85.222.171]:45955 "EHLO mail-qk1-f171.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230377AbhFOCnb (ORCPT ); Mon, 14 Jun 2021 22:43:31 -0400 Received: by mail-qk1-f171.google.com with SMTP id d196so35436287qkg.12; Mon, 14 Jun 2021 19:41:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kTfpOex7Ud8CUqQBaXyyvSHgbNeSLa/1/bU7Yfg6MDw=; b=XVHXVwtMvRvvhhwv8D1iYj02uacoltqkFTFNfKPBRR9paEqKkFk7R0o/H4rB/1V42F wXGC8gveqbFVaGC1XrJpjFlo+dZ+a6vCw0VdkwdpgLn+QtUiGLgcVTnm/MXi56NGVJsl YdTOYX8fA523G6HNQAZhoJYoVEuiigx2R0N2fZe5jKY7le7cfNlz8XyZbUqFaGq/PjHV O95Gdg8gFIbkLPDz1p4Q+GsgUghYQUtC7XyOAGo/K+XwLA7HUV9p6PVBDTlq7GvTb+wc NDMKgbeWRHlw6AJTTDTBDmTnXN8bASsfOSSt4qGbIJSTxAXbOhqIjMYbjKO6yerimIb5 sgnA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kTfpOex7Ud8CUqQBaXyyvSHgbNeSLa/1/bU7Yfg6MDw=; b=p+aASJ08+kqufCRoQZBBAIe50ACy3leRod1osmOWEdrs5rtY9SU6RTRZGm9oS5nUfv g7d6wFZ/0pe4Tm1hlQNoEFDV6/PVVnlc0k19G6VYdCvbBNMs1/eY+AHOVPKwczJtTwSk X1oedVrmENl2gc6bwuiUPhq9es4hKCpo7fAXbqjPfuDN4yS1S3lGx6S890pG8B1ld3tQ O7SF/25nfuzylkQd/PdGEzoWBDNHIf/ae9ibcQtAZrBLntioW8lUIQWQaVK8YPTfaQKJ D+1Sh8TJeGbhrOjRHsypSbRdzJlLmmcGp7cR2wDNhLcp5FwZfTwtPxT2cgdDzcXhyaq7 3c8A== X-Gm-Message-State: AOAM5320Csc0Pr4IZfA0Uo6VSr6tacwPorDMhKH7xecanktN36T+XV8U JVixielST3RaY8yPmoGwmsgyEQOh0yKNxQ== X-Google-Smtp-Source: ABdhPJxXTY2/UBWsccoEt5hq6ulqNrMPrH5lgFj8sKWKolyqsAXS/v7CZPsFZwwUfXAwK08fi9n7ew== X-Received: by 2002:a05:620a:13f0:: with SMTP id h16mr19811842qkl.32.1623723245378; Mon, 14 Jun 2021 19:14:05 -0700 (PDT) Received: from unknown.attlocal.net ([2600:1700:65a0:ab60:e9a1:5f1d:df88:4f3c]) by smtp.gmail.com with ESMTPSA id t15sm10774497qtr.35.2021.06.14.19.14.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Jun 2021 19:14:05 -0700 (PDT) From: Cong Wang To: netdev@vger.kernel.org Cc: bpf@vger.kernel.org, Cong Wang , John Fastabend , Daniel Borkmann , Jakub Sitnicki , Lorenz Bauer Subject: [PATCH RESEND bpf v3 8/8] skmsg: increase sk->sk_drops when dropping packets Date: Mon, 14 Jun 2021 19:13:42 -0700 Message-Id: <20210615021342.7416-9-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20210615021342.7416-1-xiyou.wangcong@gmail.com> References: <20210615021342.7416-1-xiyou.wangcong@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: bpf@vger.kernel.org X-Patchwork-Delegate: bpf@iogearbox.net From: Cong Wang It is hard to observe packet drops without increasing relevant drop counters, here we should increase sk->sk_drops which is a protocol-independent counter. Fortunately psock is always associated with a struct sock, we can just use psock->sk. Suggested-by: John Fastabend Cc: Daniel Borkmann Cc: Jakub Sitnicki Cc: Lorenz Bauer Signed-off-by: Cong Wang --- net/core/skmsg.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/net/core/skmsg.c b/net/core/skmsg.c index 3aa9065811ad..9b6160a191f8 100644 --- a/net/core/skmsg.c +++ b/net/core/skmsg.c @@ -578,6 +578,12 @@ static int sk_psock_handle_skb(struct sk_psock *psock, struct sk_buff *skb, return sk_psock_skb_ingress(psock, skb); } +static void sock_drop(struct sock *sk, struct sk_buff *skb) +{ + sk_drops_add(sk, skb); + kfree_skb(skb); +} + static void sk_psock_backlog(struct work_struct *work) { struct sk_psock *psock = container_of(work, struct sk_psock, work); @@ -617,7 +623,7 @@ static void sk_psock_backlog(struct work_struct *work) /* Hard errors break pipe and stop xmit. */ sk_psock_report_error(psock, ret ? -ret : EPIPE); sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED); - kfree_skb(skb); + sock_drop(psock->sk, skb); goto end; } off += ret; @@ -708,7 +714,7 @@ static void __sk_psock_zap_ingress(struct sk_psock *psock) while ((skb = skb_dequeue(&psock->ingress_skb)) != NULL) { skb_bpf_redirect_clear(skb); - kfree_skb(skb); + sock_drop(psock->sk, skb); } __sk_psock_purge_ingress_msg(psock); } @@ -834,7 +840,7 @@ static int sk_psock_skb_redirect(struct sk_psock *from, struct sk_buff *skb) * return code, but then didn't set a redirect interface. */ if (unlikely(!sk_other)) { - kfree_skb(skb); + sock_drop(from->sk, skb); return -EIO; } psock_other = sk_psock(sk_other); @@ -844,14 +850,14 @@ static int sk_psock_skb_redirect(struct sk_psock *from, struct sk_buff *skb) */ if (!psock_other || sock_flag(sk_other, SOCK_DEAD)) { skb_bpf_redirect_clear(skb); - kfree_skb(skb); + sock_drop(from->sk, skb); return -EIO; } spin_lock_bh(&psock_other->ingress_lock); if (!sk_psock_test_state(psock_other, SK_PSOCK_TX_ENABLED)) { spin_unlock_bh(&psock_other->ingress_lock); skb_bpf_redirect_clear(skb); - kfree_skb(skb); + sock_drop(from->sk, skb); return -EIO; } @@ -942,7 +948,7 @@ static int sk_psock_verdict_apply(struct sk_psock *psock, struct sk_buff *skb, case __SK_DROP: default: out_free: - kfree_skb(skb); + sock_drop(psock->sk, skb); } return err; @@ -977,7 +983,7 @@ static void sk_psock_strp_read(struct strparser *strp, struct sk_buff *skb) sk = strp->sk; psock = sk_psock(sk); if (unlikely(!psock)) { - kfree_skb(skb); + sock_drop(sk, skb); goto out; } prog = READ_ONCE(psock->progs.stream_verdict); @@ -1098,7 +1104,7 @@ static int sk_psock_verdict_recv(read_descriptor_t *desc, struct sk_buff *skb, psock = sk_psock(sk); if (unlikely(!psock)) { len = 0; - kfree_skb(skb); + sock_drop(sk, skb); goto out; } prog = READ_ONCE(psock->progs.stream_verdict);