From owner-svn-src-head@freebsd.org Sun Feb 26 09:40:43 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 A395ECEBBB2; Sun, 26 Feb 2017 09:40:43 +0000 (UTC) (envelope-from dchagin@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 61E52E6; Sun, 26 Feb 2017 09:40:43 +0000 (UTC) (envelope-from dchagin@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v1Q9egQ7029311; Sun, 26 Feb 2017 09:40:42 GMT (envelope-from dchagin@FreeBSD.org) Received: (from dchagin@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v1Q9egOq029307; Sun, 26 Feb 2017 09:40:42 GMT (envelope-from dchagin@FreeBSD.org) Message-Id: <201702260940.v1Q9egOq029307@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: dchagin set sender to dchagin@FreeBSD.org using -f From: Dmitry Chagin Date: Sun, 26 Feb 2017 09:40:42 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314293 - head/sys/compat/linux 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: Sun, 26 Feb 2017 09:40:43 -0000 Author: dchagin Date: Sun Feb 26 09:40:42 2017 New Revision: 314293 URL: https://svnweb.freebsd.org/changeset/base/314293 Log: Return EOVERFLOW error in case then the size of tv_sec field of struct timespec in COMPAT_LINUX32 Linuxulator's not equal to the size of native tv_sec. MFC after: 1 month Modified: head/sys/compat/linux/linux_misc.c head/sys/compat/linux/linux_time.c head/sys/compat/linux/linux_timer.h Modified: head/sys/compat/linux/linux_misc.c ============================================================================== --- head/sys/compat/linux/linux_misc.c Sun Feb 26 09:37:25 2017 (r314292) +++ head/sys/compat/linux/linux_misc.c Sun Feb 26 09:40:42 2017 (r314293) @@ -2290,8 +2290,9 @@ linux_pselect6(struct thread *td, struct TIMEVAL_TO_TIMESPEC(&utv, &uts); - native_to_linux_timespec(<s, &uts); - error = copyout(<s, args->tsp, sizeof(lts)); + error = native_to_linux_timespec(<s, &uts); + if (error == 0) + error = copyout(<s, args->tsp, sizeof(lts)); } return (error); @@ -2343,8 +2344,9 @@ linux_ppoll(struct thread *td, struct li } else timespecclear(&uts); - native_to_linux_timespec(<s, &uts); - error = copyout(<s, args->tsp, sizeof(lts)); + error = native_to_linux_timespec(<s, &uts); + if (error == 0) + error = copyout(<s, args->tsp, sizeof(lts)); } return (error); @@ -2438,7 +2440,9 @@ linux_sched_rr_get_interval(struct threa PROC_UNLOCK(tdt->td_proc); if (error != 0) return (error); - native_to_linux_timespec(<s, &ts); + error = native_to_linux_timespec(<s, &ts); + if (error != 0) + return (error); return (copyout(<s, uap->interval, sizeof(lts))); } Modified: head/sys/compat/linux/linux_time.c ============================================================================== --- head/sys/compat/linux/linux_time.c Sun Feb 26 09:37:25 2017 (r314292) +++ head/sys/compat/linux/linux_time.c Sun Feb 26 09:40:42 2017 (r314293) @@ -41,6 +41,7 @@ __KERNEL_RCSID(0, "$NetBSD: linux_time.c #include #include #include +#include #include #include #include @@ -118,16 +119,21 @@ LIN_SDT_PROBE_DEFINE1(time, linux_clock_ LIN_SDT_PROBE_DEFINE1(time, linux_clock_nanosleep, return, "int"); -void +int native_to_linux_timespec(struct l_timespec *ltp, struct timespec *ntp) { LIN_SDT_PROBE2(time, native_to_linux_timespec, entry, ltp, ntp); - +#ifdef COMPAT_LINUX32 + if (ntp->tv_sec > INT_MAX && + sizeof(ltp->tv_sec) != sizeof(ntp->tv_sec)) + return (EOVERFLOW); +#endif ltp->tv_sec = ntp->tv_sec; ltp->tv_nsec = ntp->tv_nsec; LIN_SDT_PROBE0(time, native_to_linux_timespec, return); + return (0); } int @@ -322,8 +328,9 @@ linux_clock_gettime(struct thread *td, s LIN_SDT_PROBE1(time, linux_clock_gettime, return, error); return (error); } - native_to_linux_timespec(<s, &tp); - + error = native_to_linux_timespec(<s, &tp); + if (error != 0) + return (error); error = copyout(<s, args->tp, sizeof lts); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_gettime, copyout_error, error); @@ -450,8 +457,9 @@ linux_clock_getres(struct thread *td, st LIN_SDT_PROBE1(time, linux_clock_getres, return, error); return (error); } - native_to_linux_timespec(<s, &ts); - + error = native_to_linux_timespec(<s, &ts); + if (error != 0) + return (error); error = copyout(<s, args->tp, sizeof lts); if (error != 0) LIN_SDT_PROBE1(time, linux_clock_getres, copyout_error, error); @@ -490,7 +498,9 @@ linux_nanosleep(struct thread *td, struc } error = kern_nanosleep(td, &rqts, rmtp); if (args->rmtp != NULL) { - native_to_linux_timespec(&lrmts, rmtp); + error2 = native_to_linux_timespec(&lrmts, rmtp); + if (error2 != 0) + return (error2); error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts)); if (error2 != 0) { LIN_SDT_PROBE1(time, linux_nanosleep, copyout_error, @@ -553,7 +563,9 @@ linux_clock_nanosleep(struct thread *td, error = kern_nanosleep(td, &rqts, rmtp); if (args->rmtp != NULL) { /* XXX. Not for TIMER_ABSTIME */ - native_to_linux_timespec(&lrmts, rmtp); + error2 = native_to_linux_timespec(&lrmts, rmtp); + if (error2 != 0) + return (error2); error2 = copyout(&lrmts, args->rmtp, sizeof(lrmts)); if (error2 != 0) { LIN_SDT_PROBE1(time, linux_clock_nanosleep, Modified: head/sys/compat/linux/linux_timer.h ============================================================================== --- head/sys/compat/linux/linux_timer.h Sun Feb 26 09:37:25 2017 (r314292) +++ head/sys/compat/linux/linux_timer.h Sun Feb 26 09:40:42 2017 (r314293) @@ -111,7 +111,7 @@ struct l_itimerspec { struct l_timespec it_value; }; -void native_to_linux_timespec(struct l_timespec *, +int native_to_linux_timespec(struct l_timespec *, struct timespec *); int linux_to_native_timespec(struct timespec *, struct l_timespec *);