bpf.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back
@ 2019-10-18 14:41 John Fastabend
  2019-10-18 16:51 ` Andrii Nakryiko
  2019-10-18 19:11 ` Daniel Borkmann
  0 siblings, 2 replies; 5+ messages in thread
From: John Fastabend @ 2019-10-18 14:41 UTC (permalink / raw)
  To: andriin, ast, daniel; +Cc: netdev, bpf, john.fastabend

With commit "libbpf: stop enforcing kern_version,..." we removed the
kernel version section parsing in favor of querying for the kernel
using uname() and populating the version using the result of the
query. After this any version sections were simply ignored.

Unfortunately, the world of kernels is not so friendly. I've found some
customized kernels where uname() does not match the in kernel version.
To fix this so programs can load in this environment this patch adds
back parsing the section and if it exists uses the user specified
kernel version to override the uname() result. However, keep most the
kernel uname() discovery bits so users are not required to insert the
version except in these odd cases.

Fixes: 5e61f27070292 ("libbpf: stop enforcing kern_version, populate it for users")
Signed-off-by: John Fastabend <john.fastabend@gmail.com>
---
 tools/lib/bpf/libbpf.c |   21 ++++++++++++++++++++-
 1 file changed, 20 insertions(+), 1 deletion(-)

diff --git a/tools/lib/bpf/libbpf.c b/tools/lib/bpf/libbpf.c
index fcea6988f962..675383131179 100644
--- a/tools/lib/bpf/libbpf.c
+++ b/tools/lib/bpf/libbpf.c
@@ -656,6 +656,21 @@ bpf_object__init_license(struct bpf_object *obj, void *data, size_t size)
 	return 0;
 }
 
+static int
+bpf_object__init_kversion(struct bpf_object *obj, void *data, size_t size)
+{
+	__u32 kver;
+
+	if (size != sizeof(kver)) {
+		pr_warning("invalid kver section in %s\n", obj->path);
+		return -LIBBPF_ERRNO__FORMAT;
+	}
+	memcpy(&kver, data, sizeof(kver));
+	obj->kern_version = kver;
+	pr_debug("kernel version of %s is %x\n", obj->path, obj->kern_version);
+	return 0;
+}
+
 static int compare_bpf_map(const void *_a, const void *_b)
 {
 	const struct bpf_map *a = _a;
@@ -1573,7 +1588,11 @@ static int bpf_object__elf_collect(struct bpf_object *obj, int flags)
 			if (err)
 				return err;
 		} else if (strcmp(name, "version") == 0) {
-			/* skip, we don't need it anymore */
+			err = bpf_object__init_kversion(obj,
+							data->d_buf,
+							data->d_size);
+			if (err)
+				return err;
 		} else if (strcmp(name, "maps") == 0) {
 			obj->efile.maps_shndx = idx;
 		} else if (strcmp(name, MAPS_ELF_SEC) == 0) {


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

* Re: [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back
  2019-10-18 14:41 [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back John Fastabend
@ 2019-10-18 16:51 ` Andrii Nakryiko
  2019-10-19  1:33   ` Alexei Starovoitov
  2019-10-18 19:11 ` Daniel Borkmann
  1 sibling, 1 reply; 5+ messages in thread
From: Andrii Nakryiko @ 2019-10-18 16:51 UTC (permalink / raw)
  To: John Fastabend, ast, daniel; +Cc: netdev, bpf

On 10/18/19 7:41 AM, John Fastabend wrote:
> With commit "libbpf: stop enforcing kern_version,..." we removed the
> kernel version section parsing in favor of querying for the kernel
> using uname() and populating the version using the result of the
> query. After this any version sections were simply ignored.
> 
> Unfortunately, the world of kernels is not so friendly. I've found some
> customized kernels where uname() does not match the in kernel version.
> To fix this so programs can load in this environment this patch adds
> back parsing the section and if it exists uses the user specified
> kernel version to override the uname() result. However, keep most the
> kernel uname() discovery bits so users are not required to insert the
> version except in these odd cases.
> 
> Fixes: 5e61f27070292 ("libbpf: stop enforcing kern_version, populate it for users")
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> ---

In the name of not breaking users of weird kernels :)

Acked-by: Andrii Nakryiko <andriin@fb.com>

>   tools/lib/bpf/libbpf.c |   21 ++++++++++++++++++++-
>   1 file changed, 20 insertions(+), 1 deletion(-)
> 

[...]


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

* Re: [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back
  2019-10-18 14:41 [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back John Fastabend
  2019-10-18 16:51 ` Andrii Nakryiko
@ 2019-10-18 19:11 ` Daniel Borkmann
  1 sibling, 0 replies; 5+ messages in thread
From: Daniel Borkmann @ 2019-10-18 19:11 UTC (permalink / raw)
  To: John Fastabend; +Cc: andriin, ast, netdev, bpf

On Fri, Oct 18, 2019 at 07:41:26AM -0700, John Fastabend wrote:
> With commit "libbpf: stop enforcing kern_version,..." we removed the
> kernel version section parsing in favor of querying for the kernel
> using uname() and populating the version using the result of the
> query. After this any version sections were simply ignored.
> 
> Unfortunately, the world of kernels is not so friendly. I've found some
> customized kernels where uname() does not match the in kernel version.
> To fix this so programs can load in this environment this patch adds
> back parsing the section and if it exists uses the user specified
> kernel version to override the uname() result. However, keep most the
> kernel uname() discovery bits so users are not required to insert the
> version except in these odd cases.
> 
> Fixes: 5e61f27070292 ("libbpf: stop enforcing kern_version, populate it for users")
> Signed-off-by: John Fastabend <john.fastabend@gmail.com>

Applied, thanks!

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

* Re: [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back
  2019-10-18 16:51 ` Andrii Nakryiko
@ 2019-10-19  1:33   ` Alexei Starovoitov
  2019-10-19  4:41     ` John Fastabend
  0 siblings, 1 reply; 5+ messages in thread
From: Alexei Starovoitov @ 2019-10-19  1:33 UTC (permalink / raw)
  To: Andrii Nakryiko; +Cc: John Fastabend, ast, daniel, netdev, bpf

On Fri, Oct 18, 2019 at 9:52 AM Andrii Nakryiko <andriin@fb.com> wrote:
>
> On 10/18/19 7:41 AM, John Fastabend wrote:
> > With commit "libbpf: stop enforcing kern_version,..." we removed the
> > kernel version section parsing in favor of querying for the kernel
> > using uname() and populating the version using the result of the
> > query. After this any version sections were simply ignored.
> >
> > Unfortunately, the world of kernels is not so friendly. I've found some
> > customized kernels where uname() does not match the in kernel version.
> > To fix this so programs can load in this environment this patch adds
> > back parsing the section and if it exists uses the user specified
> > kernel version to override the uname() result. However, keep most the
> > kernel uname() discovery bits so users are not required to insert the
> > version except in these odd cases.
> >
> > Fixes: 5e61f27070292 ("libbpf: stop enforcing kern_version, populate it for users")
> > Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> > ---
>
> In the name of not breaking users of weird kernels :)
>
> Acked-by: Andrii Nakryiko <andriin@fb.com>

What does it mean that uname is cheated?
Can libbpf read it from /proc/sys/kernel/osrelease ?
or /proc/version?
Is that read only or user space can somehow overwrite it?

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

* Re: [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back
  2019-10-19  1:33   ` Alexei Starovoitov
@ 2019-10-19  4:41     ` John Fastabend
  0 siblings, 0 replies; 5+ messages in thread
From: John Fastabend @ 2019-10-19  4:41 UTC (permalink / raw)
  To: Alexei Starovoitov, Andrii Nakryiko
  Cc: John Fastabend, ast, daniel, netdev, bpf

Alexei Starovoitov wrote:
> On Fri, Oct 18, 2019 at 9:52 AM Andrii Nakryiko <andriin@fb.com> wrote:
> >
> > On 10/18/19 7:41 AM, John Fastabend wrote:
> > > With commit "libbpf: stop enforcing kern_version,..." we removed the
> > > kernel version section parsing in favor of querying for the kernel
> > > using uname() and populating the version using the result of the
> > > query. After this any version sections were simply ignored.
> > >
> > > Unfortunately, the world of kernels is not so friendly. I've found some
> > > customized kernels where uname() does not match the in kernel version.
> > > To fix this so programs can load in this environment this patch adds
> > > back parsing the section and if it exists uses the user specified
> > > kernel version to override the uname() result. However, keep most the
> > > kernel uname() discovery bits so users are not required to insert the
> > > version except in these odd cases.
> > >
> > > Fixes: 5e61f27070292 ("libbpf: stop enforcing kern_version, populate it for users")
> > > Signed-off-by: John Fastabend <john.fastabend@gmail.com>
> > > ---
> >
> > In the name of not breaking users of weird kernels :)
> >
> > Acked-by: Andrii Nakryiko <andriin@fb.com>
> 
> What does it mean that uname is cheated?
> Can libbpf read it from /proc/sys/kernel/osrelease ?
> or /proc/version?
> Is that read only or user space can somehow overwrite it?

In this case LINUX_VERSION_CODE as shown in version.h from linux-headers
does not much what is being reported by /proc/version or osrelease.

So its a bit surprising to me as well but I haven't got to the bottom
of it. Maybe something to do with how proc is mounted in this kubernetes
setup?

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

end of thread, other threads:[~2019-10-19  4:41 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-10-18 14:41 [bpf-next PATCH] bpf: libbpf, add kernel version section parsing back John Fastabend
2019-10-18 16:51 ` Andrii Nakryiko
2019-10-19  1:33   ` Alexei Starovoitov
2019-10-19  4:41     ` John Fastabend
2019-10-18 19:11 ` Daniel Borkmann

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