public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64
@ 2020-06-30 18:45 Florian Weimer
  2020-06-30 19:12 ` Adhemerval Zanella
                   ` (2 more replies)
  0 siblings, 3 replies; 5+ messages in thread
From: Florian Weimer @ 2020-06-30 18:45 UTC (permalink / raw)
  To: libc-alpha

The time argument is NULL in this case, and attempt to convert it
leads to a null pointer dereference.

This fixes commit d2e3b697da2433c08702f95c76458c51545c3df1
("y2038: linux: Provide __settimeofday64 implementation").

---
v2: Add just a null pointer check.  Tested on x86_64-linux-gnu and
    i686-linux-gnu.

 sysdeps/unix/sysv/linux/settimeofday.c | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/settimeofday.c b/sysdeps/unix/sysv/linux/settimeofday.c
index ea45f1d7cb..6f4bc7ef3c 100644
--- a/sysdeps/unix/sysv/linux/settimeofday.c
+++ b/sysdeps/unix/sysv/linux/settimeofday.c
@@ -25,6 +25,7 @@
 int
 __settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
 {
+  /* Backwards compatibility for setting the UTC offset.  */
   if (__glibc_unlikely (tz != 0))
     {
       if (tv != 0)
@@ -45,9 +46,13 @@ libc_hidden_def (__settimeofday64)
 int
 __settimeofday (const struct timeval *tv, const struct timezone *tz)
 {
-  struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
-
-  return __settimeofday64 (&tv64, tz);
+  if (__glibc_unlikely (tv == NULL))
+      return __settimeofday64 (NULL, tz);
+  else
+    {
+      struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
+      return __settimeofday64 (&tv64, tz);
+    }
 }
 #endif
 weak_alias (__settimeofday, settimeofday);


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64
  2020-06-30 18:45 [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64 Florian Weimer
@ 2020-06-30 19:12 ` Adhemerval Zanella
  2020-06-30 19:19   ` Florian Weimer
  2020-06-30 21:07 ` Alistair Francis
  2020-07-01  0:06 ` Lukasz Majewski
  2 siblings, 1 reply; 5+ messages in thread
From: Adhemerval Zanella @ 2020-06-30 19:12 UTC (permalink / raw)
  To: Florian Weimer, libc-alpha



On 30/06/2020 15:45, Florian Weimer wrote:
> The time argument is NULL in this case, and attempt to convert it
> leads to a null pointer dereference.
> 
> This fixes commit d2e3b697da2433c08702f95c76458c51545c3df1
> ("y2038: linux: Provide __settimeofday64 implementation").

LGTM, thanks.

Reviwed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>

> 
> ---
> v2: Add just a null pointer check.  Tested on x86_64-linux-gnu and
>     i686-linux-gnu.
> 
>  sysdeps/unix/sysv/linux/settimeofday.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/settimeofday.c b/sysdeps/unix/sysv/linux/settimeofday.c
> index ea45f1d7cb..6f4bc7ef3c 100644
> --- a/sysdeps/unix/sysv/linux/settimeofday.c
> +++ b/sysdeps/unix/sysv/linux/settimeofday.c
> @@ -25,6 +25,7 @@
>  int
>  __settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
>  {
> +  /* Backwards compatibility for setting the UTC offset.  */
>    if (__glibc_unlikely (tz != 0))
>      {
>        if (tv != 0)
> @@ -45,9 +46,13 @@ libc_hidden_def (__settimeofday64)
>  int
>  __settimeofday (const struct timeval *tv, const struct timezone *tz)
>  {
> -  struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
> -
> -  return __settimeofday64 (&tv64, tz);
> +  if (__glibc_unlikely (tv == NULL))
> +      return __settimeofday64 (NULL, tz);

Indentation seems off here.

> +  else
> +    {
> +      struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
> +      return __settimeofday64 (&tv64, tz);
> +    }
>  }
>  #endif
>  weak_alias (__settimeofday, settimeofday);
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64
  2020-06-30 19:12 ` Adhemerval Zanella
@ 2020-06-30 19:19   ` Florian Weimer
  0 siblings, 0 replies; 5+ messages in thread
From: Florian Weimer @ 2020-06-30 19:19 UTC (permalink / raw)
  To: Adhemerval Zanella; +Cc: libc-alpha, Lukasz Majewski

* Adhemerval Zanella:

> On 30/06/2020 15:45, Florian Weimer wrote:
>> The time argument is NULL in this case, and attempt to convert it
>> leads to a null pointer dereference.
>> 
>> This fixes commit d2e3b697da2433c08702f95c76458c51545c3df1
>> ("y2038: linux: Provide __settimeofday64 implementation").
>
> LGTM, thanks.
>
> Reviwed-by: Adhemerval Zanella  <adhemerval.zanella@linaro.org>
>
>> 
>> ---
>> v2: Add just a null pointer check.  Tested on x86_64-linux-gnu and
>>     i686-linux-gnu.
>> 
>>  sysdeps/unix/sysv/linux/settimeofday.c | 11 ++++++++---
>>  1 file changed, 8 insertions(+), 3 deletions(-)
>> 
>> diff --git a/sysdeps/unix/sysv/linux/settimeofday.c b/sysdeps/unix/sysv/linux/settimeofday.c
>> index ea45f1d7cb..6f4bc7ef3c 100644
>> --- a/sysdeps/unix/sysv/linux/settimeofday.c
>> +++ b/sysdeps/unix/sysv/linux/settimeofday.c
>> @@ -25,6 +25,7 @@
>>  int
>>  __settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
>>  {
>> +  /* Backwards compatibility for setting the UTC offset.  */
>>    if (__glibc_unlikely (tz != 0))
>>      {
>>        if (tv != 0)
>> @@ -45,9 +46,13 @@ libc_hidden_def (__settimeofday64)
>>  int
>>  __settimeofday (const struct timeval *tv, const struct timezone *tz)
>>  {
>> -  struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
>> -
>> -  return __settimeofday64 (&tv64, tz);
>> +  if (__glibc_unlikely (tv == NULL))
>> +      return __settimeofday64 (NULL, tz);
>
> Indentation seems off here.

Thanks.  I'm going to fix this before committing.

Thanks,
Florian


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64
  2020-06-30 18:45 [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64 Florian Weimer
  2020-06-30 19:12 ` Adhemerval Zanella
@ 2020-06-30 21:07 ` Alistair Francis
  2020-07-01  0:06 ` Lukasz Majewski
  2 siblings, 0 replies; 5+ messages in thread
From: Alistair Francis @ 2020-06-30 21:07 UTC (permalink / raw)
  To: Florian Weimer; +Cc: GNU C Library

On Tue, Jun 30, 2020 at 11:45 AM Florian Weimer via Libc-alpha
<libc-alpha@sourceware.org> wrote:
>
> The time argument is NULL in this case, and attempt to convert it
> leads to a null pointer dereference.
>
> This fixes commit d2e3b697da2433c08702f95c76458c51545c3df1
> ("y2038: linux: Provide __settimeofday64 implementation").
>
> ---
> v2: Add just a null pointer check.  Tested on x86_64-linux-gnu and
>     i686-linux-gnu.
>
>  sysdeps/unix/sysv/linux/settimeofday.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
>
> diff --git a/sysdeps/unix/sysv/linux/settimeofday.c b/sysdeps/unix/sysv/linux/settimeofday.c
> index ea45f1d7cb..6f4bc7ef3c 100644
> --- a/sysdeps/unix/sysv/linux/settimeofday.c
> +++ b/sysdeps/unix/sysv/linux/settimeofday.c
> @@ -25,6 +25,7 @@
>  int
>  __settimeofday64 (const struct __timeval64 *tv, const struct timezone *tz)
>  {
> +  /* Backwards compatibility for setting the UTC offset.  */
>    if (__glibc_unlikely (tz != 0))
>      {
>        if (tv != 0)
> @@ -45,9 +46,13 @@ libc_hidden_def (__settimeofday64)
>  int
>  __settimeofday (const struct timeval *tv, const struct timezone *tz)
>  {
> -  struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
> -
> -  return __settimeofday64 (&tv64, tz);
> +  if (__glibc_unlikely (tv == NULL))
> +      return __settimeofday64 (NULL, tz);
> +  else
> +    {
> +      struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
> +      return __settimeofday64 (&tv64, tz);
> +    }

Looks good

Reviewed-by: Alistair Francis <alistair.francis@wdc.com>

Alistair

>  }
>  #endif
>  weak_alias (__settimeofday, settimeofday);
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64
  2020-06-30 18:45 [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64 Florian Weimer
  2020-06-30 19:12 ` Adhemerval Zanella
  2020-06-30 21:07 ` Alistair Francis
@ 2020-07-01  0:06 ` Lukasz Majewski
  2 siblings, 0 replies; 5+ messages in thread
From: Lukasz Majewski @ 2020-07-01  0:06 UTC (permalink / raw)
  To: Florian Weimer; +Cc: libc-alpha, Adhemerval Zanella

[-- Attachment #1: Type: text/plain, Size: 1894 bytes --]

On Tue, 30 Jun 2020 20:45:17 +0200
Florian Weimer <fweimer@redhat.com> wrote:

> The time argument is NULL in this case, and attempt to convert it
> leads to a null pointer dereference.
> 
> This fixes commit d2e3b697da2433c08702f95c76458c51545c3df1
> ("y2038: linux: Provide __settimeofday64 implementation").
> 
> ---
> v2: Add just a null pointer check.  Tested on x86_64-linux-gnu and
>     i686-linux-gnu.
> 
>  sysdeps/unix/sysv/linux/settimeofday.c | 11 ++++++++---
>  1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/settimeofday.c
> b/sysdeps/unix/sysv/linux/settimeofday.c index ea45f1d7cb..6f4bc7ef3c
> 100644 --- a/sysdeps/unix/sysv/linux/settimeofday.c
> +++ b/sysdeps/unix/sysv/linux/settimeofday.c
> @@ -25,6 +25,7 @@
>  int
>  __settimeofday64 (const struct __timeval64 *tv, const struct
> timezone *tz) {
> +  /* Backwards compatibility for setting the UTC offset.  */
>    if (__glibc_unlikely (tz != 0))
>      {
>        if (tv != 0)
> @@ -45,9 +46,13 @@ libc_hidden_def (__settimeofday64)
>  int
>  __settimeofday (const struct timeval *tv, const struct timezone *tz)
>  {
> -  struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
> -
> -  return __settimeofday64 (&tv64, tz);
> +  if (__glibc_unlikely (tv == NULL))
> +      return __settimeofday64 (NULL, tz);
> +  else
> +    {
> +      struct __timeval64 tv64 = valid_timeval_to_timeval64 (*tv);
> +      return __settimeofday64 (&tv64, tz);
> +    }
>  }
>  #endif
>  weak_alias (__settimeofday, settimeofday);
> 

Reviewed-by: Lukasz Majewski <lukma@denx.de>


Best regards,

Lukasz Majewski

--

DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-59 Fax: (+49)-8142-66989-80 Email: lukma@denx.de

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2020-07-01  0:07 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-30 18:45 [PATCH v2] Linux: Fix UTC offset setting in settimeofday for __TIMESIZE != 64 Florian Weimer
2020-06-30 19:12 ` Adhemerval Zanella
2020-06-30 19:19   ` Florian Weimer
2020-06-30 21:07 ` Alistair Francis
2020-07-01  0:06 ` Lukasz Majewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).