Date: Sun, 26 Feb 2017 09:40:42 +0000 (UTC) From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r314293 - head/sys/compat/linux Message-ID: <201702260940.v1Q9egOq029307@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
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 <sys/kernel.h> #include <sys/lock.h> #include <sys/ucred.h> +#include <sys/limits.h> #include <sys/mount.h> #include <sys/mutex.h> #include <sys/resourcevar.h> @@ -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 *);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201702260940.v1Q9egOq029307>