Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2473265yba; Mon, 15 Apr 2019 12:22:25 -0700 (PDT) X-Google-Smtp-Source: APXvYqxX1St9ZaO6HcNIsacFqlWOyTKs6YqMYukXJ40XQcAKdgQVOg5SPXL+fAKT09pRwKGla+P+ X-Received: by 2002:a63:e051:: with SMTP id n17mr71976541pgj.19.1555356145066; Mon, 15 Apr 2019 12:22:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1555356145; cv=none; d=google.com; s=arc-20160816; b=AjcSQo+2moDNoj/oqFFbBjX8Be2ylElFhvBBL+7uSIbsBBQSejfbnTH6JkYt4PfplO 2czKdHtNtmgNKhx4lTeDQmrhwaeIhwKBKg9/Acqc/IQzqsCfFslWQjKnFdLpFX6cn0fR lvRL0EByh2HmMJkUrdPBsw8JYffJtV+EEQEUdXwjqT1/EW0ecZNk888CZFnxgIrySkPD xFRm8muWIfEJzvnnZ/zbvvdQZqvJT3Kj1GYqGSIU1J9eEa6efQXoptDL1S/QBqTtjML3 Y8DTa/AIjyfr7x0tzWilPbHMbCd4dxtfphygzOovpwOkRnRLcHxOBlKRkTjH6Vj14OTd qDuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=5QcaOKcevLy3dwJtqRDj6q0D8ZRDFiOhUerEG7uxYTo=; b=FcxVIs/X5N6MeDCpJBkebLV1JYQEbfWKIPOpCDACYqJDCjYgbbzsnRTZFqJ3FHkDjB iDHdSA358LY0oA73PrTTJuFexewBu6j73yjJh1+qT/WXWkw2GKtMD5IYWJmnMfC+E2b5 DIjjm/xNF6kxGTca5DJREz1+kjcXy2EW5fkP6v6GM2luveWMhfCBmG8hoUteH0FdckXs KZrp+s4x/H0N5ruj5T8y3hXAKwM/Onz7h0laiSS+dt5KkyUDgOYZAlo6bruID05S72AR JqfkXTIhSW7TQYo+3esQl+EN/oUZd3i04UtC4Uukxdq6h17t8LtMm5Q3eS3AVaNAphf2 3ytw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HgLpohPl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t9si33937710pgp.273.2019.04.15.12.22.09; Mon, 15 Apr 2019 12:22:25 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=HgLpohPl; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731150AbfDOTVA (ORCPT + 99 others); Mon, 15 Apr 2019 15:21:00 -0400 Received: from mail.kernel.org ([198.145.29.99]:45374 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730765AbfDOTJh (ORCPT ); Mon, 15 Apr 2019 15:09:37 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B3333218A1; Mon, 15 Apr 2019 19:09:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1555355377; bh=Px4SXH4Qu7IsscEnsCciKQ9BkMvPTyG3sP1QYiqjNto=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=HgLpohPl1zsV+k3MHzx0n8pzG1f4+O4OKyhHki7G84ZQf9XCrg6x81B9F+7xNEzPN W/iOokA0IdmJyfRs8RpF51k5ThrWZ4ZM3AnwEQsh5ksiKcEeMjM/8SwKWc3I++Gdn3 KzpK9RFrB/njxD+ef8GAqz2IjISevPpMZiZxFTRw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dan Carpenter , Pablo Neira Ayuso , Sasha Levin Subject: [PATCH 5.0 004/117] netfilter: nf_tables: use-after-free in dynamic operations Date: Mon, 15 Apr 2019 20:59:34 +0200 Message-Id: <20190415183745.109568968@linuxfoundation.org> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190415183744.887851196@linuxfoundation.org> References: <20190415183744.887851196@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 3f3a390dbd59d236f62cff8e8b20355ef7069e3d ] Smatch reports: net/netfilter/nf_tables_api.c:2167 nf_tables_expr_destroy() error: dereferencing freed memory 'expr->ops' net/netfilter/nf_tables_api.c 2162 static void nf_tables_expr_destroy(const struct nft_ctx *ctx, 2163 struct nft_expr *expr) 2164 { 2165 if (expr->ops->destroy) 2166 expr->ops->destroy(ctx, expr); ^^^^ --> 2167 module_put(expr->ops->type->owner); ^^^^^^^^^ 2168 } Smatch says there are three functions which free expr->ops. Fixes: b8e204006340 ("netfilter: nft_compat: use .release_ops and remove list of extension") Reported-by: Dan Carpenter Signed-off-by: Pablo Neira Ayuso Signed-off-by: Sasha Levin --- net/netfilter/nf_tables_api.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index dc3670f2860e..f20b904873c6 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -2119,9 +2119,11 @@ static int nf_tables_newexpr(const struct nft_ctx *ctx, static void nf_tables_expr_destroy(const struct nft_ctx *ctx, struct nft_expr *expr) { + const struct nft_expr_type *type = expr->ops->type; + if (expr->ops->destroy) expr->ops->destroy(ctx, expr); - module_put(expr->ops->type->owner); + module_put(type->owner); } struct nft_expr *nft_expr_init(const struct nft_ctx *ctx, -- 2.19.1