Linux Trace Kernel
 help / color / mirror / Atom feed
From: Leon Hwang <leon.hwang@linux.dev>
To: sashiko-reviews@lists.linux.dev, bpf@vger.kernel.org
Cc: linux-trace-kernel@vger.kernel.org
Subject: Re: [PATCH bpf-next 1/6] bpf: Add syscall common attrs support for link_create
Date: Mon, 19 Oct 2026 00:28:48 +0800	[thread overview]
Message-ID: <6dc8b3e5-b4fe-45f6-9ed6-137c00e7d7db@linux.dev> (raw)
In-Reply-To: <sashiko-outbox-175562@kernel.org>

On 2026/10/17 22:39, sashiko-bot@kernel.org wrote:

[...]

>>  out:
>> -	if (ret < 0)
>> +	/* preserve original error even if log finalization is successful */
>> +	err = bpf_log_attr_finalize(&attr_log, log);
>> +	if (err)
>> +		ret = err;
>> +
>> +	kfree(log);
>> +
>> +	if (ret < 0 && prog)
>>  		bpf_prog_put(prog);
>>  	return ret;
>>  }
> 
> [Severity: Critical]
> Can this underflow the refcount on prog and leak the newly installed link
> file descriptor if bpf_log_attr_finalize() fails after link attachment
> succeeds?

Correct.

To avoid such prog leak, I'd like to report the log_true_size twice.

ret = bpf_log_attr_report_size(&attr_log, 0);
if (ret)
	goto out;

switch (prog->type) {
	/* ... */
}

out:
if (ret) {
	int err =  bpf_log_attr_finalize(&attr_log, log);

	ret = err ? err : ret;
}

if (ret < 0 && prog)
	bpf_prog_put(prog);

kfree(log);
return ret;

Thanks,
Leon

> [...]


  reply	other threads:[~2026-10-18 16:28 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-17 14:26 [PATCH bpf-next 0/6] bpf: Add syscall common attrs support for xdp link_create Leon Hwang
2026-10-17 14:26 ` [PATCH bpf-next 1/6] bpf: Add syscall common attrs support for link_create Leon Hwang
2026-10-17 14:39   ` sashiko-bot
2026-10-18 16:28     ` Leon Hwang [this message]
2026-10-17 14:26 ` [PATCH bpf-next 2/6] bpf: Add syscall common attrs support for xdp link_create Leon Hwang
2026-10-17 14:48   ` sashiko-bot
2026-10-18 16:32     ` Leon Hwang
2026-10-17 15:03   ` bot+bpf-ci
2026-10-18 16:30     ` Leon Hwang
2026-10-17 14:26 ` [PATCH bpf-next 3/6] bpf: Retire tracepoint bpf_xdp_link_attach_failed Leon Hwang
2026-10-17 14:26 ` [PATCH bpf-next 4/6] libbpf: Factor out __bpf_sys_fd helper Leon Hwang
2026-10-17 14:53   ` bot+bpf-ci
2026-10-18 16:32     ` Leon Hwang
2026-10-17 14:26 ` [PATCH bpf-next 5/6] libbpf: Add bpf_link_create_log API Leon Hwang
2026-10-17 14:43   ` sashiko-bot
2026-10-18 16:33     ` Leon Hwang
2026-10-17 15:03   ` bot+bpf-ci
2026-10-18 16:33     ` Leon Hwang
2026-10-17 14:26 ` [PATCH bpf-next 6/6] selftests/bpf: Add tests to verify link_create logs Leon Hwang
2026-10-17 15:02   ` bot+bpf-ci
2026-10-18 16:33     ` 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=6dc8b3e5-b4fe-45f6-9ed6-137c00e7d7db@linux.dev \
    --to=leon.hwang@linux.dev \
    --cc=bpf@vger.kernel.org \
    --cc=linux-trace-kernel@vger.kernel.org \
    --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