lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <alpine.DEB.2.21.1908151935320.1908@nanos.tec.linutronix.de>
Date:   Thu, 15 Aug 2019 19:38:04 +0200 (CEST)
From:   Thomas Gleixner <tglx@...utronix.de>
To:     Dmitry Safonov <dima@...sta.com>
cc:     linux-kernel@...r.kernel.org,
        Dmitry Safonov <0x7f454c46@...il.com>,
        Andrei Vagin <avagin@...il.com>,
        Adrian Reber <adrian@...as.de>,
        Andrei Vagin <avagin@...nvz.org>,
        Andy Lutomirski <luto@...nel.org>,
        Arnd Bergmann <arnd@...db.de>,
        Christian Brauner <christian.brauner@...ntu.com>,
        Cyrill Gorcunov <gorcunov@...nvz.org>,
        "Eric W. Biederman" <ebiederm@...ssion.com>,
        "H. Peter Anvin" <hpa@...or.com>, Ingo Molnar <mingo@...hat.com>,
        Jann Horn <jannh@...gle.com>, Jeff Dike <jdike@...toit.com>,
        Oleg Nesterov <oleg@...hat.com>,
        Pavel Emelyanov <xemul@...tuozzo.com>,
        Shuah Khan <shuah@...nel.org>,
        Vincenzo Frascino <vincenzo.frascino@....com>,
        containers@...ts.linux-foundation.org, criu@...nvz.org,
        linux-api@...r.kernel.org, x86@...nel.org
Subject: Re: [PATCHv6 10/36] kernel: Add do_timens_ktime_to_host() helper

On Thu, 15 Aug 2019, Dmitry Safonov wrote:
> +ktime_t do_timens_ktime_to_host(clockid_t clockid, ktime_t tim,
> +				struct timens_offsets *ns_offsets)
> +{
> +	ktime_t offset;
> +
> +	switch (clockid) {
> +	case CLOCK_MONOTONIC:
> +		offset = timespec64_to_ktime(ns_offsets->monotonic);
> +		break;
> +	case CLOCK_BOOTTIME:
> +	case CLOCK_BOOTTIME_ALARM:
> +		offset = timespec64_to_ktime(ns_offsets->boottime);
> +		break;
> +	default:
> +		return tim;
> +	}
> +
> +	/*
> +	 * Check that @tim value is in [offset, KTIME_MAX + offset]
> +	 * and subtract offset.
> +	 */
> +	if (tim < offset) {
> +		/*
> +		 * User can specify @tim *absolute* value - if it's lesser than
> +		 * the time namespace's offset - it's already expired.
> +		 */
> +		tim = 0;
> +	} else if (KTIME_MAX - tim < -offset) {
> +		/*
> +		 * User-supplied @tim may be close or even equal KTIME_MAX
> +		 * and time namespace offset can be negative.
> +		 * Let's check (tim - offset) for an overflow.
> +		 * Return KTIME_MAX in such case, as the time value is
> +		 * thousands *years* in future anyway.
> +		 */
> +		tim = KTIME_MAX;
> +	} else {
> +		tim = ktime_sub(tim, offset);
> +	}

While the overflow check is correct, wouldn't it be more intuitive to do:

      	  	tim = ktime_sub(tim, offset);
		if (unlikely(tim > KTIME_MAX))
			tim = KTIME_MAX;

Thanks,

	tglx

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ