Received: by 2002:a05:6a10:2726:0:0:0:0 with SMTP id ib38csp955873pxb; Wed, 6 Apr 2022 05:15:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzcmSArIHBWhjZALtHPNNbLURmC+0ZqEXkZ+VETfXASHJd0bqJzEcC+pCJ7sG3IZzo8FnOf X-Received: by 2002:a05:6a00:1907:b0:4f7:945:14cf with SMTP id y7-20020a056a00190700b004f7094514cfmr8524677pfi.47.1649247357141; Wed, 06 Apr 2022 05:15:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649247357; cv=none; d=google.com; s=arc-20160816; b=XjRnn//K9/aoE6mwChbx53gsEz6dGMhbsNvQMUktceQ9ZlYT4hMGYMa01P+sADxmO1 F5zJdwUgFLl7q4Ng8GCyIrtzAqLdyFI8RBEwcdaEbUdqTIlLnKGe1XzuzUKGCMPs/PKS YLYJD6+kOXyJc+FBiKKL9MI5ovWIZKEsiwF1+3MIVu6SPcE8bUwMQVhAoIXK1YbS98O/ QEOAuDTLi7d/io+KpcfO9u+LI6x45+SRDx98ougYY5/xoAowW4auA5l3zwf7kG8axFJD VGR3rSE15pjkpBNvcnybYOdImKW7bg+2ADECa/TtHDMV4TZ5rnV9F8WGiKD/uE0HSSsk OZiQ== 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=hDrEjcuz8/y/pI462gRP5axRQxlpl3O+5L7bM4wYAH9roRU3tGTS6xHK2VFKBrBKT9 sUli2EyRNRnbSxBI5+SvzoI/hwyx8UeHxL2OaoTWVrCHHmRgNh00eRzNclvz94mQqy+o gXB1t4q93bzSrEYeO/LrMTjMuhdTfBF9KYSbTk1//UO++DpmuKits6XtX5VC5/2aFeYj 1Ar3MjRdovWmNLCmDFoba9gIwCw1rc58TkLSSnVR6a7X8FuxYGWvJxaL/e7Nqa0NFNvk sOZP2lrVGOCgQw+92C7Cn1co7w0nZjkFfw0lDX/n68GfbhUtu0n1AJYfpZ+xFJjFQv97 k14Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b="H2ep/nFe"; 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 f11-20020a170902ce8b00b00153b2d1653dsi15883929plg.325.2022.04.06.05.15.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 06 Apr 2022 05:15: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="H2ep/nFe"; 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 6903D6BD82F; Wed, 6 Apr 2022 03:55:13 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1575141AbiDEXCy (ORCPT + 99 others); Tue, 5 Apr 2022 19:02:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349401AbiDEJtr (ORCPT ); Tue, 5 Apr 2022 05:49:47 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A701317049; Tue, 5 Apr 2022 02:44:57 -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 ams.source.kernel.org (Postfix) with ESMTPS id 607A3B818F3; Tue, 5 Apr 2022 09:44:56 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B7E50C385A2; Tue, 5 Apr 2022 09:44:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1649151895; bh=bMpDvhUZHs/Rk+rEvjrWU1xOX5yG+D1BVOcQTkPZsC8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=H2ep/nFeAraz6ENIfxfTImcYtyZd3DK9ee0qfE035j2TskjBkhJTAE6f+y+trXmn0 NU1K9xbl59yhwk7SboH+i1IBGMtkKcz6dK1fVxF7OmEfxuwpWn4QjEQpBWSfDaBwkm SvNjUddoWH38QJ3CdgZIbvjGqDF/QS0iBouXQUvQ= 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.15 542/913] bpf, sockmap: Fix more uncharged while msg has more_data Date: Tue, 5 Apr 2022 09:26:44 +0200 Message-Id: <20220405070356.094747595@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220405070339.801210740@linuxfoundation.org> References: <20220405070339.801210740@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