[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <50c583d7-a6f2-450c-bbc9-965f65b91197@embeddedor.com>
Date: Tue, 16 Jan 2024 10:30:53 -0600
From: "Gustavo A. R. Silva" <gustavo@...eddedor.com>
To: Erick Archer <erick.archer@....com>, Peter Zijlstra
<peterz@...radead.org>, Ingo Molnar <mingo@...hat.com>,
Arnaldo Carvalho de Melo <acme@...nel.org>,
Namhyung Kim <namhyung@...nel.org>, Thomas Gleixner <tglx@...utronix.de>,
Borislav Petkov <bp@...en8.de>, Dave Hansen <dave.hansen@...ux.intel.com>,
"Gustavo A. R. Silva" <gustavoars@...nel.org>, x86@...nel.org
Cc: Mark Rutland <mark.rutland@....com>,
Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
Jiri Olsa <jolsa@...nel.org>, Ian Rogers <irogers@...gle.com>,
Adrian Hunter <adrian.hunter@...el.com>, "H. Peter Anvin" <hpa@...or.com>,
linux-perf-users@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-hardening@...r.kernel.org
Subject: Re: [PATCH] perf/x86/amd/uncore: Use kcalloc*() instead of kzalloc*()
On 1/16/24 06:58, Erick Archer wrote:
> As noted in the "Deprecated Interfaces, Language Features, Attributes,
> and Conventions" documentation [1], size calculations (especially
> multiplication) should not be performed in memory allocator (or similar)
> function arguments due to the risk of them overflowing. This could lead
> to values wrapping around and a smaller allocation being made than the
> caller was expecting. Using those allocations could lead to linear
> overflows of heap memory and other misbehaviors.
>
> So, use the purpose specific kcalloc*() function instead of the argument
> size * count in the kzalloc*() function.
>
> [1] https://www.kernel.org/doc/html/next/process/deprecated.html#open-coded-arithmetic-in-allocator-arguments
>
> Link: https://github.com/KSPP/linux/issues/162
> Signed-off-by: Erick Archer <erick.archer@....com>
Reviewed-by: Gustavo A. R. Silva <gustavoars@...nel.org>
Thanks!
--
Gustavo
> ---
> arch/x86/events/amd/uncore.c | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/arch/x86/events/amd/uncore.c b/arch/x86/events/amd/uncore.c
> index 5bf03c575812..9073eb0613cf 100644
> --- a/arch/x86/events/amd/uncore.c
> +++ b/arch/x86/events/amd/uncore.c
> @@ -479,8 +479,8 @@ static int amd_uncore_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
> goto fail;
>
> curr->cpu = cpu;
> - curr->events = kzalloc_node(sizeof(*curr->events) *
> - pmu->num_counters,
> + curr->events = kcalloc_node(pmu->num_counters,
> + sizeof(*curr->events),
> GFP_KERNEL, node);
> if (!curr->events) {
> kfree(curr);
> @@ -928,7 +928,7 @@ int amd_uncore_umc_ctx_init(struct amd_uncore *uncore, unsigned int cpu)
> uncore->num_pmus += group_num_pmus[gid];
> }
>
> - uncore->pmus = kzalloc(sizeof(*uncore->pmus) * uncore->num_pmus,
> + uncore->pmus = kcalloc(uncore->num_pmus, sizeof(*uncore->pmus),
> GFP_KERNEL);
> if (!uncore->pmus) {
> uncore->num_pmus = 0;
> --
> 2.25.1
>
>
Powered by blists - more mailing lists