All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Emil Tsalapatis" <emil@etsalapatis.com>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH 4/6] selftests/bpf: libarena: Add calloc() call
Date: Mon, 17 Aug 2026 19:23:51 +0000	[thread overview]
Message-ID: <20260817192351.8E5C81F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260817191616.11071-5-emil@etsalapatis.com>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] arena_calloc() can silently return partially uninitialized memory for large allocations due to early termination of arena_memset().
--

--- Patch [4]: [PATCH 4/6] selftests/bpf: libarena: Add calloc() call ---
commit 6f83c4438650c93f36d2b3ed9f3991f97c46a580
Author: Emil Tsalapatis <emil@etsalapatis.com>

selftests/bpf: libarena: Add calloc() call

This commit adds a calloc() operation to the arena memory allocator. It
provides zero-initialization for the allocated memory using a naive
memset implementation.

> diff --git a/tools/testing/selftests/bpf/libarena/include/libarena/common.h b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
> --- a/tools/testing/selftests/bpf/libarena/include/libarena/common.h
> +++ b/tools/testing/selftests/bpf/libarena/include/libarena/common.h
> @@ -61,6 +62,23 @@ void arena_free(void __arena *ptr);
>   */
>  #define arena_subprog_init() do { asm volatile ("" :: "r"(&arena)); } while (0)
>  
> +/*
> + * BPF does not currently support the memset intrinsics. for large
> + * sequential copies, or assignments of large data structures,
> + * the frontend will generate an intrinsic that causes the BPF
> + * backend to exit due to a missing implementation. Provide
> + * implementations for the intrinsic.
> + */
> +static inline int arena_memset(s8 __arena *dst, s8 val, size_t size)
> +{
> +	size_t i;
> +
> +	for (i = zero; i < size && can_loop; i++)
> +		dst[i] = val;
> +
> +	return 0;
> +}

[Severity: Medium]
If the loop terminates early because the instruction limit is reached when
can_loop evaluates to false, will this function return 0 without indicating
to the caller that the memory was only partially written?

[ ... ]

> diff --git a/tools/testing/selftests/bpf/libarena/src/common.bpf.c b/tools/testing/selftests/bpf/libarena/src/common.bpf.c
> --- a/tools/testing/selftests/bpf/libarena/src/common.bpf.c
> +++ b/tools/testing/selftests/bpf/libarena/src/common.bpf.c

[ ... ]

> +__weak void __arena *arena_calloc(size_t ncount, size_t size)
> +{
> +	void __arena *mem;
> +	size_t total;
> +
> +	/*
> +	 * Ideally we'd be using __builtin_mul_overflow here,
> +	 * but the BPF compiler backend doesn't implement __multi3.
> +	 * There are ways to optimize the division away from the
> +	 * overflow check, but any costs are dwarfed by the
> +	 * buddy_alloc() call. Keep it simple for now.
> +	 */
> +	if (unlikely(ncount && size >= ULLONG_MAX / ncount))
> +		return NULL;
> +
> +	total = ncount * size;
> +
> +	mem = buddy_alloc(&buddy, total);
> +	if (likely(mem))
> +		arena_memset(mem, 0, total);
> +
> +	return mem;
> +}

[Severity: Medium]
Because arena_memset() always returns 0 even on early termination, could
arena_calloc() silently return a partially uninitialized buffer for large
allocations where the loop budget is exhausted?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260817191616.11071-1-emil@etsalapatis.com?part=4

  reply	other threads:[~2026-08-17 19:23 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-08-17 19:16 [PATCH 0/6] selftests/bpf: Fixes and improvements for libarena Emil Tsalapatis
2026-08-17 19:16 ` [PATCH 1/6] selftests/bpf: libarena: Normalize SPDX headers across files Emil Tsalapatis
2026-08-17 19:21   ` sashiko-bot
2026-08-17 19:16 ` [PATCH 2/6] selftests/bpf: libarena: Inline nonatomic bitmap operations Emil Tsalapatis
2026-08-17 19:26   ` sashiko-bot
2026-08-17 20:25   ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 3/6] selftests/bpf: libarena: Disable IRQs during allocation Emil Tsalapatis
2026-08-17 19:28   ` sashiko-bot
2026-08-17 20:38   ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 4/6] selftests/bpf: libarena: Add calloc() call Emil Tsalapatis
2026-08-17 19:23   ` sashiko-bot [this message]
2026-08-17 20:25   ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 5/6] selftests/bpf: libarena: Add a benchmark for malloc()/calloc() Emil Tsalapatis
2026-08-17 19:31   ` sashiko-bot
2026-08-17 20:25   ` bot+bpf-ci
2026-08-17 19:16 ` [PATCH 6/6] selftests/bpf: libarena: Optimize and make public arena_memset Emil Tsalapatis
2026-08-17 20:25   ` bot+bpf-ci

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260817192351.8E5C81F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=emil@etsalapatis.com \
    --cc=sashiko-reviews@lists.linux.dev \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.