BPF List
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Hui Zhu" <hui.zhu@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v6 2/2] selftests/bpf: Add memcg async reclaim test
Date: Tue, 01 Sep 2026 02:33:13 +0000	[thread overview]
Message-ID: <20260901023314.08F361F000E9@smtp.kernel.org> (raw)
In-Reply-To: <abe85ccba1c3e658d4f8dc25ef958214abaf362c.1788228773.git.zhuhui@kylinos.cn>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] Insecure temporary file creation using mkstemp() followed by close() and reopening by name.
--

commit 6ab0cdc46bdb6e587b82be1eda75b832722b30af
Author: Hui Zhu <zhuhui@kylinos.cn>
selftests/bpf: Add memcg async reclaim test

This commit adds the memcg_async_reclaim selftest. It verifies that
BPF-driven async proactive reclaim mitigates refault-induced slowdown
under memory pressure using the bpf_wq and bpf_proactive_reclaim() APIs.

> diff --git a/tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c b/tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c
> new file mode 100644
> index 0000000000000..1270d73c9116e
> --- /dev/null
> +++ b/tools/testing/selftests/bpf/prog_tests/memcg_async_reclaim.c
[ ... ]
> @@ -0,0 +1,480 @@
[ ... ]
> +static int write_file(const char *filename)
> +{
> +	int ret = -1;
> +	size_t written = 0;
> +	char *buffer;
> +	FILE *fp;
> +
> +	fp = fopen(filename, "wb");

[Severity: Medium]
Does this code reopen a securely created temporary file by name? 

The file descriptor from mkstemp() was closed earlier, which can create a
Time-of-Check to Time-of-Use (TOCTOU) race condition. If an attacker replaces
the file with a symlink during this window, it could lead to unintended file
truncation or writes.

[ ... ]
> +static int real_test_child_work(const char *cgroup_path, char *data_filename,
> +				char *time_filename, int read_times)
> +{
[ ... ]
> +	printf("%.6f\n", elapsed);
> +
> +	fp = fopen(time_filename, "w");

[Severity: Medium]
Similarly, could opening this time file by name present a symlink truncation
risk?

[ ... ]
> +static int
> +run_high_low_workload(double *high_elapsed, double *low_elapsed, int read_times)
> +{
[ ... ]
> +	snprintf(high_time_file, sizeof(high_time_file),
> +		 "%s/memcg_async_high_time_XXXXXX", dir);
> +	snprintf(low_time_file, sizeof(low_time_file),
> +		 "%s/memcg_async_low_time_XXXXXX", dir);
> +
> +	fd = mkstemp(high_data_file);
> +	if (!ASSERT_GE(fd, 0, "mkstemp"))
> +		goto cleanup;
> +	close(fd);

[Severity: Medium]
Closing the file descriptor returned by mkstemp() here discards the security
guarantees it provides, opening the race window.

Could the test be refactored to pass the open file descriptor instead of
relying on the filename string? This same pattern appears to be repeated for
all four temporary files created in this function.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1788228773.git.zhuhui@kylinos.cn?part=2

      reply	other threads:[~2026-09-01  2:33 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-01  2:21 [PATCH bpf-next v6 0/2] bpf: BPF-driven proactive memcg reclaim Hui Zhu
2026-09-01  2:21 ` [PATCH bpf-next v6 1/2] mm/bpf: Add bpf_proactive_reclaim kfunc Hui Zhu
2026-09-01 18:19   ` JP Kobryn
2026-09-02  6:57     ` Hui Zhu
2026-09-02 18:14       ` JP Kobryn
2026-09-01  2:21 ` [PATCH bpf-next v6 2/2] selftests/bpf: Add memcg async reclaim test Hui Zhu
2026-09-01  2:33   ` sashiko-bot [this message]

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=20260901023314.08F361F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=hui.zhu@linux.dev \
    --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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox