Skip to content

Conversation

kernel-patches-bot
Copy link

Pull request for series with
subject: bpf: Replace strncpy() with strscpy()
version: 2
url: https://patchwork.kernel.org/project/netdevbpf/list/?series=620253

@kernel-patches-bot
Copy link
Author

Master branch: 7df5072
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=620253
version: 2

@kernel-patches-bot
Copy link
Author

Master branch: d59e3cb
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=620253
version: 2

@kernel-patches-bot kernel-patches-bot force-pushed the series/620253=>bpf-next branch from 5dd73b2 to c73c935 Compare March 5, 2022 17:40
@kernel-patches-bot
Copy link
Author

Master branch: caec549
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=620253
version: 2

@kernel-patches-bot kernel-patches-bot force-pushed the series/620253=>bpf-next branch from c73c935 to 3076646 Compare March 5, 2022 17:50
@kernel-patches-bot
Copy link
Author

Master branch: 401af75
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=620253
version: 2

@kernel-patches-bot kernel-patches-bot force-pushed the series/620253=>bpf-next branch from 3076646 to 17a563c Compare March 5, 2022 23:40
@kernel-patches-bot
Copy link
Author

Master branch: c344b9f
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=620253
version: 2

@kernel-patches-bot kernel-patches-bot force-pushed the series/620253=>bpf-next branch from 17a563c to 998c164 Compare March 6, 2022 02:52
Nobody and others added 2 commits March 7, 2022 22:08
Using strncpy() on NUL-terminated strings is considered deprecated[1].
Moreover, if the length of 'task->comm' is less than the destination buffer
size, strncpy() will NUL-pad the destination buffer, which is a needless
performance penalty.

Replacing strncpy() with strscpy() fixes all these issues.

[1] https://www.kernel.org/doc/html/latest/process/deprecated.html#strncpy-on-nul-terminated-strings

Signed-off-by: Yuntao Wang <[email protected]>
Acked-by: Yonghong Song <[email protected]>
@kernel-patches-bot
Copy link
Author

Master branch: 9c6e6a8
series: https://patchwork.kernel.org/project/netdevbpf/list/?series=620253
version: 2

@kernel-patches-bot kernel-patches-bot force-pushed the series/620253=>bpf-next branch from 998c164 to 9c844dc Compare March 8, 2022 06:08
@kernel-patches-bot
Copy link
Author

At least one diff in series https://patchwork.kernel.org/project/netdevbpf/list/?series=620253 irrelevant now. Closing PR.

@kernel-patches-bot kernel-patches-bot deleted the series/620253=>bpf-next branch March 8, 2022 06:16
kernel-patches-bot pushed a commit that referenced this pull request Mar 19, 2022
Test case to check if BPF_F_PROG_NO_CHARGE valid.
The result as follows,
 $ ./test_progs
 ...
 #103 no_charge:OK
 ...

Signed-off-by: Yafang Shao <[email protected]>
kernel-patches-bot pushed a commit that referenced this pull request Mar 19, 2022
Test case to check if BPF_F_PROG_NO_CHARGE valid.
The result as follows,
 $ ./test_progs
 ...
 #103 no_charge:OK
 ...

Signed-off-by: Yafang Shao <[email protected]>
kernel-patches-bot pushed a commit that referenced this pull request Apr 20, 2022
…lwt hook

xmit_check_hhlen() observes the dst for getting the device hard header
length to make sure a modified packet can fit. When a helper which changes
the dst - such as bpf_skb_set_tunnel_key() - is called as part of the xmit
program the accessed dst is no longer valid.

This leads to the following splat:

 BUG: kernel NULL pointer dereference, address: 00000000000000de
 #PF: supervisor read access in kernel mode
 #PF: error_code(0x0000) - not-present page
 PGD 0 P4D 0
 Oops: 0000 [#1] PREEMPT SMP PTI
 CPU: 0 PID: 798 Comm: ping Not tainted 5.18.0-rc2+ #103
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
 RIP: 0010:bpf_xmit+0xfb/0x17f
 Code: c6 c0 4d cd 8e 48 c7 c7 7d 33 f0 8e e8 42 09 fb ff 48 8b 45 58 48 8b 95 c8 00 00 00 48 2b 95 c0 00 00 00 48 83 e0 fe 48 8b 00 <0f> b7 80 de 00 00 00 39 c2 73 22 29 d0 b9 20 0a 00 00 31 d2 48 89
 RSP: 0018:ffffb148c0bc7b98 EFLAGS: 00010282
 RAX: 0000000000000000 RBX: 0000000000240008 RCX: 0000000000000000
 RDX: 0000000000000010 RSI: 00000000ffffffea RDI: 00000000ffffffff
 RBP: ffff922a828a4e00 R08: ffffffff8f1350e8 R09: 00000000ffffdfff
 R10: ffffffff8f055100 R11: ffffffff8f105100 R12: 0000000000000000
 R13: ffff922a828a4e00 R14: 0000000000000040 R15: 0000000000000000
 FS:  00007f414e8f0080(0000) GS:ffff922afdc00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 00000000000000de CR3: 0000000002d80006 CR4: 0000000000370ef0
 Call Trace:
  <TASK>
  lwtunnel_xmit.cold+0x71/0xc8
  ip_finish_output2+0x279/0x520
  ? __ip_finish_output.part.0+0x21/0x130

Fix by fetching the device hard header length before running the bpf code.

Cc: [email protected]
Fixes: commit 3a0af8f ("bpf: BPF for lightweight tunnel infrastructure")
Signed-off-by: Eyal Birger <[email protected]>
kernel-patches-bot pushed a commit that referenced this pull request Apr 22, 2022
… lwt hook

xmit_check_hhlen() observes the dst for getting the device hard header
length to make sure a modified packet can fit. When a helper which changes
the dst - such as bpf_skb_set_tunnel_key() - is called as part of the
xmit program the accessed dst is no longer valid.

This leads to the following splat:

 BUG: kernel NULL pointer dereference, address: 00000000000000de
 #PF: supervisor read access in kernel mode
 #PF: error_code(0x0000) - not-present page
 PGD 0 P4D 0
 Oops: 0000 [#1] PREEMPT SMP PTI
 CPU: 0 PID: 798 Comm: ping Not tainted 5.18.0-rc2+ #103
 Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.14.0-2 04/01/2014
 RIP: 0010:bpf_xmit+0xfb/0x17f
 Code: c6 c0 4d cd 8e 48 c7 c7 7d 33 f0 8e e8 42 09 fb ff 48 8b 45 58 48 8b 95 c8 00 00 00 48 2b 95 c0 00 00 00 48 83 e0 fe 48 8b 00 <0f> b7 80 de 00 00 00 39 c2 73 22 29 d0 b9 20 0a 00 00 31 d2 48 89
 RSP: 0018:ffffb148c0bc7b98 EFLAGS: 00010282
 RAX: 0000000000000000 RBX: 0000000000240008 RCX: 0000000000000000
 RDX: 0000000000000010 RSI: 00000000ffffffea RDI: 00000000ffffffff
 RBP: ffff922a828a4e00 R08: ffffffff8f1350e8 R09: 00000000ffffdfff
 R10: ffffffff8f055100 R11: ffffffff8f105100 R12: 0000000000000000
 R13: ffff922a828a4e00 R14: 0000000000000040 R15: 0000000000000000
 FS:  00007f414e8f0080(0000) GS:ffff922afdc00000(0000) knlGS:0000000000000000
 CS:  0010 DS: 0000 ES: 0000 CR0: 0000000080050033
 CR2: 00000000000000de CR3: 0000000002d80006 CR4: 0000000000370ef0
 Call Trace:
  <TASK>
  lwtunnel_xmit.cold+0x71/0xc8
  ip_finish_output2+0x279/0x520
  ? __ip_finish_output.part.0+0x21/0x130

Fix by fetching the device hard header length before running the BPF code.

Fixes: 3a0af8f ("bpf: BPF for lightweight tunnel infrastructure")
Signed-off-by: Eyal Birger <[email protected]>
Signed-off-by: Daniel Borkmann <[email protected]>
Link: https://lore.kernel.org/bpf/[email protected]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants