All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Leon Hwang" <leon.hwang@linux.dev>
Cc: bpf@vger.kernel.org
Subject: Re: [PATCH bpf-next v13 6/8] bpf: Add syscall common attributes support for map_create
Date: Tue, 12 May 2026 23:36:58 +0000	[thread overview]
Message-ID: <20260512233658.CEED7C2BCB0@smtp.kernel.org> (raw)
In-Reply-To: <20260511152817.89191-7-leon.hwang@linux.dev>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Critical] Calling `close_fd()` on a published file descriptor introduces a critical race condition (File Descriptor Hijacking).
--

commit e059afefe67c83f634eb8a27db293cda839d9654
Author: Leon Hwang <leon.hwang@linux.dev>
bpf: Add syscall common attributes support for map_create

This commit introduces common attributes support and verifier logging to
the map creation process. It refactors the map creation logic to allow
reporting map-creation failure reasons back to userspace.

> diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c
> index 2fa05ba8f1619..54b43e16848a9 100644
> --- a/kernel/bpf/syscall.c
> +++ b/kernel/bpf/syscall.c

[ ... ]

> @@ -1611,6 +1632,31 @@ static int map_create(union bpf_attr *attr, bpfptr_t uattr)
>  	return err;
>  }
>  
> +static int map_create(union bpf_attr *attr, bpfptr_t uattr, struct bpf_common_attr *attr_common,
> +		      bpfptr_t uattr_common, u32 size_common)
> +{
> +	struct bpf_verifier_log *log;
> +	struct bpf_log_attr attr_log;
> +	int err, ret;
> +
> +	log = bpf_log_attr_create_vlog(&attr_log, attr_common, uattr_common, size_common);
> +	if (IS_ERR(log))
> +		return PTR_ERR(log);
> +
> +	err = __map_create(attr, uattr, log);
> +
> +	ret = bpf_log_attr_finalize(&attr_log, log);
> +	if (ret) {
> +		if (err >= 0)
> +			close_fd(err);

Is it safe to call close_fd() here? Since __map_create() uses
bpf_map_new_fd() to allocate and publish the file descriptor via
fd_install(), the file descriptor is already visible to userspace.

Could this introduce a regression where a concurrent thread closes this
file descriptor and opens a new, unrelated file that receives the exact
same fd number? If that happens, it seems this close_fd() might
inadvertently close the unrelated file.

Additionally, since the map is published globally via its ID before fd
installation in bpf_map_alloc_id(), could another thread acquire a
reference to the map before this error path? It looks like the map might
remain alive and accessible even though the syscall returns a failure.

> +		err = ret;
> +	}
> +
> +free:
> +	kfree(log);
> +	return err;
> +}

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260511152817.89191-1-leon.hwang@linux.dev?part=6

  parent reply	other threads:[~2026-05-12 23:36 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-11 15:28 [PATCH bpf-next v13 0/8] bpf: Extend BPF syscall with common attributes support Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 1/8] " Leon Hwang
2026-05-11 16:19   ` bot+bpf-ci
2026-05-11 16:53     ` Alexei Starovoitov
2026-05-12  2:41       ` Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 2/8] libbpf: Add support for extended BPF syscall Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 3/8] bpf: Refactor reporting log_true_size for prog_load Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 4/8] bpf: Add syscall common attributes support " Leon Hwang
2026-05-12 22:18   ` sashiko-bot
2026-05-13 10:44     ` Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 5/8] bpf: Add syscall common attributes support for btf_load Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 6/8] bpf: Add syscall common attributes support for map_create Leon Hwang
2026-05-11 16:19   ` bot+bpf-ci
2026-05-11 17:07     ` Alexei Starovoitov
2026-05-12  2:47       ` Leon Hwang
2026-05-12 23:36   ` sashiko-bot [this message]
2026-05-13 10:45     ` Leon Hwang
2026-05-13 17:02       ` Alexei Starovoitov
2026-05-14 13:59         ` Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 7/8] libbpf: " Leon Hwang
2026-05-12 23:56   ` sashiko-bot
2026-05-13 10:46     ` Leon Hwang
2026-05-11 15:28 ` [PATCH bpf-next v13 8/8] selftests/bpf: Add tests to verify map create failure log Leon Hwang
2026-05-13  0:33   ` sashiko-bot
2026-05-13 10:47     ` Leon Hwang
2026-05-13 16:58       ` Alexei Starovoitov
2026-05-14 13:59         ` Leon Hwang

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=20260512233658.CEED7C2BCB0@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=leon.hwang@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 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.