Skip to content

Commit 86cdd2f

Browse files
d-goldinmasahir0y
authored andcommitted
kheaders: make headers archive reproducible
In commit 43d8ce9 ("Provide in-kernel headers to make extending kernel easier") a new mechanism was introduced, for kernels >=5.2, which embeds the kernel headers in the kernel image or a module and exposes them in procfs for use by userland tools. The archive containing the header files has nondeterminism caused by header files metadata. This patch normalizes the metadata and utilizes KBUILD_BUILD_TIMESTAMP if provided and otherwise falls back to the default behaviour. In commit f7b101d ("kheaders: Move from proc to sysfs") it was modified to use sysfs and the script for generation of the archive was renamed to what is being patched. Signed-off-by: Dmitry Goldin <[email protected]> Reviewed-by: Greg Kroah-Hartman <[email protected]> Reviewed-by: Joel Fernandes (Google) <[email protected]> Signed-off-by: Masahiro Yamada <[email protected]>
1 parent d188b8c commit 86cdd2f

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

Documentation/kbuild/reproducible-builds.rst

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,16 +16,21 @@ the kernel may be unreproducible, and how to avoid them.
1616
Timestamps
1717
----------
1818

19-
The kernel embeds a timestamp in two places:
19+
The kernel embeds timestamps in three places:
2020

2121
* The version string exposed by ``uname()`` and included in
2222
``/proc/version``
2323

2424
* File timestamps in the embedded initramfs
2525

26-
By default the timestamp is the current time. This must be overridden
27-
using the `KBUILD_BUILD_TIMESTAMP`_ variable. If you are building
28-
from a git commit, you could use its commit date.
26+
* If enabled via ``CONFIG_IKHEADERS``, file timestamps of kernel
27+
headers embedded in the kernel or respective module,
28+
exposed via ``/sys/kernel/kheaders.tar.xz``
29+
30+
By default the timestamp is the current time and in the case of
31+
``kheaders`` the various files' modification times. This must
32+
be overridden using the `KBUILD_BUILD_TIMESTAMP`_ variable.
33+
If you are building from a git commit, you could use its commit date.
2934

3035
The kernel does *not* use the ``__DATE__`` and ``__TIME__`` macros,
3136
and enables warnings if they are used. If you incorporate external

kernel/gen_kheaders.sh

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,10 @@ done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1
7171
find $cpio_dir -type f -print0 |
7272
xargs -0 -P8 -n1 perl -pi -e 'BEGIN {undef $/;}; s/\/\*((?!SPDX).)*?\*\///smg;'
7373

74-
tar -Jcf $tarfile -C $cpio_dir/ . > /dev/null
74+
# Create archive and try to normalize metadata for reproducibility
75+
tar "${KBUILD_BUILD_TIMESTAMP:+--mtime=$KBUILD_BUILD_TIMESTAMP}" \
76+
--owner=0 --group=0 --sort=name --numeric-owner \
77+
-Jcf $tarfile -C $cpio_dir/ . > /dev/null
7578

7679
echo "$src_files_md5" > kernel/kheaders.md5
7780
echo "$obj_files_md5" >> kernel/kheaders.md5

0 commit comments

Comments
 (0)