From: Andrii Nakryiko <andrii.nakryiko@gmail.com>
To: "Toke Høiland-Jørgensen" <toke@redhat.com>
Cc: Daniel Borkmann <daniel@iogearbox.net>,
Alexei Starovoitov <ast@kernel.org>,
Martin KaFai Lau <kafai@fb.com>, Song Liu <songliubraving@fb.com>,
Yonghong Song <yhs@fb.com>,
Jesper Dangaard Brouer <brouer@redhat.com>,
David Miller <davem@davemloft.net>,
Networking <netdev@vger.kernel.org>, bpf <bpf@vger.kernel.org>
Subject: Re: [PATCH bpf-next v2 1/4] libbpf: Fix error handling in bpf_map__reuse_fd()
Date: Thu, 24 Oct 2019 19:46:31 -0700 [thread overview]
Message-ID: <CAEf4BzaazESQUQNYVJdDX_7WY-=UBoKbKJk_pTK_PguHxoo8uQ@mail.gmail.com> (raw)
In-Reply-To: <157192269854.234778.6284587028332090249.stgit@toke.dk>
On Thu, Oct 24, 2019 at 6:11 AM Toke Høiland-Jørgensen <toke@redhat.com> wrote:
>
> From: Toke Høiland-Jørgensen <toke@redhat.com>
>
> bpf_map__reuse_fd() was calling close() in the error path before returning
> an error value based on errno. However, close can change errno, so that can
> lead to potentially misleading error messages. Instead, explicitly store
> errno in the err variable before each goto.
>
> Signed-off-by: Toke Høiland-Jørgensen <toke@redhat.com>
> ---
Thanks!
Acked-by: Andrii Nakryiko <andriin@fb.com>
> tools/lib/bpf/libbpf.c | 14 ++++++++++----
> 1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
> index cccfd9355134..a2a7d074ac48 100644
> --- a/tools/lib/bpf/libbpf.c
> +++ b/tools/lib/bpf/libbpf.c
> @@ -1918,16 +1918,22 @@ int bpf_map__reuse_fd(struct bpf_map *map, int fd)
> return -errno;
>
> new_fd = open("/", O_RDONLY | O_CLOEXEC);
> - if (new_fd < 0)
> + if (new_fd < 0) {
> + err = -errno;
> goto err_free_new_name;
> + }
>
> new_fd = dup3(fd, new_fd, O_CLOEXEC);
> - if (new_fd < 0)
> + if (new_fd < 0) {
> + err = -errno;
> goto err_close_new_fd;
> + }
>
> err = zclose(map->fd);
> - if (err)
> + if (err) {
> + err = -errno;
> goto err_close_new_fd;
> + }
> free(map->name);
>
> map->fd = new_fd;
> @@ -1946,7 +1952,7 @@ int bpf_map__reuse_fd(struct bpf_map *map, int fd)
> close(new_fd);
> err_free_new_name:
> free(new_name);
> - return -errno;
> + return err;
> }
>
> int bpf_map__resize(struct bpf_map *map, __u32 max_entries)
>
next prev parent reply other threads:[~2019-10-25 2:46 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-10-24 13:11 [PATCH bpf-next v2 0/4] libbpf: Support automatic pinning of maps using 'pinning' BTF attribute Toke Høiland-Jørgensen
2019-10-24 13:11 ` [PATCH bpf-next v2 1/4] libbpf: Fix error handling in bpf_map__reuse_fd() Toke Høiland-Jørgensen
2019-10-25 2:46 ` Andrii Nakryiko [this message]
2019-10-24 13:11 ` [PATCH bpf-next v2 2/4] libbpf: Store map pin path and status in struct bpf_map Toke Høiland-Jørgensen
2019-10-25 3:00 ` Andrii Nakryiko
2019-10-24 13:11 ` [PATCH bpf-next v2 3/4] libbpf: Support configurable pinning of maps from BTF annotations Toke Høiland-Jørgensen
2019-10-24 13:25 ` Toke Høiland-Jørgensen
2019-10-25 3:19 ` Andrii Nakryiko
2019-10-25 12:32 ` Jesper Dangaard Brouer
2019-10-25 17:28 ` Andrii Nakryiko
2019-10-24 13:11 ` [PATCH bpf-next v2 4/4] libbpf: Add option to auto-pin maps when opening BPF object Toke Høiland-Jørgensen
2019-10-25 4:41 ` Andrii Nakryiko
2019-10-27 12:04 ` Toke Høiland-Jørgensen
2019-10-27 20:12 ` Andrii Nakryiko
2019-10-27 20:44 ` 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='CAEf4BzaazESQUQNYVJdDX_7WY-=UBoKbKJk_pTK_PguHxoo8uQ@mail.gmail.com' \
--to=andrii.nakryiko@gmail.com \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=brouer@redhat.com \
--cc=daniel@iogearbox.net \
--cc=davem@davemloft.net \
--cc=kafai@fb.com \
--cc=netdev@vger.kernel.org \
--cc=songliubraving@fb.com \
--cc=toke@redhat.com \
--cc=yhs@fb.com \
/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).