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 X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no 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 09B29C4727E for ; Fri, 25 Sep 2020 20:35:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7BA1020838 for ; Fri, 25 Sep 2020 20:35:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=buslov.dev header.i=@buslov.dev header.b="KHTgSAAC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728932AbgIYUdV (ORCPT ); Fri, 25 Sep 2020 16:33:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727258AbgIYU2f (ORCPT ); Fri, 25 Sep 2020 16:28:35 -0400 Received: from mail.buslov.dev (mail.buslov.dev [IPv6:2001:19f0:5001:2e3f:5400:1ff:feed:a259]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C7DEFC0613B5 for ; Fri, 25 Sep 2020 12:50:14 -0700 (PDT) Received: from vlad-x1g6.mellanox.com (unknown [IPv6:2a0b:2bc3:193f:1:a5fe:a7d6:6345:fe8d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by mail.buslov.dev (Postfix) with ESMTPSA id F1CC520B4F; Fri, 25 Sep 2020 22:45:11 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=buslov.dev; s=2019; t=1601063112; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=byEbDwzk5WHU4FygOZ8muKPjI0PrrXeInFq+yfTsF0A=; b=KHTgSAACBr8CjcReRiWRDgaCKlHhGvHqKHfhGGk9+ud+ETFcVzicu3dFOh4SvpgQoTgnRZ TP5RzIO8cYeMRVcH5x/Y+ascqLwYOGx5gpOI9tH2k80WDv/f9qybCQ1WzSrpy08fQzUfjk 9466FXzL/yFQ8HNF+eCwXd9dvJ5l/UMIcB2yQzpJWgXjtEn5YHAr6qXZ1jeXvXGkICa+1X ASnuSAW7dgh97ehueAJTlgnNWZOm4LjpPupbGeErZrwBJPu9kljICzvUpgNXqd6V/KCaGB +sgpzXoAitb6JLvK4ZU75U6BbfiEqWdtobc6Cx++wu0iNTf0+ILWZr1Ua8iMlw== References: <20200923035624.7307-1-xiyou.wangcong@gmail.com> <20200923035624.7307-2-xiyou.wangcong@gmail.com> <877dsh98wq.fsf@buslov.dev> User-agent: mu4e 1.4.13; emacs 26.3 From: Vlad Buslov To: Cong Wang Cc: Linux Kernel Network Developers , Vlad Buslov , Jamal Hadi Salim , Jiri Pirko Subject: Re: [Patch net 1/2] net_sched: defer tcf_idr_insert() in tcf_action_init_1() In-reply-to: Message-ID: <8736358wu0.fsf@buslov.dev> Date: Fri, 25 Sep 2020 22:45:11 +0300 MIME-Version: 1.0 Content-Type: text/plain Authentication-Results: ORIGINATING; auth=pass smtp.auth=vlad@buslov.dev smtp.mailfrom=vlad@buslov.dev Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org On Fri 25 Sep 2020 at 22:22, Cong Wang wrote: > On Fri, Sep 25, 2020 at 8:24 AM Vlad Buslov wrote: >> > + if (TC_ACT_EXT_CMP(a->tcfa_action, TC_ACT_GOTO_CHAIN) && >> > + !rcu_access_pointer(a->goto_chain)) { >> > + tcf_action_destroy_1(a, bind); >> > + NL_SET_ERR_MSG(extack, "can't use goto chain with NULL chain"); >> > + return ERR_PTR(-EINVAL); >> > + } >> >> I don't think calling tcf_action_destoy_1() is enough here. Since you >> moved this block before assigning cookie and releasing the module, you >> also need to release them manually in addition to destroying the action >> instance. >> > > tcf_action_destoy_1() eventually calls free_tcf() which frees cookie and > tcf_action_destroy() which releases module refcnt. > > What am I missing here? > > Thanks. The memory referenced by the function local pointer "cookie" hasn't been assigned yet to the a->act_cookie because in your patch you moved goto_chain validation code before the cookie change. That means that if user overwrites existing action, then action old a->act_cookie will be freed by tcf_action_destroy_1() but new cookie that was allocated by nla_memdup_cookie() will leak. Regards, Vlad