]> Git Repo - buildroot-mgba.git/commitdiff
package/pkg-download: lookup hash files in global-patch-dir
authorYann E. MORIN <[email protected]>
Mon, 6 Nov 2023 19:09:13 +0000 (20:09 +0100)
committerPeter Korsgaard <[email protected]>
Tue, 7 Nov 2023 10:48:46 +0000 (11:48 +0100)
Currently, we expect and only use hash files that lie within the package
directory, alongside the .mk file. Those hash files are thus bundled
with Buildroot.

This implies that only what's known to Buildroot can ever get into those
hash files. For packages where the version is fixed (or a static
choice), then we can carry hashes for those known versions.

However, we do have a few packages for which the version is a free-form
entry, where the user can provide a custom location and/or version.  like
a custom VCS tree and revision, or a custom tarball URL. This means that
Buildroot has no way to be able to cary hashes for such custom versions.

This means that there is no integrity check that what was downloaded is
what was expected. For a sha1 in a git tree, this is a minor issue,
because the sha1 by itself is already a hash of the expected content.
But for custom tarballs URLs, or for a tag in a VCS, there is indeed no
integrity check.

Buildroot can't provide such hashes, but interested users may want to
provide those, and currently there is no (easy) way to do so.

We leverage the existing global-patch-dir mechanism to look for extra
hash files. We use the same heuristic that is used for bundled hash
files, and for each global patch directory <dir>, we use the first file
to exist among:
 1. look into <dir>/<package>/<version>/<package>.hash
 2. look into <dir>/<package>/<package>.hash

Reported-by: "Martin Zeiser (mzeiser)" <[email protected]>
Signed-off-by: Yann E. MORIN <[email protected]>
Signed-off-by: Peter Korsgaard <[email protected]>
Config.in
docs/manual/adding-packages-directory.adoc
docs/manual/customize-patches.adoc
package/pkg-download.mk
package/pkg-generic.mk
package/pkg-utils.mk

index 7dd49567f60057a1db3b289b50309a3d78ef6951..b344d0e80aec113ef80c4186e4c9ae3fdd44ad8c 100644 (file)
--- a/Config.in
+++ b/Config.in
@@ -674,12 +674,12 @@ config BR2_PACKAGE_OVERRIDE_FILE
          documentation for more details on this feature.
 
 config BR2_GLOBAL_PATCH_DIR
-       string "global patch directories"
+       string "global patch and hash directories"
        help
          You may specify a space separated list of one or more
-         directories containing global package patches. For a specific
-         version <packageversion> of a specific package <packagename>,
-         patches are applied as follows:
+         directories containing global package patches and/or hashes.
+         For a specific version <packageversion> of a specific package
+         <packagename>, patches are looked up as follows:
 
          First, the default Buildroot patch set for the package is
          applied from the package's directory in Buildroot.
@@ -693,6 +693,8 @@ config BR2_GLOBAL_PATCH_DIR
          exists, then all *.patch files in the directory will be
          applied.
 
+         The hash files are looked up similarly to the patches.
+
 menu "Advanced"
 
 config BR2_FORCE_HOST_BUILD
index 7150018a3b848c3a6727b440890e0bb4c1c41e7b..5a0f298eb140da60577f6bbc04b4b7e719a29cf6 100644 (file)
@@ -540,6 +540,12 @@ mercurial) because Buildroot currently does not generate reproducible
 tarballs when source code is fetched from such version control
 systems.
 
+Additionally, for packages for which it is possible to specify a custom
+version (e.g. a custom version string, a remote tarball URL, or a VCS
+repository location and changeset), Buildroot can't carry hashes for
+those. It is however possible to xref:customize-hashes[provide a list of
+extra hashes] that can cover such cases.
+
 Hashes should only be added in +.hash+ files for files that are
 guaranteed to be stable. For example, patches auto-generated by Github
 are not guaranteed to be stable, and therefore their hashes can change
index eb98d1bea2c8529f89f58b6eb80626a2c45b16db..72e87c3c0494f7dd1f4c155f618d48f7f2975a92 100644 (file)
@@ -1,8 +1,10 @@
 // -*- mode:doc -*- ;
 // vim: set syntax=asciidoc:
 
+=== Adding project-specific patches and hashes
+
 [[customize-patches]]
-=== Adding project-specific patches
+==== Providing extra patches
 
 It is sometimes useful to apply 'extra' patches to packages - on top of
 those provided in Buildroot. This might be used to support custom
@@ -57,3 +59,23 @@ are available at a URL. *Note:* +BR2_LINUX_KERNEL_PATCH+ specifies kernel
 patches that are applied after patches available in +BR2_GLOBAL_PATCH_DIR+,
 as it is done from a post-patch hook of the Linux package.
 
+
+[[customize-hashes]]
+==== Providing extra hashes
+
+Buildroot bundles a xref:adding-packages-hash[list of hashes] against
+which it checks the integrity of the downloaded archives, or of those
+it generates locally from VCS checkouts. However, it can only do so
+for the known versions; for packages where it is possible to specify
+a custom version (e.g. a custom version string, a remote tarball URL,
+or a VCS repository location and changeset), Buildroot can't carry
+hashes for those.
+
+For users concerned with the integrity of such downloads, it is possible
+to provide a list of hashes that Buildroot can use to check arbitrary
+downloaded files. Those extra hashes are looked up similarly to the
+extra patches (above); for each directory in +BR2_GLOBAL_PATCH_DIR+,
+the first file to exist is used to check a package download:
+
+* +<global-patch-dir>/<packagename>/<packageversion>/<packagename>.hash+
+* +<global-patch-dir>/<packagename>/<packagename>.hash+
index e5cd83d859d5700bcc2e095dbbbf2b7a83941285..bf1c19e5ecf4186105f914809e2c7346fb42c34c 100644 (file)
@@ -115,7 +115,7 @@ define DOWNLOAD
                -d '$($(2)_DL_DIR)' \
                -D '$(DL_DIR)' \
                -f '$(notdir $(1))' \
-               -H '$($(2)_HASH_FILE)' \
+               $(foreach f,$($(2)_HASH_FILES),-H '$(f)') \
                -n '$($(2)_BASENAME_RAW)' \
                -N '$($(2)_RAWNAME)' \
                -o '$($(2)_DL_DIR)/$(notdir $(1))' \
index 6c24be750562fa05dda7022ffdfb0d87e7d437b7..577a148c1e629f8164fe59b008fdf578e6310bc2 100644 (file)
@@ -509,11 +509,15 @@ else
 endif
 $(2)_VERSION := $$(call sanitize,$$($(2)_DL_VERSION))
 
-$(2)_HASH_FILE = \
+$(2)_HASH_FILES = \
        $$(strip \
-               $$(if $$(wildcard $$($(2)_PKGDIR)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash),\
-                       $$($(2)_PKGDIR)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash,\
-                       $$($(2)_PKGDIR)/$$($(2)_RAWNAME).hash))
+               $$(foreach d, $$($(2)_PKGDIR) $$(addsuffix /$$($(2)_RAWNAME), $$(call qstrip,$$(BR2_GLOBAL_PATCH_DIR))),\
+                       $$(if $$(wildcard $$(d)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash),\
+                               $$(d)/$$($(2)_VERSION)/$$($(2)_RAWNAME).hash,\
+                               $$(d)/$$($(2)_RAWNAME).hash\
+                       )\
+               )\
+       )
 
 ifdef $(3)_OVERRIDE_SRCDIR
   $(2)_OVERRIDE_SRCDIR ?= $$($(3)_OVERRIDE_SRCDIR)
@@ -1138,7 +1142,7 @@ ifneq ($$(call qstrip,$$($(2)_SOURCE)),)
 ifeq ($$(call qstrip,$$($(2)_LICENSE_FILES)),)
        $(Q)$$(call legal-warning-pkg,$$($(2)_BASENAME_RAW),cannot save license ($(2)_LICENSE_FILES not defined))
 else
-       $(Q)$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$(call UPPERCASE,$(4)),$$($(2)_RAWNAME),$$($(2)_BASENAME_RAW),$$(F),$$($(2)_DIR)/$$(F),$$($(2)_HASH_FILE))$$(sep))
+       $(Q)$$(foreach F,$$($(2)_LICENSE_FILES),$$(call legal-license-file,$$(call UPPERCASE,$(4)),$$($(2)_RAWNAME),$$($(2)_BASENAME_RAW),$$(F),$$($(2)_DIR)/$$(F),$$($(2)_HASH_FILES))$$(sep))
 endif # license files
 
 ifeq ($$($(2)_REDISTRIBUTE),YES)
index b91061a572f910d3a0ccc6e077682aec7086cc1c..059e86ae0a01ca0da7eb1dc0f61403193ae2ed12 100644 (file)
@@ -280,7 +280,7 @@ define legal-manifest # {HOST|TARGET}, pkg, version, license, license-files, sou
        echo '"$(2)","$(3)","$(4)","$(5)","$(6)","$(7)","$(8)"' >>$(LEGAL_MANIFEST_CSV_$(1))
 endef
 
-define legal-license-file # {HOST|TARGET}, pkgname, pkgname-pkgver, filename, file-fullpath, pkg-hashfile
+define legal-license-file # {HOST|TARGET}, pkgname, pkgname-pkgver, filename, file-fullpath, pkg-hashfiles
        mkdir -p $(LICENSE_FILES_DIR_$(1))/$(3)/$(dir $(4)) && \
        { \
                support/download/check-hash $(5) $(4) $(6); \
This page took 0.049208 seconds and 4 git commands to generate.