Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

alpha: unbreak osf_setsysinfo(SSI_NVPAIRS, [SSIN_UACPROC, UAC_SIGBUS])

The bug was accidentally found by the following program:

#include <asm/sysinfo.h>
#include <asm/unistd.h>
#include <sys/syscall.h>
static int setsysinfo(unsigned long op, void *buffer, unsigned long size,
int *start, void *arg, unsigned long flag) {
return syscall(__NR_osf_setsysinfo, op, buffer, size, start, arg, flag);
}

int main(int argc, char **argv) {
short x[10];
unsigned int buf[2] = { SSIN_UACPROC, UAC_SIGBUS, };
setsysinfo(SSI_NVPAIRS, buf, 1, 0, 0, 0);

int *y = (int*) (x+1);
*y = 0;
return 0;
}

The program shoud fail on SIGBUS, but didn't.

The patch is a second part of userspace flag fix (commit 745dd2405e28
"Alpha: Rearrange thread info flags fixing two regressions").

Deleted outdated out-of-sync 'UAC_SHIFT' (the cause of bug) in favour of
'ALPHA_UAC_SHIFT'.

[akpm@linux-foundation.org: coding-style fixes]
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
Acked-by: Michael Cree <mcree@orcon.net.nz>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>

authored by

Sergei Trofimovich and committed by
Linus Torvalds
2df7a7d1 06ed4625

+11 -18
-9
arch/alpha/include/asm/sysinfo.h
··· 27 27 #define UAC_NOFIX 2 28 28 #define UAC_SIGBUS 4 29 29 30 - 31 - #ifdef __KERNEL__ 32 - 33 - /* This is the shift that is applied to the UAC bits as stored in the 34 - per-thread flags. See thread_info.h. */ 35 - #define UAC_SHIFT 6 36 - 37 - #endif 38 - 39 30 #endif /* __ASM_ALPHA_SYSINFO_H */
+4 -4
arch/alpha/include/asm/thread_info.h
··· 74 74 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */ 75 75 #define TIF_POLLING_NRFLAG 8 /* poll_idle is polling NEED_RESCHED */ 76 76 #define TIF_DIE_IF_KERNEL 9 /* dik recursion lock */ 77 - #define TIF_UAC_NOPRINT 10 /* see sysinfo.h */ 78 - #define TIF_UAC_NOFIX 11 79 - #define TIF_UAC_SIGBUS 12 77 + #define TIF_UAC_NOPRINT 10 /* ! Preserve sequence of following */ 78 + #define TIF_UAC_NOFIX 11 /* ! flags as they match */ 79 + #define TIF_UAC_SIGBUS 12 /* ! userspace part of 'osf_sysinfo' */ 80 80 #define TIF_MEMDIE 13 /* is terminating due to OOM killer */ 81 81 #define TIF_RESTORE_SIGMASK 14 /* restore signal mask in do_signal */ 82 82 #define TIF_FREEZE 16 /* is freezing for suspend */ ··· 97 97 #define _TIF_ALLWORK_MASK (_TIF_WORK_MASK \ 98 98 | _TIF_SYSCALL_TRACE) 99 99 100 - #define ALPHA_UAC_SHIFT 10 100 + #define ALPHA_UAC_SHIFT TIF_UAC_NOPRINT 101 101 #define ALPHA_UAC_MASK (1 << TIF_UAC_NOPRINT | 1 << TIF_UAC_NOFIX | \ 102 102 1 << TIF_UAC_SIGBUS) 103 103
+7 -5
arch/alpha/kernel/osf_sys.c
··· 42 42 #include <asm/uaccess.h> 43 43 #include <asm/system.h> 44 44 #include <asm/sysinfo.h> 45 + #include <asm/thread_info.h> 45 46 #include <asm/hwrpb.h> 46 47 #include <asm/processor.h> 47 48 ··· 634 633 case GSI_UACPROC: 635 634 if (nbytes < sizeof(unsigned int)) 636 635 return -EINVAL; 637 - w = (current_thread_info()->flags >> UAC_SHIFT) & UAC_BITMASK; 638 - if (put_user(w, (unsigned int __user *)buffer)) 639 - return -EFAULT; 636 + w = (current_thread_info()->flags >> ALPHA_UAC_SHIFT) & 637 + UAC_BITMASK; 638 + if (put_user(w, (unsigned int __user *)buffer)) 639 + return -EFAULT; 640 640 return 1; 641 641 642 642 case GSI_PROC_TYPE: ··· 758 756 case SSIN_UACPROC: 759 757 again: 760 758 old = current_thread_info()->flags; 761 - new = old & ~(UAC_BITMASK << UAC_SHIFT); 762 - new = new | (w & UAC_BITMASK) << UAC_SHIFT; 759 + new = old & ~(UAC_BITMASK << ALPHA_UAC_SHIFT); 760 + new = new | (w & UAC_BITMASK) << ALPHA_UAC_SHIFT; 763 761 if (cmpxchg(&current_thread_info()->flags, 764 762 old, new) != old) 765 763 goto again;