CVE-2026-139060: microblaze: don't clobber r3/r4 restored by rt_sigreturn
In the Linux kernel, the following vulnerability has been resolved:
microblaze: don't clobber r3/r4 restored by rtsigreturn
retfromtrap begins by storing the system call return values r3 and r4 back into the saved user ptregs. That is right for an ordinary system call, but sysrtsigreturn() returns through the same path and has to be transparent: restoresigcontext() has just filled ptregs from the signal frame, and every register must reach userspace exactly as saved. The two stores overwrite the restored r3/r4 with whatever the C function left in those registers.
Only r4 is actually lost, and that follows from how sigreturn is written everywhere rather than from chance. Architectures have sysrtsigreturn() return the restored return-value register precisely so that this writeback stores the restored value -- arm returns regs->ARMr0, riscv and csky regs->a0, arc regs->r0 -- and microblaze does the same through rvalp = regs->r3 in restoresigcontext(). But the entry macros treat r3 and r4 as a pair, so retfromtrap writes back two registers while a C function has only one return value; nothing carries the restored r4.
Commit 791d0a169b91 ("microblaze: Fix sysrtsigreturnwrapper") introduced this in v2.6.37. The old wrapper saved r3/r4 before the call and reloaded them from ptregs afterwards; switching brlid to brid removed the only point where they were reloaded, and the stores have been overwriting them ever since.
Fix it the way the sibling paths already behave: retfromirq and retfromexc restore the full register set and do not perform these stores at all. Label the instruction after the stores retfromtrapnorval and enter there, biasing r15 by -8 so that the ABI return "rtsd r15, 8" lands on it; naming the entry rather than computing retfromtrap + 8 keeps it correct if the number of stores ever changes. Restoring the old save/reload would work too, but costs four memory accesses and a branch to undo damage that is better not done.
Any value the compiler keeps in r4 across a signal is lost. The tightest windows are the lwx/swx compare-and-swap retry loops gcc emits for atomics: in uClibc-ng's libc.so alone, 50 of 364 such loops hold the address in r4. This is not specific to one libc -- musl passes the address as "r"(p), and glibc has no microblaze atomic-machine.h and so uses gcc's atomic builtins, which expand the same way. Triggering it needs threads plus a signal storm, which is why it survived 15 years.
Reproduced on qemu-system-microblazeel (petalogix-s3adsp1800) by running the uClibc-ng NPTL test tst-eintr1 40 times against an unchanged userspace: on v7.2 built with gcc 16.2.0, 23 of 40 iterations died with SIGSEGV without this patch and 0 of 40 with it; on v7.0 built with gcc 12.5.0 the same comparison gave 6 of 40 against 0 of 40. The register dump of a failing iteration shows the signature: a zero r4 and a fault at address 0, while r3 came back intact.
Affected Software
Remediation
Recommended actions to resolve this vulnerability, in priority order.
- Compensating control
Update the MicroBlaze rt_sigreturn return path to enter at ret_from_trap_no_rval, after the stores that overwrite r3/r4; bias r15 by -8 so the ABI return lands at that entry, and use brid instead of brlid to avoid clobbering the restored registers.
Event History
Frequently Asked Questions
Which systems are affected?
The issue affects Linux kernel systems running on the MicroBlaze architecture. It is relevant when a process returns from a signal handler through rt_sigreturn.
What state is corrupted when the issue is triggered?
The r4 register value restored from the signal frame can be overwritten before execution returns to userspace. The restored r3 value is preserved through the sigreturn return-value handling, but no equivalent mechanism carries the restored r4 value.