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);