BPF List
 help / color / mirror / Atom feed
From: Eduard Zingerman <eddyz87@gmail.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>, ast@kernel.org
Cc: bpf@vger.kernel.org, andrii@kernel.org, daniel@iogearbox.net,
	 martin.lau@linux.dev, kernel-team@fb.com,
	yonghong.song@linux.dev, Liu RuiTong <cnitlrt@gmail.com>
Subject: Re: [PATCH bpf-next] bpf: bpf_core_calc_relo_insn() should verify relocation type id
Date: Wed, 21 Aug 2024 15:32:38 -0700	[thread overview]
Message-ID: <b377eda1c4cd9d6c4ad1c3d6cbed9cb1e14242f9.camel@gmail.com> (raw)
In-Reply-To: <CAEf4Bza9Y-JO0MeomB9S+6tOr-rRp0kDe_-1_tf2ArNddfUEpA@mail.gmail.com>

On Wed, 2024-08-21 at 13:08 -0700, Andrii Nakryiko wrote:

[...]

> Ok, then let's do that. I don't want static analysers complaining
> about this when checking libbpf code base.

Just want to rant a bit.
Here is a footgun in the relo_core.c:

    #ifdef __KERNEL__
    ...
    #undef pr_warn
    #undef pr_info
    #undef pr_debug
    #define pr_warn(fmt, log, ...)      bpf_log((void *)log, fmt, "", ##__VA_ARGS__)
    #define pr_info(fmt, log, ...)      bpf_log((void *)log, fmt, "", ##__VA_ARGS__)
    #define pr_debug(fmt, log, ...)     bpf_log((void *)log, fmt, "", ##__VA_ARGS__)
                          ^^^                   ^^^^^^^^^^^       ^^
                     first format param,        prog_name         replacement for
                     usually prog_name          cast to           first param
                                                verifier log
    ...
    #else
    ...
    #endif

    int bpf_core_calc_relo_insn(const char *prog_name, ...)
    {
        ...
        pr_warn("prog '%s': relo #%d: bad type id %u\n",
                prog_name, relo_idx, local_id);
        ...
    }

And in the verifier.c:

    err = bpf_core_calc_relo_insn((void *)ctx->log, relo, ...);
                                  ^^^^^^^^^^^^^^^^
                                  This is a prog_name parameter

Just spent more than an hour trying to figure out why passing real
program name (char *) does not work.
I'll think on a refactoring, but that is for another series.


  reply	other threads:[~2024-08-21 22:32 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-21 16:46 [PATCH bpf-next] bpf: bpf_core_calc_relo_insn() should verify relocation type id Eduard Zingerman
2024-08-21 16:59 ` Andrii Nakryiko
2024-08-21 17:46   ` Eduard Zingerman
2024-08-21 19:10     ` Andrii Nakryiko
2024-08-21 19:28       ` Eduard Zingerman
2024-08-21 20:08         ` Andrii Nakryiko
2024-08-21 22:32           ` Eduard Zingerman [this message]
2024-08-21 22:38             ` Eduard Zingerman

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=b377eda1c4cd9d6c4ad1c3d6cbed9cb1e14242f9.camel@gmail.com \
    --to=eddyz87@gmail.com \
    --cc=andrii.nakryiko@gmail.com \
    --cc=andrii@kernel.org \
    --cc=ast@kernel.org \
    --cc=bpf@vger.kernel.org \
    --cc=cnitlrt@gmail.com \
    --cc=daniel@iogearbox.net \
    --cc=kernel-team@fb.com \
    --cc=martin.lau@linux.dev \
    --cc=yonghong.song@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