* [PATCH] [next] initramfs: Parse KBUILD_BUILD_TIMESTAMP as UTC date
@ 2023-07-29 5:02 Paulo Miguel Almeida
2023-08-16 6:38 ` Nicolas Schier
2023-08-18 0:32 ` Andrew Donnellan
0 siblings, 2 replies; 4+ messages in thread
From: Paulo Miguel Almeida @ 2023-07-29 5:02 UTC (permalink / raw)
To: masahiroy, bgray, ajd, n.schier
Cc: paulo.miguel.almeida.rodenas, linux-kernel, keescook
When KBUILD_BUILD_TIMESTAMP is specified, the date command will parse
it to Unix Epoch time in UTC. However, the date command is
timezone-aware so it will convert from the local timezone to UTC first
which hits some of the sanity checks added on commit 5efb685bb3af1
("initramfs: Check negative timestamp to prevent broken cpio archive")
This creates an edge case for the UTC+<N> part of the world. For instance
- In New Zealand (UTC+12:00):
$ date -d"1970-01-01" +%s
-43200
$ make KBUILD_BUILD_TIMESTAMP=1970-01-01
make[1]: Entering directory '<snip>/linux/'
GEN Makefile
DESCEND objtool
INSTALL libsubcmd_headers
CALL ../scripts/checksyscalls.sh
GEN usr/initramfs_data.cpio
ERROR: Timestamp out of range for cpio format
make[4]: *** [../usr/Makefile:76: usr/initramfs_data.cpio] Error 1
- In Seattle, WA (UTC-07:00):
$ date -d"1970-01-01" +%s
32400
$ make KBUILD_BUILD_TIMESTAMP=1970-01-01
<builds fine>
Parse KBUILD_BUILD_TIMESTAMP date string as UTC so no localtime
conversion is done which fixes the edge case aforementioned.
Signed-off-by: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
---
usr/gen_initramfs.sh | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh
index 14b5782f961a..a90316d9a080 100755
--- a/usr/gen_initramfs.sh
+++ b/usr/gen_initramfs.sh
@@ -221,7 +221,7 @@ while [ $# -gt 0 ]; do
shift
;;
"-d") # date for file mtimes
- timestamp="$(date -d"$1" +%s || :)"
+ timestamp="$(date -d"$1" -u +%s || :)"
if test -n "$timestamp"; then
timestamp="-t $timestamp"
fi
--
2.40.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH] [next] initramfs: Parse KBUILD_BUILD_TIMESTAMP as UTC date
2023-07-29 5:02 [PATCH] [next] initramfs: Parse KBUILD_BUILD_TIMESTAMP as UTC date Paulo Miguel Almeida
@ 2023-08-16 6:38 ` Nicolas Schier
2023-08-18 0:32 ` Andrew Donnellan
1 sibling, 0 replies; 4+ messages in thread
From: Nicolas Schier @ 2023-08-16 6:38 UTC (permalink / raw)
To: Paulo Miguel Almeida; +Cc: masahiroy, bgray, ajd, linux-kernel, keescook
On Sat, Jul 29, 2023 at 05:02:09PM +1200, Paulo Miguel Almeida wrote:
> When KBUILD_BUILD_TIMESTAMP is specified, the date command will parse
> it to Unix Epoch time in UTC. However, the date command is
> timezone-aware so it will convert from the local timezone to UTC first
> which hits some of the sanity checks added on commit 5efb685bb3af1
> ("initramfs: Check negative timestamp to prevent broken cpio archive")
>
> This creates an edge case for the UTC+<N> part of the world. For instance
>
> - In New Zealand (UTC+12:00):
> $ date -d"1970-01-01" +%s
> -43200
>
> $ make KBUILD_BUILD_TIMESTAMP=1970-01-01
> make[1]: Entering directory '<snip>/linux/'
> GEN Makefile
> DESCEND objtool
> INSTALL libsubcmd_headers
> CALL ../scripts/checksyscalls.sh
> GEN usr/initramfs_data.cpio
> ERROR: Timestamp out of range for cpio format
> make[4]: *** [../usr/Makefile:76: usr/initramfs_data.cpio] Error 1
>
> - In Seattle, WA (UTC-07:00):
> $ date -d"1970-01-01" +%s
> 32400
>
> $ make KBUILD_BUILD_TIMESTAMP=1970-01-01
> <builds fine>
>
> Parse KBUILD_BUILD_TIMESTAMP date string as UTC so no localtime
> conversion is done which fixes the edge case aforementioned.
>
> Signed-off-by: Paulo Miguel Almeida <paulo.miguel.almeida.rodenas@gmail.com>
> ---
Thanks for the patch!
Looking at 1970-01-01 concretely, you could circumvent your reported
issue by using KBUILD_BUILD_TIMESTAMP="1970-01-01 UTC". But I think you
found an interesting point w/ regard to reproducibility, as time zone is
neither mentioned in Documentation/kbuild/reproducibility.rst
nor in Documentation/kbuild/kbuild.rst but influences the output of
'date -d' (w/o '-u') (or comparable) calls in usr/gen_initramfs.sh as
well as in kernel/gen_kheaders.sh ('TZ=UTC tar'?) and possibly in
scripts/kernel-doc.
I think some might be suprised that giving a YYYY-MM-DD date to
KBUILD_BUILD_TIMESTAMP leads to an effectively different timestamp in
initramfs_data.cpio, but I think your change is still reasonable.
Reviewed-by: Nicolas Schier <n.schier@avm.de>
> usr/gen_initramfs.sh | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/usr/gen_initramfs.sh b/usr/gen_initramfs.sh
> index 14b5782f961a..a90316d9a080 100755
> --- a/usr/gen_initramfs.sh
> +++ b/usr/gen_initramfs.sh
> @@ -221,7 +221,7 @@ while [ $# -gt 0 ]; do
> shift
> ;;
> "-d") # date for file mtimes
> - timestamp="$(date -d"$1" +%s || :)"
> + timestamp="$(date -d"$1" -u +%s || :)"
> if test -n "$timestamp"; then
> timestamp="-t $timestamp"
> fi
> --
> 2.40.1
>
--
Nicolas Schier
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [next] initramfs: Parse KBUILD_BUILD_TIMESTAMP as UTC date
2023-07-29 5:02 [PATCH] [next] initramfs: Parse KBUILD_BUILD_TIMESTAMP as UTC date Paulo Miguel Almeida
2023-08-16 6:38 ` Nicolas Schier
@ 2023-08-18 0:32 ` Andrew Donnellan
2023-08-21 7:45 ` Paulo Miguel Almeida
1 sibling, 1 reply; 4+ messages in thread
From: Andrew Donnellan @ 2023-08-18 0:32 UTC (permalink / raw)
To: Paulo Miguel Almeida, masahiroy, bgray, n.schier; +Cc: linux-kernel, keescook
On Sat, 2023-07-29 at 17:02 +1200, Paulo Miguel Almeida wrote:
> When KBUILD_BUILD_TIMESTAMP is specified, the date command will parse
> it to Unix Epoch time in UTC. However, the date command is
> timezone-aware so it will convert from the local timezone to UTC
> first
> which hits some of the sanity checks added on commit 5efb685bb3af1
> ("initramfs: Check negative timestamp to prevent broken cpio
> archive")
>
> This creates an edge case for the UTC+<N> part of the world. For
> instance
>
> - In New Zealand (UTC+12:00):
> $ date -d"1970-01-01" +%s
> -43200
>
> $ make KBUILD_BUILD_TIMESTAMP=1970-01-01
> make[1]: Entering directory '<snip>/linux/'
> GEN Makefile
> DESCEND objtool
> INSTALL libsubcmd_headers
> CALL ../scripts/checksyscalls.sh
> GEN usr/initramfs_data.cpio
> ERROR: Timestamp out of range for cpio format
> make[4]: *** [../usr/Makefile:76: usr/initramfs_data.cpio]
> Error 1
>
> - In Seattle, WA (UTC-07:00):
> $ date -d"1970-01-01" +%s
> 32400
>
> $ make KBUILD_BUILD_TIMESTAMP=1970-01-01
> <builds fine>
>
> Parse KBUILD_BUILD_TIMESTAMP date string as UTC so no localtime
> conversion is done which fixes the edge case aforementioned.
>
> Signed-off-by: Paulo Miguel Almeida
> <paulo.miguel.almeida.rodenas@gmail.com>
This should also be documented in Documentation/kbuild/kbuild.rst,
including a note that you can still use local time if you include the
timezone specifier.
Thanks,
--
Andrew Donnellan OzLabs, ADL Canberra
ajd@linux.ibm.com IBM Australia Limited
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH] [next] initramfs: Parse KBUILD_BUILD_TIMESTAMP as UTC date
2023-08-18 0:32 ` Andrew Donnellan
@ 2023-08-21 7:45 ` Paulo Miguel Almeida
0 siblings, 0 replies; 4+ messages in thread
From: Paulo Miguel Almeida @ 2023-08-21 7:45 UTC (permalink / raw)
To: Andrew Donnellan; +Cc: masahiroy, bgray, n.schier, linux-kernel, keescook
On Fri, Aug 18, 2023 at 10:32:46AM +1000, Andrew Donnellan wrote:
> >
> > Parse KBUILD_BUILD_TIMESTAMP date string as UTC so no localtime
> > conversion is done which fixes the edge case aforementioned.
> >
> > Signed-off-by: Paulo Miguel Almeida
> > <paulo.miguel.almeida.rodenas@gmail.com>
>
> This should also be documented in Documentation/kbuild/kbuild.rst,
> including a note that you can still use local time if you include the
> timezone specifier.
>
> Thanks,
Thanks for the review Andrew and Nicolas.
Will send a new patch shortly with the changes requested.
thanks,
- Paulo A.
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2023-08-21 7:45 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-07-29 5:02 [PATCH] [next] initramfs: Parse KBUILD_BUILD_TIMESTAMP as UTC date Paulo Miguel Almeida
2023-08-16 6:38 ` Nicolas Schier
2023-08-18 0:32 ` Andrew Donnellan
2023-08-21 7:45 ` Paulo Miguel Almeida
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox