diff mbox series

lib/vdso: Make clock_getres() POSIX compliant again

Message ID alpine.DEB.2.21.1910211202260.1904@nanos.tec.linutronix.de (mailing list archive)
State Not Applicable
Headers show
Series lib/vdso: Make clock_getres() POSIX compliant again | expand

Checks

Context Check Description
snowpatch_ozlabs/apply_patch success Successfully applied on branch next (600802af9049be799465b24d14162918545634bf)
snowpatch_ozlabs/build-ppc64le success Build succeeded
snowpatch_ozlabs/build-ppc64be success Build succeeded
snowpatch_ozlabs/build-ppc64e success Build succeeded
snowpatch_ozlabs/build-pmac32 success Build succeeded
snowpatch_ozlabs/checkpatch success total: 0 errors, 0 warnings, 0 checks, 21 lines checked

Commit Message

Thomas Gleixner Oct. 21, 2019, 10:07 a.m. UTC
A recent commit removed the NULL pointer check from the clock_getres()
implementation causing a test case to fault.

POSIX requires an explicit NULL pointer check for clock_getres() aside of
the validity check of the clock_id argument for obscure reasons.

Add it back for both 32bit and 64bit.

Note, this is only a partial revert of the offending commit which does not
bring back the broken fallback invocation in the the 32bit compat
implementations of clock_getres() and clock_gettime().

Fixes: a9446a906f52 ("lib/vdso/32: Remove inconsistent NULL pointer checks")
Reported-by: Andreas Schwab <schwab@linux-m68k.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Cc: stable@vger.kernel.org
---
 lib/vdso/gettimeofday.c |    9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

Comments

Christophe Leroy Oct. 21, 2019, 3:23 p.m. UTC | #1
Le 21/10/2019 à 12:07, Thomas Gleixner a écrit :
> A recent commit removed the NULL pointer check from the clock_getres()
> implementation causing a test case to fault.
> 
> POSIX requires an explicit NULL pointer check for clock_getres() aside of
> the validity check of the clock_id argument for obscure reasons.
> 
> Add it back for both 32bit and 64bit.
> 
> Note, this is only a partial revert of the offending commit which does not
> bring back the broken fallback invocation in the the 32bit compat
> implementations of clock_getres() and clock_gettime().
> 
> Fixes: a9446a906f52 ("lib/vdso/32: Remove inconsistent NULL pointer checks")
> Reported-by: Andreas Schwab <schwab@linux-m68k.org>
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>

Tested-by: Christophe Leroy <christophe.leroy@c-s.fr>

> Cc: stable@vger.kernel.org
> ---
>   lib/vdso/gettimeofday.c |    9 +++++----
>   1 file changed, 5 insertions(+), 4 deletions(-)
> 
> --- a/lib/vdso/gettimeofday.c
> +++ b/lib/vdso/gettimeofday.c
> @@ -214,9 +214,10 @@ int __cvdso_clock_getres_common(clockid_
>   		return -1;
>   	}
>   
> -	res->tv_sec = 0;
> -	res->tv_nsec = ns;
> -
> +	if (likely(res)) {
> +		res->tv_sec = 0;
> +		res->tv_nsec = ns;
> +	}
>   	return 0;
>   }
>   
> @@ -245,7 +246,7 @@ static __maybe_unused int
>   		ret = clock_getres_fallback(clock, &ts);
>   #endif
>   
> -	if (likely(!ret)) {
> +	if (likely(!ret && res)) {
>   		res->tv_sec = ts.tv_sec;
>   		res->tv_nsec = ts.tv_nsec;
>   	}
>
diff mbox series

Patch

--- a/lib/vdso/gettimeofday.c
+++ b/lib/vdso/gettimeofday.c
@@ -214,9 +214,10 @@  int __cvdso_clock_getres_common(clockid_
 		return -1;
 	}
 
-	res->tv_sec = 0;
-	res->tv_nsec = ns;
-
+	if (likely(res)) {
+		res->tv_sec = 0;
+		res->tv_nsec = ns;
+	}
 	return 0;
 }
 
@@ -245,7 +246,7 @@  static __maybe_unused int
 		ret = clock_getres_fallback(clock, &ts);
 #endif
 
-	if (likely(!ret)) {
+	if (likely(!ret && res)) {
 		res->tv_sec = ts.tv_sec;
 		res->tv_nsec = ts.tv_nsec;
 	}