History

kheaders: make headers archive reproducible

In commit 43d8ce9d65a5 ("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 f7b101d33046 ("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.

Dmitry Goldin committed 7 years ago

Commit 86cdd2f1 parent d188b8c2 files · +13 −5Browse files

Unified · Split

2 files
  1. Documentation/kbuild/reproducible-builds.rst +9 −4
  2. kernel/gen_kheaders.sh +4 −1
Documentation/kbuild/reproducible-builds.rst+9−4
@@ -16,16 +16,21 @@ the kernel may be unreproducible, and how to avoid them. · 15 unmodified lines
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+4−1
@@ -71,7 +71,10 @@ done | cpio --quiet -pd $cpio_dir >/dev/null 2>&1 · 70 unmodified lines
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

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t