From patchwork Fri Apr 12 18:50:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1923220 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 4VGQc64D9Kz1yYs for ; Sat, 13 Apr 2024 04:50:14 +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 1rvLyT-0007lE-9a; Fri, 12 Apr 2024 18:50:09 +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 1rvLyR-0007jk-QB for kernel-team@lists.ubuntu.com; Fri, 12 Apr 2024 18:50:07 +0000 Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) (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 7509A3F297 for ; Fri, 12 Apr 2024 18:50:07 +0000 (UTC) Received: by mail-il1-f199.google.com with SMTP id e9e14a558f8ab-36660582091so13271395ab.0 for ; Fri, 12 Apr 2024 11:50:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712947806; x=1713552606; 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=mSFOFn4oWJls1aSbC8BvIZDTPJB2kPkvz63Tg7jPZYA=; b=kfN4ZHRVivRSIBrUx8zCEcZ8QkA+UdFaNCu7dM9ej+ePP72Kk7ZKb1taY1qe4QxvbR I3xexbuwdPRjscYqOah7VP4wjlTHRh/rJKAuv1Hzq6NoEmKnniaRJjD+qvgHDBjQ4XZT gjCbOE1ag2O91nQv/dXwlrJTtohJbZ1+eJniky0BXsZQelPRwI8N1LAcyfcx4W44WuEJ PKokmHy5A3dmDL6x/xjjYfVAoDVknBxpwdA1knhEzRbV/Rqg05Mdbyl+gA/5JAcMwPw1 4qnnpXBSJrHf1bLlgqddofYj9GBYCsPVA7ZR51pu2yXG9Zdy5pfmOeZS2gzO7CfX2VtI 60bg== X-Gm-Message-State: AOJu0YwHMxjbN5aSXY+QuIgis2iKRfcGZ9FhmsnD+44LsMfkjnJSUBga zXMg3gehrY/6sX+amzZbBurA6w3YsUaAyLvOlhHhUFCVmW5NaL8XXtrIpEnz6BwfNe/6/aIYwP4 bO5kcXjXFcDyZKJr5yyXVs9rqP/rt2w14xbVkIu7KJYYZ9xL2GlrMBn4YlFnfp0Pz1SCuGnsTzU nPOPxu6JP6yQ== X-Received: by 2002:a05:6e02:1985:b0:36a:2812:f067 with SMTP id g5-20020a056e02198500b0036a2812f067mr4095209ilf.28.1712947806098; Fri, 12 Apr 2024 11:50:06 -0700 (PDT) X-Google-Smtp-Source: AGHT+IF+tELk632ufK05vJ5ezZTGfz5spIGP9tXAEqbQSKIb4u/IYvU3z1HBjrFM+8uULh1e0CEDHw== X-Received: by 2002:a05:6e02:1985:b0:36a:2812:f067 with SMTP id g5-20020a056e02198500b0036a2812f067mr4095195ilf.28.1712947805826; Fri, 12 Apr 2024 11:50:05 -0700 (PDT) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id n16-20020a056638265000b004829fa50273sm1208462jat.161.2024.04.12.11.50.05 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 11:50:05 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][J][PATCH 1/1] netfilter: nft_set_pipapo: release elements in clone only from destroy path Date: Fri, 12 Apr 2024 13:50:00 -0500 Message-Id: <20240412185000.22195-6-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412185000.22195-1-bethany.jamison@canonical.com> References: <20240412185000.22195-1-bethany.jamison@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 Clone already always provides a current view of the lookup table, use it to destroy the set, otherwise it is possible to destroy elements twice. This fix requires: 212ed75dc5fb ("netfilter: nf_tables: integrate pipapo into commit protocol") which came after: 9827a0e6e23b ("netfilter: nft_set_pipapo: release elements in clone from abort path"). Fixes: 9827a0e6e23b ("netfilter: nft_set_pipapo: release elements in clone from abort path") Signed-off-by: Pablo Neira Ayuso (cherry picked from commit b0e256f3dd2ba6532f37c5c22e07cb07a36031ee) CVE-2024-26809 Signed-off-by: Bethany Jamison --- net/netfilter/nft_set_pipapo.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index e1969209b3abb..58eca26162735 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -2240,8 +2240,6 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, if (m) { rcu_barrier(); - nft_set_pipapo_match_destroy(ctx, set, m); - for_each_possible_cpu(cpu) pipapo_free_scratch(m, cpu); free_percpu(m->scratch); @@ -2253,8 +2251,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, if (priv->clone) { m = priv->clone; - if (priv->dirty) - nft_set_pipapo_match_destroy(ctx, set, m); + nft_set_pipapo_match_destroy(ctx, set, m); for_each_possible_cpu(cpu) pipapo_free_scratch(priv->clone, cpu); From patchwork Fri Apr 12 18:49:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1923217 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 4VGQc50sDZz1yYs for ; Sat, 13 Apr 2024 04:50:13 +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 1rvLyR-0007jl-Q7; Fri, 12 Apr 2024 18:50:07 +0000 Received: from smtp-relay-internal-1.internal ([10.131.114.114] helo=smtp-relay-internal-1.canonical.com) by lists.ubuntu.com with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1rvLyP-0007is-OF for kernel-team@lists.ubuntu.com; Fri, 12 Apr 2024 18:50:05 +0000 Received: from mail-il1-f199.google.com (mail-il1-f199.google.com [209.85.166.199]) (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-1.canonical.com (Postfix) with ESMTPS id 9187E3F17B for ; Fri, 12 Apr 2024 18:50:05 +0000 (UTC) Received: by mail-il1-f199.google.com with SMTP id e9e14a558f8ab-36a0b315926so13588805ab.2 for ; Fri, 12 Apr 2024 11:50:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712947804; x=1713552604; 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=Zh0Ujz+ort8ngwiFbYFHN42UTXpR8Ocl4MUg6YovtEk=; b=jpK5zG2qVgMtgW6Efe4nOsOpGZvDjzsJD6JH4ConL7Ne/mGvW98L1SUQWmmRZNKQ/r Mx9EewlUZf9AzLqCefQOHGECjSXAScmcJY0LnuHS8eKKDSJrH0U+uNPPJyHdSriHWhmT CvQNO7lt9ErUy7fV7JxNsfVFsh568MUXO8gvvAbcxs+FPzVjwbgQt2Mp+jtTJ3ZDdamu gviwrizP6pDQshOQ5iBj/0ZKmD8G8CV2AfezpPR0SRu/491a5CqsRPDN6w4XAxY2SeFZ 7cse46dRfH+hz1M++twFhZ9WYLNdTL/1mv4k/T83JYzCvxoMaiTqQJjv40BnRt0Thbfn IomQ== X-Gm-Message-State: AOJu0YzTJe97H7dTjyr20SMKtUSqzWVmnH6AioqPkRioBD/vpu6Yttd/ /oQ1ALTpJepNur4eJeNwlenbvTF5PjamhiL82PhgppmXlbV67tgn4JHUIbzenITQKzH1rwoV443 r7jQefRo3OyKO/TvxVUaO7ItapXoE4/4DAZZ7aRvpJcTqV5LY58ymnwIaT1Ai8xtqjBQtdiIwi/ vojSTCpKidsA== X-Received: by 2002:a05:6e02:168a:b0:36a:29dc:37ea with SMTP id f10-20020a056e02168a00b0036a29dc37eamr4429580ila.32.1712947804295; Fri, 12 Apr 2024 11:50:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH95JM8N+nesuohgnUQyO/gq4iui9IDvwbBI2fB/a63085equOLkzmb+Zx0Sz5duw6hGbk6CA== X-Received: by 2002:a05:6e02:168a:b0:36a:29dc:37ea with SMTP id f10-20020a056e02168a00b0036a29dc37eamr4429567ila.32.1712947804031; Fri, 12 Apr 2024 11:50:04 -0700 (PDT) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id n16-20020a056638265000b004829fa50273sm1208462jat.161.2024.04.12.11.50.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 11:50:03 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH 2/4] netfilter: nft_set_pipapo: add helper to release pcpu scratch area Date: Fri, 12 Apr 2024 13:49:57 -0500 Message-Id: <20240412185000.22195-3-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412185000.22195-1-bethany.jamison@canonical.com> References: <20240412185000.22195-1-bethany.jamison@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: Florian Westphal After next patch simple kfree() is not enough anymore, so add a helper for it. Reviewed-by: Stefano Brivio Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso (cherry picked from commit 47b1c03c3c1a119435480a1e73f27197dc59131d) CVE-2024-26809 Signed-off-by: Bethany Jamison --- net/netfilter/nft_set_pipapo.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index 58e595a84cd08..b6bca59b7ba66 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -1101,6 +1101,24 @@ static void pipapo_map(struct nft_pipapo_match *m, f->mt[map[i].to + j].e = e; } +/** + * pipapo_free_scratch() - Free per-CPU map at original (not aligned) address + * @m: Matching data + * @cpu: CPU number + */ +static void pipapo_free_scratch(const struct nft_pipapo_match *m, unsigned int cpu) +{ + struct nft_pipapo_scratch *s; + void *mem; + + s = *per_cpu_ptr(m->scratch, cpu); + if (!s) + return; + + mem = s; + kfree(mem); +} + /** * pipapo_realloc_scratch() - Reallocate scratch maps for partial match results * @clone: Copy of matching data with pending insertions and deletions @@ -1133,7 +1151,7 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone, return -ENOMEM; } - kfree(*per_cpu_ptr(clone->scratch, i)); + pipapo_free_scratch(clone, i); *per_cpu_ptr(clone->scratch, i) = scratch; @@ -1358,7 +1376,7 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old) } out_scratch_realloc: for_each_possible_cpu(i) - kfree(*per_cpu_ptr(new->scratch, i)); + pipapo_free_scratch(new, i); #ifdef NFT_PIPAPO_ALIGN free_percpu(new->scratch_aligned); #endif @@ -1646,7 +1664,7 @@ static void pipapo_free_match(struct nft_pipapo_match *m) int i; for_each_possible_cpu(i) - kfree(*per_cpu_ptr(m->scratch, i)); + pipapo_free_scratch(m, i); #ifdef NFT_PIPAPO_ALIGN free_percpu(m->scratch_aligned); @@ -2247,7 +2265,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, free_percpu(m->scratch_aligned); #endif for_each_possible_cpu(cpu) - kfree(*per_cpu_ptr(m->scratch, cpu)); + pipapo_free_scratch(m, cpu); free_percpu(m->scratch); pipapo_free_fields(m); kfree(m); @@ -2264,7 +2282,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, free_percpu(priv->clone->scratch_aligned); #endif for_each_possible_cpu(cpu) - kfree(*per_cpu_ptr(priv->clone->scratch, cpu)); + pipapo_free_scratch(priv->clone, cpu); free_percpu(priv->clone->scratch); pipapo_free_fields(priv->clone); From patchwork Fri Apr 12 18:49:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1923219 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 4VGQc60cyxz1yYP for ; Sat, 13 Apr 2024 04:50:13 +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 1rvLyT-0007ko-2Z; Fri, 12 Apr 2024 18:50:09 +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 1rvLyR-0007iz-3b for kernel-team@lists.ubuntu.com; Fri, 12 Apr 2024 18:50:07 +0000 Received: from mail-io1-f72.google.com (mail-io1-f72.google.com [209.85.166.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 5F6283F297 for ; Fri, 12 Apr 2024 18:50:06 +0000 (UTC) Received: by mail-io1-f72.google.com with SMTP id ca18e2360f4ac-7c7e21711d0so94894539f.3 for ; Fri, 12 Apr 2024 11:50:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712947805; x=1713552605; 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=YSazrFi9oEIfFcO73KIjytcGinFBM2K0AaAWAui6GUs=; b=G9ScN3+L3sfFSNMa7IdAHcNybaT7WUEhS9sV4fWWBai73WY0PiOeDIHHPnaMvQ8D3A ZhxB3HrSLsSGEamZG/ACCLBBf26N08uqpL9WIQ0yBDP+ZpUyg5uOEbXkJQkQejeIOAhO G/jSxe0cZnn3+74B9Q9vUoslqGzUaWYz42RO6WifjmIdYdGL3Nv8JXqh4+FIts4FlKPo UwJ1nmKYw838rqNvQKjXVCsQLQH0hinrAeDiC5ewwq2+jME+51vUTWAGoM30H2aiSPXP 76KBOhx0kIoMywZos8PGsX2O0pU7alHBGdCWn6wQ923igbxz7TMbGGJDrSADN+py7sqG IpIg== X-Gm-Message-State: AOJu0Yy4AJ6zaE1GGA9T+ZoIytNu7UI94ccLAb/WH/44tWjS3tjpcAKk y8aJZJMdME9ridcfO4wfdBbNIHhJJg999TIvAhQbSJmSOiHDPwBcxf/EXJz7hsYyw1n3RKJgi9m aDyKhnW0Ka9SLnHFR6CuZMmzmHTjgYgCCXLacv2iY5NdjNzI5flJD9kubnMMyMhyrTbFWaqXTM8 SNWYsYY6KEqg== X-Received: by 2002:a92:cd84:0:b0:368:a724:f757 with SMTP id r4-20020a92cd84000000b00368a724f757mr3756537ilb.6.1712947804925; Fri, 12 Apr 2024 11:50:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEDNYMOmP59pCfqUzdHF0ki1kFJDSum52sQRI4KKtgntAuYhwCK0mDI/gleq/5pDqcor7LXPg== X-Received: by 2002:a92:cd84:0:b0:368:a724:f757 with SMTP id r4-20020a92cd84000000b00368a724f757mr3756515ilb.6.1712947804576; Fri, 12 Apr 2024 11:50:04 -0700 (PDT) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id n16-20020a056638265000b004829fa50273sm1208462jat.161.2024.04.12.11.50.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 11:50:04 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH 3/4] netfilter: nft_set_pipapo: remove scratch_aligned pointer Date: Fri, 12 Apr 2024 13:49:58 -0500 Message-Id: <20240412185000.22195-4-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412185000.22195-1-bethany.jamison@canonical.com> References: <20240412185000.22195-1-bethany.jamison@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: Florian Westphal use ->scratch for both avx2 and the generic implementation. After previous change the scratch->map member is always aligned properly for AVX2, so we can just use scratch->map in AVX2 too. The alignoff delta is stored in the scratchpad so we can reconstruct the correct address to free the area again. Fixes: 7400b063969b ("nft_set_pipapo: Introduce AVX2-based lookup implementation") Reviewed-by: Stefano Brivio Signed-off-by: Florian Westphal Signed-off-by: Pablo Neira Ayuso (cherry picked from commit 5a8cdf6fd860ac5e6d08d72edbcecee049a7fec4) CVE-2024-25809 Signed-off-by: Bethany Jamison --- net/netfilter/nft_set_pipapo.c | 41 +++++------------------------ net/netfilter/nft_set_pipapo.h | 6 ++--- net/netfilter/nft_set_pipapo_avx2.c | 2 +- 3 files changed, 10 insertions(+), 39 deletions(-) diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index b6bca59b7ba66..8e9b200779666 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -1116,6 +1116,7 @@ static void pipapo_free_scratch(const struct nft_pipapo_match *m, unsigned int c return; mem = s; + mem -= s->align_off; kfree(mem); } @@ -1135,6 +1136,7 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone, struct nft_pipapo_scratch *scratch; #ifdef NFT_PIPAPO_ALIGN void *scratch_aligned; + u32 align_off; #endif scratch = kzalloc_node(struct_size(scratch, map, bsize_max * 2) + @@ -1153,8 +1155,6 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone, pipapo_free_scratch(clone, i); - *per_cpu_ptr(clone->scratch, i) = scratch; - #ifdef NFT_PIPAPO_ALIGN /* Align &scratch->map (not the struct itself): the extra * %NFT_PIPAPO_ALIGN_HEADROOM bytes passed to kzalloc_node() @@ -1166,8 +1166,12 @@ static int pipapo_realloc_scratch(struct nft_pipapo_match *clone, scratch_aligned = NFT_PIPAPO_LT_ALIGN(&scratch->map); scratch_aligned -= offsetof(struct nft_pipapo_scratch, map); - *per_cpu_ptr(clone->scratch_aligned, i) = scratch_aligned; + align_off = scratch_aligned - (void *)scratch; + + scratch = scratch_aligned; + scratch->align_off = align_off; #endif + *per_cpu_ptr(clone->scratch, i) = scratch; } return 0; @@ -1320,11 +1324,6 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old) if (!new->scratch) goto out_scratch; -#ifdef NFT_PIPAPO_ALIGN - new->scratch_aligned = alloc_percpu(*new->scratch_aligned); - if (!new->scratch_aligned) - goto out_scratch; -#endif for_each_possible_cpu(i) *per_cpu_ptr(new->scratch, i) = NULL; @@ -1377,9 +1376,6 @@ static struct nft_pipapo_match *pipapo_clone(struct nft_pipapo_match *old) out_scratch_realloc: for_each_possible_cpu(i) pipapo_free_scratch(new, i); -#ifdef NFT_PIPAPO_ALIGN - free_percpu(new->scratch_aligned); -#endif out_scratch: free_percpu(new->scratch); kfree(new); @@ -1666,11 +1662,7 @@ static void pipapo_free_match(struct nft_pipapo_match *m) for_each_possible_cpu(i) pipapo_free_scratch(m, i); -#ifdef NFT_PIPAPO_ALIGN - free_percpu(m->scratch_aligned); -#endif free_percpu(m->scratch); - pipapo_free_fields(m); kfree(m); @@ -2165,16 +2157,6 @@ static int nft_pipapo_init(const struct nft_set *set, for_each_possible_cpu(i) *per_cpu_ptr(m->scratch, i) = NULL; -#ifdef NFT_PIPAPO_ALIGN - m->scratch_aligned = alloc_percpu(struct nft_pipapo_scratch *); - if (!m->scratch_aligned) { - err = -ENOMEM; - goto out_free; - } - for_each_possible_cpu(i) - *per_cpu_ptr(m->scratch_aligned, i) = NULL; -#endif - rcu_head_init(&m->rcu); nft_pipapo_for_each_field(f, i, m) { @@ -2205,9 +2187,6 @@ static int nft_pipapo_init(const struct nft_set *set, return 0; out_free: -#ifdef NFT_PIPAPO_ALIGN - free_percpu(m->scratch_aligned); -#endif free_percpu(m->scratch); out_scratch: kfree(m); @@ -2261,9 +2240,6 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, nft_set_pipapo_match_destroy(ctx, set, m); -#ifdef NFT_PIPAPO_ALIGN - free_percpu(m->scratch_aligned); -#endif for_each_possible_cpu(cpu) pipapo_free_scratch(m, cpu); free_percpu(m->scratch); @@ -2278,9 +2254,6 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, if (priv->dirty) nft_set_pipapo_match_destroy(ctx, set, m); -#ifdef NFT_PIPAPO_ALIGN - free_percpu(priv->clone->scratch_aligned); -#endif for_each_possible_cpu(cpu) pipapo_free_scratch(priv->clone, cpu); free_percpu(priv->clone->scratch); diff --git a/net/netfilter/nft_set_pipapo.h b/net/netfilter/nft_set_pipapo.h index de96e1a01dc0b..30a3d092cd841 100644 --- a/net/netfilter/nft_set_pipapo.h +++ b/net/netfilter/nft_set_pipapo.h @@ -133,10 +133,12 @@ struct nft_pipapo_field { /** * struct nft_pipapo_scratch - percpu data used for lookup and matching * @map_index: Current working bitmap index, toggled between field matches + * @align_off: Offset to get the originally allocated address * @map: store partial matching results during lookup */ struct nft_pipapo_scratch { u8 map_index; + u32 align_off; unsigned long map[]; }; @@ -144,16 +146,12 @@ struct nft_pipapo_scratch { * struct nft_pipapo_match - Data used for lookup and matching * @field_count Amount of fields in set * @scratch: Preallocated per-CPU maps for partial matching results - * @scratch_aligned: Version of @scratch aligned to NFT_PIPAPO_ALIGN bytes * @bsize_max: Maximum lookup table bucket size of all fields, in longs * @rcu Matching data is swapped on commits * @f: Fields, with lookup and mapping tables */ struct nft_pipapo_match { int field_count; -#ifdef NFT_PIPAPO_ALIGN - struct nft_pipapo_scratch * __percpu *scratch_aligned; -#endif struct nft_pipapo_scratch * __percpu *scratch; size_t bsize_max; struct rcu_head rcu; diff --git a/net/netfilter/nft_set_pipapo_avx2.c b/net/netfilter/nft_set_pipapo_avx2.c index 78213c73af2e2..90e275bb3e5d7 100644 --- a/net/netfilter/nft_set_pipapo_avx2.c +++ b/net/netfilter/nft_set_pipapo_avx2.c @@ -1139,7 +1139,7 @@ bool nft_pipapo_avx2_lookup(const struct net *net, const struct nft_set *set, */ kernel_fpu_begin_mask(0); - scratch = *raw_cpu_ptr(m->scratch_aligned); + scratch = *raw_cpu_ptr(m->scratch); if (unlikely(!scratch)) { kernel_fpu_end(); return false; From patchwork Fri Apr 12 18:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bethany Jamison X-Patchwork-Id: 1923222 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 4VGQcD2BB0z1yYP for ; Sat, 13 Apr 2024 04:50:20 +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 1rvLyZ-0007v5-J3; Fri, 12 Apr 2024 18:50:15 +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 1rvLyR-0007jH-5Z for kernel-team@lists.ubuntu.com; Fri, 12 Apr 2024 18:50:07 +0000 Received: from mail-il1-f198.google.com (mail-il1-f198.google.com [209.85.166.198]) (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 C7000411DF for ; Fri, 12 Apr 2024 18:50:06 +0000 (UTC) Received: by mail-il1-f198.google.com with SMTP id e9e14a558f8ab-3689678c5efso13112095ab.1 for ; Fri, 12 Apr 2024 11:50:06 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712947805; x=1713552605; 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=3VPLNdVTYVSeFdpyh5U9yGiZo/YAgWRNVa+IFvGGA0E=; b=dIqNe829avQQICp8bz21YRMYgwxJPGhkytTLAjvqD5Mb+NYVSQtjLQzVlEecvqAriD LLPkaKqJmSEcckKxmllLWcwoYqgbMYitMU/aydUdxl7Wur46kSoArM2TT0idvFAT9aIF fwSfBqmgGgoHeznaNazTbKwbxAtj7tQIH6vc3t+xUuZ+1YufsdLiOse8cprSyh6iotl9 dY27RL02U3Ou77dFG8l/yES8dYJR8+szt5dygHZhsWGK1/4YPtvormBuhidrLv7ulVxh UG1rG7Z0AOxE9C7eUJg6DSiiIkvEgcXAw34h0bdbK7sLQlsPB4QIyX99AphyN+lPFBFa scaQ== X-Gm-Message-State: AOJu0YyUa5+LON4mY6UbAAsnzEvd/VfJeG8w7vY00xVdMrvYU9gZub9L ge2jSkmkbiemwjfrtyEQnazarwWNYuOccPCDTrR/QTedbZcRK0bsHgozO5kees5hoxyBCRhPzha fuDW06021CTvLXaX4MFrh25UWhd48M0nbeKfzfK/1KYd+QPD64xfyJYs2SxavqdAMK+gtPInmh4 ZuXzSlkYH4pA== X-Received: by 2002:a05:6e02:154c:b0:36a:1e55:535b with SMTP id j12-20020a056e02154c00b0036a1e55535bmr3894776ilu.16.1712947805505; Fri, 12 Apr 2024 11:50:05 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFfNpzu11vYmXLfS0ZbTH+yQG2cDnFIZOv6WFIM4+kTVGDDUHmmkpFLk+x5K0o5oCq+BKKUqw== X-Received: by 2002:a05:6e02:154c:b0:36a:1e55:535b with SMTP id j12-20020a056e02154c00b0036a1e55535bmr3894768ilu.16.1712947805220; Fri, 12 Apr 2024 11:50:05 -0700 (PDT) Received: from smtp.gmail.com (104-218-69-129.dynamic.lnk.ne.allofiber.net. [104.218.69.129]) by smtp.gmail.com with ESMTPSA id n16-20020a056638265000b004829fa50273sm1208462jat.161.2024.04.12.11.50.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 11:50:04 -0700 (PDT) From: Bethany Jamison To: kernel-team@lists.ubuntu.com Subject: [SRU][M][PATCH 4/4] netfilter: nft_set_pipapo: release elements in clone only from destroy path Date: Fri, 12 Apr 2024 13:49:59 -0500 Message-Id: <20240412185000.22195-5-bethany.jamison@canonical.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240412185000.22195-1-bethany.jamison@canonical.com> References: <20240412185000.22195-1-bethany.jamison@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 Clone already always provides a current view of the lookup table, use it to destroy the set, otherwise it is possible to destroy elements twice. This fix requires: 212ed75dc5fb ("netfilter: nf_tables: integrate pipapo into commit protocol") which came after: 9827a0e6e23b ("netfilter: nft_set_pipapo: release elements in clone from abort path"). Fixes: 9827a0e6e23b ("netfilter: nft_set_pipapo: release elements in clone from abort path") Signed-off-by: Pablo Neira Ayuso (cherry picked from commit b0e256f3dd2ba6532f37c5c22e07cb07a36031ee) CVE-2024-26809 Signed-off-by: Bethany Jamison --- net/netfilter/nft_set_pipapo.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/net/netfilter/nft_set_pipapo.c b/net/netfilter/nft_set_pipapo.c index 8e9b200779666..a890aa0abad58 100644 --- a/net/netfilter/nft_set_pipapo.c +++ b/net/netfilter/nft_set_pipapo.c @@ -2238,8 +2238,6 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, if (m) { rcu_barrier(); - nft_set_pipapo_match_destroy(ctx, set, m); - for_each_possible_cpu(cpu) pipapo_free_scratch(m, cpu); free_percpu(m->scratch); @@ -2251,8 +2249,7 @@ static void nft_pipapo_destroy(const struct nft_ctx *ctx, if (priv->clone) { m = priv->clone; - if (priv->dirty) - nft_set_pipapo_match_destroy(ctx, set, m); + nft_set_pipapo_match_destroy(ctx, set, m); for_each_possible_cpu(cpu) pipapo_free_scratch(priv->clone, cpu);