lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:   Mon, 30 Nov 2020 14:24:38 -0800
From:   Andrii Nakryiko <andrii.nakryiko@...il.com>
To:     Toke Høiland-Jørgensen <toke@...hat.com>
Cc:     Daniel Borkmann <daniel@...earbox.net>,
        Alexei Starovoitov <ast@...com>,
        Andrii Nakryiko <andrii@...nel.org>, bpf <bpf@...r.kernel.org>,
        Networking <netdev@...r.kernel.org>
Subject: Re: [PATCH bpf] libbpf: reset errno after probing kernel features

On Mon, Nov 30, 2020 at 7:42 AM Toke Høiland-Jørgensen <toke@...hat.com> wrote:
>
> The kernel feature probing results in 'errno' being set if the probing
> fails (as is often the case). This can stick around and leak to the caller,
> which can lead to confusion later. So let's make sure we always reset errno
> after calling a probe function.

What specifically is the problem and what sort of confusion we are
talking about here? You are not supposed to check errno, unless the
function returned -1 or other error result.

In some cases, you have to reset errno manually just to avoid
confusion (see how strtol() is used, as an example).

I.e., I don't see the problem here, any printf() technically can set
errno to <0, we don't reset errno after each printf call though,
right?

>
> Fixes: 47b6cb4d0add ("libbpf: Make kernel feature probing lazy")
> Signed-off-by: Toke Høiland-Jørgensen <toke@...hat.com>
> ---
>  tools/lib/bpf/libbpf.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index 28baee7ba1ca..8d05132e1945 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -4021,6 +4021,8 @@ static bool kernel_supports(enum kern_feature_id feat_id)
>                         pr_warn("Detection of kernel %s support failed: %d\n", feat->desc, ret);
>                         WRITE_ONCE(feat->res, FEAT_MISSING);
>                 }
> +               /* reset errno after probing to prevent leaking it to caller */
> +               errno = 0;
>         }
>
>         return READ_ONCE(feat->res) == FEAT_SUPPORTED;
> --
> 2.29.2
>

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ