linux: fix ntp_gettime abi break

Message ID CAKVti-BRav=mmfcQBEz_qpezmKfR_fFW9uihJb+QXiJazugTmA@mail.gmail.com
State Superseded
Headers
Series linux: fix ntp_gettime abi break |

Checks

Context Check Description
dj/TryBot-apply_patch fail Patch failed to apply to master at the time it was sent
dj/TryBot-32bit fail Patch series failed to apply

Commit Message

Kacper Piwiński Feb. 21, 2023, 4:04 a.m. UTC
  Between versions v2.11 and v2.12 struct ntptimeval got new fields.
That wasn't a problem because new function ntp_gettimex was created
(and made default) to support new struct. Old ntp_gettime was not
using new fields so it was safe to call with old struct
definition. Then between versions v2.31 and v2.32 when working on
y2038 bugs, ntp_gettime start setting new fields.

Sets fields manually to maintain compatibility with v2.11 struct definition.

Author: Kacper Piwiński <vfjpl1@gmail.com>
---
 sysdeps/unix/sysv/linux/ntp_gettime.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

--
2.38.1.windows.1
  

Comments

Andreas Schwab Feb. 21, 2023, 11:24 a.m. UTC | #1
Could you please file a bug at https://sourceware.org/bugzilla/?
  
Kacper Piwiński Feb. 24, 2023, 3:15 p.m. UTC | #2
>
> Could you please file a bug at https://sourceware.org/bugzilla/?
>
> --
> Andreas Schwab, SUSE Labs, schwab@suse.de
> GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
> "And now for something completely different."

https://sourceware.org/bugzilla/show_bug.cgi?id=30156
  
Carlos O'Donell March 2, 2023, 5:47 p.m. UTC | #3
On 2/20/23 23:04, Kacper Piwiński via Libc-alpha wrote:
> Between versions v2.11 and v2.12 struct ntptimeval got new fields.
> That wasn't a problem because new function ntp_gettimex was created
> (and made default) to support new struct. Old ntp_gettime was not
> using new fields so it was safe to call with old struct
> definition. Then between versions v2.31 and v2.32 when working on
> y2038 bugs, ntp_gettime start setting new fields.
> 
> Sets fields manually to maintain compatibility with v2.11 struct definition.

The patch fails to apply.

This fails pre-commit CI:
https://patchwork.sourceware.org/project/glibc/patch/CAKVti-BRav=mmfcQBEz_qpezmKfR_fFW9uihJb+QXiJazugTmA@mail.gmail.com/

Please have a look at:
https://sourceware.org/glibc/wiki/Contribution%20checklist

Did you generate the patch with `git format-patch`?


> 
> Author: Kacper Piwiński <vfjpl1@gmail.com>
> ---
>  sysdeps/unix/sysv/linux/ntp_gettime.c | 6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c
> b/sysdeps/unix/sysv/linux/ntp_gettime.c
> index 4879573530..3844b2e487 100644
> --- a/sysdeps/unix/sysv/linux/ntp_gettime.c
> +++ b/sysdeps/unix/sysv/linux/ntp_gettime.c
> @@ -54,7 +54,11 @@ __ntp_gettime (struct ntptimeval *ntv)
>    int result;
> 
>    result = __ntp_gettime64 (&ntv64);
> -  *ntv = valid_ntptimeval64_to_ntptimeval (ntv64);
> +  //manually update fields to maintain abi with v2.11 struct definition
> +  struct ntptimeval tntv = valid_ntptimeval64_to_ntptimeval (ntv64);
> +  ntv->time = tntv.time;
> +  ntv->maxerror = tntv.maxerror;
> +  ntv->esterror = tntv.esterror;
> 
>    return result;
>  }
> --
> 2.38.1.windows.1
>
  
Kacper Piwiński March 3, 2023, 8:47 a.m. UTC | #4
czw., 2 mar 2023 o 18:47 Carlos O'Donell <carlos@redhat.com> napisał(a):
>
> On 2/20/23 23:04, Kacper Piwiński via Libc-alpha wrote:
> > Between versions v2.11 and v2.12 struct ntptimeval got new fields.
> > That wasn't a problem because new function ntp_gettimex was created
> > (and made default) to support new struct. Old ntp_gettime was not
> > using new fields so it was safe to call with old struct
> > definition. Then between versions v2.31 and v2.32 when working on
> > y2038 bugs, ntp_gettime start setting new fields.
> >
> > Sets fields manually to maintain compatibility with v2.11 struct definition.
>
> The patch fails to apply.
>
> This fails pre-commit CI:
> https://patchwork.sourceware.org/project/glibc/patch/CAKVti-BRav=mmfcQBEz_qpezmKfR_fFW9uihJb+QXiJazugTmA@mail.gmail.com/
>
> Please have a look at:
> https://sourceware.org/glibc/wiki/Contribution%20checklist
>
> Did you generate the patch with `git format-patch`?
>

Hi, yes I did but I didn't copy the whole thing. Anyway this patch is
not correct. I attatched new patch here
https://sourceware.org/bugzilla/show_bug.cgi?id=30156


>
> >
> > Author: Kacper Piwiński <vfjpl1@gmail.com>
> > ---
> >  sysdeps/unix/sysv/linux/ntp_gettime.c | 6 +++++-
> >  1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c
> > b/sysdeps/unix/sysv/linux/ntp_gettime.c
> > index 4879573530..3844b2e487 100644
> > --- a/sysdeps/unix/sysv/linux/ntp_gettime.c
> > +++ b/sysdeps/unix/sysv/linux/ntp_gettime.c
> > @@ -54,7 +54,11 @@ __ntp_gettime (struct ntptimeval *ntv)
> >    int result;
> >
> >    result = __ntp_gettime64 (&ntv64);
> > -  *ntv = valid_ntptimeval64_to_ntptimeval (ntv64);
> > +  //manually update fields to maintain abi with v2.11 struct definition
> > +  struct ntptimeval tntv = valid_ntptimeval64_to_ntptimeval (ntv64);
> > +  ntv->time = tntv.time;
> > +  ntv->maxerror = tntv.maxerror;
> > +  ntv->esterror = tntv.esterror;
> >
> >    return result;
> >  }
> > --
> > 2.38.1.windows.1
> >
>
> --
> Cheers,
> Carlos.
>
  
Adhemerval Zanella March 3, 2023, 1:03 p.m. UTC | #5
On 03/03/23 05:47, Kacper Piwiński via Libc-alpha wrote:
> czw., 2 mar 2023 o 18:47 Carlos O'Donell <carlos@redhat.com> napisał(a):
>>
>> On 2/20/23 23:04, Kacper Piwiński via Libc-alpha wrote:
>>> Between versions v2.11 and v2.12 struct ntptimeval got new fields.
>>> That wasn't a problem because new function ntp_gettimex was created
>>> (and made default) to support new struct. Old ntp_gettime was not
>>> using new fields so it was safe to call with old struct
>>> definition. Then between versions v2.31 and v2.32 when working on
>>> y2038 bugs, ntp_gettime start setting new fields.
>>>
>>> Sets fields manually to maintain compatibility with v2.11 struct definition.
>>
>> The patch fails to apply.
>>
>> This fails pre-commit CI:
>> https://patchwork.sourceware.org/project/glibc/patch/CAKVti-BRav=mmfcQBEz_qpezmKfR_fFW9uihJb+QXiJazugTmA@mail.gmail.com/
>>
>> Please have a look at:
>> https://sourceware.org/glibc/wiki/Contribution%20checklist
>>
>> Did you generate the patch with `git format-patch`?
>>
> 
> Hi, yes I did but I didn't copy the whole thing. Anyway this patch is
> not correct. I attatched new patch here
> https://sourceware.org/bugzilla/show_bug.cgi?id=30156

Could you please resend as v2? Patch submission and discussion are done through
the maillist.

PS: maybe we should be more clear on wiki that patches are done discussed on
bugzilla.
  
Kacper Piwiński March 3, 2023, 4:43 p.m. UTC | #6
From 64bbb7cc698c8e2c8d8c94247e0bc47ac3b18f77 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20Piwi=C5=84ski?= <vfjpl1@gmail.com>
Date: Wed, 22 Feb 2023 18:58:38 +0100
Subject: [PATCH] linux: fix ntp_gettime abi break

---
 sysdeps/unix/sysv/linux/ntp_gettime.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c
b/sysdeps/unix/sysv/linux/ntp_gettime.c
index 4879573530..a577314636 100644
--- a/sysdeps/unix/sysv/linux/ntp_gettime.c
+++ b/sysdeps/unix/sysv/linux/ntp_gettime.c
@@ -40,7 +40,6 @@ __ntp_gettime64 (struct __ntptimeval64 *ntv)
   ntv->time = tntx.time;
   ntv->maxerror = tntx.maxerror;
   ntv->esterror = tntx.esterror;
-  ntv->tai = tntx.tai;
   return result;
 }

@@ -54,7 +53,10 @@ __ntp_gettime (struct ntptimeval *ntv)
   int result;

   result = __ntp_gettime64 (&ntv64);
-  *ntv = valid_ntptimeval64_to_ntptimeval (ntv64);
+  //manually update fields to maintain abi with v2.11 struct definition
+  ntv->time = valid_timeval64_to_timeval (ntv64.time);
+  ntv->maxerror = ntv64.maxerror;
+  ntv->esterror = ntv64.esterror;

   return result;
 }
  
Adhemerval Zanella March 7, 2023, 2:11 p.m. UTC | #7
On 03/03/23 13:43, Kacper Piwiński wrote:
> From 64bbb7cc698c8e2c8d8c94247e0bc47ac3b18f77 Mon Sep 17 00:00:00 2001
> From: =?UTF-8?q?Kacper=20Piwi=C5=84ski?= <vfjpl1@gmail.com>
> Date: Wed, 22 Feb 2023 18:58:38 +0100
> Subject: [PATCH] linux: fix ntp_gettime abi break
> 
> ---
>  sysdeps/unix/sysv/linux/ntp_gettime.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c
> b/sysdeps/unix/sysv/linux/ntp_gettime.c
> index 4879573530..a577314636 100644
> --- a/sysdeps/unix/sysv/linux/ntp_gettime.c
> +++ b/sysdeps/unix/sysv/linux/ntp_gettime.c
> @@ -40,7 +40,6 @@ __ntp_gettime64 (struct __ntptimeval64 *ntv)
>    ntv->time = tntx.time;
>    ntv->maxerror = tntx.maxerror;
>    ntv->esterror = tntx.esterror;
> -  ntv->tai = tntx.tai;
>    return result;
>  }
> 
> @@ -54,7 +53,10 @@ __ntp_gettime (struct ntptimeval *ntv)
>    int result;
> 
>    result = __ntp_gettime64 (&ntv64);
> -  *ntv = valid_ntptimeval64_to_ntptimeval (ntv64);
> +  //manually update fields to maintain abi with v2.11 struct definition

Sigh, so we decided to not add symbol versioning, and add ntp_gettimex
instead.

Comments should be in the form of '/* ... */', with first uppercase
and with final period.  

But I think we should make it clear that this function should not work
on 'struct ntptimeval', even though users might call glibc 2.12 version:

/* glibc 2.12 added the 'tai' field to follow along the kernel, but it did
   not add a compatibility symbol, instead it added __ntp_gettimex.  However
   ntptimeval was still used in both cases, so to keep compatibility it
   can not set all the new field.  */

struct old_ntptimeval
{
  struct timeval time;
  long int maxerror;
  long int esterror;
};

int
__old_ntp_gettime (struct old_ntptimeval *ntv)
{
  struct __ntptimeval64 ntv64;
  int result;

  result = __ntp_gettime64 (&ntv64);
  ntv->time = valid_timeval64_to_timeval (ntv64.time);
  ntv->maxerror = ntv64.maxerror;
  ntv->esterror = ntv64.esterror;

  return result;
}
strong_alias (__old_ntp_gettime, __ntp_gettime)


> +  ntv->time = valid_timeval64_to_timeval (ntv64.time);
> +  ntv->maxerror = ntv64.maxerror;
> +  ntv->esterror = ntv64.esterror;
> 
>    return result;
>  }
  

Patch

diff --git a/sysdeps/unix/sysv/linux/ntp_gettime.c
b/sysdeps/unix/sysv/linux/ntp_gettime.c
index 4879573530..3844b2e487 100644
--- a/sysdeps/unix/sysv/linux/ntp_gettime.c
+++ b/sysdeps/unix/sysv/linux/ntp_gettime.c
@@ -54,7 +54,11 @@  __ntp_gettime (struct ntptimeval *ntv)
   int result;

   result = __ntp_gettime64 (&ntv64);
-  *ntv = valid_ntptimeval64_to_ntptimeval (ntv64);
+  //manually update fields to maintain abi with v2.11 struct definition
+  struct ntptimeval tntv = valid_ntptimeval64_to_ntptimeval (ntv64);
+  ntv->time = tntv.time;
+  ntv->maxerror = tntv.maxerror;
+  ntv->esterror = tntv.esterror;

   return result;
 }