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 90783C433EF for ; Tue, 7 Jun 2022 09:55:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229974AbiFGJzZ (ORCPT ); Tue, 7 Jun 2022 05:55:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233223AbiFGJxT (ORCPT ); Tue, 7 Jun 2022 05:53:19 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 37952443C2; Tue, 7 Jun 2022 02:53:18 -0700 (PDT) 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 ams.source.kernel.org (Postfix) with ESMTPS id D4275B81E7A; Tue, 7 Jun 2022 09:53:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 20CFFC385A5; Tue, 7 Jun 2022 09:53:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654595595; bh=rJi6JVdPD/Vt/We2v1o6pGUM/NCh4V1zqrJdX8XVc70=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=e0wyeJe4RRlXeal6Z+sLvUSf07W46/lpY6YL0a8z4AiDNG4AmZk72dxRJO5pXe/nH rcokZ7hkDqXoV8wvVobZNFkL+0PDaWy/E63G54sg5t3Oe8gDxuK6GdR797fW1f6q7A nHZfl7A88UZu+l/wLic1uX2Eh7/kX5snYFBNc6Wo= Date: Tue, 7 Jun 2022 11:53:09 +0200 From: Greg KH To: Ajay Kaher Cc: stable@vger.kernel.org, pablo@netfilter.org, kadlec@netfilter.org, fw@strlen.de, davem@davemloft.net, netfilter-devel@vger.kernel.org, srivatsab@vmware.com, srivatsa@csail.mit.edu, amakhalov@vmware.com, anishs@vmware.com, vsirnapalli@vmware.com, er.ajay.kaher@gmail.com Subject: Re: [PATCH v4.9.y] netfilter: nf_tables: disallow non-stateful expression in sets earlier Message-ID: References: <1654575921-2590-1-git-send-email-akaher@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1654575921-2590-1-git-send-email-akaher@vmware.com> Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org On Tue, Jun 07, 2022 at 09:55:21AM +0530, Ajay Kaher wrote: > From: Pablo Neira Ayuso > > commit 520778042ccca019f3ffa136dd0ca565c486cedd upstream. > > Since 3e135cd499bf ("netfilter: nft_dynset: dynamic stateful expression > instantiation"), it is possible to attach stateful expressions to set > elements. > > cd5125d8f518 ("netfilter: nf_tables: split set destruction in deactivate > and destroy phase") introduces conditional destruction on the object to > accomodate transaction semantics. > > nft_expr_init() calls expr->ops->init() first, then check for > NFT_STATEFUL_EXPR, this stills allows to initialize a non-stateful > lookup expressions which points to a set, which might lead to UAF since > the set is not properly detached from the set->binding for this case. > Anyway, this combination is non-sense from nf_tables perspective. > > This patch fixes this problem by checking for NFT_STATEFUL_EXPR before > expr->ops->init() is called. > > The reporter provides a KASAN splat and a poc reproducer (similar to > those autogenerated by syzbot to report use-after-free errors). It is > unknown to me if they are using syzbot or if they use similar automated > tool to locate the bug that they are reporting. > > For the record, this is the KASAN splat. > > [ 85.431824] ================================================================== > [ 85.432901] BUG: KASAN: use-after-free in nf_tables_bind_set+0x81b/0xa20 > [ 85.433825] Write of size 8 at addr ffff8880286f0e98 by task poc/776 > [ 85.434756] > [ 85.434999] CPU: 1 PID: 776 Comm: poc Tainted: G W 5.18.0+ #2 > [ 85.436023] Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014 > > Fixes: 0b2d8a7b638b ("netfilter: nf_tables: add helper functions for expression handling") > Reported-and-tested-by: Aaron Adams > Signed-off-by: Pablo Neira Ayuso > [Ajay: Regenerated the patch for v4.9.y] > Signed-off-by: Ajay Kaher Both now queued up, thanks. greg k-h