From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A95A0C433FE for ; Tue, 1 Mar 2022 01:49:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232043AbiCABuX (ORCPT ); Mon, 28 Feb 2022 20:50:23 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40616 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232085AbiCABuQ (ORCPT ); Mon, 28 Feb 2022 20:50:16 -0500 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E2B605DE5D; Mon, 28 Feb 2022 17:49:15 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.56]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4K70Vj3YRHz9snW; Tue, 1 Mar 2022 09:47:25 +0800 (CST) Received: from [10.174.177.215] (10.174.177.215) by canpemm500010.china.huawei.com (7.192.105.118) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Tue, 1 Mar 2022 09:49:12 +0800 Subject: Re: [PATCH bpf-next 1/4] bpf, sockmap: Fix memleak in sk_psock_queue_msg To: Cong Wang CC: , , , , , , , , , , , , , , , , References: <20220225014929.942444-1-wangyufen@huawei.com> <20220225014929.942444-2-wangyufen@huawei.com> From: wangyufen Message-ID: <43776e3f-08c0-5d1a-1c2b-dd6084a6de33@huawei.com> Date: Tue, 1 Mar 2022 09:49:12 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.215] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To canpemm500010.china.huawei.com (7.192.105.118) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 在 2022/2/28 3:21, Cong Wang 写道: > On Fri, Feb 25, 2022 at 09:49:26AM +0800, Wang Yufen wrote: >> If tcp_bpf_sendmsg is running during a tear down operation we may enqueue >> data on the ingress msg queue while tear down is trying to free it. >> >> sk1 (redirect sk2) sk2 >> ------------------- --------------- >> tcp_bpf_sendmsg() >> tcp_bpf_send_verdict() >> tcp_bpf_sendmsg_redir() >> bpf_tcp_ingress() >> sock_map_close() >> lock_sock() >> lock_sock() ... blocking >> sk_psock_stop >> sk_psock_clear_state(psock, SK_PSOCK_TX_ENABLED); >> release_sock(sk); >> lock_sock() >> sk_mem_charge() >> get_page() >> sk_psock_queue_msg() >> sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED); >> drop_sk_msg() >> release_sock() >> >> While drop_sk_msg(), the msg has charged memory form sk by sk_mem_charge >> and has sg pages need to put. To fix we use sk_msg_free() and then kfee() >> msg. >> > What about the other code path? That is, sk_psock_skb_ingress_enqueue(). > I don't see skmsg is charged there. sk_psock_skb_ingress_self() | sk_psock_skb_ingress()    skb_set_owner_r()       sk_mem_charge()    sk_psock_skb_ingress_enqueue() The other code path skmsg is charged by skb_set_owner_r()->sk_mem_charge() > > Thanks. > .