From owner-svn-src-head@freebsd.org Sat Mar 18 20:16:25 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 32B70D12115; Sat, 18 Mar 2017 20:16:25 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id E7BC210DD; Sat, 18 Mar 2017 20:16:24 +0000 (UTC) (envelope-from vangyzen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v2IKGODf016113; Sat, 18 Mar 2017 20:16:24 GMT (envelope-from vangyzen@FreeBSD.org) Received: (from vangyzen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v2IKGNt3016110; Sat, 18 Mar 2017 20:16:23 GMT (envelope-from vangyzen@FreeBSD.org) Message-Id: <201703182016.v2IKGNt3016110@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: vangyzen set sender to vangyzen@FreeBSD.org using -f From: Eric van Gyzen Date: Sat, 18 Mar 2017 20:16:23 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r315510 - in head/sys: compat/freebsd32 compat/linux kern X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 18 Mar 2017 20:16:25 -0000 Author: vangyzen Date: Sat Mar 18 20:16:23 2017 New Revision: 315510 URL: https://svnweb.freebsd.org/changeset/base/315510 Log: nanosleep: plug a kernel memory disclosure nanosleep() updates rmtp on EINVAL. In that case, kern_nanosleep() has not updated rmt, so sys_nanosleep() updates the user-space rmtp by copying garbage from its stack frame. This is not only a kernel memory disclosure, it's also not POSIX-compliant. Fix it to update rmtp only on EINTR. Reviewed by: jilles (via D10020), dchagin MFC after: 3 days Security: possibly Sponsored by: Dell EMC Differential Revision: https://reviews.freebsd.org/D10044 Modified: head/sys/compat/freebsd32/freebsd32_misc.c head/sys/compat/linux/linux_time.c head/sys/kern/kern_time.c Modified: head/sys/compat/freebsd32/freebsd32_misc.c ============================================================================== --- head/sys/compat/freebsd32/freebsd32_misc.c Sat Mar 18 19:59:21 2017 (r315509) +++ head/sys/compat/freebsd32/freebsd32_misc.c Sat Mar 18 20:16:23 2017 (r315510) @@ -2241,7 +2241,7 @@ freebsd32_nanosleep(struct thread *td, s !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE)) return (EFAULT); error = kern_nanosleep(td, &rqt, &rmt); - if (error && uap->rmtp) { + if (error == EINTR && uap->rmtp) { int error2; CP(rmt, rmt32, tv_sec); Modified: head/sys/compat/linux/linux_time.c ============================================================================== --- head/sys/compat/linux/linux_time.c Sat Mar 18 19:59:21 2017 (r315509) +++ head/sys/compat/linux/linux_time.c Sat Mar 18 20:16:23 2017 (r315510) @@ -519,7 +519,7 @@ linux_nanosleep(struct thread *td, struc return (error); } error = kern_nanosleep(td, &rqts, rmtp); - if (args->rmtp != NULL) { + if (error == EINTR && args->rmtp != NULL) { error2 = native_to_linux_timespec(&lrmts, rmtp); if (error2 != 0) return (error2); @@ -583,7 +583,7 @@ linux_clock_nanosleep(struct thread *td, return (error); } error = kern_nanosleep(td, &rqts, rmtp); - if (args->rmtp != NULL) { + if (error == EINTR && args->rmtp != NULL) { /* XXX. Not for TIMER_ABSTIME */ error2 = native_to_linux_timespec(&lrmts, rmtp); if (error2 != 0) Modified: head/sys/kern/kern_time.c ============================================================================== --- head/sys/kern/kern_time.c Sat Mar 18 19:59:21 2017 (r315509) +++ head/sys/kern/kern_time.c Sat Mar 18 20:16:23 2017 (r315510) @@ -548,7 +548,7 @@ sys_nanosleep(struct thread *td, struct !useracc((caddr_t)uap->rmtp, sizeof(rmt), VM_PROT_WRITE)) return (EFAULT); error = kern_nanosleep(td, &rqt, &rmt); - if (error && uap->rmtp) { + if (error == EINTR && uap->rmtp) { int error2; error2 = copyout(&rmt, uap->rmtp, sizeof(rmt));