В ядре Linux была устранена следующая уязвимость: csky: Восстановление Fix a4/a5 в пути трассировки syscall Путь трассировки syscall перезагружает аргументы syscall из pt_regs перед вызовом обработчика syscall. На C-SKY ABIv2 аргументы 5-го и 6-го сискэллов готовятся как аргументы стека перед вызовом сискэллидов. Текущий код корректирует sp перед загрузкой LSAVE_A4 и LSAVE_A5.
Поскольку эти смещения относятся к исходной базе pt_regs, загрузка их после изменения sp вызывает неправильные слоты. В результате отслеженные сискэллы, использующие 5-й или 6-й аргумент, могут получать искаженные аргументы. Это видно с помощью mmap2 (), который принимает шесть аргументов.
Маленький репродуцент PTRACE_SYSCALL открывает файл и отображает одну страницу с: mmap(NULL, 4096, PROT_READ PROT_EXEC, MAP_PRIVATE, fd, 0) Before исправление, отслеженный ребенок выходит из mmap и выходит с 12. После исправления сопоставление проходит успешно, и ребенок выходит с 0. Исправьте путь трассировки, загрузив a4/a5 из pt_regs перед изменением sp.
Испытано на: ck860f, linux-4.19.15, C-SKY abiv2
Показать оригинальное описание (EN)
In the Linux kernel, the following vulnerability has been resolved: csky: Fix a4/a5 restoration in syscall trace path The syscall trace path reloads syscall arguments from pt_regs before calling the syscall handler. On C-SKY ABIv2, the 5th and 6th syscall arguments are prepared as stack arguments before invoking syscallid. The current code adjusts sp before loading LSAVE_A4 and LSAVE_A5. Since those offsets are relative to the original pt_regs base, loading them after changing sp fetches the wrong slots. As a result, traced syscalls that use the 5th or 6th argument may receive corrupted arguments. This is visible with mmap2(), which takes six arguments. A small PTRACE_SYSCALL reproducer opens a file and maps one page with: mmap(NULL, 4096, PROT_READ | PROT_EXEC, MAP_PRIVATE, fd, 0) Before the fix, the traced child fails the mmap and exits with 12. After the fix, the mapping succeeds and the child exits with 0. Fix the trace path by loading a4/a5 from pt_regs before changing sp. Tested on: ck860f, linux-4.19.15, C-SKY abiv2