blob: 2c0878ae833970d361e52176f04d5ad78631e811 [file] [log] [blame]
From: Daniel Borkmann <>
Date: Thu, 14 Jul 2016 13:57:55 +0200
Subject: bpf, mips: fix off-by-one in ctx offset allocation
commit b4e76f7e6d3200462c6354a6ad4ae167459e61f8 upstream.
Dan Carpenter reported [1] a static checker warning that ctx->offsets[]
may be accessed off by one from build_body(), since it's allocated with
fp->len * sizeof(*ctx.offsets) as length. The cBPF arm and ppc code
doesn't have this issue as claimed, so only mips seems to be affected and
should like most other JITs allocate with fp->len + 1. A few number of
JITs (x86, sparc, arm64) handle this differently, where they only require
fp->len array elements.
Fixes: c6610de353da ("MIPS: net: Add BPF JIT")
Reported-by: Dan Carpenter <>
Signed-off-by: Daniel Borkmann <>
Cc: Alexei Starovoitov <>
Signed-off-by: Ralf Baechle <>
Signed-off-by: Ben Hutchings <>
arch/mips/net/bpf_jit.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
--- a/arch/mips/net/bpf_jit.c
+++ b/arch/mips/net/bpf_jit.c
@@ -1365,7 +1365,7 @@ void bpf_jit_compile(struct sk_filter *f
memset(&ctx, 0, sizeof(ctx));
- ctx.offsets = kcalloc(fp->len, sizeof(*ctx.offsets), GFP_KERNEL);
+ ctx.offsets = kcalloc(fp->len + 1, sizeof(*ctx.offsets), GFP_KERNEL);
if (ctx.offsets == NULL)