Source-Changes archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

CVS commit: src/sys



Module Name:    src
Committed By:   tls
Date:           Sun May 10 23:51:38 UTC 2026

Modified Files:
        src/sys/arch/alpha/alpha: syscall.c
        src/sys/arch/mips/mips: syscall.c
        src/sys/arch/riscv/riscv: syscall.c
        src/sys/kern: init_sysent.c makesyscalls.sh syscalls.c
            syscalls_autoload.c systrace_args.c
        src/sys/rump/include/rump: rump_syscalls.h
        src/sys/rump/librump/rumpkern: rump_syscalls.c
        src/sys/sys: syscall.h syscallargs.h systm.h

Log Message:
Fix a longstanding bug on 64 bit ports with ABIs requiring sign-extension when returning 32-bit values in registers.  Alpha, MIPS N64, RISCV.

With these ABIs it is necessary for the syscall return code to manually
sign-extend all 32-bit return values.  If we don't, everything may look
just fine, until a syscall return value is spilled to the stack and then
reloaded.  At that point, the zero-extended form produced by C assignment
into the 64-bit register for return to userspace will be sign-extended
upon reload, producing a different, corrupt value which will fail comparisons.
This was observed with a getuid() != geteuid() deep inside sshd on N64, on an
unusual system that had some very large UIDs with bit 31 set - but is quite
difficult to reproduce with small tests, since register pressure and compiler
behavior determine whether the conditions necessary to trigger the bug will
exist.

The easiest way to see whether a new target needs this treatment is to
look at its GCC configuratrion; if its PROMOTE_MODE has UNSIGNEDP = 0
for SImode, the sign-extension in syscall() is necessary.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/sys/arch/alpha/alpha/syscall.c
cvs rdiff -u -r1.51 -r1.52 src/sys/arch/mips/mips/syscall.c
cvs rdiff -u -r1.6 -r1.7 src/sys/arch/riscv/riscv/syscall.c
cvs rdiff -u -r1.346 -r1.347 src/sys/kern/init_sysent.c
cvs rdiff -u -r1.188 -r1.189 src/sys/kern/makesyscalls.sh
cvs rdiff -u -r1.334 -r1.335 src/sys/kern/syscalls.c
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/syscalls_autoload.c
cvs rdiff -u -r1.56 -r1.57 src/sys/kern/systrace_args.c
cvs rdiff -u -r1.133 -r1.134 src/sys/rump/include/rump/rump_syscalls.h
cvs rdiff -u -r1.165 -r1.166 src/sys/rump/librump/rumpkern/rump_syscalls.c
cvs rdiff -u -r1.329 -r1.330 src/sys/sys/syscall.h
cvs rdiff -u -r1.312 -r1.313 src/sys/sys/syscallargs.h
cvs rdiff -u -r1.306 -r1.307 src/sys/sys/systm.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.




Home | Main Index | Thread Index | Old Index