Repository navigation
sysctl: allow only log level and sync over serial SysRq - #2641
Conversation
A BREAK on the console line followed by any byte runs that byte as a SysRq key, and the kernel default enables every one. Hot-plugging a UART adapter makes exactly that. On a lab XM550 it fired an emergency thaw, which on the pre-4.9 kernels loops for ever (OpenIPC/linux#113) and took the camera off the network until it was power-cycled; a later boot of the same board took 96 framing errors and a BREAK from plugging an adapter in, and logged "SysRq : HELP" from the stray key. kernel.sysrq = 18 keeps log level (2) and sync (16). Everything else -- reboot, power-off, crash, kill-all, remount read-only, thaw -- is refused from the console. /proc/sysrq-trigger ignores the mask, so root on the camera can still run any of them. S02sysctl applies it early in boot; the kernel's own default can't be narrowed on these kernels, so the window before that remains.
PR Summary by QodoRestrict serial SysRq to log level and sync
AI Description
Diagram
High-Level Assessment
Files changed (1)
|
Code Review by Qodo
1.
|
rcS hands a failsafe boot to failsafe-rescue before any init script runs, so S02sysctl -- and with it the serial SysRq mask -- never ran there. A rescue session is when someone is attaching a UART adapter, whose BREAK and stray byte would run any SysRq key. Start S02sysctl first in its hand-written service list.
Problem
A serial BREAK followed by any byte runs that byte as a SysRq key, and the kernel default (
kernel.sysrq = 1) enables every key. Hot-plugging a UART adapter produces exactly that sequence.jstarted an emergency thaw. On every kernel before 4.9 that loops for ever (fixed in fs: thaw_bdev: report an unfrozen device, so SysRq-j cannot loop forever linux#113–[EV300] Free up space and remove currently not used sensor drivers #121). The console filled with "Emergency Thaw on mtdblock3" and the camera dropped off the network until it was power-cycled.SysRq : HELPfor the stray key.The same path can just as easily reboot, power off, crash, kill every process, or remount filesystems read-only, depending on which byte arrives.
Change
general/overlay/etc/sysctl.confgainskernel.sysrq = 18: log level (2) and sync (16) only. S02sysctl (Buildroot's busybox package) already applies this file early in boot.breboot,opower-off,ccrash,e/i/fkill tasks,uremount read-only,jthaw,nRT-nice, and the show-timers/show-locks keys. The dump keys (t,m,w,l,p) share the dump bit with crashcin these kernels, so allowing them would allow crash too./proc/sysrq-triggerignores the mask (write_sysrq_trigger()calls__handle_sysrq(c, false)), so root on the camera can still run any key.CONFIG_MAGIC_SYSRQ(hi3520dv200, gk710x boards) have nokernel.sysrqentry. Busyboxsysctl -plogs it as an unknown key and exits 0, the same as the existingnet.core.bpf_jit_enableline already does on boards without a BPF JIT.rcShands these tofailsafe-rescuebefore any init script runs, sofailsafe-rescuenow startsS02sysctlfirst in its own service list. A rescue session is when someone is likely to be attaching a UART. That path is untested here: it ships only on the failsafe families.SYSRQ_DEFAULT_ENABLE 1) and have no Kconfig option to change it.Hardware tested on
XM550 (XM530 die) + IMX335,
xm550_litenightly with kernel#6 SMP Sun Oct 18.This branch's
sysctl.confwas copied over/etc/sysctl.conf(overlay) and the camera rebooted. The overlay copy was removed afterwards. Not tested as a built image.Evidence
Before (stock image):
After (this branch's file, after a reboot):
(The
bpf_jit_enableerror predates this change.)Mask behaviour, QEMU
xm530machine, stock (unfixed) xm530 nightly kernel,init=/bin/sh, keys sent as serial BREAK + key:Checks:
ci-matrix.py --self-testok.STRICT=1 test_shell_parse.shclean.ci-matrix.py --stdinselects every board: "general/overlay/etc/sysctl.conf affects every board".Scope
general/package/all-patches/linux/(those go to OpenIPC/linux)general/overlay/or in a sharedload_<vendor>script hardcodes a value specific to my boardLD_PRELOAD, and no binaries that cannot be rebuilt from source