diff mbox series

[bpf-next] libbpf: poison strlcpy()

Message ID tencent_5695A257C4D16B4413036BA1DAACDECB0B07@qq.com (mailing list archive)
State Accepted
Commit 6d0c4b11e743b84eb57898783e9adecb9083b269
Delegated to: BPF
Headers show
Series [bpf-next] libbpf: poison strlcpy() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for bpf-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 12 of 12 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 10 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0
bpf/vmtest-bpf-next-VM_Test-10 success Logs for test_maps on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-12 success Logs for test_maps on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-13 success Logs for test_maps on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-14 success Logs for test_progs on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-15 success Logs for test_progs on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-17 fail Logs for test_progs on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-18 fail Logs for test_progs on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-19 success Logs for test_progs_no_alu32 on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-20 success Logs for test_progs_no_alu32 on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-22 fail Logs for test_progs_no_alu32 on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-23 fail Logs for test_progs_no_alu32 on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-24 success Logs for test_progs_no_alu32_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-25 success Logs for test_progs_no_alu32_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-26 success Logs for test_progs_no_alu32_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-27 success Logs for test_progs_no_alu32_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-28 success Logs for test_progs_no_alu32_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-29 success Logs for test_progs_parallel on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-30 success Logs for test_progs_parallel on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-32 success Logs for test_progs_parallel on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-33 success Logs for test_progs_parallel on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-34 success Logs for test_verifier on aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-35 success Logs for test_verifier on aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-36 success Logs for test_verifier on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-37 success Logs for test_verifier on x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-38 success Logs for test_verifier on x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-16 success Logs for test_progs on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-21 success Logs for test_progs_no_alu32 on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-31 success Logs for test_progs_parallel on s390x with gcc
bpf/vmtest-bpf-next-VM_Test-11 success Logs for test_maps on s390x with gcc
bpf/vmtest-bpf-next-PR fail PR summary
bpf/vmtest-bpf-next-VM_Test-1 success Logs for ${{ matrix.test }} on ${{ matrix.arch }} with ${{ matrix.toolchain }}
bpf/vmtest-bpf-next-VM_Test-2 success Logs for ShellCheck
bpf/vmtest-bpf-next-VM_Test-3 success Logs for build for aarch64 with gcc
bpf/vmtest-bpf-next-VM_Test-4 success Logs for build for aarch64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-5 fail Logs for build for s390x with gcc
bpf/vmtest-bpf-next-VM_Test-6 success Logs for build for x86_64 with gcc
bpf/vmtest-bpf-next-VM_Test-7 success Logs for build for x86_64 with llvm-16
bpf/vmtest-bpf-next-VM_Test-8 success Logs for llvm-toolchain
bpf/vmtest-bpf-next-VM_Test-9 success Logs for set-matrix

Commit Message

Rong Tao Jan. 5, 2023, 2:36 p.m. UTC
From: Rong Tao <rongtao@cestc.cn>

Since commit 9fc205b413b3("libbpf: Add sane strncpy alternative and use
it internally") introduce libbpf_strlcpy(), thus add strlcpy() to a poison
list to prevent accidental use of it.

Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
 tools/lib/bpf/libbpf_internal.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Comments

Stanislav Fomichev Jan. 5, 2023, 6:47 p.m. UTC | #1
On 01/05, Rong Tao wrote:
> From: Rong Tao <rongtao@cestc.cn>

> Since commit 9fc205b413b3("libbpf: Add sane strncpy alternative and use
> it internally") introduce libbpf_strlcpy(), thus add strlcpy() to a poison
> list to prevent accidental use of it.

> Signed-off-by: Rong Tao <rongtao@cestc.cn>

Acked-by: Stanislav Fomichev <sdf@google.com>

> ---
>   tools/lib/bpf/libbpf_internal.h | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)

> diff --git a/tools/lib/bpf/libbpf_internal.h  
> b/tools/lib/bpf/libbpf_internal.h
> index 377642ff51fc..2d26ded383ca 100644
> --- a/tools/lib/bpf/libbpf_internal.h
> +++ b/tools/lib/bpf/libbpf_internal.h
> @@ -20,8 +20,8 @@
>   /* make sure libbpf doesn't use kernel-only integer typedefs */
>   #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64

> -/* prevent accidental re-addition of reallocarray() */
> -#pragma GCC poison reallocarray
> +/* prevent accidental re-addition of reallocarray()/strlcpy() */
> +#pragma GCC poison reallocarray strlcpy

>   #include "libbpf.h"
>   #include "btf.h"
> --
> 2.39.0
patchwork-bot+netdevbpf@kernel.org Jan. 6, 2023, 4:10 p.m. UTC | #2
Hello:

This patch was applied to bpf/bpf-next.git (master)
by Daniel Borkmann <daniel@iogearbox.net>:

On Thu,  5 Jan 2023 22:36:33 +0800 you wrote:
> From: Rong Tao <rongtao@cestc.cn>
> 
> Since commit 9fc205b413b3("libbpf: Add sane strncpy alternative and use
> it internally") introduce libbpf_strlcpy(), thus add strlcpy() to a poison
> list to prevent accidental use of it.
> 
> Signed-off-by: Rong Tao <rongtao@cestc.cn>
> 
> [...]

Here is the summary with links:
  - [bpf-next] libbpf: poison strlcpy()
    https://git.kernel.org/bpf/bpf-next/c/6d0c4b11e743

You are awesome, thank you!
Boris Burkov March 9, 2023, 12:30 a.m. UTC | #3
On Thu, Jan 05, 2023 at 10:47:15AM -0800, sdf@google.com wrote:
> On 01/05, Rong Tao wrote:
> > From: Rong Tao <rongtao@cestc.cn>
> 
> > Since commit 9fc205b413b3("libbpf: Add sane strncpy alternative and use
> > it internally") introduce libbpf_strlcpy(), thus add strlcpy() to a poison
> > list to prevent accidental use of it.
> 
> > Signed-off-by: Rong Tao <rongtao@cestc.cn>
> 
> Acked-by: Stanislav Fomichev <sdf@google.com>
> 
> > ---
> >   tools/lib/bpf/libbpf_internal.h | 4 ++--
> >   1 file changed, 2 insertions(+), 2 deletions(-)
> 
> > diff --git a/tools/lib/bpf/libbpf_internal.h
> > b/tools/lib/bpf/libbpf_internal.h
> > index 377642ff51fc..2d26ded383ca 100644
> > --- a/tools/lib/bpf/libbpf_internal.h
> > +++ b/tools/lib/bpf/libbpf_internal.h
> > @@ -20,8 +20,8 @@
> >   /* make sure libbpf doesn't use kernel-only integer typedefs */
> >   #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
> 
> > -/* prevent accidental re-addition of reallocarray() */
> > -#pragma GCC poison reallocarray
> > +/* prevent accidental re-addition of reallocarray()/strlcpy() */
> > +#pragma GCC poison reallocarray strlcpy

On my musl system, I believe this broke compilation, as string.h defines
strlcpy, and is included after this poisoning when compiling strset.c

FWIW, I could work around it by adding
#include <string.h>
above
#include <libbpf_internal.h>
in strset.c, since the poison doesn't apply to symbols that existed
before it ran, but this feels like a kludge, and not in the spirit of
the original poisoning patch..

I'm curious what the proper workaround should be for a libc that defines
strlcpy.

Thanks,
Boris

> 
> >   #include "libbpf.h"
> >   #include "btf.h"
> > --
> > 2.39.0
>
Stanislav Fomichev March 9, 2023, 12:32 a.m. UTC | #4
On Wed, Mar 8, 2023 at 4:30 PM Boris Burkov <boris@bur.io> wrote:
>
> On Thu, Jan 05, 2023 at 10:47:15AM -0800, sdf@google.com wrote:
> > On 01/05, Rong Tao wrote:
> > > From: Rong Tao <rongtao@cestc.cn>
> >
> > > Since commit 9fc205b413b3("libbpf: Add sane strncpy alternative and use
> > > it internally") introduce libbpf_strlcpy(), thus add strlcpy() to a poison
> > > list to prevent accidental use of it.
> >
> > > Signed-off-by: Rong Tao <rongtao@cestc.cn>
> >
> > Acked-by: Stanislav Fomichev <sdf@google.com>
> >
> > > ---
> > >   tools/lib/bpf/libbpf_internal.h | 4 ++--
> > >   1 file changed, 2 insertions(+), 2 deletions(-)
> >
> > > diff --git a/tools/lib/bpf/libbpf_internal.h
> > > b/tools/lib/bpf/libbpf_internal.h
> > > index 377642ff51fc..2d26ded383ca 100644
> > > --- a/tools/lib/bpf/libbpf_internal.h
> > > +++ b/tools/lib/bpf/libbpf_internal.h
> > > @@ -20,8 +20,8 @@
> > >   /* make sure libbpf doesn't use kernel-only integer typedefs */
> > >   #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
> >
> > > -/* prevent accidental re-addition of reallocarray() */
> > > -#pragma GCC poison reallocarray
> > > +/* prevent accidental re-addition of reallocarray()/strlcpy() */
> > > +#pragma GCC poison reallocarray strlcpy
>
> On my musl system, I believe this broke compilation, as string.h defines
> strlcpy, and is included after this poisoning when compiling strset.c
>
> FWIW, I could work around it by adding
> #include <string.h>
> above
> #include <libbpf_internal.h>
> in strset.c, since the poison doesn't apply to symbols that existed
> before it ran, but this feels like a kludge, and not in the spirit of
> the original poisoning patch..
>
> I'm curious what the proper workaround should be for a libc that defines
> strlcpy.

Let's move this discussion into [0]? There is a similar issue for
uclibc it seems.

0: https://lore.kernel.org/bpf/CAKH8qBshq-J2H+Bo1xA=FzAJ6x_mo5yfW6oYjQ_u1QwLJ5CDog@mail.gmail.com/T/#t

> Thanks,
> Boris
>
> >
> > >   #include "libbpf.h"
> > >   #include "btf.h"
> > > --
> > > 2.39.0
> >
diff mbox series

Patch

diff --git a/tools/lib/bpf/libbpf_internal.h b/tools/lib/bpf/libbpf_internal.h
index 377642ff51fc..2d26ded383ca 100644
--- a/tools/lib/bpf/libbpf_internal.h
+++ b/tools/lib/bpf/libbpf_internal.h
@@ -20,8 +20,8 @@ 
 /* make sure libbpf doesn't use kernel-only integer typedefs */
 #pragma GCC poison u8 u16 u32 u64 s8 s16 s32 s64
 
-/* prevent accidental re-addition of reallocarray() */
-#pragma GCC poison reallocarray
+/* prevent accidental re-addition of reallocarray()/strlcpy() */
+#pragma GCC poison reallocarray strlcpy
 
 #include "libbpf.h"
 #include "btf.h"