* [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime
@ 2024-03-14 14:25 syzbot
2024-03-23 21:22 ` [syzbot] [PATCH] fix " syzbot
` (5 more replies)
0 siblings, 6 replies; 7+ messages in thread
From: syzbot @ 2024-03-14 14:25 UTC (permalink / raw)
To: andrii, ast, bpf, daniel, eddyz87, haoluo, john.fastabend, jolsa,
kpsingh, linux-kernel, martin.lau, sdf, song, syzkaller-bugs,
yonghong.song
Hello,
syzbot found the following issue on:
HEAD commit: 9187210eee7d Merge tag 'net-next-6.9' of git://git.kernel...
git tree: upstream
console+strace: https://syzkaller.appspot.com/x/log.txt?x=1736a3da180000
kernel config: https://syzkaller.appspot.com/x/.config?x=222448ff79dba2ea
dashboard link: https://syzkaller.appspot.com/bug?extid=d2a2c639d03ac200a4f1
compiler: gcc (Debian 12.2.0-14) 12.2.0, GNU ld (GNU Binutils for Debian) 2.40
syz repro: https://syzkaller.appspot.com/x/repro.syz?x=16b3fdc1180000
C reproducer: https://syzkaller.appspot.com/x/repro.c?x=11201969180000
Downloadable assets:
disk image: https://storage.googleapis.com/syzbot-assets/98c1ea7ddb95/disk-9187210e.raw.xz
vmlinux: https://storage.googleapis.com/syzbot-assets/343c5524f68f/vmlinux-9187210e.xz
kernel image: https://storage.googleapis.com/syzbot-assets/6c0c68b0ee90/bzImage-9187210e.xz
The issue was bisected to:
commit 011832b97b311bb9e3c27945bc0d1089a14209c9
Author: Alexei Starovoitov <ast@kernel.org>
Date: Wed Mar 6 03:19:26 2024 +0000
bpf: Introduce may_goto instruction
bisection log: https://syzkaller.appspot.com/x/bisect.txt?x=115e578e180000
final oops: https://syzkaller.appspot.com/x/report.txt?x=135e578e180000
console output: https://syzkaller.appspot.com/x/log.txt?x=155e578e180000
IMPORTANT: if you fix the issue, please add the following tag to the commit:
Reported-by: syzbot+d2a2c639d03ac200a4f1@syzkaller.appspotmail.com
Fixes: 011832b97b31 ("bpf: Introduce may_goto instruction")
------------[ cut here ]------------
UBSAN: array-index-out-of-bounds in kernel/bpf/core.c:2349:29
index 16 is out of range for type '<unknown> *[16]'
CPU: 1 PID: 5060 Comm: syz-executor255 Not tainted 6.8.0-syzkaller-05202-g9187210eee7d #0
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 02/29/2024
Call Trace:
<TASK>
__dump_stack lib/dump_stack.c:88 [inline]
dump_stack_lvl+0x125/0x1b0 lib/dump_stack.c:106
ubsan_epilogue lib/ubsan.c:217 [inline]
__ubsan_handle_out_of_bounds+0x110/0x150 lib/ubsan.c:415
bpf_prog_select_func kernel/bpf/core.c:2349 [inline]
bpf_prog_select_runtime+0x5aa/0x640 kernel/bpf/core.c:2380
bpf_prog_load+0xf0f/0x2660 kernel/bpf/syscall.c:2899
__sys_bpf+0x9b4/0x4b40 kernel/bpf/syscall.c:5631
__do_sys_bpf kernel/bpf/syscall.c:5738 [inline]
__se_sys_bpf kernel/bpf/syscall.c:5736 [inline]
__x64_sys_bpf+0x78/0xc0 kernel/bpf/syscall.c:5736
do_syscall_x64 arch/x86/entry/common.c:52 [inline]
do_syscall_64+0xd2/0x260 arch/x86/entry/common.c:83
entry_SYSCALL_64_after_hwframe+0x6d/0x75
RIP: 0033:0x7fa2a0fe73e9
Code: 48 83 c4 28 c3 e8 37 17 00 00 0f 1f 80 00 00 00 00 48 89 f8 48 89 f7 48 89 d6 48 89 ca 4d 89 c2 4d 89 c8 4c 8b 4c 24 08 0f 05 <48> 3d 01 f0 ff ff 73 01 c3 48 c7 c1 b8 ff ff ff f7 d8 64 89 01 48
RSP: 002b:00007ffdd829a698 EFLAGS: 00000246 ORIG_RAX: 0000000000000141
RAX: ffffffffffffffda RBX: 00007ffdd829a878 RCX: 00007fa2a0fe73e9
RDX: 0000000000000048 RSI: 00000000200017c0 RDI: 0000000000000005
RBP: 00007fa2a105a610 R08: 0000000000000000 R09: 0000000000000000
R10: 00000000ffffffff R11: 0000000000000246 R12: 0000000000000001
R13: 00007ffdd829a868 R14: 0000000000000001 R15: 0000000000000001
</TASK>
---[ end trace ]---
---
This report is generated by a bot. It may contain errors.
See https://goo.gl/tpsmEJ for more information about syzbot.
syzbot engineers can be reached at syzkaller@googlegroups.com.
syzbot will keep track of this issue. See:
https://goo.gl/tpsmEJ#status for how to communicate with syzbot.
For information about bisection process see: https://goo.gl/tpsmEJ#bisection
If the report is already addressed, let syzbot know by replying with:
#syz fix: exact-commit-title
If you want syzbot to run the reproducer, reply with:
#syz test: git://repo/address.git branch-or-commit-hash
If you attach or paste a git patch, syzbot will apply it before testing.
If you want to overwrite report's subsystems, reply with:
#syz set subsystems: new-subsystem
(See the list of subsystem names on the web dashboard)
If the report is a duplicate of another one, reply with:
#syz dup: exact-subject-of-another-report
If you want to undo deduplication, reply with:
#syz undup
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [syzbot] [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
2024-03-14 14:25 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime syzbot
@ 2024-03-23 21:22 ` syzbot
2024-03-23 22:54 ` syzbot
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-03-23 21:22 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
Author: cam.alvarez.i@gmail.com
#syz test
BPF documentation specifies that the maximum stack depth for a BPF
program is 512 bytes. This is not enforced when selecting a bpf
interpreter, thus casuing an index out of bounds error when trying to
obtain an interpreter with a bigger stack size.
This patch enforces the stack size to be not bigger than
512.
Signed-off-by: Camila Alvarez <cam.alvarez.i@gmail.com>
---
kernel/bpf/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 696bc55de8e8..8167b3a721e9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2196,7 +2196,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
BUG_ON(1);
return 0;
}
-
+#define BPF_MAX_STACK_SIZE 512
#define PROG_NAME(stack_size) __bpf_prog_run##stack_size
#define DEFINE_BPF_PROG_RUN(stack_size) \
static unsigned int PROG_NAME(stack_size)(const void *ctx, const struct bpf_insn *insn) \
@@ -2345,7 +2345,7 @@ static void bpf_prog_select_func(struct bpf_prog *fp)
{
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1);
-
+ stack_depth = min_t(u32, stack_depth, BPF_MAX_STACK_SIZE);
fp->bpf_func = interpreters[(round_up(stack_depth, 32) / 32) - 1];
#else
fp->bpf_func = __bpf_prog_ret0_warn;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [syzbot] [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
2024-03-14 14:25 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime syzbot
2024-03-23 21:22 ` [syzbot] [PATCH] fix " syzbot
@ 2024-03-23 22:54 ` syzbot
2024-03-24 13:38 ` syzbot
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-03-23 22:54 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
Author: cam.alvarez.i@gmail.com
Please test the following
#syz test
BPF documentation specifies that the maximum stack depth for a BPF
program is 512 bytes. This is not enforced when selecting a bpf
interpreter, thus casuing an index out of bounds error when trying to
obtain an interpreter with a bigger stack size.
This patch enforces the stack size to be not bigger than
512.
Signed-off-by: Camila Alvarez <cam.alvarez.i@gmail.com>
---
kernel/bpf/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 696bc55de8e8..8167b3a721e9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2196,7 +2196,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
BUG_ON(1);
return 0;
}
-
+#define BPF_MAX_STACK_SIZE 512
#define PROG_NAME(stack_size) __bpf_prog_run##stack_size
#define DEFINE_BPF_PROG_RUN(stack_size) \
static unsigned int PROG_NAME(stack_size)(const void *ctx, const struct bpf_insn *insn) \
@@ -2345,7 +2345,7 @@ static void bpf_prog_select_func(struct bpf_prog *fp)
{
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1);
-
+ stack_depth = min_t(u32, stack_depth, BPF_MAX_STACK_SIZE);
fp->bpf_func = interpreters[(round_up(stack_depth, 32) / 32) - 1];
#else
fp->bpf_func = __bpf_prog_ret0_warn;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [syzbot] [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
2024-03-14 14:25 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime syzbot
2024-03-23 21:22 ` [syzbot] [PATCH] fix " syzbot
2024-03-23 22:54 ` syzbot
@ 2024-03-24 13:38 ` syzbot
2024-03-24 14:30 ` syzbot
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-03-24 13:38 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
Author: cam.alvarez.i@gmail.com
Please test the following
#syz test
BPF documentation specifies that the maximum stack depth for a BPF
program is 512 bytes. This is not enforced when selecting a bpf
interpreter, thus casuing an index out of bounds error when trying to
obtain an interpreter with a bigger stack size.
This patch enforces the stack size to be not bigger than
512.
Signed-off-by: Camila Alvarez <cam.alvarez.i@gmail.com>
---
kernel/bpf/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 696bc55de8e8..8167b3a721e9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2196,7 +2196,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
BUG_ON(1);
return 0;
}
-
+#define BPF_MAX_STACK_SIZE 512
#define PROG_NAME(stack_size) __bpf_prog_run##stack_size
#define DEFINE_BPF_PROG_RUN(stack_size) \
static unsigned int PROG_NAME(stack_size)(const void *ctx, const struct bpf_insn *insn) \
@@ -2345,7 +2345,7 @@ static void bpf_prog_select_func(struct bpf_prog *fp)
{
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1);
-
+ stack_depth = min_t(u32, stack_depth, BPF_MAX_STACK_SIZE);
fp->bpf_func = interpreters[(round_up(stack_depth, 32) / 32) - 1];
#else
fp->bpf_func = __bpf_prog_ret0_warn;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [syzbot] [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
2024-03-14 14:25 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime syzbot
` (2 preceding siblings ...)
2024-03-24 13:38 ` syzbot
@ 2024-03-24 14:30 ` syzbot
2024-03-24 23:12 ` syzbot
2024-05-05 0:03 ` syzbot
5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-03-24 14:30 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
Author: cam.alvarez.i@gmail.com
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git master
BPF documentation specifies that the maximum stack depth for a BPF
program is 512 bytes. This is not enforced when selecting a bpf
interpreter, thus casuing an index out of bounds error when trying to
obtain an interpreter with a bigger stack size.
This patch enforces the stack size to be not bigger than
512.
Signed-off-by: Camila Alvarez <cam.alvarez.i@gmail.com>
---
kernel/bpf/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 696bc55de8e8..8167b3a721e9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2196,7 +2196,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
BUG_ON(1);
return 0;
}
-
+#define BPF_MAX_STACK_SIZE 512
#define PROG_NAME(stack_size) __bpf_prog_run##stack_size
#define DEFINE_BPF_PROG_RUN(stack_size) \
static unsigned int PROG_NAME(stack_size)(const void *ctx, const struct bpf_insn *insn) \
@@ -2345,7 +2345,7 @@ static void bpf_prog_select_func(struct bpf_prog *fp)
{
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1);
-
+ stack_depth = min_t(u32, stack_depth, BPF_MAX_STACK_SIZE);
fp->bpf_func = interpreters[(round_up(stack_depth, 32) / 32) - 1];
#else
fp->bpf_func = __bpf_prog_ret0_warn;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [syzbot] [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
2024-03-14 14:25 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime syzbot
` (3 preceding siblings ...)
2024-03-24 14:30 ` syzbot
@ 2024-03-24 23:12 ` syzbot
2024-05-05 0:03 ` syzbot
5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-03-24 23:12 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
Author: cam.alvarez.i@gmail.com
Please test the following
#syz test https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 9187210eee7d
BPF documentation specifies that the maximum stack depth for a BPF
program is 512 bytes. This is not enforced when selecting a bpf
interpreter, thus casuing an index out of bounds error when trying to
obtain an interpreter with a bigger stack size.
This patch enforces the stack size to be not bigger than
512.
Signed-off-by: Camila Alvarez <cam.alvarez.i@gmail.com>
---
kernel/bpf/core.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/core.c b/kernel/bpf/core.c
index 696bc55de8e8..8167b3a721e9 100644
--- a/kernel/bpf/core.c
+++ b/kernel/bpf/core.c
@@ -2196,7 +2196,7 @@ static u64 ___bpf_prog_run(u64 *regs, const struct bpf_insn *insn)
BUG_ON(1);
return 0;
}
-
+#define BPF_MAX_STACK_SIZE 512
#define PROG_NAME(stack_size) __bpf_prog_run##stack_size
#define DEFINE_BPF_PROG_RUN(stack_size) \
static unsigned int PROG_NAME(stack_size)(const void *ctx, const struct bpf_insn *insn) \
@@ -2345,7 +2345,7 @@ static void bpf_prog_select_func(struct bpf_prog *fp)
{
#ifndef CONFIG_BPF_JIT_ALWAYS_ON
u32 stack_depth = max_t(u32, fp->aux->stack_depth, 1);
-
+ stack_depth = min_t(u32, stack_depth, BPF_MAX_STACK_SIZE);
fp->bpf_func = interpreters[(round_up(stack_depth, 32) / 32) - 1];
#else
fp->bpf_func = __bpf_prog_ret0_warn;
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [syzbot] [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
2024-03-14 14:25 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime syzbot
` (4 preceding siblings ...)
2024-03-24 23:12 ` syzbot
@ 2024-05-05 0:03 ` syzbot
5 siblings, 0 replies; 7+ messages in thread
From: syzbot @ 2024-05-05 0:03 UTC (permalink / raw)
To: linux-kernel
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org.
***
Subject: [PATCH] fix array-index-out-of-bounds in bpf_prog_select_runtime
Author: cam.alvarez.i@gmail.com
#syz test
The error indicates that the verifier is letting through a program with
a stack depth bigger than 512.
This is due to the verifier not checking the stack depth after
instruction rewrites are perfomed. For example, the MAY_GOTO instruction
adds 8 bytes to the stack, which means that if the stack at the moment
was already 512 bytes it would overflow after rewriting the instruction.
The fix involves adding a stack depth check after all instruction
rewrites are performed.
Reported-by: syzbot+d2a2c639d03ac200a4f1@syzkaller.appspotmail.com
Signed-off-by: Camila Alvarez <cam.alvarez.i@gmail.com>
---
kernel/bpf/verifier.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 63749ad5ac6b..a9e23b6b8e8f 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -21285,6 +21285,10 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr, __u3
if (ret == 0)
ret = do_misc_fixups(env);
+ /* max stack depth verification must be done after rewrites as well */
+ if (ret == 0)
+ ret = check_max_stack_depth(env);
+
/* do 32-bit optimization after insn patching has done so those patched
* insns could be handled correctly.
*/
--
2.34.1
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2024-05-05 0:03 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-03-14 14:25 [syzbot] [bpf?] UBSAN: array-index-out-of-bounds in bpf_prog_select_runtime syzbot
2024-03-23 21:22 ` [syzbot] [PATCH] fix " syzbot
2024-03-23 22:54 ` syzbot
2024-03-24 13:38 ` syzbot
2024-03-24 14:30 ` syzbot
2024-03-24 23:12 ` syzbot
2024-05-05 0:03 ` syzbot
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.