* [PATCH] libbpf: fix str_has_sfx()
@ 2022-07-19 9:53 Dan Carpenter
2022-07-19 17:19 ` Martin KaFai Lau
2022-07-21 13:00 ` patchwork-bot+netdevbpf
0 siblings, 2 replies; 9+ messages in thread
From: Dan Carpenter @ 2022-07-19 9:53 UTC (permalink / raw)
To: Alexei Starovoitov, Alan Maguire
Cc: Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, bpf, kernel-janitors
The return from strcmp() is inverted so the it returns true instead
of false and vise versa.
Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
Spotted during review. *cmp() functions should always have a comparison
to zero.
if (strcmp(a, b) < 0) { <-- means a < b
if (strcmp(a, b) >= 0) { <-- means a >= b
if (strcmp(a, b) != 0) { <-- means a != b
etc.
tools/lib/bpf/libbpf_internal.h | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 9cd7829cbe41..008485296a29 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
size_t str_len = strlen(str);
size_t sfx_len = strlen(sfx);
- if (sfx_len <= str_len)
- return strcmp(str + str_len - sfx_len, sfx);
- return false;
+ if (sfx_len > str_len)
+ return false;
+ return strcmp(str + str_len - sfx_len, sfx) == 0;
}
/* Symbol versioning is different between static and shared library.
--
2.35.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-19 9:53 [PATCH] libbpf: fix str_has_sfx() Dan Carpenter
@ 2022-07-19 17:19 ` Martin KaFai Lau
2022-07-19 17:50 ` Dan Carpenter
2022-07-19 17:51 ` Alexei Starovoitov
2022-07-21 13:00 ` patchwork-bot+netdevbpf
1 sibling, 2 replies; 9+ messages in thread
From: Martin KaFai Lau @ 2022-07-19 17:19 UTC (permalink / raw)
To: Dan Carpenter
Cc: Alexei Starovoitov, Alan Maguire, Daniel Borkmann,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
kernel-janitors
On Tue, Jul 19, 2022 at 12:53:01PM +0300, Dan Carpenter wrote:
> The return from strcmp() is inverted so the it returns true instead
> of false and vise versa.
>
> Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Spotted during review. *cmp() functions should always have a comparison
> to zero.
> if (strcmp(a, b) < 0) { <-- means a < b
> if (strcmp(a, b) >= 0) { <-- means a >= b
> if (strcmp(a, b) != 0) { <-- means a != b
> etc.
>
> tools/lib/bpf/libbpf_internal.h | 6 +++---
> 1 file changed, 3 insertions(+), 3 deletions(-)
>
> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> index 9cd7829cbe41..008485296a29 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
> size_t str_len = strlen(str);
> size_t sfx_len = strlen(sfx);
>
> - if (sfx_len <= str_len)
> - return strcmp(str + str_len - sfx_len, sfx);
> - return false;
> + if (sfx_len > str_len)
> + return false;
> + return strcmp(str + str_len - sfx_len, sfx) == 0;
Please tag the subject with "bpf" next time.
Acked-by: Martin KaFai Lau <kafai@fb.com>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-19 17:19 ` Martin KaFai Lau
@ 2022-07-19 17:50 ` Dan Carpenter
2022-07-19 17:54 ` Alexei Starovoitov
2022-07-19 17:51 ` Alexei Starovoitov
1 sibling, 1 reply; 9+ messages in thread
From: Dan Carpenter @ 2022-07-19 17:50 UTC (permalink / raw)
To: Martin KaFai Lau
Cc: Alexei Starovoitov, Alan Maguire, Daniel Borkmann,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
kernel-janitors
On Tue, Jul 19, 2022 at 10:19:02AM -0700, Martin KaFai Lau wrote:
> > @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
> > size_t str_len = strlen(str);
> > size_t sfx_len = strlen(sfx);
> >
> > - if (sfx_len <= str_len)
> > - return strcmp(str + str_len - sfx_len, sfx);
> > - return false;
> > + if (sfx_len > str_len)
> > + return false;
> > + return strcmp(str + str_len - sfx_len, sfx) == 0;
> Please tag the subject with "bpf" next time.
I always work against linux-next. Would it help if I put that in the
subject?
Otherwise I don't have a way to figure this stuff out. I kind of know
networking tree but not 100% and that is a massive pain in the butt.
Until there is an automated way that then those kind of requests are
not reasonable.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-19 17:19 ` Martin KaFai Lau
2022-07-19 17:50 ` Dan Carpenter
@ 2022-07-19 17:51 ` Alexei Starovoitov
2022-07-20 7:37 ` Alan Maguire
1 sibling, 1 reply; 9+ messages in thread
From: Alexei Starovoitov @ 2022-07-19 17:51 UTC (permalink / raw)
To: Martin KaFai Lau
Cc: Dan Carpenter, Alexei Starovoitov, Alan Maguire, Daniel Borkmann,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
kernel-janitors
On Tue, Jul 19, 2022 at 10:19 AM Martin KaFai Lau <kafai@fb.com> wrote:
>
> On Tue, Jul 19, 2022 at 12:53:01PM +0300, Dan Carpenter wrote:
> > The return from strcmp() is inverted so the it returns true instead
> > of false and vise versa.
> >
> > Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
> > Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> > ---
> > Spotted during review. *cmp() functions should always have a comparison
> > to zero.
> > if (strcmp(a, b) < 0) { <-- means a < b
> > if (strcmp(a, b) >= 0) { <-- means a >= b
> > if (strcmp(a, b) != 0) { <-- means a != b
> > etc.
> >
> > tools/lib/bpf/libbpf_internal.h | 6 +++---
> > 1 file changed, 3 insertions(+), 3 deletions(-)
> >
> > diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> > index 9cd7829cbe41..008485296a29 100644
> > --- a/tools/lib/bpf/libbpf_internal.h
> > +++ b/tools/lib/bpf/libbpf_internal.h
> > @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
> > size_t str_len = strlen(str);
> > size_t sfx_len = strlen(sfx);
> >
> > - if (sfx_len <= str_len)
> > - return strcmp(str + str_len - sfx_len, sfx);
> > - return false;
> > + if (sfx_len > str_len)
> > + return false;
> > + return strcmp(str + str_len - sfx_len, sfx) == 0;
> Please tag the subject with "bpf" next time.
>
> Acked-by: Martin KaFai Lau <kafai@fb.com>
Alan,
If it was so broken how did it work earlier?
Do we have a test for this?
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-19 17:50 ` Dan Carpenter
@ 2022-07-19 17:54 ` Alexei Starovoitov
2022-07-20 9:11 ` Dan Carpenter
0 siblings, 1 reply; 9+ messages in thread
From: Alexei Starovoitov @ 2022-07-19 17:54 UTC (permalink / raw)
To: Dan Carpenter
Cc: Martin KaFai Lau, Alexei Starovoitov, Alan Maguire,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
bpf, kernel-janitors
On Tue, Jul 19, 2022 at 10:51 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
>
> On Tue, Jul 19, 2022 at 10:19:02AM -0700, Martin KaFai Lau wrote:
> > > @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
> > > size_t str_len = strlen(str);
> > > size_t sfx_len = strlen(sfx);
> > >
> > > - if (sfx_len <= str_len)
> > > - return strcmp(str + str_len - sfx_len, sfx);
> > > - return false;
> > > + if (sfx_len > str_len)
> > > + return false;
> > > + return strcmp(str + str_len - sfx_len, sfx) == 0;
> > Please tag the subject with "bpf" next time.
>
> I always work against linux-next. Would it help if I put that in the
> subject?
>
> Otherwise I don't have a way to figure this stuff out. I kind of know
> networking tree but not 100% and that is a massive pain in the butt.
> Until there is an automated way that then those kind of requests are
> not reasonable.
Dan,
you were told multiple times to follow the rules.
bpf patches should target bpf of bpf-next trees only.
If you send against linux-next you're taking a random chance
that they will pass CI.
In turn making everyone waste time.
Please follow the simple rules.
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-19 17:51 ` Alexei Starovoitov
@ 2022-07-20 7:37 ` Alan Maguire
2022-07-28 22:10 ` Andrii Nakryiko
0 siblings, 1 reply; 9+ messages in thread
From: Alan Maguire @ 2022-07-20 7:37 UTC (permalink / raw)
To: Alexei Starovoitov, Martin KaFai Lau
Cc: Dan Carpenter, Alexei Starovoitov, Daniel Borkmann,
Martin KaFai Lau, Song Liu, Yonghong Song, John Fastabend,
KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa, bpf,
kernel-janitors
On 19/07/2022 18:51, Alexei Starovoitov wrote:
> On Tue, Jul 19, 2022 at 10:19 AM Martin KaFai Lau <kafai@fb.com> wrote:
>>
>> On Tue, Jul 19, 2022 at 12:53:01PM +0300, Dan Carpenter wrote:
>>> The return from strcmp() is inverted so the it returns true instead
>>> of false and vise versa.
>>>
>>> Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
>>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
>>> ---
>>> Spotted during review. *cmp() functions should always have a comparison
>>> to zero.
>>> if (strcmp(a, b) < 0) { <-- means a < b
>>> if (strcmp(a, b) >= 0) { <-- means a >= b
>>> if (strcmp(a, b) != 0) { <-- means a != b
>>> etc.
>>>
>>> tools/lib/bpf/libbpf_internal.h | 6 +++---
>>> 1 file changed, 3 insertions(+), 3 deletions(-)
>>>
>>> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
>>> index 9cd7829cbe41..008485296a29 100644
>>> --- a/tools/lib/bpf/libbpf_internal.h
>>> +++ b/tools/lib/bpf/libbpf_internal.h
>>> @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
>>> size_t str_len = strlen(str);
>>> size_t sfx_len = strlen(sfx);
>>>
>>> - if (sfx_len <= str_len)
>>> - return strcmp(str + str_len - sfx_len, sfx);
>>> - return false;
>>> + if (sfx_len > str_len)
>>> + return false;
>>> + return strcmp(str + str_len - sfx_len, sfx) == 0;
>> Please tag the subject with "bpf" next time.
>>
>> Acked-by: Martin KaFai Lau <kafai@fb.com>
>
> Alan,
>
> If it was so broken how did it work earlier?
> Do we have a test for this?
>
We have tests for automatic path determination, yes, but those
tests specify libc.so.6, so are testing the strstr(file, ".so.")
predicate below:
if (str_has_sfx(file, ".so") || strstr(file, ".so.")) {
Problem is, on many systems, libc.so is a GNU ld script rather
than an actual library:
cat /usr/lib64/libc.so
/* GNU ld script
Use the shared library, but some functions are only in
the static library, so try that secondarily. */
OUTPUT_FORMAT(elf64-x86-64)
GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
...so we can't rely on system library .so files actually containing
the library to instrument.
Maybe we can do something with liburandom_read.so now we have it
there; I was looking at extending the auto-path determination
to usdt too, so we could add a new test to cover this then I think.
Alan
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-19 17:54 ` Alexei Starovoitov
@ 2022-07-20 9:11 ` Dan Carpenter
0 siblings, 0 replies; 9+ messages in thread
From: Dan Carpenter @ 2022-07-20 9:11 UTC (permalink / raw)
To: Alexei Starovoitov
Cc: Martin KaFai Lau, Alexei Starovoitov, Alan Maguire,
Daniel Borkmann, Martin KaFai Lau, Song Liu, Yonghong Song,
John Fastabend, KP Singh, Stanislav Fomichev, Hao Luo, Jiri Olsa,
bpf, kernel-janitors
On Tue, Jul 19, 2022 at 10:54:13AM -0700, Alexei Starovoitov wrote:
> On Tue, Jul 19, 2022 at 10:51 AM Dan Carpenter <dan.carpenter@oracle.com> wrote:
> >
> > On Tue, Jul 19, 2022 at 10:19:02AM -0700, Martin KaFai Lau wrote:
> > > > @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
> > > > size_t str_len = strlen(str);
> > > > size_t sfx_len = strlen(sfx);
> > > >
> > > > - if (sfx_len <= str_len)
> > > > - return strcmp(str + str_len - sfx_len, sfx);
> > > > - return false;
> > > > + if (sfx_len > str_len)
> > > > + return false;
> > > > + return strcmp(str + str_len - sfx_len, sfx) == 0;
> > > Please tag the subject with "bpf" next time.
> >
> > I always work against linux-next. Would it help if I put that in the
> > subject?
> >
> > Otherwise I don't have a way to figure this stuff out. I kind of know
> > networking tree but not 100% and that is a massive pain in the butt.
> > Until there is an automated way that then those kind of requests are
> > not reasonable.
>
> Dan,
>
> you were told multiple times to follow the rules.
> bpf patches should target bpf of bpf-next trees only.
> If you send against linux-next you're taking a random chance
> that they will pass CI.
> In turn making everyone waste time.
> Please follow the simple rules.
That's true. We have this discussion every time and I always tell you
that the rules are untenable. I'm just going to send bug reports to
whoever introduces bug and they can deal with it.
regards,
dan carpenter
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-19 9:53 [PATCH] libbpf: fix str_has_sfx() Dan Carpenter
2022-07-19 17:19 ` Martin KaFai Lau
@ 2022-07-21 13:00 ` patchwork-bot+netdevbpf
1 sibling, 0 replies; 9+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-07-21 13:00 UTC (permalink / raw)
To: Dan Carpenter
Cc: ast, alan.maguire, daniel, martin.lau, song, yhs, john.fastabend,
kpsingh, sdf, haoluo, jolsa, bpf, kernel-janitors
Hello:
This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:
On Tue, 19 Jul 2022 12:53:01 +0300 you wrote:
> The return from strcmp() is inverted so the it returns true instead
> of false and vise versa.
>
> Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> ---
> Spotted during review. *cmp() functions should always have a comparison
> to zero.
> if (strcmp(a, b) < 0) { <-- means a < b
> if (strcmp(a, b) >= 0) { <-- means a >= b
> if (strcmp(a, b) != 0) { <-- means a != b
> etc.
>
> [...]
Here is the summary with links:
- libbpf: fix str_has_sfx()
https://git.kernel.org/bpf/bpf-next/c/14229b8153a3
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH] libbpf: fix str_has_sfx()
2022-07-20 7:37 ` Alan Maguire
@ 2022-07-28 22:10 ` Andrii Nakryiko
0 siblings, 0 replies; 9+ messages in thread
From: Andrii Nakryiko @ 2022-07-28 22:10 UTC (permalink / raw)
To: Alan Maguire
Cc: Alexei Starovoitov, Martin KaFai Lau, Dan Carpenter,
Alexei Starovoitov, Daniel Borkmann, Martin KaFai Lau, Song Liu,
Yonghong Song, John Fastabend, KP Singh, Stanislav Fomichev,
Hao Luo, Jiri Olsa, bpf, kernel-janitors
On Wed, Jul 20, 2022 at 12:48 AM Alan Maguire <alan.maguire@oracle.com> wrote:
>
> On 19/07/2022 18:51, Alexei Starovoitov wrote:
> > On Tue, Jul 19, 2022 at 10:19 AM Martin KaFai Lau <kafai@fb.com> wrote:
> >>
> >> On Tue, Jul 19, 2022 at 12:53:01PM +0300, Dan Carpenter wrote:
> >>> The return from strcmp() is inverted so the it returns true instead
> >>> of false and vise versa.
> >>>
> >>> Fixes: a1c9d61b19cb ("libbpf: Improve library identification for uprobe binary path resolution")
> >>> Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
> >>> ---
> >>> Spotted during review. *cmp() functions should always have a comparison
> >>> to zero.
> >>> if (strcmp(a, b) < 0) { <-- means a < b
> >>> if (strcmp(a, b) >= 0) { <-- means a >= b
> >>> if (strcmp(a, b) != 0) { <-- means a != b
> >>> etc.
> >>>
> >>> tools/lib/bpf/libbpf_internal.h | 6 +++---
> >>> 1 file changed, 3 insertions(+), 3 deletions(-)
> >>>
> >>> diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
> >>> index 9cd7829cbe41..008485296a29 100644
> >>> --- a/tools/lib/bpf/libbpf_internal.h
> >>> +++ b/tools/lib/bpf/libbpf_internal.h
> >>> @@ -108,9 +108,9 @@ static inline bool str_has_sfx(const char *str, const char *sfx)
> >>> size_t str_len = strlen(str);
> >>> size_t sfx_len = strlen(sfx);
> >>>
> >>> - if (sfx_len <= str_len)
> >>> - return strcmp(str + str_len - sfx_len, sfx);
> >>> - return false;
> >>> + if (sfx_len > str_len)
> >>> + return false;
> >>> + return strcmp(str + str_len - sfx_len, sfx) == 0;
> >> Please tag the subject with "bpf" next time.
> >>
> >> Acked-by: Martin KaFai Lau <kafai@fb.com>
> >
> > Alan,
> >
> > If it was so broken how did it work earlier?
> > Do we have a test for this?
> >
>
> We have tests for automatic path determination, yes, but those
> tests specify libc.so.6, so are testing the strstr(file, ".so.")
> predicate below:
>
> if (str_has_sfx(file, ".so") || strstr(file, ".so.")) {
>
> Problem is, on many systems, libc.so is a GNU ld script rather
> than an actual library:
>
> cat /usr/lib64/libc.so
> /* GNU ld script
> Use the shared library, but some functions are only in
> the static library, so try that secondarily. */
> OUTPUT_FORMAT(elf64-x86-64)
> GROUP ( /lib64/libc.so.6 /usr/lib64/libc_nonshared.a AS_NEEDED ( /lib64/ld-linux-x86-64.so.2 ) )
>
> ...so we can't rely on system library .so files actually containing
> the library to instrument.
>
> Maybe we can do something with liburandom_read.so now we have it
> there; I was looking at extending the auto-path determination
> to usdt too, so we could add a new test to cover this then I think.
Library path resolution should already work for USDTs (note that I
reuse resolve_full_path() in bpf_program__attach_usdt()), but having
explicit tests would be great. It might be simplest to temporarily
override LD_LIBRARY_PATH with a path to liburandom_read.so? So please
consider sending a patch with tests, thanks!
>
> Alan
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2022-07-28 22:11 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-07-19 9:53 [PATCH] libbpf: fix str_has_sfx() Dan Carpenter
2022-07-19 17:19 ` Martin KaFai Lau
2022-07-19 17:50 ` Dan Carpenter
2022-07-19 17:54 ` Alexei Starovoitov
2022-07-20 9:11 ` Dan Carpenter
2022-07-19 17:51 ` Alexei Starovoitov
2022-07-20 7:37 ` Alan Maguire
2022-07-28 22:10 ` Andrii Nakryiko
2022-07-21 13:00 ` patchwork-bot+netdevbpf
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.