bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH bpf-next] libbpf: handle ENOTSUPP errno in libbpf_strerror()
@ 2021-04-24 22:16 Pedro Tammela
  2021-04-27 16:18 ` Daniel Borkmann
  0 siblings, 1 reply; 3+ messages in thread
From: Pedro Tammela @ 2021-04-24 22:16 UTC (permalink / raw)
  To: Alexei Starovoitov, Daniel Borkmann, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, netdev, bpf, linux-kernel
  Cc: Pedro Tammela

The 'bpf()' syscall is leaking the ENOTSUPP errno that is internal to the kernel[1].
More recent code is already using the correct EOPNOTSUPP, but changing
older return codes is not possible due to dependency concerns, so handle ENOTSUPP
in libbpf_strerror().

[1] https://lore.kernel.org/netdev/20200511165319.2251678-1-kuba@kernel.org/

Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
---
 tools/lib/bpf/libbpf_errno.c | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/tools/lib/bpf/libbpf_errno.c b/tools/lib/bpf/libbpf_errno.c
index 0afb51f7a919..7de8bbc34a37 100644
--- a/tools/lib/bpf/libbpf_errno.c
+++ b/tools/lib/bpf/libbpf_errno.c
@@ -13,6 +13,9 @@
 
 #include "libbpf.h"
 
+/* This errno is internal to the kernel but leaks in the bpf() syscall. */
+#define ENOTSUPP 524
+
 /* make sure libbpf doesn't use kernel-only integer typedefs */
 #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
 
@@ -43,6 +46,12 @@ int libbpf_strerror(int err, char *buf, size_t size)
 
 	err = err > 0 ? err : -err;
 
+	if (err == ENOTSUPP) {
+		snprintf(buf, size, "Operation not supported");
+		buf[size - 1] = '\0';
+		return 0;
+	}
+
 	if (err < __LIBBPF_ERRNO__START) {
 		int ret;
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: handle ENOTSUPP errno in libbpf_strerror()
  2021-04-24 22:16 [PATCH bpf-next] libbpf: handle ENOTSUPP errno in libbpf_strerror() Pedro Tammela
@ 2021-04-27 16:18 ` Daniel Borkmann
  2021-04-30 14:16   ` Pedro Tammela
  0 siblings, 1 reply; 3+ messages in thread
From: Daniel Borkmann @ 2021-04-27 16:18 UTC (permalink / raw)
  To: Pedro Tammela, Alexei Starovoitov, Andrii Nakryiko,
	Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
	KP Singh, netdev, bpf, linux-kernel
  Cc: Pedro Tammela

On 4/25/21 12:16 AM, Pedro Tammela wrote:
> The 'bpf()' syscall is leaking the ENOTSUPP errno that is internal to the kernel[1].
> More recent code is already using the correct EOPNOTSUPP, but changing
> older return codes is not possible due to dependency concerns, so handle ENOTSUPP
> in libbpf_strerror().
> 
> [1] https://lore.kernel.org/netdev/20200511165319.2251678-1-kuba@kernel.org/
> 
> Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
> ---
>   tools/lib/bpf/libbpf_errno.c | 9 +++++++++
>   1 file changed, 9 insertions(+)
> 
> diff --git a/tools/lib/bpf/libbpf_errno.c b/tools/lib/bpf/libbpf_errno.c
> index 0afb51f7a919..7de8bbc34a37 100644
> --- a/tools/lib/bpf/libbpf_errno.c
> +++ b/tools/lib/bpf/libbpf_errno.c
> @@ -13,6 +13,9 @@
>   
>   #include "libbpf.h"
>   
> +/* This errno is internal to the kernel but leaks in the bpf() syscall. */
> +#define ENOTSUPP 524
> +
>   /* make sure libbpf doesn't use kernel-only integer typedefs */
>   #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
>   
> @@ -43,6 +46,12 @@ int libbpf_strerror(int err, char *buf, size_t size)
>   
>   	err = err > 0 ? err : -err;
>   
> +	if (err == ENOTSUPP) {
> +		snprintf(buf, size, "Operation not supported");
> +		buf[size - 1] = '\0';
> +		return 0;
> +	}
> +
>   	if (err < __LIBBPF_ERRNO__START) {
>   		int ret;

Could you fold this into the __LIBBPF_ERRNO__START test body to denote that it
belongs outside the libbpf error range? For example, could be simplified like this:

         if (err < __LIBBPF_ERRNO__START) {
                 int ret;

                 /* Handle ENOTSUPP separate here given it's kernel internal,
                  * but for sake of error string it has the same meaning as
                  * the EOPNOTSUPP error.
                  */
                 if (err == ENOTSUPP)
                         err = EOPNOTSUPP;
                 ret = strerror_r(err, buf, size);
                 buf[size - 1] = '\0';
                 return ret;
         }

Thanks,
Daniel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH bpf-next] libbpf: handle ENOTSUPP errno in libbpf_strerror()
  2021-04-27 16:18 ` Daniel Borkmann
@ 2021-04-30 14:16   ` Pedro Tammela
  0 siblings, 0 replies; 3+ messages in thread
From: Pedro Tammela @ 2021-04-30 14:16 UTC (permalink / raw)
  To: Daniel Borkmann
  Cc: Alexei Starovoitov, Andrii Nakryiko, Martin KaFai Lau, Song Liu,
	Yonghong Song, John Fastabend, KP Singh, Networking, bpf,
	open list, Pedro Tammela

Em ter., 27 de abr. de 2021 às 13:18, Daniel Borkmann
<daniel@iogearbox.net> escreveu:
>
> On 4/25/21 12:16 AM, Pedro Tammela wrote:
> > The 'bpf()' syscall is leaking the ENOTSUPP errno that is internal to the kernel[1].
> > More recent code is already using the correct EOPNOTSUPP, but changing
> > older return codes is not possible due to dependency concerns, so handle ENOTSUPP
> > in libbpf_strerror().
> >
> > [1] https://lore.kernel.org/netdev/20200511165319.2251678-1-kuba@kernel.org/
> >
> > Signed-off-by: Pedro Tammela <pctammela@mojatatu.com>
> > ---
> >   tools/lib/bpf/libbpf_errno.c | 9 +++++++++
> >   1 file changed, 9 insertions(+)
> >
> > diff --git a/tools/lib/bpf/libbpf_errno.c b/tools/lib/bpf/libbpf_errno.c
> > index 0afb51f7a919..7de8bbc34a37 100644
> > --- a/tools/lib/bpf/libbpf_errno.c
> > +++ b/tools/lib/bpf/libbpf_errno.c
> > @@ -13,6 +13,9 @@
> >
> >   #include "libbpf.h"
> >
> > +/* This errno is internal to the kernel but leaks in the bpf() syscall. */
> > +#define ENOTSUPP 524
> > +
> >   /* make sure libbpf doesn't use kernel-only integer typedefs */
> >   #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
> >
> > @@ -43,6 +46,12 @@ int libbpf_strerror(int err, char *buf, size_t size)
> >
> >       err = err > 0 ? err : -err;
> >
> > +     if (err == ENOTSUPP) {
> > +             snprintf(buf, size, "Operation not supported");
> > +             buf[size - 1] = '\0';
> > +             return 0;
> > +     }
> > +
> >       if (err < __LIBBPF_ERRNO__START) {
> >               int ret;
>
> Could you fold this into the __LIBBPF_ERRNO__START test body to denote that it
> belongs outside the libbpf error range? For example, could be simplified like this:
>
>          if (err < __LIBBPF_ERRNO__START) {
>                  int ret;
>
>                  /* Handle ENOTSUPP separate here given it's kernel internal,
>                   * but for sake of error string it has the same meaning as
>                   * the EOPNOTSUPP error.
>                   */
>                  if (err == ENOTSUPP)
>                          err = EOPNOTSUPP;
>                  ret = strerror_r(err, buf, size);
>                  buf[size - 1] = '\0';
>                  return ret;
>          }
>
> Thanks,
> Daniel

Sure, looks simpler indeed.

Pedro

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-30 14:17 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-24 22:16 [PATCH bpf-next] libbpf: handle ENOTSUPP errno in libbpf_strerror() Pedro Tammela
2021-04-27 16:18 ` Daniel Borkmann
2021-04-30 14:16   ` Pedro Tammela

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).