[bpf-next] samples/bpf: xdp_router_ipv4_user: Fix write overflow

Message ID tencent_F9E2E81922B0C181D05B96DAE5AB0ACE6B06@qq.com
State New
Headers
Series [bpf-next] samples/bpf: xdp_router_ipv4_user: Fix write overflow |

Commit Message

Rong Tao Nov. 22, 2022, 2:32 a.m. UTC
  From: Rong Tao <rongtao@cestc.cn>

prefix_key->data allocates three bytes using alloca(), but four bytes are
accessed in the program.

Signed-off-by: Rong Tao <rongtao@cestc.cn>
---
 samples/bpf/xdp_router_ipv4_user.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
  

Comments

patchwork-bot+netdevbpf@kernel.org Nov. 24, 2022, 11:30 p.m. UTC | #1
Hello:

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

On Tue, 22 Nov 2022 10:32:56 +0800 you wrote:
> From: Rong Tao <rongtao@cestc.cn>
> 
> prefix_key->data allocates three bytes using alloca(), but four bytes are
> accessed in the program.
> 
> Signed-off-by: Rong Tao <rongtao@cestc.cn>
> 
> [...]

Here is the summary with links:
  - [bpf-next] samples/bpf: xdp_router_ipv4_user: Fix write overflow
    https://git.kernel.org/bpf/bpf-next/c/19a2bdbaaddc

You are awesome, thank you!
  

Patch

diff --git a/samples/bpf/xdp_router_ipv4_user.c b/samples/bpf/xdp_router_ipv4_user.c
index 683913bbf279..9d41db09c480 100644
--- a/samples/bpf/xdp_router_ipv4_user.c
+++ b/samples/bpf/xdp_router_ipv4_user.c
@@ -162,7 +162,7 @@  static void read_route(struct nlmsghdr *nh, int nll)
 				__be32 gw;
 			} *prefix_value;
 
-			prefix_key = alloca(sizeof(*prefix_key) + 3);
+			prefix_key = alloca(sizeof(*prefix_key) + 4);
 			prefix_value = alloca(sizeof(*prefix_value));
 
 			prefix_key->prefixlen = 32;