CVS commit: [netbsd-7] src/sys/compat/linux/common

2017-08-11 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Aug 12 04:50:31 UTC 2017

Modified Files:
src/sys/compat/linux/common [netbsd-7]: linux_time.c

Log Message:
Pull up following revision(s) (requested by mrg in ticket #1486):
sys/compat/linux/common/linux_time.c: revision 1.38-1.39 via patch
Only let the superuser set the compat_linux timezone.
Not really keen to invent a new kauth cookie for this useless purpose.
>From Ilja Van Sprundel.
--
Put suser check in the right function: settimeofday, not gettimeofday.
While here, remove wrong comment.
Noted by kre@.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.37.4.1 src/sys/compat/linux/common/linux_time.c

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

Modified files:

Index: src/sys/compat/linux/common/linux_time.c
diff -u src/sys/compat/linux/common/linux_time.c:1.37 src/sys/compat/linux/common/linux_time.c:1.37.4.1
--- src/sys/compat/linux/common/linux_time.c:1.37	Mon Jan 13 10:33:03 2014
+++ src/sys/compat/linux/common/linux_time.c	Sat Aug 12 04:50:31 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_time.c,v 1.37 2014/01/13 10:33:03 njoly Exp $ */
+/*	$NetBSD: linux_time.c,v 1.37.4.1 2017/08/12 04:50:31 snj Exp $ */
 
 /*-
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.37 2014/01/13 10:33:03 njoly Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_time.c,v 1.37.4.1 2017/08/12 04:50:31 snj Exp $");
 
 #include 
 #include 
@@ -102,11 +102,10 @@ linux_sys_settimeofday(struct lwp *l, co
 			return (error);
 	}
 
-	/*
-	 * If user is not the superuser, we returned
-	 * after the sys_settimeofday() call.
-	 */
 	if (SCARG(uap, tzp)) {
+		if (kauth_authorize_generic(kauth_cred_get(),
+			KAUTH_GENERIC_ISSUSER, NULL) != 0)
+			return (EPERM);
 		error = copyin(SCARG(uap, tzp), _sys_tz, sizeof(linux_sys_tz));
 		if (error)
 			return (error);



CVS commit: [netbsd-7] src/sys/compat/linux/common

2017-04-19 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Wed Apr 19 16:58:28 UTC 2017

Modified Files:
src/sys/compat/linux/common [netbsd-7]: linux_signal.h

Log Message:
Fix fallout from ticket #1354 by applying:
sys/compat/linux/common/linux_signal.h: revision 1.32
Provide a dummy linux_sigset_t for all architectures that do not have
any machdep one. This make kdump compile again.


To generate a diff of this commit:
cvs rdiff -u -r1.30.38.1 -r1.30.38.2 \
src/sys/compat/linux/common/linux_signal.h

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

Modified files:

Index: src/sys/compat/linux/common/linux_signal.h
diff -u src/sys/compat/linux/common/linux_signal.h:1.30.38.1 src/sys/compat/linux/common/linux_signal.h:1.30.38.2
--- src/sys/compat/linux/common/linux_signal.h:1.30.38.1	Mon Apr 17 05:19:09 2017
+++ src/sys/compat/linux/common/linux_signal.h	Wed Apr 19 16:58:28 2017
@@ -1,4 +1,4 @@
-/* 	$NetBSD: linux_signal.h,v 1.30.38.1 2017/04/17 05:19:09 snj Exp $	*/
+/* 	$NetBSD: linux_signal.h,v 1.30.38.2 2017/04/19 16:58:28 snj Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998 The NetBSD Foundation, Inc.
@@ -46,6 +46,8 @@
 #include 
 #elif defined(__amd64__)
 #include 
+#else
+typedef void linux_sigset_t;
 #endif
 
 typedef struct {



CVS commit: [netbsd-7] src/sys/compat/linux/arch

2017-04-16 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Mon Apr 17 05:23:01 UTC 2017

Modified Files:
src/sys/compat/linux/arch/alpha [netbsd-7]: linux_syscall.h
linux_syscallargs.h linux_syscalls.c linux_sysent.c
src/sys/compat/linux/arch/amd64 [netbsd-7]: linux_syscall.h
linux_syscallargs.h linux_syscalls.c linux_sysent.c
src/sys/compat/linux/arch/arm [netbsd-7]: linux_syscall.h
linux_syscallargs.h linux_syscalls.c linux_sysent.c
src/sys/compat/linux/arch/i386 [netbsd-7]: linux_syscall.h
linux_syscallargs.h linux_syscalls.c linux_sysent.c
src/sys/compat/linux/arch/m68k [netbsd-7]: linux_syscall.h
linux_syscallargs.h linux_syscalls.c linux_sysent.c
src/sys/compat/linux/arch/mips [netbsd-7]: linux_syscall.h
linux_syscallargs.h linux_syscalls.c linux_sysent.c
src/sys/compat/linux/arch/powerpc [netbsd-7]: linux_syscall.h
linux_syscallargs.h linux_syscalls.c linux_sysent.c

Log Message:
regen for ticket 1354


To generate a diff of this commit:
cvs rdiff -u -r1.94 -r1.94.2.1 \
src/sys/compat/linux/arch/alpha/linux_syscall.h \
src/sys/compat/linux/arch/alpha/linux_sysent.c
cvs rdiff -u -r1.93 -r1.93.2.1 \
src/sys/compat/linux/arch/alpha/linux_syscallargs.h
cvs rdiff -u -r1.95 -r1.95.2.1 \
src/sys/compat/linux/arch/alpha/linux_syscalls.c
cvs rdiff -u -r1.54 -r1.54.2.1 \
src/sys/compat/linux/arch/amd64/linux_syscall.h \
src/sys/compat/linux/arch/amd64/linux_syscallargs.h \
src/sys/compat/linux/arch/amd64/linux_syscalls.c \
src/sys/compat/linux/arch/amd64/linux_sysent.c
cvs rdiff -u -r1.64 -r1.64.2.1 src/sys/compat/linux/arch/arm/linux_syscall.h \
src/sys/compat/linux/arch/arm/linux_syscallargs.h \
src/sys/compat/linux/arch/arm/linux_syscalls.c \
src/sys/compat/linux/arch/arm/linux_sysent.c
cvs rdiff -u -r1.103 -r1.103.2.1 \
src/sys/compat/linux/arch/i386/linux_syscall.h \
src/sys/compat/linux/arch/i386/linux_syscallargs.h \
src/sys/compat/linux/arch/i386/linux_sysent.c
cvs rdiff -u -r1.104 -r1.104.2.1 \
src/sys/compat/linux/arch/i386/linux_syscalls.c
cvs rdiff -u -r1.94 -r1.94.2.1 src/sys/compat/linux/arch/m68k/linux_syscall.h \
src/sys/compat/linux/arch/m68k/linux_syscalls.c \
src/sys/compat/linux/arch/m68k/linux_sysent.c
cvs rdiff -u -r1.93 -r1.93.2.1 \
src/sys/compat/linux/arch/m68k/linux_syscallargs.h
cvs rdiff -u -r1.61 -r1.61.2.1 src/sys/compat/linux/arch/mips/linux_syscall.h
cvs rdiff -u -r1.60 -r1.60.2.1 \
src/sys/compat/linux/arch/mips/linux_syscallargs.h \
src/sys/compat/linux/arch/mips/linux_syscalls.c \
src/sys/compat/linux/arch/mips/linux_sysent.c
cvs rdiff -u -r1.70 -r1.70.2.1 \
src/sys/compat/linux/arch/powerpc/linux_syscall.h \
src/sys/compat/linux/arch/powerpc/linux_sysent.c
cvs rdiff -u -r1.69 -r1.69.2.1 \
src/sys/compat/linux/arch/powerpc/linux_syscallargs.h \
src/sys/compat/linux/arch/powerpc/linux_syscalls.c

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

Modified files:

Index: src/sys/compat/linux/arch/alpha/linux_syscall.h
diff -u src/sys/compat/linux/arch/alpha/linux_syscall.h:1.94 src/sys/compat/linux/arch/alpha/linux_syscall.h:1.94.2.1
--- src/sys/compat/linux/arch/alpha/linux_syscall.h:1.94	Thu May 29 10:36:31 2014
+++ src/sys/compat/linux/arch/alpha/linux_syscall.h	Mon Apr 17 05:23:00 2017
@@ -1,10 +1,10 @@
-/* $NetBSD: linux_syscall.h,v 1.94 2014/05/29 10:36:31 njoly Exp $ */
+/* $NetBSD: linux_syscall.h,v 1.94.2.1 2017/04/17 05:23:00 snj Exp $ */
 
 /*
  * System call numbers.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.88 2014/05/29 10:35:26 njoly Exp
+ * created from	NetBSD: syscalls.master,v 1.88.2.1 2017/04/17 05:19:09 snj Exp
  */
 
 #ifndef _LINUX_SYS_SYSCALL_H_
@@ -639,6 +639,9 @@
 /* syscall: "faccessat" ret: "int" args: "int" "const char *" "int" */
 #define	LINUX_SYS_faccessat	462
 
+/* syscall: "pselect6" ret: "int" args: "int" "fd_set *" "fd_set *" "fd_set *" "struct linux_timespec *" "linux_sized_sigset_t *" */
+#define	LINUX_SYS_pselect6	463
+
 /* syscall: "ppoll" ret: "int" args: "struct pollfd *" "int" "struct linux_timespec *" "linux_sigset_t *" */
 #define	LINUX_SYS_ppoll	464
 
Index: src/sys/compat/linux/arch/alpha/linux_sysent.c
diff -u src/sys/compat/linux/arch/alpha/linux_sysent.c:1.94 src/sys/compat/linux/arch/alpha/linux_sysent.c:1.94.2.1
--- src/sys/compat/linux/arch/alpha/linux_sysent.c:1.94	Thu May 29 10:36:31 2014
+++ src/sys/compat/linux/arch/alpha/linux_sysent.c	Mon Apr 17 05:23:00 2017
@@ -1,14 +1,14 @@
-/* $NetBSD: linux_sysent.c,v 1.94 2014/05/29 10:36:31 njoly Exp $ */
+/* $NetBSD: linux_sysent.c,v 1.94.2.1 2017/04/17 05:23:00 snj Exp $ */
 
 /*
  * System call switch table.
  *
  * DO NOT EDIT-- this file is automatically generated.
- * created from	NetBSD: syscalls.master,v 1.88 

CVS commit: [netbsd-7] src/sys/compat/linux

2017-04-16 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Mon Apr 17 05:19:09 UTC 2017

Modified Files:
src/sys/compat/linux/arch/alpha [netbsd-7]: syscalls.master
src/sys/compat/linux/arch/amd64 [netbsd-7]: syscalls.master
src/sys/compat/linux/arch/arm [netbsd-7]: syscalls.master
src/sys/compat/linux/arch/i386 [netbsd-7]: syscalls.master
src/sys/compat/linux/arch/m68k [netbsd-7]: syscalls.master
src/sys/compat/linux/arch/mips [netbsd-7]: syscalls.master
src/sys/compat/linux/arch/powerpc [netbsd-7]: syscalls.master
src/sys/compat/linux/common [netbsd-7]: linux_misc.c linux_signal.h

Log Message:
Pull up following revision(s) (requested by manu in ticket #1354):
sys/compat/linux/arch/alpha/syscalls.master: revision 1.92 via patch
sys/compat/linux/arch/amd64/syscalls.master: revision 1.58 via patch
sys/compat/linux/arch/arm/syscalls.master: revision 1.65 via patch
sys/compat/linux/arch/i386/syscalls.master: revision 1.122 via patch
sys/compat/linux/arch/m68k/syscalls.master: revision 1.91 via patch
sys/compat/linux/arch/mips/syscalls.master: revision 1.61 via patch
sys/compat/linux/arch/powerpc/syscalls.master: revision 1.70 via patch
sys/compat/linux/common/linux_misc.c: revision 1.234
sys/compat/linux/common/linux_signal.h: revision 1.31
Add pselect6 Linux system call.
This lets Matlab R2016A run on NetBSD/amd64


To generate a diff of this commit:
cvs rdiff -u -r1.88 -r1.88.2.1 \
src/sys/compat/linux/arch/alpha/syscalls.master
cvs rdiff -u -r1.52 -r1.52.2.1 \
src/sys/compat/linux/arch/amd64/syscalls.master
cvs rdiff -u -r1.61 -r1.61.2.1 src/sys/compat/linux/arch/arm/syscalls.master
cvs rdiff -u -r1.118 -r1.118.2.1 \
src/sys/compat/linux/arch/i386/syscalls.master
cvs rdiff -u -r1.88 -r1.88.2.1 src/sys/compat/linux/arch/m68k/syscalls.master
cvs rdiff -u -r1.56 -r1.56.2.1 src/sys/compat/linux/arch/mips/syscalls.master
cvs rdiff -u -r1.65 -r1.65.2.1 \
src/sys/compat/linux/arch/powerpc/syscalls.master
cvs rdiff -u -r1.229 -r1.229.2.1 src/sys/compat/linux/common/linux_misc.c
cvs rdiff -u -r1.30 -r1.30.38.1 src/sys/compat/linux/common/linux_signal.h

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

Modified files:

Index: src/sys/compat/linux/arch/alpha/syscalls.master
diff -u src/sys/compat/linux/arch/alpha/syscalls.master:1.88 src/sys/compat/linux/arch/alpha/syscalls.master:1.88.2.1
--- src/sys/compat/linux/arch/alpha/syscalls.master:1.88	Thu May 29 10:35:26 2014
+++ src/sys/compat/linux/arch/alpha/syscalls.master	Mon Apr 17 05:19:09 2017
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.88 2014/05/29 10:35:26 njoly Exp $
+	$NetBSD: syscalls.master,v 1.88.2.1 2017/04/17 05:19:09 snj Exp $
 ;
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -728,7 +728,10 @@
 			linux_umode_t mode); }
 462	STD		{ int|linux_sys||faccessat(int fd, const char *path, \
 			int amode); }
-463	UNIMPL		pselect6
+463	STD		{ int|linux_sys||pselect6(int nfds, fd_set *readfds, \
+			fd_set *writefds, fd_set *exceptfds, \
+			struct linux_timespec *timeout, \
+			linux_sized_sigset_t *ss); }
 464	STD		{ int|linux_sys||ppoll(struct pollfd *fds, int nfds, \
 			struct linux_timespec *timeout, \
 			linux_sigset_t *sigset); }

Index: src/sys/compat/linux/arch/amd64/syscalls.master
diff -u src/sys/compat/linux/arch/amd64/syscalls.master:1.52 src/sys/compat/linux/arch/amd64/syscalls.master:1.52.2.1
--- src/sys/compat/linux/arch/amd64/syscalls.master:1.52	Sat May 31 08:51:19 2014
+++ src/sys/compat/linux/arch/amd64/syscalls.master	Mon Apr 17 05:19:09 2017
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.52 2014/05/31 08:51:19 njoly Exp $
+	$NetBSD: syscalls.master,v 1.52.2.1 2017/04/17 05:19:09 snj Exp $
 
 ;	@(#)syscalls.master	8.1 (Berkeley) 7/19/93
 
@@ -489,7 +489,10 @@
 			linux_umode_t mode); }
 269	STD		{ int|linux_sys||faccessat(int fd, const char *path, \
 			int amode); }
-270	UNIMPL		pselect6
+270	STD		{ int|linux_sys||pselect6(int nfds, fd_set *readfds, \
+			fd_set *writefds, fd_set *exceptfds, \
+			struct linux_timespec *timeout, \
+			linux_sized_sigset_t *ss); }
 271	STD		{ int|linux_sys||ppoll(struct pollfd *fds, int nfds, \
 			struct linux_timespec *timeout, \
 			linux_sigset_t *sigset); }

Index: src/sys/compat/linux/arch/arm/syscalls.master
diff -u src/sys/compat/linux/arch/arm/syscalls.master:1.61 src/sys/compat/linux/arch/arm/syscalls.master:1.61.2.1
--- src/sys/compat/linux/arch/arm/syscalls.master:1.61	Sat May 31 08:51:19 2014
+++ src/sys/compat/linux/arch/arm/syscalls.master	Mon Apr 17 05:19:09 2017
@@ -1,4 +1,4 @@
-	$NetBSD: syscalls.master,v 1.61 2014/05/31 08:51:19 njoly Exp $
+	$NetBSD: syscalls.master,v 1.61.2.1 2017/04/17 05:19:09 snj Exp $
 
 ; Derived from sys/compat/linux/arch/*/syscalls.master
 ; and from Linux 2.4.12 arch/arm/kernel/calls.S
@@ 

CVS commit: [netbsd-7] src/sys/compat/linux/arch/amd64

2017-02-14 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Feb 14 16:54:25 UTC 2017

Modified Files:
src/sys/compat/linux/arch/amd64 [netbsd-7]: linux_machdep.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #1359):
sys/compat/linux/arch/amd64/linux_machdep.c: revisions 1.50, 1.51
Don't let userland choose %rip. This is the Intel Sysret vulnerability
again.
--
Make sure %rip is in userland. This is harmless, since the return to
userland is made with iret instead of sysret in this path. While here, use
size_t.


To generate a diff of this commit:
cvs rdiff -u -r1.48 -r1.48.4.1 \
src/sys/compat/linux/arch/amd64/linux_machdep.c

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

Modified files:

Index: src/sys/compat/linux/arch/amd64/linux_machdep.c
diff -u src/sys/compat/linux/arch/amd64/linux_machdep.c:1.48 src/sys/compat/linux/arch/amd64/linux_machdep.c:1.48.4.1
--- src/sys/compat/linux/arch/amd64/linux_machdep.c:1.48	Wed Feb 19 20:50:56 2014
+++ src/sys/compat/linux/arch/amd64/linux_machdep.c	Tue Feb 14 16:54:24 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_machdep.c,v 1.48 2014/02/19 20:50:56 dsl Exp $ */
+/*	$NetBSD: linux_machdep.c,v 1.48.4.1 2017/02/14 16:54:24 snj Exp $ */
 
 /*-
  * Copyright (c) 2005 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include 
 
-__KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.48 2014/02/19 20:50:56 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_machdep.c,v 1.48.4.1 2017/02/14 16:54:24 snj Exp $");
 
 #include 
 #include 
@@ -230,7 +230,12 @@ linux_sendsig(const ksiginfo_t *ksi, con
 	if (error != 0) {
 		sigexit(l, SIGILL);
 		return;
-	}	
+	}
+
+	if ((vaddr_t)catcher >= VM_MAXUSER_ADDRESS) {
+		sigexit(l, SIGILL);
+		return;
+	}
 
 	linux_buildcontext(l, catcher, sp);
 	tf->tf_rdi = sigframe.info.lsi_signo;
@@ -448,7 +453,7 @@ linux_usertrap(struct lwp *l, vaddr_t tr
 {
 	struct trapframe *tf = arg;
 	uint64_t retaddr;
-	int vsyscallnr;
+	size_t vsyscallnr;
 
 	/*
 	 * Check for a vsyscall. %rip must be the fault address,
@@ -478,6 +483,8 @@ linux_usertrap(struct lwp *l, vaddr_t tr
 	 */
 	if (copyin((void *)tf->tf_rsp, , sizeof retaddr) != 0)
 		return 0;
+	if ((vaddr_t)retaddr >= VM_MAXUSER_ADDRESS)
+		return 0;
 	tf->tf_rip = retaddr;
 	tf->tf_rax = linux_vsyscall_to_syscall[vsyscallnr];
 	tf->tf_rsp += 8;	/* "pop" the return address */



CVS commit: [netbsd-7] src/sys/compat/linux/common

2016-12-30 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Sat Dec 31 07:38:31 UTC 2016

Modified Files:
src/sys/compat/linux/common [netbsd-7]: linux_sched.c

Log Message:
Pull up following revision(s) (requested by rin in ticket #1343):
sys/compat/linux/common/linux_sched.c: revision 1.68
PR/50021: Rin Okuyama: Fix linux affinity syscalls


To generate a diff of this commit:
cvs rdiff -u -r1.66.4.1 -r1.66.4.2 src/sys/compat/linux/common/linux_sched.c

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

Modified files:

Index: src/sys/compat/linux/common/linux_sched.c
diff -u src/sys/compat/linux/common/linux_sched.c:1.66.4.1 src/sys/compat/linux/common/linux_sched.c:1.66.4.2
--- src/sys/compat/linux/common/linux_sched.c:1.66.4.1	Sat Jan 17 12:10:54 2015
+++ src/sys/compat/linux/common/linux_sched.c	Sat Dec 31 07:38:31 2016
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_sched.c,v 1.66.4.1 2015/01/17 12:10:54 martin Exp $	*/
+/*	$NetBSD: linux_sched.c,v 1.66.4.2 2016/12/31 07:38:31 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.66.4.1 2015/01/17 12:10:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_sched.c,v 1.66.4.2 2016/12/31 07:38:31 snj Exp $");
 
 #include 
 #include 
@@ -65,6 +65,9 @@ __KERNEL_RCSID(0, "$NetBSD: linux_sched.
 static int linux_clone_nptl(struct lwp *, const struct linux_sys_clone_args *,
 register_t *);
 
+/* Unlike Linux, dynamically calculate CPU mask size */
+#define	LINUX_CPU_MASK_SIZE (sizeof(long) * ((ncpu + LONG_BIT - 1) / LONG_BIT))
+
 #if DEBUG_LINUX
 #define DPRINTF(x) uprintf x
 #else
@@ -627,6 +630,10 @@ linux_sys_gettid(struct lwp *l, const vo
 	return 0;
 }
 
+/*
+ * The affinity syscalls assume that the layout of our cpu kcpuset is
+ * the same as linux's: a linear bitmask.
+ */
 int
 linux_sys_sched_getaffinity(struct lwp *l, const struct linux_sys_sched_getaffinity_args *uap, register_t *retval)
 {
@@ -635,39 +642,45 @@ linux_sys_sched_getaffinity(struct lwp *
 		syscallarg(unsigned int) len;
 		syscallarg(unsigned long *) mask;
 	} */
-	proc_t *p;
-	unsigned long *lp, *data;
-	int error, size, nb = ncpu;
+	struct lwp *t;
+	kcpuset_t *kcset;
+	size_t size;
+	cpuid_t i;
+	int error;
 
-	/* Unlike Linux, dynamically calculate cpu mask size */
-	size = sizeof(long) * ((ncpu + LONG_BIT - 1) / LONG_BIT);
+	size = LINUX_CPU_MASK_SIZE;
 	if (SCARG(uap, len) < size)
 		return EINVAL;
 
-	/* XXX: Pointless check.  TODO: Actually implement this. */
-	mutex_enter(proc_lock);
-	p = proc_find(SCARG(uap, pid));
-	mutex_exit(proc_lock);
-	if (p == NULL) {
+	/* Lock the LWP */
+	t = lwp_find2(SCARG(uap, pid), l->l_lid);
+	if (t == NULL)
 		return ESRCH;
-	}
-
-	/* 
-	 * return the actual number of CPU, tag all of them as available 
-	 * The result is a mask, the first CPU being in the least significant
-	 * bit.
-	 */
-	data = kmem_zalloc(size, KM_SLEEP);
-	lp = data;
-	while (nb > LONG_BIT) {
-		*lp++ = ~0UL;
-		nb -= LONG_BIT;
-	}
-	if (nb)
-		*lp = (1 << ncpu) - 1;
 
-	error = copyout(data, SCARG(uap, mask), size);
-	kmem_free(data, size);
+	/* Check the permission */
+	if (kauth_authorize_process(l->l_cred,
+	KAUTH_PROCESS_SCHEDULER_GETAFFINITY, t->l_proc, NULL, NULL, NULL)) {
+		mutex_exit(t->l_proc->p_lock);
+		return EPERM;
+	}
+
+	kcpuset_create(, true);
+	lwp_lock(t);
+	if (t->l_affinity != NULL)
+		kcpuset_copy(kcset, t->l_affinity);
+	else {
+		/*
+		 * All available CPUs should be masked when affinity has not
+		 * been set.
+		 */
+		kcpuset_zero(kcset);
+		for (i = 0; i < ncpu; i++)
+			kcpuset_set(kcset, i);
+	}
+	lwp_unlock(t);
+	mutex_exit(t->l_proc->p_lock);
+	error = kcpuset_copyout(kcset, (cpuset_t *)SCARG(uap, mask), size);
+	kcpuset_unuse(kcset, NULL);
 	*retval = size;
 	return error;
 }
@@ -680,17 +693,17 @@ linux_sys_sched_setaffinity(struct lwp *
 		syscallarg(unsigned int) len;
 		syscallarg(unsigned long *) mask;
 	} */
-	proc_t *p;
+	struct sys__sched_setaffinity_args ssa;
+	size_t size;
 
-	/* XXX: Pointless check.  TODO: Actually implement this. */
-	mutex_enter(proc_lock);
-	p = proc_find(SCARG(uap, pid));
-	mutex_exit(proc_lock);
-	if (p == NULL) {
-		return ESRCH;
-	}
+	size = LINUX_CPU_MASK_SIZE;
+	if (SCARG(uap, len) < size)
+		return EINVAL;
 
-	/* Let's ignore it */
-	DPRINTF(("%s\n", __func__));
-	return 0;
+	SCARG(, pid) = SCARG(uap, pid);
+	SCARG(, lid) = l->l_lid;
+	SCARG(, size) = size;
+	SCARG(, cpuset) = (cpuset_t *)SCARG(uap, mask);
+
+	return sys__sched_setaffinity(l, , retval);
 }



CVS commit: [netbsd-7] src/sys/compat/linux/arch

2015-11-05 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Thu Nov  5 09:24:47 UTC 2015

Modified Files:
src/sys/compat/linux/arch/arm [netbsd-7]: linux_ptrace.c
src/sys/compat/linux/arch/i386 [netbsd-7]: linux_ptrace.c
src/sys/compat/linux/arch/powerpc [netbsd-7]: linux_ptrace.c

Log Message:
Pull up following revision(s) (requested by pgoyette in ticket #998):
sys/compat/linux/arch/arm/linux_ptrace.c: revision 1.19
sys/compat/linux/arch/i386/linux_ptrace.c: revision 1.31
sys/compat/linux/arch/powerpc/linux_ptrace.c: revision 1.29
Don't release proc_lock until we're done looking at things that are
protected by the lock, particularly p_stat and p_waited.  Found by
Robert Elz.


To generate a diff of this commit:
cvs rdiff -u -r1.17.14.1 -r1.17.14.2 \
src/sys/compat/linux/arch/arm/linux_ptrace.c
cvs rdiff -u -r1.28.2.2 -r1.28.2.3 \
src/sys/compat/linux/arch/i386/linux_ptrace.c
cvs rdiff -u -r1.25.2.2 -r1.25.2.3 \
src/sys/compat/linux/arch/powerpc/linux_ptrace.c

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

Modified files:

Index: src/sys/compat/linux/arch/arm/linux_ptrace.c
diff -u src/sys/compat/linux/arch/arm/linux_ptrace.c:1.17.14.1 src/sys/compat/linux/arch/arm/linux_ptrace.c:1.17.14.2
--- src/sys/compat/linux/arch/arm/linux_ptrace.c:1.17.14.1	Sat Jan 17 12:10:55 2015
+++ src/sys/compat/linux/arch/arm/linux_ptrace.c	Thu Nov  5 09:24:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ptrace.c,v 1.17.14.1 2015/01/17 12:10:55 martin Exp $	*/
+/*	$NetBSD: linux_ptrace.c,v 1.17.14.2 2015/11/05 09:24:47 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.17.14.1 2015/01/17 12:10:55 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.17.14.2 2015/11/05 09:24:47 snj Exp $");
 
 #include 
 #include 
@@ -140,7 +140,6 @@ linux_sys_ptrace_arch(struct lwp *l, con
 		goto out;
 	}
 	mutex_enter(t->p_lock);
-	mutex_exit(proc_lock);
 
 	/*
 	 * You cannot do what you want to the process if:
@@ -148,6 +147,7 @@ linux_sys_ptrace_arch(struct lwp *l, con
 	 */
 	if (!ISSET(t->p_slflag, PSL_TRACED)) {
 		mutex_exit(t->p_lock);
+		mutex_exit(proc_lock);
 		error = EPERM;
 		goto out;
 	}
@@ -160,9 +160,11 @@ linux_sys_ptrace_arch(struct lwp *l, con
 	if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p ||
 	t->p_stat != SSTOP || !t->p_waited) {
 		mutex_exit(t->p_lock);
+		mutex_exit(proc_lock);
 		error = EBUSY;
 		goto out;
 	}
+	mutex_exit(proc_lock);
 	/* XXX: ptrace needs revamp for multi-threading support. */
 	if (t->p_nlwps > 1) {
 		mutex_exit(t->p_lock);

Index: src/sys/compat/linux/arch/i386/linux_ptrace.c
diff -u src/sys/compat/linux/arch/i386/linux_ptrace.c:1.28.2.2 src/sys/compat/linux/arch/i386/linux_ptrace.c:1.28.2.3
--- src/sys/compat/linux/arch/i386/linux_ptrace.c:1.28.2.2	Sat Jan 17 12:10:53 2015
+++ src/sys/compat/linux/arch/i386/linux_ptrace.c	Thu Nov  5 09:24:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ptrace.c,v 1.28.2.2 2015/01/17 12:10:53 martin Exp $	*/
+/*	$NetBSD: linux_ptrace.c,v 1.28.2.3 2015/11/05 09:24:47 snj Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.28.2.2 2015/01/17 12:10:53 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.28.2.3 2015/11/05 09:24:47 snj Exp $");
 
 #include 
 #include 
@@ -185,7 +185,6 @@ linux_sys_ptrace_arch(struct lwp *l, con
 		goto out;
 	}
 	mutex_enter(t->p_lock);
-	mutex_exit(proc_lock);
 
 	/*
 	 * You cannot do what you want to the process if:
@@ -193,6 +192,7 @@ linux_sys_ptrace_arch(struct lwp *l, con
 	 */
 	if (!ISSET(t->p_slflag, PSL_TRACED)) {
 		mutex_exit(t->p_lock);
+		mutex_exit(proc_lock);
 		error = EPERM;
 		goto out;
 	}
@@ -205,9 +205,11 @@ linux_sys_ptrace_arch(struct lwp *l, con
 	if (ISSET(t->p_slflag, PSL_FSTRACE) || t->p_pptr != p ||
 	t->p_stat != SSTOP || !t->p_waited) {
 		mutex_exit(t->p_lock);
+		mutex_exit(proc_lock);
 		error = EBUSY;
 		goto out;
 	}
+	mutex_exit(proc_lock);
 	/* XXX: ptrace needs revamp for multi-threading support. */
 	if (t->p_nlwps > 1) {
 		mutex_exit(t->p_lock);

Index: src/sys/compat/linux/arch/powerpc/linux_ptrace.c
diff -u src/sys/compat/linux/arch/powerpc/linux_ptrace.c:1.25.2.2 src/sys/compat/linux/arch/powerpc/linux_ptrace.c:1.25.2.3
--- src/sys/compat/linux/arch/powerpc/linux_ptrace.c:1.25.2.2	Sat Jan 17 12:10:56 2015
+++ src/sys/compat/linux/arch/powerpc/linux_ptrace.c	Thu Nov  5 09:24:47 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ptrace.c,v 1.25.2.2 2015/01/17 12:10:56 martin Exp $ */
+/*	$NetBSD: linux_ptrace.c,v 1.25.2.3 2015/11/05 09:24:47 snj Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include 
-__KERNEL_RCSID(0, "$NetBSD: linux_ptrace.c,v 1.25.2.2 2015/01/17 12:10:56 martin Exp $");

CVS commit: [netbsd-7] src/sys/compat/linux/arch

2014-10-30 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Thu Oct 30 11:51:18 UTC 2014

Modified Files:
src/sys/compat/linux/arch/i386 [netbsd-7]: linux_ptrace.c
src/sys/compat/linux/arch/powerpc [netbsd-7]: linux_ptrace.c

Log Message:
Pull up following revision(s) (requested by maxv in ticket #163):
sys/compat/linux/arch/i386/linux_ptrace.c: revision 1.29
sys/compat/linux/arch/powerpc/linux_ptrace.c: revision 1.26
sys/compat/linux/arch/powerpc/linux_ptrace.c: revision 1.27
Fix four memory leaks in compat/linux.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.28.2.1 src/sys/compat/linux/arch/i386/linux_ptrace.c
cvs rdiff -u -r1.25 -r1.25.2.1 \
src/sys/compat/linux/arch/powerpc/linux_ptrace.c

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

Modified files:

Index: src/sys/compat/linux/arch/i386/linux_ptrace.c
diff -u src/sys/compat/linux/arch/i386/linux_ptrace.c:1.28 src/sys/compat/linux/arch/i386/linux_ptrace.c:1.28.2.1
--- src/sys/compat/linux/arch/i386/linux_ptrace.c:1.28	Tue Apr 15 17:53:09 2014
+++ src/sys/compat/linux/arch/i386/linux_ptrace.c	Thu Oct 30 11:51:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ptrace.c,v 1.28 2014/04/15 17:53:09 maxv Exp $	*/
+/*	$NetBSD: linux_ptrace.c,v 1.28.2.1 2014/10/30 11:51:18 martin Exp $	*/
 
 /*-
  * Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: linux_ptrace.c,v 1.28 2014/04/15 17:53:09 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: linux_ptrace.c,v 1.28.2.1 2014/10/30 11:51:18 martin Exp $);
 
 #include sys/param.h
 #include sys/malloc.h
@@ -182,7 +182,8 @@ linux_sys_ptrace_arch(struct lwp *l, con
 	mutex_enter(proc_lock);
 	if ((t = proc_find(SCARG(uap, pid))) == NULL) {
 		mutex_exit(proc_lock);
-		return ESRCH;
+		error = ESRCH;
+		goto out;
 	}
 	mutex_enter(t-p_lock);
 	mutex_exit(proc_lock);

Index: src/sys/compat/linux/arch/powerpc/linux_ptrace.c
diff -u src/sys/compat/linux/arch/powerpc/linux_ptrace.c:1.25 src/sys/compat/linux/arch/powerpc/linux_ptrace.c:1.25.2.1
--- src/sys/compat/linux/arch/powerpc/linux_ptrace.c:1.25	Tue Apr 15 17:53:09 2014
+++ src/sys/compat/linux/arch/powerpc/linux_ptrace.c	Thu Oct 30 11:51:18 2014
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_ptrace.c,v 1.25 2014/04/15 17:53:09 maxv Exp $ */
+/*	$NetBSD: linux_ptrace.c,v 1.25.2.1 2014/10/30 11:51:18 martin Exp $ */
 
 /*-
  * Copyright (c) 1999, 2001 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: linux_ptrace.c,v 1.25 2014/04/15 17:53:09 maxv Exp $);
+__KERNEL_RCSID(0, $NetBSD: linux_ptrace.c,v 1.25.2.1 2014/10/30 11:51:18 martin Exp $);
 
 #include sys/param.h
 #include sys/malloc.h
@@ -159,7 +159,8 @@ linux_sys_ptrace_arch(struct lwp *l, con
 	mutex_enter(proc_lock);
 	if ((t = proc_find(SCARG(uap, pid))) == NULL) {
 		mutex_exit(proc_lock);
-		return ESRCH;
+		error = ESRCH;
+		goto out;
 	}
 	mutex_enter(t-p_lock);
 	mutex_exit(proc_lock);