В ядре Linux устранена следующая уязвимость:
bpf: сохранить идентификатор регистра в sync_linked_regs()
sync_linked_regs() копирует идентификаторknown_reg в reg при распространении
границы известного_рега для регистрации с использованием отключения известного_рега, но когда
известный_рег был связан с регистром следующим образом:
известный_рег = рег; и известный_reg, и reg имеют одинаковый идентификатор
известный_рег += 4; известный_рег получает значение = 4, а его идентификатор получает BPF_ADD_CONST
теперь, когда происходит вызов sync_linked_regs(), скажем, следующим образом:
если известный_рег >= 10, перейдите на компьютер+2
новые границыknown_reg передаются в reg, но теперь reg получает
BPF_ADD_CONST из копии. Это означает, что если создается еще одна ссылка на reg, например:
другой_рег = рег; other_reg должен получить идентификатор reg, но
Assign_scalar_id_before_mov() видит
BPF_ADD_CONST в регистре и присваивает ему новый идентификатор. Поскольку у reg теперь новый идентификатор, ссылкаknown_reg на reg не работает.
Если мы найдем
новые границы дляknown_reg, они не будут распространяться на reg. Это можно увидеть в самотестировании, добавленном в следующий коммит:
0: (85) вызвать bpf_get_prandom_u32#7 ; R0=скаляр()
1: (57) r0 &= 255 ; R0=скаляр(smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff))
2: (бф) r1 = r0 ; R0=скаляр(id=1,smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) R1=скаляр(id=1,smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff))
3: (07) r1 += 4 ; R1=скаляр(id=1+4,smin=umin=smin32=umin32=4,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff))
4: (a5) если r1 < 0xa, переход к pc+4 ; R1=скаляр(id=1+4,smin=umin=smin32=umin32=10,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff))
5: (бф) r2 = r0 ; R0=скаляр(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=255) R2=скаляр(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=255)
6: (a5) если r1 < 0xe, переход к pc+2 ; R1=скаляр(id=1+4,smin=umin=smin32=umin32=14,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff))
7: (35) если r0 >= 0xa, переходим к pc+1 ; R0=скаляр(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=9,var_off=(0x0; 0xf))
8: (37) г0 /= 0
деление на ноль
Когда проверяется 4, границы r1 распространяются на r0, но r0 также получает
BPF_ADD_CONST (ошибка). Когда 5 проверено, r0 получает новый идентификатор (2), и его связь с r1 разрывается.
После 6 мы знаем, что r1 имеет границы [14, 259], и поэтому r0 должно иметь границы [10, 255], поэтому всегда выбирается ветвь в точке 7. Но потому что Идентификатор r0 был изменен на 2, новые границы r1 не распространяются на r0. Верификатор все еще считает, что r0 имеет границы [6, 255] до 7 и выполнение может достигать div на ноль.
Исправьте это, сохранив id в sync_linked_regs(), например off и subreg_def.
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: bpf: Preserve id of register in sync_linked_regs() sync_linked_regs() copies the id of known_reg to reg when propagating bounds of known_reg to reg using the off of known_reg, but when known_reg was linked to reg like: known_reg = reg ; both known_reg and reg get same id known_reg += 4 ; known_reg gets off = 4, and its id gets BPF_ADD_CONST now when a call to sync_linked_regs() happens, let's say with the following: if known_reg >= 10 goto pc+2 known_reg's new bounds are propagated to reg but now reg gets BPF_ADD_CONST from the copy. This means if another link to reg is created like: another_reg = reg ; another_reg should get the id of reg but assign_scalar_id_before_mov() sees BPF_ADD_CONST on reg and assigns a new id to it. As reg has a new id now, known_reg's link to reg is broken. If we find new bounds for known_reg, they will not be propagated to reg. This can be seen in the selftest added in the next commit: 0: (85) call bpf_get_prandom_u32#7 ; R0=scalar() 1: (57) r0 &= 255 ; R0=scalar(smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) 2: (bf) r1 = r0 ; R0=scalar(id=1,smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) R1=scalar(id=1,smin=smin32=0,smax=umax=smax32=umax32=255,var_off=(0x0; 0xff)) 3: (07) r1 += 4 ; R1=scalar(id=1+4,smin=umin=smin32=umin32=4,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff)) 4: (a5) if r1 < 0xa goto pc+4 ; R1=scalar(id=1+4,smin=umin=smin32=umin32=10,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff)) 5: (bf) r2 = r0 ; R0=scalar(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=255) R2=scalar(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=255) 6: (a5) if r1 < 0xe goto pc+2 ; R1=scalar(id=1+4,smin=umin=smin32=umin32=14,smax=umax=smax32=umax32=259,var_off=(0x0; 0x1ff)) 7: (35) if r0 >= 0xa goto pc+1 ; R0=scalar(id=2,smin=umin=smin32=umin32=6,smax=umax=smax32=umax32=9,var_off=(0x0; 0xf)) 8: (37) r0 /= 0 div by zero When 4 is verified, r1's bounds are propagated to r0 but r0 also gets BPF_ADD_CONST (bug). When 5 is verified, r0 gets a new id (2) and its link with r1 is broken. After 6 we know r1 has bounds [14, 259] and therefore r0 should have bounds [10, 255], therefore the branch at 7 is always taken. But because r0's id was changed to 2, r1's new bounds are not propagated to r0. The verifier still thinks r0 has bounds [6, 255] before 7 and execution can reach div by zero. Fix this by preserving id in sync_linked_regs() like off and subreg_def.
Характеристики атаки
Последствия
Строка CVSS v3.1
Тип уязвимости (CWE)
Уязвимые продукты 3
| Конфигурация | От (включительно) | До (исключительно) |
|---|---|---|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.11
|
6.12.75
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.13
|
6.18.14
|
|
Linux Linux_Kernel
cpe:2.3:o:linux:linux_kernel:*:*:*:*:*:*:*:*
|
6.19
|
6.19.4
|