Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp636975pxb; Tue, 5 Apr 2022 16:49:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwyL01DwHg84FO/Ch6Xkgmnq+UG2jxcJA9J0nvvUf4YkpvYYbQ/2NYqsJfi1NKaRTSePPgL X-Received: by 2002:a17:90b:4f8c:b0:1c7:2217:e980 with SMTP id qe12-20020a17090b4f8c00b001c72217e980mr6657687pjb.17.1649202597141; Tue, 05 Apr 2022 16:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649202597; cv=none; d=google.com; s=arc-20160816; b=Cv6BpJUiB8KPAxh+lBd/y7od7uROW/1KYNJnN11j9pgtHIirBrJPQmhCp4zxcdnCHw cAImNkpPJTqXDE5J97nEPGAawzn83qeaEzaiRkXMkCdE5jnWVUBbPdiqDKGvadiKV8nA 1fGJpZQUFfWEmfuhhOYKFf37gue5EHER5LeZQfGizu4j5lvLWuMCKnHJucURYPnJr3EW 98/XLtRv8qh9nzU3Cfv8DfnzZYtxcCeErYoxhCsf+Skj2bkATq7EUFGz71zwMONMZHYR EW1+B6QRekfDeFLZ9Vomfdy0F7QbZjY5YKWBQAXsuf4p08WWeIR5G1mKv5LpldMUIVsz V9tA== 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=HOVNlPmoenCd05r/cI0EMYMa3M2kM6a19wrCO42UB+I=; b=xX/vuNU3CnXnmtWmuW8JhOfm0TXmHsc6Q9tI/kzjvSjJbQ7f07PrrU4Pw+yMpReeWO SsB8LnwF4Sk+VHiHWGQLDT6yec/lYb3Xnj3MWgA/iEDdYcIJ5xhuDi+/bnOyHy9bIiW1 vkmjwu6bLHmZ+wzN2iOSJx7l5WiK+opWZ324UqRXxJ/8q50p3sPBlEdnwqXIGo2DuCal WVZG1A9D+IxXZdDnmM38ihaHYpk5Sa2qfL4WeIHsnawgDHGTxeAd7rEExhh3z1X3lfpU m7qcP08I2r5/iwJ8rGdsNASr/MmRhJqiqbxKsa5ya5DFo7EGYnY7X+WLzASs9lPkWW0v n91w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vqAk8Vpb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id e4-20020a656bc4000000b00398729a9c16si1921358pgw.271.2022.04.05.16.49.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Apr 2022 16:49:57 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=vqAk8Vpb; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 914F61162BC; Tue, 5 Apr 2022 16:34:11 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377109AbiDEMw2 (ORCPT + 99 others); Tue, 5 Apr 2022 08:52:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41890 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S243786AbiDEJJQ (ORCPT ); Tue, 5 Apr 2022 05:09:16 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F7B0CC528; Tue, 5 Apr 2022 01:58:38 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A306061574; Tue, 5 Apr 2022 08:58:37 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A775EC385A0; Tue, 5 Apr 2022 08:58:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649149117; bh=bMpDvhUZHs/Rk+rEvjrWU1xOX5yG+D1BVOcQTkPZsC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=vqAk8VpbyMSw/hJtAAgk3AY9vmBF853r6/22bESykGIp03/VtD+KAsdy7uEyQempQ bCslzJdSFeO/FZPmAMtwyQs+nFytq4vhvNJe8TRApm/UbVBc7Mrzqy0mZBLLx4tAEb jhBGCQc/E+bn0Qkq3vf3PYLOgsFYv9lGGhkmc/cg= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Wang Yufen , Daniel Borkmann , John Fastabend , Sasha Levin Subject: [PATCH 5.16 0601/1017] bpf, sockmap: Fix more uncharged while msg has more_data Date: Tue, 5 Apr 2022 09:25:14 +0200 Message-Id: <20220405070412.118002939@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070354.155796697@linuxfoundation.org> References: <20220405070354.155796697@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 From: Wang Yufen [ Upstream commit 84472b436e760ba439e1969a9e3c5ae7c86de39d ] In tcp_bpf_send_verdict(), if msg has more data after tcp_bpf_sendmsg_redir(): tcp_bpf_send_verdict() tosend = msg->sg.size //msg->sg.size = 22220 case __SK_REDIRECT: sk_msg_return() //uncharged msg->sg.size(22220) sk->sk_forward_alloc tcp_bpf_sendmsg_redir() //after tcp_bpf_sendmsg_redir, msg->sg.size=11000 goto more_data; tosend = msg->sg.size //msg->sg.size = 11000 case __SK_REDIRECT: sk_msg_return() //uncharged msg->sg.size(11000) to sk->sk_forward_alloc The msg->sg.size(11000) has been uncharged twice, to fix we can charge the remaining msg->sg.size before goto more data. This issue can cause the following info: WARNING: CPU: 0 PID: 9860 at net/core/stream.c:208 sk_stream_kill_queues+0xd4/0x1a0 Call Trace: inet_csk_destroy_sock+0x55/0x110 __tcp_close+0x279/0x470 tcp_close+0x1f/0x60 inet_release+0x3f/0x80 __sock_release+0x3d/0xb0 sock_close+0x11/0x20 __fput+0x92/0x250 task_work_run+0x6a/0xa0 do_exit+0x33b/0xb60 do_group_exit+0x2f/0xa0 get_signal+0xb6/0x950 arch_do_signal_or_restart+0xac/0x2a0 ? vfs_write+0x237/0x290 exit_to_user_mode_prepare+0xa9/0x200 syscall_exit_to_user_mode+0x12/0x30 do_syscall_64+0x46/0x80 entry_SYSCALL_64_after_hwframe+0x44/0xae WARNING: CPU: 0 PID: 2136 at net/ipv4/af_inet.c:155 inet_sock_destruct+0x13c/0x260 Call Trace: __sk_destruct+0x24/0x1f0 sk_psock_destroy+0x19b/0x1c0 process_one_work+0x1b3/0x3c0 worker_thread+0x30/0x350 ? process_one_work+0x3c0/0x3c0 kthread+0xe6/0x110 ? kthread_complete_and_exit+0x20/0x20 ret_from_fork+0x22/0x30 Fixes: 604326b41a6f ("bpf, sockmap: convert to generic sk_msg interface") Signed-off-by: Wang Yufen Signed-off-by: Daniel Borkmann Acked-by: John Fastabend Link: https://lore.kernel.org/bpf/20220304081145.2037182-4-wangyufen@huawei.com Signed-off-by: Sasha Levin --- net/ipv4/tcp_bpf.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/net/ipv4/tcp_bpf.c b/net/ipv4/tcp_bpf.c index 9b9b02052fd3..304800c60427 100644 --- a/net/ipv4/tcp_bpf.c +++ b/net/ipv4/tcp_bpf.c @@ -335,7 +335,7 @@ static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock, cork = true; psock->cork = NULL; } - sk_msg_return(sk, msg, tosend); + sk_msg_return(sk, msg, msg->sg.size); release_sock(sk); ret = tcp_bpf_sendmsg_redir(sk_redir, msg, tosend, flags); @@ -375,8 +375,11 @@ static int tcp_bpf_send_verdict(struct sock *sk, struct sk_psock *psock, } if (msg && msg->sg.data[msg->sg.start].page_link && - msg->sg.data[msg->sg.start].length) + msg->sg.data[msg->sg.start].length) { + if (eval == __SK_REDIRECT) + sk_mem_charge(sk, msg->sg.size); goto more_data; + } } return ret; } -- 2.34.1