Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp3119067pxm; Mon, 28 Feb 2022 12:25:33 -0800 (PST) X-Google-Smtp-Source: ABdhPJwQs8rdBOK1bn9nkmyO3upFOKutDtp2R7gjFE2GFxfhYx8HH2MOX1NbHMIHlFqk7bV3z+cW X-Received: by 2002:a17:902:d4ce:b0:14f:cd14:4fe7 with SMTP id o14-20020a170902d4ce00b0014fcd144fe7mr21991768plg.165.1646079933421; Mon, 28 Feb 2022 12:25:33 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646079933; cv=none; d=google.com; s=arc-20160816; b=o6ArFT6dGiahRRaKdnlzbboNWS3a2dAvpdOaZ6czPnrk79GlLkHk6LysmemOGK+6H/ kSz+istRzETgCtMBeMObIkL7t0zhXWxgeJN7gCW0/Y3be/sjl7yroJRNwJBBlyh9/FnO mz1HDksMOfNYY8OkPvrXEyyn7yesidRyh8HdxLFZ1w0KvDbH3Nl3kJqHXA1fHipkXoa0 +CZooyA9BvZDGHaDReCXvqBqWU+oYkY3UO6AnFH4i3hX3YnH2efhh6xs7JAn9lS4g9mq 3xqzuiYZAcmXr7pctBUg/EC2z02EOpMy5qjZWr4ZkvwkN0aLZeph/aLVHA7Nt7pfwNIk YQ1g== 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=0risXC4et4CV9CFO05BQ6tdWwWZMgyIJJYuRzCq1LJM=; b=y+k+vTSRguJ76XGILY/AE4O541OyK+Yn8cGg91geS+fq+esSupfLbdEsPxZynpLwoS i75u536W3MriMTQrqpt/c9FBowFtSqY1uMV6zX+sj9CT/UF78PBZIasOEa+oTJzknkZc HmhSeM04XrWsRnBy0dnIJ6RDbg0VnG9jsuX69+MNbpOSNiyrAl2nxOLoHU/IWdadFbu8 nq06/m9EmOD6FxBI9Gvj80WBfli7MOuTk1ZZaGTwAnooZuuCsjoX5L1Dte+tZ59r88Bb n6FBrx/3xdpkUaL+XdKXPYkIiUviIkWVRBonwhOkDjGSxpY+nI2t2s8SoPl72ikmnfVX OadQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=GBSxoFH1; 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 k4-20020aa788c4000000b004dff0e45b5fsi11086420pff.138.2022.02.28.12.25.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 28 Feb 2022 12:25:33 -0800 (PST) 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=GBSxoFH1; 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 1E7441C1EFD; Mon, 28 Feb 2022 11:42:57 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240497AbiB1RyV (ORCPT + 99 others); Mon, 28 Feb 2022 12:54:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239069AbiB1RvJ (ORCPT ); Mon, 28 Feb 2022 12:51:09 -0500 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97C18A645A; Mon, 28 Feb 2022 09:39:17 -0800 (PST) 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 sin.source.kernel.org (Postfix) with ESMTPS id E6A66CE17AC; Mon, 28 Feb 2022 17:39:15 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D3EF4C340F1; Mon, 28 Feb 2022 17:39:13 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1646069954; bh=W7CMdv5uDv19IYXVsY7pf+BDkj7Ul3n+XTxUNsLiY04=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=GBSxoFH1Yv8JMs2cGJiXizguyaxt2xsooTqAZ8p7iWTe3JEV8qgVdx/F8pACgwyHA U1ae0JdVtN5BoU46YnM2wAETygfg8SLddY/DDPEOhXR86PL/EM6PRB+6Df+4+8Z48Y SLpsOBiWR6n9h0yvVgObwr4Oo4NO7Nr2iUj9kNDY= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Fernando Fernandez Mancera , Florian Westphal , Pablo Neira Ayuso Subject: [PATCH 5.15 072/139] netfilter: nf_tables: fix memory leak during stateful obj update Date: Mon, 28 Feb 2022 18:24:06 +0100 Message-Id: <20220228172355.314943753@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220228172347.614588246@linuxfoundation.org> References: <20220228172347.614588246@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.4 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=unavailable 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: Florian Westphal commit dad3bdeef45f81a6e90204bcc85360bb76eccec7 upstream. stateful objects can be updated from the control plane. The transaction logic allocates a temporary object for this purpose. The ->init function was called for this object, so plain kfree() leaks resources. We must call ->destroy function of the object. nft_obj_destroy does this, but it also decrements the module refcount, but the update path doesn't increment it. To avoid special-casing the update object release, do module_get for the update case too and release it via nft_obj_destroy(). Fixes: d62d0ba97b58 ("netfilter: nf_tables: Introduce stateful object update operation") Cc: Fernando Fernandez Mancera Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso Signed-off-by: Greg Kroah-Hartman --- net/netfilter/nf_tables_api.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -6535,12 +6535,15 @@ static int nf_tables_updobj(const struct { struct nft_object *newobj; struct nft_trans *trans; - int err; + int err = -ENOMEM; + + if (!try_module_get(type->owner)) + return -ENOENT; trans = nft_trans_alloc(ctx, NFT_MSG_NEWOBJ, sizeof(struct nft_trans_obj)); if (!trans) - return -ENOMEM; + goto err_trans; newobj = nft_obj_init(ctx, type, attr); if (IS_ERR(newobj)) { @@ -6557,6 +6560,8 @@ static int nf_tables_updobj(const struct err_free_trans: kfree(trans); +err_trans: + module_put(type->owner); return err; } @@ -8169,7 +8174,7 @@ static void nft_obj_commit_update(struct if (obj->ops->update) obj->ops->update(obj, newobj); - kfree(newobj); + nft_obj_destroy(&trans->ctx, newobj); } static void nft_commit_release(struct nft_trans *trans) @@ -8914,7 +8919,7 @@ static int __nf_tables_abort(struct net break; case NFT_MSG_NEWOBJ: if (nft_trans_obj_update(trans)) { - kfree(nft_trans_obj_newobj(trans)); + nft_obj_destroy(&trans->ctx, nft_trans_obj_newobj(trans)); nft_trans_destroy(trans); } else { trans->ctx.table->use--;