From: "Toke Høiland-Jørgensen" <toke@redhat.com>
To: Andrii Nakryiko <andrii.nakryiko@gmail.com>
Cc: Alexei Starovoitov <ast@kernel.org>,
Daniel Borkmann <daniel@iogearbox.net>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf] libbpf: Prevent overriding errno when logging errors
Date: Thu, 13 Aug 2020 21:52:20 +0200 [thread overview]
Message-ID: <87d03u1fyj.fsf@toke.dk> (raw)
In-Reply-To: <CAEf4BzZ6yM_QWu0x4b51NAVzN6-EAoQN4ff4BNiof5CJ5ukhpg@mail.gmail.com>
Andrii Nakryiko <andrii.nakryiko@gmail.com> writes:
> On Thu, Aug 13, 2020 at 7:29 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>>
>> Turns out there were a few more instances where libbpf didn't save the
>> errno before writing an error message, causing errno to be overridden by
>> the printf() return and the error disappearing if logging is enabled.
>>
>> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
>> ---
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>
>
>> tools/lib/bpf/libbpf.c | 12 +++++++-----
>> 1 file changed, 7 insertions(+), 5 deletions(-)
>>
>> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
>> index 0a06124f7999..fd256440e233 100644
>> --- a/tools/lib/bpf/libbpf.c
>> +++ b/tools/lib/bpf/libbpf.c
>> @@ -3478,10 +3478,11 @@ bpf_object__probe_global_data(struct bpf_object *obj)
>>
>> map = bpf_create_map_xattr(&map_attr);
>> if (map < 0) {
>> - cp = libbpf_strerror_r(errno, errmsg, sizeof(errmsg));
>> + ret = -errno;
>> + cp = libbpf_strerror_r(-ret, errmsg, sizeof(errmsg));
>
> fyi, libbpf_strerror_r() is smart enough to work with both negative
> and positive error numbers (it basically takes abs(err)), so no need
> to ensure it's positive here and below.
Noted. Although that also means it doesn't hurt either, I suppose; so
not going to bother respinning this unless someone insists :)
-Toke
next prev parent reply other threads:[~2020-08-13 19:52 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-13 14:29 [PATCH bpf] libbpf: Prevent overriding errno when logging errors Toke Høiland-Jørgensen
2020-08-13 16:41 ` Andrii Nakryiko
2020-08-13 19:52 ` Toke Høiland-Jørgensen [this message]
2020-08-13 20:35 ` Daniel Borkmann
2020-08-13 20:52 ` Toke Høiland-Jørgensen
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=87d03u1fyj.fsf@toke.dk \
--to=toke@redhat.com \
--cc=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=netdev@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).