Re: [patch] sys_epoll_wait() timeout saga ...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, 24 Sep 2005, Davide Libenzi wrote:

> On Sat, 24 Sep 2005, Nishanth Aravamudan wrote:
>
> > Description: The @timeout parameter to ep_poll() is in milliseconds but
> > we compare it to (MAX_SCHEDULE_TIMEOUT - 1000 / HZ), which is
> > (jiffies/jiffies-per-sec) or seconds. That seems blatantly broken.  This
> > led to improper overflow checking for @timeout. As Andrew Morton pointed
> > out in a similar fix for sys_poll(), the best solution is to to check
> > for potential overflow first, then either select an indefinite value or
> > convert @timeout.
> >
> > To achieve this and clean-up the code, change the prototype of the
> > ep_poll() to make it clear that the parameter is in milliseconds and
> > rename jtimeout to timeout_jiffies to hold the corresonding jiffies
> > value.
> >
> > fs/eventpoll.c |   46 ++++++++++++++++++++++++++++++++++++++--------
> > 1 files changed, 38 insertions(+), 8 deletions(-)
>
> Eh? "To achieve this and clean-up the code"? :)
>
>
> - Davide
>
>
> eventpoll.c |    7 +++++--
> 1 file changed, 5 insertions(+), 2 deletions(-)
>
> --- a/fs/eventpoll.c	2005-09-24 11:07:04.000000000 -0700
> +++ b/fs/eventpoll.c	2005-09-24 11:11:06.000000000 -0700
> @@ -101,6 +101,10 @@
>   /* Maximum number of poll wake up nests we are allowing */
>   #define EP_MAX_POLLWAKE_NESTS 4
>
> +/* Maximum msec timeout value storeable in a long int */
> +#define EP_MAX_MSTIMEO min(1000ULL * MAX_SCHEDULE_TIMEOUT / HZ, LONG_MAX / HZ - 1000ULL)

Not quite. It really should be:
#define EP_MAX_MSTIMEO min(1000ULL * MAX_SCHEDULETIMEOUT / HZ, (LONG_MAX - 999ULL) / HZ);

> +
> +
>   struct epoll_filefd {
>   	struct file *file;
>   	int fd;
> @@ -1507,8 +1511,7 @@
>   	 * and the overflow condition. The passed timeout is in milliseconds,
>   	 * that why (t * HZ) / 1000.
>   	 */
> -	jtimeout = (timeout < 0 ||
> -		    (timeout / 1000) >= (MAX_SCHEDULE_TIMEOUT / HZ)) ?
> +	jtimeout = (timeout < 0 || timeout >= EP_MAX_MSTIMEO) ?
>   		MAX_SCHEDULE_TIMEOUT: (timeout * HZ + 999) / 1000;
>
>   retry:
> -

-Vadim Lobanov
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux