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 BE765C433F5 for ; Fri, 4 Mar 2022 06:46:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238479AbiCDGqu (ORCPT ); Fri, 4 Mar 2022 01:46:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40346 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229889AbiCDGqt (ORCPT ); Fri, 4 Mar 2022 01:46:49 -0500 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 92B6F18CC0C; Thu, 3 Mar 2022 22:46:01 -0800 (PST) Received: from canpemm500010.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4K8yyJ736QzdZdk; Fri, 4 Mar 2022 14:44:40 +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; Fri, 4 Mar 2022 14:45:58 +0800 Subject: Re: [PATCH bpf-next v2 1/4] bpf, sockmap: Fix memleak in sk_psock_queue_msg To: Cong Wang CC: , , , , , , , , , , , , , , , , References: <20220302022755.3876705-1-wangyufen@huawei.com> <20220302022755.3876705-2-wangyufen@huawei.com> From: wangyufen Message-ID: <2ebeeba1-f06d-9ebf-b59c-b0289ad89885@huawei.com> Date: Fri, 4 Mar 2022 14:45:58 +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="gbk"; format=flowed Content-Transfer-Encoding: 8bit X-Originating-IP: [10.174.177.215] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) 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/3/3 8:41, Cong Wang дµÀ: > On Wed, Mar 02, 2022 at 10:27:52AM +0800, Wang Yufen wrote: >> diff --git a/include/linux/skmsg.h b/include/linux/skmsg.h >> index fdb5375f0562..c5a2d6f50f25 100644 >> --- a/include/linux/skmsg.h >> +++ b/include/linux/skmsg.h >> @@ -304,21 +304,16 @@ static inline void sock_drop(struct sock *sk, struct sk_buff *skb) >> kfree_skb(skb); >> } >> >> -static inline void drop_sk_msg(struct sk_psock *psock, struct sk_msg *msg) >> -{ >> - if (msg->skb) >> - sock_drop(psock->sk, msg->skb); >> - kfree(msg); >> -} >> - >> static inline void sk_psock_queue_msg(struct sk_psock *psock, >> struct sk_msg *msg) >> { >> spin_lock_bh(&psock->ingress_lock); >> if (sk_psock_test_state(psock, SK_PSOCK_TX_ENABLED)) >> list_add_tail(&msg->list, &psock->ingress_msg); >> - else >> - drop_sk_msg(psock, msg); >> + else { >> + sk_msg_free(psock->sk, msg); > __sk_msg_free() calls sk_msg_init() at the end. > >> + kfree(msg); > Now you free it, hence the above sk_msg_init() is completely > unnecessary. Invoking of sk_msg_free() does not always follow kfree(). That is, sk_msg needs to be reused in some cases. We can implement sk_msg_free_xx() without sk_msg_init(), but I don't think it is necessary. Thanks > > Thanks. > .