From patchwork Sat Sep 16 00:48:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Cengiz Can X-Patchwork-Id: 1835331 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ubuntu.com (client-ip=185.125.189.65; helo=lists.ubuntu.com; envelope-from=kernel-team-bounces@lists.ubuntu.com; receiver=patchwork.ozlabs.org) Received: from lists.ubuntu.com (lists.ubuntu.com [185.125.189.65]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4RnXd34W84z1yhP for ; Sat, 16 Sep 2023 10:54:15 +1000 (AEST) Received: from localhost ([127.0.0.1] helo=lists.ubuntu.com) by lists.ubuntu.com with esmtp (Exim 4.86_2) (envelope-from ) id 1qhJZN-0001yt-Kh; Sat, 16 Sep 2023 00:53:58 +0000 Received: from smtp-relay-internal-0.internal ([10.131.114.225] helo=smtp-relay-internal-0.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1qhJX7-0008Kl-CT for kernel-team@lists.ubuntu.com; Sat, 16 Sep 2023 00:51:40 +0000 Received: from mail-pj1-f72.google.com (mail-pj1-f72.google.com [209.85.216.72]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by smtp-relay-internal-0.canonical.com (Postfix) with ESMTPS id 32F6C3F665 for ; Sat, 16 Sep 2023 00:51:36 +0000 (UTC) Received: by mail-pj1-f72.google.com with SMTP id 98e67ed59e1d1-274bc2cb2dbso215099a91.0 for ; Fri, 15 Sep 2023 17:51:36 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694825494; x=1695430294; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cc0MVukaZr2nDd8c7ssdlT/HglHNvcjIoV2plhgq7Co=; b=kKrmdV8VXlj/HZiF4ov6VDvNzcWL1i1H0XrHYt4rWbg3iFIBTmt1GQ/wC79azCX8zR WYJoTEomg96nX8Zmemk4vC0Qtij3s5NqoE0C6SKs/DyS2e19+0P0nmdYYDJ0+uRXcHbQ hX3OWUalzDXWUah9w0/H4po5Uidu720CFnf1JLWoV6kyACPNqWP5nNH/PA4lkE9XIDx3 Eod2gswMmx18u3o7IuCTOFz+iWHDH7J1J1IQyCfXd0HIYOOHHP+K0krljX4n984Apscx 33RQX8UMWoHVPuGs6drq355pKR1rKq3jRHnQYAYo1jtylkBm69bUQBGc/QX6gowQi2wo WESQ== X-Gm-Message-State: AOJu0YwWrySsDqY8UT+e7QLE8Ahay+eLJnGKYkljeHxhozyb6LgKp/x/ RiZSHaoNdwsGfb2TGFGv1otUqIfdQ4wXQLtnReTFcvqb68hffu/6A43/u4W4xl9qOiZihPS1DeI 0ViPZBR4xeIhsv4ktVYhgPPdo3xNdTFJX8RVOkGvoIQpxd2zqAE7f X-Received: by 2002:a17:90b:1017:b0:26d:3d86:9a8e with SMTP id gm23-20020a17090b101700b0026d3d869a8emr3049795pjb.25.1694825494517; Fri, 15 Sep 2023 17:51:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH39vtw84zKG4Ohb5BjeerHmIh8Kplgo8KJyiRRfLB0ou/wf1ZZVC1ErB7ZFvTY5D6TIIsYJA== X-Received: by 2002:a17:90b:1017:b0:26d:3d86:9a8e with SMTP id gm23-20020a17090b101700b0026d3d869a8emr3049789pjb.25.1694825494223; Fri, 15 Sep 2023 17:51:34 -0700 (PDT) Received: from localhost (uk.sesame.canonical.com. [185.125.190.60]) by smtp.gmail.com with ESMTPSA id 26-20020a17090a019a00b0026fb228fafasm5812792pjc.18.2023.09.15.17.51.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Sep 2023 17:51:33 -0700 (PDT) From: Cengiz Can To: kernel-team@lists.ubuntu.com Subject: [SRU Jammy, OEM-6.0, OEM-6.1, Lunar] netfilter: nf_tables: GC transaction race with netns dismantle Date: Sat, 16 Sep 2023 03:48:35 +0300 Message-Id: <20230916004839.706452-26-cengiz.can@canonical.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230916004839.706452-1-cengiz.can@canonical.com> References: <20230916004839.706452-1-cengiz.can@canonical.com> MIME-Version: 1.0 X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.20 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: "kernel-team" From: Pablo Neira Ayuso Use maybe_get_net() since GC workqueue might race with netns exit path. Fixes: 5f68718b34a5 ("netfilter: nf_tables: GC transaction API to avoid race with control plane") Signed-off-by: Pablo Neira Ayuso Signed-off-by: Florian Westphal (cherry picked from commit 02c6c24402bf1c1e986899c14ba22a10b510916b) CVE-2023-4244 [cengizcan: fixes the fix commit] Signed-off-by: Cengiz Can --- net/netfilter/nf_tables_api.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/net/netfilter/nf_tables_api.c b/net/netfilter/nf_tables_api.c index 0d50c7784ee9..13912f504776 100644 --- a/net/netfilter/nf_tables_api.c +++ b/net/netfilter/nf_tables_api.c @@ -9088,9 +9088,14 @@ struct nft_trans_gc *nft_trans_gc_alloc(struct nft_set *set, if (!trans) return NULL; + trans->net = maybe_get_net(net); + if (!trans->net) { + kfree(trans); + return NULL; + } + refcount_inc(&set->refs); trans->set = set; - trans->net = get_net(net); trans->seq = gc_seq; return trans;