Date: Fri, 17 Jun 2022 19:39:24 GMT From: Dmitry Chagin <dchagin@FreeBSD.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org Subject: git: c78e5c4c6ac3 - stable/13 - linux(4): Copyout pselect timeout. Message-ID: <202206171939.25HJdOQU015960@gitrepo.freebsd.org>
next in thread | raw e-mail | index | archive | help
The branch stable/13 has been updated by dchagin: URL: https://cgit.FreeBSD.org/src/commit/?id=c78e5c4c6ac358a05195b249b65a1a42c4291c03 commit c78e5c4c6ac358a05195b249b65a1a42c4291c03 Author: Dmitry Chagin <dchagin@FreeBSD.org> AuthorDate: 2022-04-26 16:35:56 +0000 Commit: Dmitry Chagin <dchagin@FreeBSD.org> CommitDate: 2022-06-17 19:34:04 +0000 linux(4): Copyout pselect timeout. According to pselect6 manual, on error timeout becomes undefined, by fact Linux modifies the timeout and ignore EFAULT error if so. MFC after: 2 weeks (cherry picked from commit 5171ed79f6d1fc3948a7ebfb32b02d698224c29b) --- sys/compat/linux/linux_misc.c | 46 ++++++++++++++++++------------------------- 1 file changed, 19 insertions(+), 27 deletions(-) diff --git a/sys/compat/linux/linux_misc.c b/sys/compat/linux/linux_misc.c index 096bbcbf0008..ff8c1b26d1d8 100644 --- a/sys/compat/linux/linux_misc.c +++ b/sys/compat/linux/linux_misc.c @@ -2386,7 +2386,7 @@ linux_pselect6(struct thread *td, struct linux_pselect6_args *args) { struct l_timespec lts; struct timespec ts, *tsp; - int error; + int error, error2; if (args->tsp != NULL) { error = copyin(args->tsp, <s, sizeof(lts)); @@ -2401,13 +2401,11 @@ linux_pselect6(struct thread *td, struct linux_pselect6_args *args) error = linux_common_pselect6(td, args->nfds, args->readfds, args->writefds, args->exceptfds, tsp, args->sig); - if (error != 0) - return (error); if (args->tsp != NULL) { - error = native_to_linux_timespec(<s, tsp); - if (error == 0) - error = copyout(<s, args->tsp, sizeof(lts)); + error2 = native_to_linux_timespec(<s, tsp); + if (error2 == 0) + copyout(<s, args->tsp, sizeof(lts)); } return (error); } @@ -2459,21 +2457,17 @@ linux_common_pselect6(struct thread *td, l_int nfds, l_fd_set *readfds, error = kern_pselect(td, nfds, readfds, writefds, exceptfds, tvp, ssp, LINUX_NFDBITS); - if (error == 0 && tsp != NULL) { - if (td->td_retval[0] != 0) { - /* - * Compute how much time was left of the timeout, - * by subtracting the current time and the time - * before we started the call, and subtracting - * that result from the user-supplied value. - */ - - microtime(&tv1); - timevalsub(&tv1, &tv0); - timevalsub(&utv, &tv1); - if (utv.tv_sec < 0) - timevalclear(&utv); - } else + if (tsp != NULL) { + /* + * Compute how much time was left of the timeout, + * by subtracting the current time and the time + * before we started the call, and subtracting + * that result from the user-supplied value. + */ + microtime(&tv1); + timevalsub(&tv1, &tv0); + timevalsub(&utv, &tv1); + if (utv.tv_sec < 0) timevalclear(&utv); TIMEVAL_TO_TIMESPEC(&utv, tsp); } @@ -2487,7 +2481,7 @@ linux_pselect6_time64(struct thread *td, { struct l_timespec64 lts; struct timespec ts, *tsp; - int error; + int error, error2; if (args->tsp != NULL) { error = copyin(args->tsp, <s, sizeof(lts)); @@ -2502,13 +2496,11 @@ linux_pselect6_time64(struct thread *td, error = linux_common_pselect6(td, args->nfds, args->readfds, args->writefds, args->exceptfds, tsp, args->sig); - if (error != 0) - return (error); if (args->tsp != NULL) { - error = native_to_linux_timespec64(<s, tsp); - if (error == 0) - error = copyout(<s, args->tsp, sizeof(lts)); + error2 = native_to_linux_timespec64(<s, tsp); + if (error2 == 0) + copyout(<s, args->tsp, sizeof(lts)); } return (error); }
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202206171939.25HJdOQU015960>