Salted build ids via linker sections
Subsystems (4)
v2 cover Salted build ids via linker sections
Hi,
This is v2 of my proposal to allow unique build-ids in the kernel. from last time:
""
In Fedora, the debug information is packaged separately (foo-debuginfo) and can be installed separately. There's been a long standing issue where only one version of a debuginfo info package can be installed at a time. Mark Wielaard made an effort for Fedora 27 to allow parallel installation of debuginfo (see
https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo for more details)
Part of the requirement to allow this to work is that build ids are unique between builds. The existing upstream rpm implementation ensures this by re-calculating the build-id using the version and release as a seed. This doesn't work 100% for the kernel because of the vDSO which is its own binary and doesn't get updated. After poking holes in a few of my ideas, there was a discussion with some people from the binutils team about adding --build-id-salt to let ld do the calculation debugedit is doing. There was a counter proposal made about adding some extra information via a .comment which will affect the build id calculation but just get stripped out. ""
This v2 cleans up the naming to be consistent and also switches to a config option vs. an environment variable. I've seen some sporadic failures about missing the generated header so I think I'm still missing a dependency somewhere. I'm still mostly looking for feedback whether this would be acceptable for merging or if we should just persue a --build-id-salt in binutils.
Thanks,
Laura
Laura Abbott (3):
kbuild: Introduce build-salt generated header
kbuild: Link with generated build-salt header
x86/vdso: Add build salt to the vDSO
Makefile | 13 +++++++++++-- arch/x86/entry/vdso/vdso-layout.lds.S | 3 +++ init/Kconfig | 8 ++++++++ scripts/.gitignore | 1 + scripts/Makefile | 2 +- scripts/build-salt.lds.S | 5 +++++ scripts/gensalt | 21 +++++++++++++++++++++ scripts/link-vmlinux.sh | 3 ++- 8 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 scripts/build-salt.lds.S create mode 100755 scripts/gensalt
Signature · 1 line
2.16.2
RFC PATCH v2 1/3 kbuild: Introduce build-salt generated header
The build id generated from --build-id can be generated in several different ways, with the default being the sha1 on the output of the linked file. For distributions, it can be useful to make sure this ID is unique, even if the actual file contents don't change. The easiest way to do this is to insert a comment section with some data.
Introduce a header which is generated from a config setting. If this config is set, an appropriate .comment section is generated. If the config isn't set, the define is simply empty and there is no change to the build.
---
v2: Switched to Kconfig vs. environment variable per suggestion of Nick Clifton. Changed names to be consistent.
--- Makefile | 9 ++++++++- init/Kconfig | 8 ++++++++ scripts/gensalt | 21 +++++++++++++++++++++ 3 files changed, 37 insertions(+), 1 deletion(-) create mode 100755 scripts/gensalt
Makefile +8 -1
@@ -1096,7 +1096,7 @@ endif prepare2: prepare3 prepare-compiler-check outputmakefile asm-generic prepare1: prepare2 $(version_h) include/generated/utsrelease.h \ - include/config/auto.conf + include/config/auto.conf include/generated/build-salt.h $(cmd_crmodverdir) archprepare: archheaders archscripts prepare1 scripts_basic
@@ -1184,6 +1184,13 @@ $(version_h): $(srctree)/Makefile FORCE include/generated/utsrelease.h: include/config/kernel.release FORCE $(call filechk,utsrelease.h) +define filechk_build-salt.h + ($(CONFIG_SHELL) $(srctree)/scripts/gensalt $(CONFIG_BUILD_ID_SALT)) +endef + +include/generated/build-salt.h: $(srctree)/Makefile FORCE + $(call filechk,build-salt.h) + PHONY += headerdep headerdep: $(Q)find $(srctree)/include/ -name '*.h' | xargs --max-args 1 \
init/Kconfig +8 -0
@@ -1924,3 +1924,11 @@ source "kernel/Kconfig.locks" config ARCH_HAS_SYNC_CORE_BEFORE_USERMODE bool + +config BUILD_ID_SALT + string "Build ID Salt" + help + The build ID is used to link binaries and their debug info. Setting + this option will use the value in the calculation of the build id. + This is mostly useful for distributions which want to ensure the + build is unique between builds. It's safe to leave this empty.
scripts/gensalt new file +21 -0
@@ -0,0 +1,21 @@ +#!/bin/sh + +if [[ $1 = "" ]]; then + echo "#define BUILD_ID_SALT" + exit 0 +fi + +BUILD_ID_SALT=$1 + +echo "#define BUILD_ID_SALT \\" +echo ".comment (INFO) : \\" +echo " { \\" + +_TAG=`echo $BUILD_ID_SALT | sed -e 's/\(.\)/\1 /g'` +for c in $_TAG; do + _HEX=`echo -n $c | od -A n -t x1 | tr -d ' ' ` + echo "BYTE(0x$_HEX); \\" +done +echo "BYTE(0x00); \\" + +echo " } "
Signature · 1 line
2.16.2
RFC PATCH v2 2/3 kbuild: Link with generated build-salt header
In reply to Laura AbbottNow that we have a header with appropriate data, link it into the kernel and modules. If BUILD_ID_SALT isn't set, the script should be empty.
---
v2: Changed names to be consistent
--- Makefile | 4 +++- scripts/.gitignore | 1 + scripts/Makefile | 2 +- scripts/build-salt.lds.S | 5 +++++ scripts/link-vmlinux.sh | 3 ++- 5 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 scripts/build-salt.lds.S
Makefile +3 -1
@@ -425,7 +425,8 @@ KBUILD_AFLAGS_KERNEL := KBUILD_CFLAGS_KERNEL := KBUILD_AFLAGS_MODULE := -DMODULE KBUILD_CFLAGS_MODULE := -DMODULE -KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds +KBUILD_LDFLAGS_MODULE := -T $(srctree)/scripts/module-common.lds \ + -T $(srctree)/scripts/build-salt.lds GCC_PLUGINS_CFLAGS := export ARCH SRCARCH CONFIG_SHELL HOSTCC HOSTCFLAGS CROSS_COMPILE AS LD CC
@@ -1004,6 +1005,7 @@ export KBUILD_VMLINUX_INIT := $(head-y) $(init-y) export KBUILD_VMLINUX_MAIN := $(core-y) $(libs-y2) $(drivers-y) $(net-y) $(virt-y) export KBUILD_VMLINUX_LIBS := $(libs-y1) export KBUILD_LDS := arch/$(SRCARCH)/kernel/vmlinux.lds +export EXTRA_LDS := scripts/build-salt.lds export LDFLAGS_vmlinux # used by scripts/package/Makefile export KBUILD_ALLDIRS := $(sort $(filter-out arch/%,$(vmlinux-alldirs)) arch Documentation include samples scripts tools)
scripts/.gitignore +1 -0
@@ -13,3 +13,4 @@ asn1_compiler extract-cert sign-file insert-sys-cert +build-salt.lds
scripts/Makefile +1 -1
@@ -25,7 +25,7 @@ HOSTCFLAGS_asn1_compiler.o = -I$(srctree)/include HOSTLOADLIBES_sign-file = -lcrypto HOSTLOADLIBES_extract-cert = -lcrypto -always := $(hostprogs-y) $(hostprogs-m) +always := $(hostprogs-y) $(hostprogs-m) build-salt.lds # The following hostprogs-y programs are only build on demand hostprogs-y += unifdef
scripts/build-salt.lds.S new file +5 -0
@@ -0,0 +1,5 @@ +#include <generated/build-salt.h> + +SECTIONS { + BUILD_ID_SALT +}
scripts/link-vmlinux.sh +2 -1
@@ -93,6 +93,7 @@ modpost_link() vmlinux_link() { local lds="${objtree}/${KBUILD_LDS}" + local extra_lds="${objtree}/${EXTRA_LDS}" local objects if [ "${SRCARCH}" != "um" ]; then
@@ -114,7 +115,7 @@ vmlinux_link() fi ${LD} ${LDFLAGS} ${LDFLAGS_vmlinux} -o ${2} \ - -T ${lds} ${objects} + -T ${lds} -T ${extra_lds} ${objects} else if [ -n "${CONFIG_THIN_ARCHIVES}" ]; then objects="-Wl,--whole-archive \
Signature · 1 line
2.16.2
Re: [RFCv2 PATCH 2/3] kbuild: Link with generated build-salt header
2018-03-30 3:01 GMT+09:00 Laura Abbott <[email protected]>:
scripts/build-salt.lds.S line 5
Quoted 11 lines
scripts/build-salt.lds.S new file +5
-0@@ -0,0 +1,5 @@ +#include <generated/build-salt.h> + +SECTIONS { + BUILD_ID_SALT +}
Do you need this just for wrapping <generate/build-salt.h> ?
How about generating scripts/build-salt.lds
directly by scripts/gensalt ?
<generated/build-salt.h> is unneeded, then
"some sporadic failures about missing the generated header" will be solved.
I think something like follows will be simpler and better.
always := $(hostprogs-y) $(hostprogs-m) build-salt.lds
define filechk_build-salt.lds
($(CONFIG_SHELL) $(srctree)/scripts/gensalt $(CONFIG_BUILD_ID_SALT))
endef
$(obj)/build-salt.lds: $(src)/gensalt FORCE
$(call filechk,build-salt.lds)
Signature · 2 lines
Best Regards Masahiro Yamada
RFC PATCH v2 3/3 x86/vdso: Add build salt to the vDSO
In reply to Laura AbbottThe vDSO is linked separately from the kernel and modules. Ensure it picks up the comment section, if available.
---
v2: Updated name
--- arch/x86/entry/vdso/vdso-layout.lds.S | 3 +++ 1 file changed, 3 insertions(+)
arch/x86/entry/vdso/vdso-layout.lds.S +3 -0
@@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <asm/vdso.h> +#include <generated/build-salt.h> /* * Linker script for vDSO. This is an ELF shared object prelinked to
@@ -95,6 +96,8 @@ SECTIONS .altinstructions : { *(.altinstructions) } :text .altinstr_replacement : { *(.altinstr_replacement) } :text + BUILD_ID_SALT + /DISCARD/ : { *(.discard) *(.discard.*)
Signature · 1 line
2.16.2
Re: [RFCv2 PATCH 3/3] x86/vdso: Add build salt to the vDSO
2018-03-30 3:01 GMT+09:00 Laura Abbott <[email protected]>:
Quoted 31 lines
The vDSO is linked separately from the kernel and modules. Ensure it picks up the comment section, if available.
Signed-off-by Laura Abbott <[email protected]>---
v2: Updated name--- arch/x86/entry/vdso/vdso-layout.lds.S | 3 +++ 1 file changed, 3 insertions(+)arch/x86/entry/vdso/vdso-layout.lds.S +3
-1@@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0 */ #include <asm/vdso.h> +#include <generated/build-salt.h> /* * Linker script for vDSO. This is an ELF shared object prelinked to@@ -95,6 +96,8 @@ SECTIONS .altinstructions : { *(.altinstructions) } :text .altinstr_replacement : { *(.altinstr_replacement) } :text + BUILD_ID_SALT + /DISCARD/ : { *(.discard) *(.discard.*) --
Quoted 2 lines
2.16.2
For consistency, I think '-T scripts/build-salt.lds' should be passed to cmd_vdso
in arch/x86/entry/vdso/Makefile.
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 3 lines · Laura Abbott
I'm still mostly looking for feedback whether
this would be acceptable for merging or if we should just persue a --build-id-salt in binutils.
Personally I would go with this approach. It seems simple and it might take years before a new linker option is available everywhere.
To simplify things I think you could just always add the extra vdso .comment initialized to something like KERNELRELEASE. Which distros seem to update anyway to include their build number, so they wouldn't need to do anything special to "update the build salt".
Cheers,
Mark
2018-03-30 21:40 GMT+09:00 Mark Wielaard <[email protected]>:
Quoted 7 lines · Laura Abbott
Quoted 3 lines
I'm still mostly looking for feedback whether
this would be acceptable for merging or if we should just persue a --build-id-salt in binutils.Personally I would go with this approach. It seems simple and it might take years before a new linker option is available everywhere.
Indeed. This series is easier than --build-id-salt.
If you do not see any better solution, I can accept this.
BTW, when I read
https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo
I thought "we could reverse the symlink direction from debug file to build-id file)"
sensible (but I understand it is not easy to change this way).
If two packages share an identical image, one package can borrow the image from the other, then the storage space will be saved.
So, having identical ID should be advantage, but we actually see only disadvantage...
Quoted 5 lines
To simplify things I think you could just always add the extra vdso .comment initialized to something like KERNELRELEASE. Which distros seem to update anyway to include their build number, so they wouldn't need to do anything special to "update the build salt".
Signature · 2 lines
Best Regards Masahiro Yamada
Andy Lutomirski
maintainerQuoted 22 lines · Masahiro Yamada
2018-03-30 21:40 GMT+09:00 Mark Wielaard <[email protected]>:
Quoted 7 lines · Laura Abbott
Quoted 3 lines
I'm still mostly looking for feedback whether
this would be acceptable for merging or if we should just persue a --build-id-salt in binutils.Personally I would go with this approach. It seems simple and it might take years before a new linker option is available everywhere.
Indeed. This series is easier than --build-id-salt.
If you do not see any better solution, I can accept this.
BTW, when I read
https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo
I thought "we could reverse the symlink direction from debug file to build-id file)"
sensible (but I understand it is not easy to change this way).
Quoted 15 lines
If two packages share an identical image, one package can borrow the image from the other, then the storage space will be saved.
So, having identical ID should be advantage, but we actually see only disadvantage...
Quoted 5 lines
To simplify things I think you could just always add the extra vdso .comment initialized to something like KERNELRELEASE. Which distros seem to update anyway to include their build number, so they wouldn't need to do anything special to "update the build salt".
That's what I was thinking, too. Would that solve Fedora's problem?
Quoted 35 lines · Andy Lutomirski
Quoted 28 lines · Masahiro Yamada
2018-03-30 21:40 GMT+09:00 Mark Wielaard <[email protected]>:
Quoted 7 lines · Laura Abbott
Quoted 3 lines
I'm still mostly looking for feedback whether
this would be acceptable for merging or if we should just persue a --build-id-salt in binutils.Personally I would go with this approach. It seems simple and it might take years before a new linker option is available everywhere.
Indeed. This series is easier than --build-id-salt.
If you do not see any better solution, I can accept this.
BTW, when I read
https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo
I thought "we could reverse the symlink direction from debug file to build-id file)"
sensible (but I understand it is not easy to change this way).If two packages share an identical image, one package can borrow the image from the other, then the storage space will be saved.
So, having identical ID should be advantage, but we actually see only disadvantage...
Quoted 8 lines
Quoted 5 lines
Quoted 5 lines
To simplify things I think you could just always add the extra vdso .comment initialized to something like KERNELRELEASE. Which distros seem to update anyway to include their build number, so they wouldn't need to do anything special to "update the build salt".
That's what I was thinking, too. Would that solve Fedora's problem?
Yes, that seems reasonable.
2018-03-30 3:01 GMT+09:00 Laura Abbott <[email protected]>:
Quoted 13 lines
Hi,
This is v2 of my proposal to allow unique build-ids in the kernel. from last time:
""
In Fedora, the debug information is packaged separately (foo-debuginfo) and can be installed separately. There's been a long standing issue where only one version of a debuginfo info package can be installed at a time. Mark Wielaard made an effort for Fedora 27 to allow parallel installation of debuginfo (see
https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo for more details)
Quoted 10 lines
Part of the requirement to allow this to work is that build ids are unique between builds. The existing upstream rpm implementation ensures this by re-calculating the build-id using the version and release as a seed. This doesn't work 100% for the kernel because of the vDSO which is its own binary and doesn't get updated. After poking holes in a few of my ideas, there was a discussion with some people from the binutils team about adding --build-id-salt to let ld do the calculation debugedit is doing. There was a counter proposal made about adding some extra information via a .comment which will affect the build id calculation but just get stripped out. ""
I think you already know '--build-id=uuid' linker option.
Doesn't this solve your problem?
The disadvantage of this option is,
we will lose reproducible building because --build-id=uuid adds every time random salt.
The advantage is, the implementation is even simpler, and easier to migrate to --build-id-salt once it is supported in the future.
Quoted 4 lines
This v2 cleans up the naming to be consistent and also switches to a config option vs. an environment variable. I've seen some sporadic failures about missing the generated header so I think I'm still missing a dependency somewhere.
Right.
There is no dependency between 'prepare' and 'scripts' in the top Makefile.
Therefore, Kbuild can run them simultaneously, which would cause a race in parallel building.
I'm still mostly looking for feedback whether
Quoted 31 lines
this would be acceptable for merging or if we should just persue a --build-id-salt in binutils.
Thanks,
LauraLaura Abbott (3):
kbuild: Introduce build-salt generated header
kbuild: Link with generated build-salt header
x86/vdso: Add build salt to the vDSOMakefile | 13 +++++++++++-- arch/x86/entry/vdso/vdso-layout.lds.S | 3 +++ init/Kconfig | 8 ++++++++ scripts/.gitignore | 1 + scripts/Makefile | 2 +- scripts/build-salt.lds.S | 5 +++++ scripts/gensalt | 21 +++++++++++++++++++++ scripts/link-vmlinux.sh | 3 ++- 8 files changed, 52 insertions(+), 4 deletions(-) create mode 100644 scripts/build-salt.lds.S create mode 100755 scripts/gensalt--
2.16.2--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Signature · 2 lines
Best Regards Masahiro Yamada
Quoted 30 lines · Masahiro Yamada
2018-03-30 3:01 GMT+09:00 Laura Abbott <[email protected]>:
Quoted 13 lines
Hi,
This is v2 of my proposal to allow unique build-ids in the kernel. from last time:
""
In Fedora, the debug information is packaged separately (foo-debuginfo) and can be installed separately. There's been a long standing issue where only one version of a debuginfo info package can be installed at a time. Mark Wielaard made an effort for Fedora 27 to allow parallel installation of debuginfo (see
https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo for more details)Quoted 10 lines
Part of the requirement to allow this to work is that build ids are unique between builds. The existing upstream rpm implementation ensures this by re-calculating the build-id using the version and release as a seed. This doesn't work 100% for the kernel because of the vDSO which is its own binary and doesn't get updated. After poking holes in a few of my ideas, there was a discussion with some people from the binutils team about adding --build-id-salt to let ld do the calculation debugedit is doing. There was a counter proposal made about adding some extra information via a .comment which will affect the build id calculation but just get stripped out. ""
I think you already know '--build-id=uuid' linker option.
Doesn't this solve your problem?
Quoted 9 lines
The disadvantage of this option is,
we will lose reproducible building because --build-id=uuid adds every time random salt.The advantage is, the implementation is even simpler, and easier to migrate to --build-id-salt once it is supported in the future.
It could, theoretically. The reproducibility is nice though and I'd like to keep the kernel close to matching what other packages do though.
Thanks,
Laura
Quoted 54 lines
Quoted 4 lines
This v2 cleans up the naming to be consistent and also switches to a config option vs. an environment variable. I've seen some sporadic failures about missing the generated header so I think I'm still missing a dependency somewhere.
Right.
There is no dependency between 'prepare' and 'scripts' in the top
Makefile.
Therefore,Kbuildcan run them simultaneously, which would cause a race in parallel building.I'm still mostly looking for feedback whether
Quoted 31 lines
this would be acceptable for merging or if we should just persue a --build-id-salt in binutils.
Thanks,
LauraLaura Abbott (3):
kbuild: Introduce build-salt generated header
kbuild: Link with generated build-salt header
x86/vdso: Add build salt to the vDSOMakefile | 13 +++++++++++-- arch/x86/entry/vdso/vdso-layout.lds.S | 3 +++ init/Kconfig | 8 ++++++++ scripts/.gitignore | 1 + scripts/Makefile | 2 +- scripts/build-salt.lds.S | 5 +++++ scripts/gensalt | 21 +++++++++++++++++++++ scripts/link-vmlinux.sh | 3 ++- 8 files changed, 52 insertions(+), 4 deletions(-)create mode 100644
scripts/build-salt.lds.S
create mode 100755scripts/gensalt--
2.16.2--
To unsubscribe from this list: send the line "unsubscribe linux-kbuild" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
2018-05-15 6:02 GMT+09:00 Laura Abbott <[email protected]>:
Quoted 51 lines · Masahiro Yamada
Quoted 40 lines
2018-03-30 3:01 GMT+09:00 Laura Abbott <[email protected]>:
Quoted 18 lines
Hi,
This is v2 of my proposal to allow unique build-ids in the kernel. from last time:
""
In Fedora, the debug information is packaged separately (foo-debuginfo) and
can be installed separately. There's been a long standing issue where only one
version of a debuginfo info package can be installed at a time. Mark Wielaard
made an effort for Fedora 27 to allow parallel installation of debuginfo (see
https://fedoraproject.org/wiki/Changes/ParallelInstallableDebuginfo for more details)Quoted 13 lines
Part of the requirement to allow this to work is that build ids are unique between builds. The existing upstream rpm implementation ensures this by re-calculating the build-id using the version and release as a seed. This doesn't work 100% for the kernel because of the vDSO which is its own binary and doesn't get updated. After poking holes in a few of my ideas, there was a discussion with some people from the binutils team about
adding --build-id-salt to let ld do the calculation debugedit is doing. There
was a counter proposal made about adding some extra information via a .comment
which will affect the build id calculation but just get stripped out. ""I think you already know '--build-id=uuid' linker option.
Doesn't this solve your problem?
Quoted 9 lines
The disadvantage of this option is,
we will lose reproducible building because --build-id=uuid adds every time random salt.The advantage is, the implementation is even simpler, and easier to migrate to --build-id-salt once it is supported in the future.
Quoted 3 lines
It could, theoretically. The reproducibility is nice though and I'd like to keep the kernel close to matching what other packages do though.
Okay.
I left some comments in v2
about improvement, and cause of
the sporadic build failures.
Will wait for v3.
Signature · 2 lines
Best Regards Masahiro Yamada