| 1 |
# Demo of Adding Provenance Information to Debug Packages |
| 2 |
|
| 3 |
[Debian](https://www.debian.org/), |
| 4 |
one of the most popular Linux distributions, distributes its software components as |
| 5 |
precompiled "binary packages." Since binary packages have debugging information removed, they |
| 6 |
also distribute "debug packages" that include such information for debugging purposes. |
| 7 |
|
| 8 |
In this demo, from a perspective of Linux distributors, we will demonstrate a way to include |
| 9 |
provenance information obtained using ESSTRA into a debug package by modifying the |
| 10 |
`debian/rules` file. This approach extends the concept of Debian debug package. |
| 11 |
|
| 12 |
We will use a relatively compact **unzip** package as an example to explain the specific steps. |
| 13 |
|
| 14 |
## Purpose of This Demo |
| 15 |
|
| 16 |
By including in the packages to distribute the provenance information of the binary files, |
| 17 |
which details the source files used to create the binary flies, Linux distributions can offer |
| 18 |
the following benefits to distributors, users, and the entire software supply chain: |
| 19 |
|
| 20 |
* **Identify Binary Provenance**: With clear provenance information for each binary, |
| 21 |
distributors can more easily guarantee quality and reliability, and users can verify the |
| 22 |
quality and safety of the software. |
| 23 |
* **Provide Accurate License Information**: By precisely identifying the license information of |
| 24 |
source files, distributors can provide more accurate license details, and users can better |
| 25 |
comply with licenses when using or redistributing binaries. |
| 26 |
* **Identify and Respond to Vulnerabilities Rapidly**: When vulnerabilities are reported, |
| 27 |
provenance information allows for the quick identification of affected components and the |
| 28 |
implementation of countermeasures, minimizing security risks. |
| 29 |
* **Enhance Software Supply Chain Transparency**: Sharing accurate provenance information |
| 30 |
improves transparency across the entire supply chain. |
| 31 |
* **Generate SBOMs**: By utilizing provenance information, the accuracy of the Software Bill of |
| 32 |
Materials (SBOM) can be enhanced. This allows for detailed documentation of components and |
| 33 |
dependencies, thereby improving transparency and security. |
| 34 |
|
| 35 |
Based on the above background, this demo will illustrate how to package binary provenance |
| 36 |
information with ESSTRA, using Debian as an example, which is one of the most popular Linux |
| 37 |
distributions. The concepts demonstrated here can be applied not only to Debian but to any |
| 38 |
Linux distribution. |
| 39 |
|
| 40 |
## Execution Environment |
| 41 |
|
| 42 |
This document assumes an x86_64 PC with Ubuntu 22.04 installed as the execution environment, |
| 43 |
just as described in the top directory's [README.md](/README.md) for ESSTRA. |
| 44 |
|
| 45 |
First, build and install ESSTRA on your PC: |
| 46 |
|
| 47 |
```shell |
| 48 |
$ sudo apt install -y gcc-11-plugin-dev python3-yaml |
| 49 |
$ git clone https://github.com/sony/esstra.git |
| 50 |
$ cd esstra |
| 51 |
$ make |
| 52 |
$ sudo make install |
| 53 |
``` |
| 54 |
|
| 55 |
Next, uncomment the `deb-src` lines in `/etc/apt/sources.list` and update the package list: |
| 56 |
|
| 57 |
```shell |
| 58 |
$ sudo sed -i 's/^# deb-src/deb-src/' /etc/apt/sources.list |
| 59 |
$ sudo apt update |
| 60 |
``` |
| 61 |
|
| 62 |
Then, install the necessary packages for building and managing Debian packages: |
| 63 |
|
| 64 |
```shell |
| 65 |
$ sudo apt install -y debhelper devscripts |
| 66 |
``` |
| 67 |
|
| 68 |
If you have already installed the Spec File as described in Section |
| 69 |
[Installing Spec File](/README.md#installing-spec-file) in the top directory's README.md, |
| 70 |
**uninstall it before proceeding**: |
| 71 |
|
| 72 |
```shell |
| 73 |
$ sudo make uninstall-specs |
| 74 |
``` |
| 75 |
|
| 76 |
## Debian Package Types |
| 77 |
|
| 78 |
Debian offers several types of packages. In this demo, we will focus on the following three types: |
| 79 |
|
| 80 |
* **Binary Package**: Software in executable form. Ready to use upon installation. |
| 81 |
* **Debug Package**: Contains debugging information. Helps developers identify issues. |
| 82 |
* **Source Package**: Includes source code and build information. Used to create binary and debug packages. |
| 83 |
|
| 84 |
Using the **unzip** package as an example, the steps to build packages from a source package are as follows: |
| 85 |
|
| 86 |
1. Install the build dependencies: |
| 87 |
```shell |
| 88 |
$ sudo apt build-dep unzip |
| 89 |
``` |
| 90 |
2. Download and unpack the source package: |
| 91 |
```shell |
| 92 |
$ apt source unzip |
| 93 |
$ ls -l |
| 94 |
drwxrwxr-x 31 snagao snagao 4.0K Apr 21 16:02 unzip-6.0/ |
| 95 |
-rw-r--r-- 1 snagao snagao 29K Feb 8 2024 unzip_6.0-26ubuntu3.2.debian.tar.xz |
| 96 |
-rw-r--r-- 1 snagao snagao 1.8K Feb 8 2024 unzip_6.0-26ubuntu3.2.dsc |
| 97 |
-rw-r--r-- 1 snagao snagao 1.4M Jun 8 2009 unzip_6.0.orig.tar.gz |
| 98 |
``` |
| 99 |
3. Go to the unpacked source directory: |
| 100 |
```shell |
| 101 |
$ cd unzip-6.0 |
| 102 |
``` |
| 103 |
4. Run the build command: |
| 104 |
```shell |
| 105 |
$ dpkg-buildpackage -us -uc |
| 106 |
``` |
| 107 |
5. Return to the parent directory and verify the generated packages. |
| 108 |
```shell |
| 109 |
$ cd .. |
| 110 |
$ ls -l |
| 111 |
drwxrwxr-x 31 snagao snagao 4.0K Apr 21 16:02 unzip-6.0/ |
| 112 |
-rw-rw-r-- 1 snagao snagao 6.9K Apr 21 16:02 unzip_6.0-26ubuntu3.2_amd64.buildinfo |
| 113 |
-rw-rw-r-- 1 snagao snagao 2.1K Apr 21 16:02 unzip_6.0-26ubuntu3.2_amd64.changes |
| 114 |
-rw-r--r-- 1 snagao snagao 178K Apr 21 16:02 unzip_6.0-26ubuntu3.2_amd64.deb # binary package |
| 115 |
-rw-r--r-- 1 snagao snagao 29K Apr 21 16:02 unzip_6.0-26ubuntu3.2.debian.tar.xz |
| 116 |
-rw-r--r-- 1 snagao snagao 928 Apr 21 16:02 unzip_6.0-26ubuntu3.2.dsc |
| 117 |
-rw-r--r-- 1 snagao snagao 1.4M Jun 8 2009 unzip_6.0.orig.tar.gz |
| 118 |
-rw-r--r-- 1 snagao snagao 284K Apr 21 16:02 unzip-dbgsym_6.0-26ubuntu3.2_amd64.ddeb # debug package |
| 119 |
``` |
| 120 |
|
| 121 |
The following files generated are the binary and debug packages for **unzip**: |
| 122 |
|
| 123 |
* `unzip_6.0-26ubuntu3.2_amd64.deb` (binary package) |
| 124 |
* `unzip-dbgsym_6.0-26ubuntu3.2_amd64.ddeb` (debug package) |
| 125 |
|
| 126 |
The contents of these packages are shown below using the `dpkg -c` command: |
| 127 |
|
| 128 |
* **`unzip_6.0-26ubuntu3.2_amd64.deb`** |
| 129 |
```shell |
| 130 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./ |
| 131 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/ |
| 132 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/bin/ |
| 133 |
-rwxr-xr-x root/root 22832 2024-02-02 00:52 ./usr/bin/funzip |
| 134 |
-rwxr-xr-x root/root 182720 2024-02-02 00:52 ./usr/bin/unzip |
| 135 |
-rwxr-xr-x root/root 84400 2024-02-02 00:52 ./usr/bin/unzipsfx |
| 136 |
-rwxr-xr-x root/root 2959 2024-02-02 00:52 ./usr/bin/zipgrep |
| 137 |
hrwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/bin/zipinfo link to ./usr/bin/unzip |
| 138 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/ |
| 139 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/mime/ |
| 140 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/mime/packages/ |
| 141 |
-rw-r--r-- root/root 77 2021-01-11 06:44 ./usr/lib/mime/packages/unzip |
| 142 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/ |
| 143 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/doc/ |
| 144 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/doc/unzip/ |
| 145 |
-rw-r--r-- root/root 4633 2009-01-03 01:33 ./usr/share/doc/unzip/BUGS |
| 146 |
-rw-r--r-- root/root 21529 2009-04-20 09:02 ./usr/share/doc/unzip/History.600.gz |
| 147 |
-rw-r--r-- root/root 9113 2009-04-20 08:10 ./usr/share/doc/unzip/ToDo |
| 148 |
-rw-r--r-- root/root 7169 2024-02-02 00:52 ./usr/share/doc/unzip/changelog.Debian.gz |
| 149 |
-rw-r--r-- root/root 4086 2021-01-11 06:44 ./usr/share/doc/unzip/copyright |
| 150 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/man/ |
| 151 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/man/man1/ |
| 152 |
-rw-r--r-- root/root 1977 2024-02-02 00:52 ./usr/share/man/man1/funzip.1.gz |
| 153 |
-rw-r--r-- root/root 18130 2024-02-02 00:52 ./usr/share/man/man1/unzip.1.gz |
| 154 |
-rw-r--r-- root/root 5508 2024-02-02 00:52 ./usr/share/man/man1/unzipsfx.1.gz |
| 155 |
-rw-r--r-- root/root 1541 2024-02-02 00:52 ./usr/share/man/man1/zipgrep.1.gz |
| 156 |
-rw-r--r-- root/root 8884 2024-02-02 00:52 ./usr/share/man/man1/zipinfo.1.gz |
| 157 |
lrwxrwxrwx root/root 0 2024-02-02 00:52 ./usr/share/doc/unzip/changelog.gz -> History.600.gz |
| 158 |
``` |
| 159 |
* **`unzip-dbgsym_6.0-26ubuntu3.2_amd64.ddeb`** |
| 160 |
```shell |
| 161 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./ |
| 162 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/ |
| 163 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/ |
| 164 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/ |
| 165 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/ |
| 166 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/40/ |
| 167 |
-rw-r--r-- root/root 101808 2024-02-02 00:52 ./usr/lib/debug/.build-id/40/0caf854a6ba84bfaaa39ae64da5f9197ad5dde.debug |
| 168 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/e2/ |
| 169 |
-rw-r--r-- root/root 187936 2024-02-02 00:52 ./usr/lib/debug/.build-id/e2/b924e80bdd8fa01cb2ebeee7d8074d91315fe4.debug |
| 170 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/e9/ |
| 171 |
-rw-r--r-- root/root 25800 2024-02-02 00:52 ./usr/lib/debug/.build-id/e9/0bae57722e2d11de6912bb7ff1e3003af0c372.debug |
| 172 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.dwz/ |
| 173 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.dwz/x86_64-linux-gnu/ |
| 174 |
-rw-r--r-- root/root 15752 2024-02-02 00:52 ./usr/lib/debug/.dwz/x86_64-linux-gnu/unzip.debug |
| 175 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/ |
| 176 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/doc/ |
| 177 |
lrwxrwxrwx root/root 0 2024-02-02 00:52 ./usr/share/doc/unzip-dbgsym -> unzip |
| 178 |
``` |
| 179 |
|
| 180 |
For more detail of building packages, |
| 181 |
refer to [the official site](https://www.debian.org/doc/manuals/maint-guide/build.en.html). |
| 182 |
|
| 183 |
## Editing `debian/rules` |
| 184 |
|
| 185 |
Debian source packages include a `debian/` directory that contains some files related to |
| 186 |
packaging. |
| 187 |
|
| 188 |
Among these files, the `debian/rules` file is written in Makefile format and specifies the |
| 189 |
rules for building packages. |
| 190 |
When the `dpkg-buildpackage` command is executed, the compilation and packaging processes are |
| 191 |
carried out according to the content of the file. |
| 192 |
|
| 193 |
In this demo, we aim to achieve the following two objectives, |
| 194 |
both of these objectives can be done by editing the rules in the `debian/rules` file: |
| 195 |
|
| 196 |
* Apply the ESSTRA Core during compilation to include the obtained provenance information in |
| 197 |
the debug package in YAML format. |
| 198 |
* Remove the metadata embedded by the ESSTRA Core from the binaries to be included in the |
| 199 |
packages, ensuring they are in the same state as the original package. |
| 200 |
|
| 201 |
In this demo, we will describe how to "separate" provenance information from each binaries and |
| 202 |
write it to an individual file as mentioned above. However, it is also possible to keep the |
| 203 |
information within the binaries. |
| 204 |
|
| 205 |
### Applying ESSTRA Core during Compilation |
| 206 |
|
| 207 |
The `debian/rules` file defines the variable `CFLAGS` that are passed to GCC. |
| 208 |
|
| 209 |
By adding the option |
| 210 |
`-fplugin=/usr/local/lib/gcc/<gcc-arch>/<gcc-major-version>/plugin/esstracore.so`, the |
| 211 |
ESSTRA Core will intervene in the compiler during the package build process. |
| 212 |
Since we are using GCC version 11 on an x86\_64 PC, make the following modifications: |
| 213 |
|
| 214 |
```diff |
| 215 |
#!/usr/bin/make -f |
| 216 |
|
| 217 |
+ESSTRA_CORE := -fplugin=/usr/local/lib/gcc/x86_64-linux-gnu/11/plugin/esstracore.so |
| 218 |
|
| 219 |
export DEB_BUILD_MAINT_OPTIONS=hardening=-format |
| 220 |
|
| 221 |
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) |
| 222 |
CC = $(DEB_HOST_GNU_TYPE)-gcc |
| 223 |
CFLAGS := `dpkg-buildflags --get CFLAGS` -Wall |
| 224 |
+CFLAGS += $(ESSTRA_CORE) |
| 225 |
LDFLAGS := `dpkg-buildflags --get LDFLAGS` |
| 226 |
: |
| 227 |
: |
| 228 |
``` |
| 229 |
|
| 230 |
### Adding Provenance Information to Debug Packages |
| 231 |
|
| 232 |
By adding a rule with the target name `override_dh_strip:` to the `debian/rules` file, you can |
| 233 |
[override `dh_strip`](https://wiki.debian.org/DebugPackage) and add custom processing during |
| 234 |
the generation of the debug package. |
| 235 |
|
| 236 |
`dh_strip` is a `dehelper` command that generates files for a debug package and removes debug |
| 237 |
information from ELF files which are to be included in the binary package. |
| 238 |
|
| 239 |
Note that source packages for some software may already have an `override_dh_strip:` |
| 240 |
target. For example, the **unzip** package includes the following `override_dh_strip:` rule: |
| 241 |
|
| 242 |
```makfile |
| 243 |
override_dh_strip: |
| 244 |
dh_strip |
| 245 |
cd debian/unzip/usr/bin && rm -f zipinfo && ln unzip zipinfo |
| 246 |
``` |
| 247 |
|
| 248 |
In such cases, you only need to add some lines after the existing `override_dh_strip:` rule. |
| 249 |
|
| 250 |
When the command `dpkg-buildflags -us -uc` is executed, it creates files and directories under |
| 251 |
`debian/unzip/` and `debian/.debhelper/unzip/dbgsym-root/`, which are to be included in the |
| 252 |
binary package and the debug package, respectively. It also strips debug information from |
| 253 |
binaries under `debian/unzip/`: |
| 254 |
|
| 255 |
* **`debian/unzip`**: Temporary directory for the binary package |
| 256 |
```shell |
| 257 |
$ find debian/unzip |
| 258 |
debian/unzip/ |
| 259 |
debian/unzip/usr |
| 260 |
debian/unzip/usr/bin |
| 261 |
debian/unzip/usr/bin/zipinfo |
| 262 |
debian/unzip/usr/bin/funzip |
| 263 |
debian/unzip/usr/bin/unzip |
| 264 |
debian/unzip/usr/bin/unzipsfx |
| 265 |
debian/unzip/usr/bin/zipgrep |
| 266 |
debian/unzip/usr/lib |
| 267 |
: |
| 268 |
(snip) |
| 269 |
: |
| 270 |
``` |
| 271 |
* **`debian/.debhelper/unzip/dbgsym-root/`**: Temporary directory for the debug package |
| 272 |
```shell |
| 273 |
$ find debian/.debhelper/unzip/dbgsym-root |
| 274 |
debian/.debhelper/unzip/ |
| 275 |
debian/.debhelper/unzip/dbgsym-root |
| 276 |
debian/.debhelper/unzip/dbgsym-root/usr |
| 277 |
debian/.debhelper/unzip/dbgsym-root/usr/lib |
| 278 |
debian/.debhelper/unzip/dbgsym-root/usr/lib/debug |
| 279 |
debian/.debhelper/unzip/dbgsym-root/usr/lib/debug/.build-id |
| 280 |
debian/.debhelper/unzip/dbgsym-root/usr/lib/debug/.build-id/e9 |
| 281 |
debian/.debhelper/unzip/dbgsym-root/usr/lib/debug/.build-id/e9/0bae57722e2d11de6912bb7ff1e3003af0c372.debug |
| 282 |
debian/.debhelper/unzip/dbgsym-root/usr/lib/debug/.build-id/e2 |
| 283 |
debian/.debhelper/unzip/dbgsym-root/usr/lib/debug/.build-id/e2/b924e80bdd8fa01cb2ebeee7d8074d91315fe4.debug |
| 284 |
: |
| 285 |
(snip) |
| 286 |
: |
| 287 |
``` |
| 288 |
|
| 289 |
Note that binaries under `debian/unzip/` contain ESSTRA's provenance information due to the |
| 290 |
recent changes in `debian/rules`. |
| 291 |
This is because the `strip` command removes debug information but does not recognize ESSTRA's |
| 292 |
metadata. |
| 293 |
|
| 294 |
To begin with, we use the `rm` command of the ESSTRA Utility to remove ESSTRA's metadata from |
| 295 |
all the ELF files that are to be included in the binary package: |
| 296 |
|
| 297 |
```diff |
| 298 |
#!/usr/bin/make -f |
| 299 |
|
| 300 |
+ESSTRA_CORE := -fplugin=/usr/local/lib/gcc/x86_64-linux-gnu/11/plugin/esstracore.so |
| 301 |
+ESSTRA_UTIL := /usr/local/bin/esstra |
| 302 |
: |
| 303 |
(snip) |
| 304 |
: |
| 305 |
override_dh_strip: |
| 306 |
dh_strip |
| 307 |
cd debian/unzip/usr/bin && rm -f zipinfo && ln unzip zipinfo |
| 308 |
+ $(ESSTRA_UTIL) rm --ignore-errors `find debian/unzip/ -type f -executable` |
| 309 |
``` |
| 310 |
|
| 311 |
Next, we will describe the process to include provenance information in the debug package. |
| 312 |
For each ELF file in the binary package, a corresponding file named |
| 313 |
`usr/lib/debug/.build-id/AA/XX...XX.debug` |
| 314 |
is created to be stored in the debug package. |
| 315 |
This file is essentially a copy of the corresponding ELF file, and just renamed. |
| 316 |
|
| 317 |
The name of the `.debug` file is based on the BuildID of the ELF file, and it varies for each |
| 318 |
file and each build. |
| 319 |
|
| 320 |
Therefore, the `.debug` file contains embedded ESSTRA's metadata. So, we will use the ESSTRA |
| 321 |
Utility to: |
| 322 |
|
| 323 |
* Export the metadata content from the `.debug` file to a `.yaml` file by the `show` command, and |
| 324 |
* Remove the metadata from the `.debug` file by the `rm` command: |
| 325 |
|
| 326 |
```diff |
| 327 |
override_dh_strip: |
| 328 |
dh_strip |
| 329 |
cd debian/unzip/usr/bin && rm -f zipinfo && ln unzip zipinfo |
| 330 |
+ $(ESSTRA_UTIL) rm --ignore-errors `find debian/unzip/ -type f -executable` |
| 331 |
+ for debug in `find debian/.debhelper/unzip/dbgsym-root/ -name "*.debug"` ; do \ |
| 332 |
+ yaml=$${debug%.debug}.yaml ; \ |
| 333 |
+ ($(ESSTRA_UTIL) show --no-comments $$debug > $$yaml && $(ESSTRA_UTIL) rm $$debug) || rm -f $$yaml ; \ |
| 334 |
+ done |
| 335 |
``` |
| 336 |
|
| 337 |
As a result, a `.yaml` file with the same name will be placed in the same location as the |
| 338 |
`.debug` file and will be included in the debug package. |
| 339 |
|
| 340 |
### Summary of Changes to `debian/rules` |
| 341 |
|
| 342 |
To summarize the changes to `debian/rules` explained so far, the following lines starting |
| 343 |
with `+` should be added: |
| 344 |
|
| 345 |
```diff |
| 346 |
#!/usr/bin/make -f |
| 347 |
|
| 348 |
+ESSTRA_CORE := -fplugin=/usr/local/lib/gcc/x86_64-linux-gnu/11/plugin/esstracore.so |
| 349 |
+ESSTRA_UTIL := /usr/local/bin/esstra |
| 350 |
|
| 351 |
export DEB_BUILD_MAINT_OPTIONS=hardening=-format |
| 352 |
|
| 353 |
DEB_HOST_GNU_TYPE := $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE) |
| 354 |
CC = $(DEB_HOST_GNU_TYPE)-gcc |
| 355 |
CFLAGS := `dpkg-buildflags --get CFLAGS` -Wall |
| 356 |
+CFLAGS += $(ESSTRA_CORE) |
| 357 |
LDFLAGS := `dpkg-buildflags --get LDFLAGS` |
| 358 |
|
| 359 |
: |
| 360 |
(snip) |
| 361 |
: |
| 362 |
|
| 363 |
override_dh_strip: |
| 364 |
dh_strip |
| 365 |
cd debian/unzip/usr/bin && rm -f zipinfo && ln unzip zipinfo |
| 366 |
+ $(ESSTRAUTIL) rm --ignore-errors `find debian/unzip/ -type f -executable` |
| 367 |
+ for debug in `find debian/.debhelper/unzip/dbgsym-root/ -name "*.debug"` ; do \ |
| 368 |
+ yaml=$${debug%.debug}.yaml ; \ |
| 369 |
+ ($(ESSTRA_UTIL) show --no-comments $$debug > $$yaml && $(ESSTRAUTIL) rm $$debug) || rm -f $$yaml ; \ |
| 370 |
+ done |
| 371 |
|
| 372 |
override_dh_compress: |
| 373 |
dh_compress -XBUGS -XToDo |
| 374 |
``` |
| 375 |
|
| 376 |
## The LTO Issue and Its Workaround |
| 377 |
|
| 378 |
There is a known issue with the current ESSTRA Core: |
| 379 |
|
| 380 |
* When the GCC's LTO (Link Time Optimization) option is enabled, the ESSTRA's metadata is not |
| 381 |
embedded as expected in the generated binaries. |
| 382 |
|
| 383 |
Since the Debian packaging system enables the LTO option by default, the known issue prevents |
| 384 |
the expected results. |
| 385 |
|
| 386 |
However, we have found that packages listed in the file |
| 387 |
`/usr/share/lto-disabled-list/lto-disabled-list` have the LTO option disabled during |
| 388 |
packaging. |
| 389 |
|
| 390 |
As a workaround, we will use this feature to ensure that the LTO option is not specified during |
| 391 |
the packaging of **unzip**: |
| 392 |
|
| 393 |
```diff |
| 394 |
# list of source packages not to build with link time optimization (LTO). |
| 395 |
# format: <source> any | <arch> [<arch> ...] |
| 396 |
: |
| 397 |
(snip) |
| 398 |
: |
| 399 |
zemberek-ooo amd64 |
| 400 |
zfs-fuse amd64 ppc64el |
| 401 |
|
| 402 |
+unzip any # added as a workaround |
| 403 |
``` |
| 404 |
|
| 405 |
The cause of the known issue is currently under investigation. This workaround is expected to |
| 406 |
be unnecessary in the future. |
| 407 |
|
| 408 |
## Building and Verifying the Package |
| 409 |
|
| 410 |
Build the package using the following command. The `debian/rules` file edited so far will be |
| 411 |
referenced during the process: |
| 412 |
|
| 413 |
```shell |
| 414 |
$ cd unzip-6.0 |
| 415 |
$ dpkg-buildpackage -us -uc |
| 416 |
``` |
| 417 |
|
| 418 |
This will compile and package the files, and the following files will be generated in the |
| 419 |
parent directory: |
| 420 |
|
| 421 |
* `unzip_6.0-26ubuntu3.2_amd64.deb` (binary package) |
| 422 |
* `unzip-dbgsym_6.0-26ubuntu3.2_amd64.ddeb` (debug package) |
| 423 |
|
| 424 |
The content of the binary package is shown below: |
| 425 |
|
| 426 |
* **`unzip_6.0-26ubuntu3.2_amd64.deb`** |
| 427 |
```shell |
| 428 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./ |
| 429 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/ |
| 430 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/bin/ |
| 431 |
-rwxr-xr-x root/root 22832 2024-02-02 00:52 ./usr/bin/funzip |
| 432 |
-rwxr-xr-x root/root 182720 2024-02-02 00:52 ./usr/bin/unzip |
| 433 |
-rwxr-xr-x root/root 84400 2024-02-02 00:52 ./usr/bin/unzipsfx |
| 434 |
-rwxr-xr-x root/root 2959 2024-02-02 00:52 ./usr/bin/zipgrep |
| 435 |
hrwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/bin/zipinfo link to ./usr/bin/unzip |
| 436 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/ |
| 437 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/mime/ |
| 438 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/mime/packages/ |
| 439 |
-rw-r--r-- root/root 77 2021-01-11 06:44 ./usr/lib/mime/packages/unzip |
| 440 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/ |
| 441 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/doc/ |
| 442 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/doc/unzip/ |
| 443 |
-rw-r--r-- root/root 4633 2009-01-03 01:33 ./usr/share/doc/unzip/BUGS |
| 444 |
-rw-r--r-- root/root 21529 2009-04-20 09:02 ./usr/share/doc/unzip/History.600.gz |
| 445 |
-rw-r--r-- root/root 9113 2009-04-20 08:10 ./usr/share/doc/unzip/ToDo |
| 446 |
-rw-r--r-- root/root 7169 2024-02-02 00:52 ./usr/share/doc/unzip/changelog.Debian.gz |
| 447 |
-rw-r--r-- root/root 4086 2021-01-11 06:44 ./usr/share/doc/unzip/copyright |
| 448 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/man/ |
| 449 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/man/man1/ |
| 450 |
-rw-r--r-- root/root 1977 2024-02-02 00:52 ./usr/share/man/man1/funzip.1.gz |
| 451 |
-rw-r--r-- root/root 18130 2024-02-02 00:52 ./usr/share/man/man1/unzip.1.gz |
| 452 |
-rw-r--r-- root/root 5508 2024-02-02 00:52 ./usr/share/man/man1/unzipsfx.1.gz |
| 453 |
-rw-r--r-- root/root 1541 2024-02-02 00:52 ./usr/share/man/man1/zipgrep.1.gz |
| 454 |
-rw-r--r-- root/root 8884 2024-02-02 00:52 ./usr/share/man/man1/zipinfo.1.gz |
| 455 |
lrwxrwxrwx root/root 0 2024-02-02 00:52 ./usr/share/doc/unzip/changelog.gz -> History.600.gz |
| 456 |
``` |
| 457 |
|
| 458 |
Due to the modifications made so far to the `debian/rules`, the metadata embedded by the ESSTRA |
| 459 |
Core has been removed from the ELF files included in the binary package. |
| 460 |
So, this binary package is essentially identical to the original **unzip** binary package as shown |
| 461 |
in Section [Debian Package Types](#debian-package-types). |
| 462 |
|
| 463 |
And the content of the debug package is as follows: |
| 464 |
|
| 465 |
* **`unzip-dbgsym_6.0-26ubuntu3.2_amd64.ddeb`** |
| 466 |
```shell |
| 467 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./ |
| 468 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/ |
| 469 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/ |
| 470 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/ |
| 471 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/ |
| 472 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/3f/ |
| 473 |
-rw-r--r-- root/root 187936 2024-02-02 00:52 ./usr/lib/debug/.build-id/3f/651fe9f8c7e40beea539860aef9689cfc6f4f9.debug |
| 474 |
-rw-r--r-- root/root 6522 2024-02-02 00:52 ./usr/lib/debug/.build-id/3f/651fe9f8c7e40beea539860aef9689cfc6f4f9.yaml |
| 475 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/52/ |
| 476 |
-rw-r--r-- root/root 25800 2024-02-02 00:52 ./usr/lib/debug/.build-id/52/86e01e3211833017e926a0fba155740f9fe5a8.debug |
| 477 |
-rw-r--r-- root/root 5611 2024-02-02 00:52 ./usr/lib/debug/.build-id/52/86e01e3211833017e926a0fba155740f9fe5a8.yaml |
| 478 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.build-id/ad/ |
| 479 |
-rw-r--r-- root/root 101816 2024-02-02 00:52 ./usr/lib/debug/.build-id/ad/0846b45034ff52f175f07613318a974c5bf190.debug |
| 480 |
-rw-r--r-- root/root 6307 2024-02-02 00:52 ./usr/lib/debug/.build-id/ad/0846b45034ff52f175f07613318a974c5bf190.yaml |
| 481 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.dwz/ |
| 482 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/lib/debug/.dwz/x86_64-linux-gnu/ |
| 483 |
-rw-r--r-- root/root 15792 2024-02-02 00:52 ./usr/lib/debug/.dwz/x86_64-linux-gnu/unzip.debug |
| 484 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/ |
| 485 |
drwxr-xr-x root/root 0 2024-02-02 00:52 ./usr/share/doc/ |
| 486 |
lrwxrwxrwx root/root 0 2024-02-02 00:52 ./usr/share/doc/unzip-dbgsym -> unzip |
| 487 |
``` |
| 488 |
|
| 489 |
Similarly, the metadata from each `.debug` file (actually an ELF file with debug information) |
| 490 |
has been removed, making them essentially identical to the original `.debug` files. |
| 491 |
Instead, the package includes `.yaml` files corresponding to each `.debug` file. |
| 492 |
Note that the filenames are based on the BuildID's, so they differ with each build. |
| 493 |
|
| 494 |
The following shows the first few dozen lines of the three `.yaml` files. |
| 495 |
From these results, we can confirm that the provenance information of each ELF file has been |
| 496 |
successfully included in the debug package in YAML format: |
| 497 |
|
| 498 |
```yaml |
| 499 |
$ head -20 usr/lib/debug/.build-id/3f/651fe9f8c7e40beea539860aef9689cfc6f4f9.yaml |
| 500 |
SourceFiles: |
| 501 |
/home/snagao/src/unzip-6.0: |
| 502 |
- File: unreduce.c |
| 503 |
SHA1: 8a4d010e61dbb691082f8aba66730cd4adcca3c1 |
| 504 |
- File: unshrink.c |
| 505 |
SHA1: 29816ed9e4f3392a76045678cc14a33f6655d552 |
| 506 |
- File: unzip.c |
| 507 |
SHA1: ae9d9773630b2f1d537f1de549769ed39b1d5de5 |
| 508 |
- File: unzip.h |
| 509 |
SHA1: b1e9d52ca7ae76936dcb2c175ec7def191a46576 |
| 510 |
- File: unzpriv.h |
| 511 |
SHA1: 7db7e87adcdd4288cb52b417987060bd988c9aa3 |
| 512 |
- File: unzvers.h |
| 513 |
SHA1: 78e5390d9dd17971dc7a29eb43fd7084277d92fe |
| 514 |
- File: zip.h |
| 515 |
SHA1: 8d8abe7a4b3c0ba5ec6414562e4f2f41520e81fb |
| 516 |
- File: zipinfo.c |
| 517 |
SHA1: f038797cca43c178801dd5ef24436568b55555dd |
| 518 |
/home/snagao/src/unzip-6.0/unix: |
| 519 |
- File: unix.c |
| 520 |
$ head -20 usr/lib/debug/.build-id/52/86e01e3211833017e926a0fba155740f9fe5a8.yaml |
| 521 |
SourceFiles: |
| 522 |
/home/snagao/src/unzip-6.0: |
| 523 |
- File: unzip.h |
| 524 |
SHA1: b1e9d52ca7ae76936dcb2c175ec7def191a46576 |
| 525 |
- File: unzpriv.h |
| 526 |
SHA1: 7db7e87adcdd4288cb52b417987060bd988c9aa3 |
| 527 |
- File: zip.h |
| 528 |
SHA1: 8d8abe7a4b3c0ba5ec6414562e4f2f41520e81fb |
| 529 |
/home/snagao/src/unzip-6.0/unix: |
| 530 |
- File: unxcfg.h |
| 531 |
SHA1: 7fb54a3538642300c1ad27f1b8f047e82a7149b4 |
| 532 |
/usr/include: |
| 533 |
- File: locale.h |
| 534 |
SHA1: 5ed60979e46357bea95cba5eeebd82d5e516add0 |
| 535 |
- File: signal.h |
| 536 |
SHA1: 8c1b26c724f82828d838e51667f208d7b4c164de |
| 537 |
- File: stdc-predef.h |
| 538 |
SHA1: 2fef05d80514ca0be77efec90bda051cf87d771f |
| 539 |
- File: stdio.h |
| 540 |
SHA1: c7181b48c4194cd122024971527aab4056baf600 |
| 541 |
$ head -20 usr/lib/debug/.build-id/ad/0846b45034ff52f175f07613318a974c5bf190.yaml |
| 542 |
SourceFiles: |
| 543 |
/home/snagao/src/unzip-6.0: |
| 544 |
- File: unzip.c |
| 545 |
SHA1: ae9d9773630b2f1d537f1de549769ed39b1d5de5 |
| 546 |
- File: unzip.h |
| 547 |
SHA1: b1e9d52ca7ae76936dcb2c175ec7def191a46576 |
| 548 |
- File: unzpriv.h |
| 549 |
SHA1: 7db7e87adcdd4288cb52b417987060bd988c9aa3 |
| 550 |
- File: unzvers.h |
| 551 |
SHA1: 78e5390d9dd17971dc7a29eb43fd7084277d92fe |
| 552 |
- File: zip.h |
| 553 |
SHA1: 8d8abe7a4b3c0ba5ec6414562e4f2f41520e81fb |
| 554 |
/home/snagao/src/unzip-6.0/unix: |
| 555 |
- File: unix.c |
| 556 |
SHA1: c8e3fc02d41d405f88992921611fd0aaa8b74271 |
| 557 |
- File: unxcfg.h |
| 558 |
SHA1: 7fb54a3538642300c1ad27f1b8f047e82a7149b4 |
| 559 |
/usr/include: |
| 560 |
- File: locale.h |
| 561 |
SHA1: 5ed60979e46357bea95cba5eeebd82d5e516add0 |
| 562 |
``` |
| 563 |
|
| 564 |
## Examples of Other Software |
| 565 |
|
| 566 |
By editing the `debian/rules` file with the same approach, you can include provenance |
| 567 |
information in the debug package for packages other than **unzip**. |
| 568 |
|
| 569 |
Below are examples for **bzip2** and **openssl**. |
| 570 |
Note that the person responsible for creating or maintaining the `debian/rules` file may differ |
| 571 |
for each package, so the ways of defining variables and rules may vary. |
| 572 |
|
| 573 |
### bzip2 |
| 574 |
|
| 575 |
```diff |
| 576 |
!/usr/bin/make -f |
| 577 |
# debian/rules file for building the Debian GNU/Linux package bzip2. |
| 578 |
# Copyright (C) 1999, 2000, 2001, 2002 Philippe Troin |
| 579 |
# Copyright (C) 2004-2007 Anibal Monsalve Salazar <[email protected]> |
| 580 |
# Copyright 2014 Canonical Ltd. |
| 581 |
|
| 582 |
include /usr/share/dpkg/architecture.mk |
| 583 |
ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE)) |
| 584 |
CC=$(DEB_HOST_GNU_TYPE)-gcc |
| 585 |
else |
| 586 |
CC=gcc |
| 587 |
endif |
| 588 |
|
| 589 |
+ESSTRA_CORE := -fplugin=/usr/local/lib/gcc/x86_64-linux-gnu/11/plugin/esstracore.so |
| 590 |
+ESSTRA_UTIL := /usr/local/bin/esstra |
| 591 |
|
| 592 |
DEB_BUILD_MAINT_OPTIONS := hardening=+all |
| 593 |
DEB_CFLAGS_MAINT_APPEND := -Wall -Winline |
| 594 |
+DEB_CFLAGS_MAINT_APPEND += $(ESSTRA_CORE) |
| 595 |
DEB_CPPFLAGS_MAINT_APPEND := -D_REENTRANT |
| 596 |
: |
| 597 |
(snip) |
| 598 |
: |
| 599 |
.PHONY: override_dh_installdocs |
| 600 |
override_dh_installdocs: |
| 601 |
dh_installdocs -plibbz2-dev --link-doc=libbz2-1.0 |
| 602 |
dh_installdocs --remaining-packages |
| 603 |
|
| 604 |
+.PHONY: override_dh_strip |
| 605 |
+override_dh_strip: |
| 606 |
+ dh_strip |
| 607 |
+ $(ESSTRA_UTIL) rm --ignore-errors `find debian/bzip2/ -type f -executable` |
| 608 |
+ for debug in `find debian/.debhelper/bzip2/dbgsym-root/ -name "*.debug"` ; do \ |
| 609 |
+ yaml=$${debug%.debug}.yaml ; \ |
| 610 |
+ ($(ESSTRA_UTIL) show --no-comments $$debug > $$yaml && $(ESSTRA_UTIL) rm $$debug) || rm -f $$yaml ; \ |
| 611 |
+ done |
| 612 |
``` |
| 613 |
|
| 614 |
### openssl |
| 615 |
|
| 616 |
```diff |
| 617 |
#!/usr/bin/make -f |
| 618 |
# Sample debian.rules file - for GNU Hello (1.3). |
| 619 |
# Copyright 1994,1995 by Ian Jackson. |
| 620 |
: |
| 621 |
(snip) |
| 622 |
: |
| 623 |
include /usr/share/dpkg/architecture.mk |
| 624 |
include /usr/share/dpkg/pkg-info.mk |
| 625 |
|
| 626 |
+ESSTRA_CORE := -fplugin=/usr/local/lib/gcc/x86_64-linux-gnu/11/plugin/esstracore.so |
| 627 |
+ESSTRA_UTIL := /usr/local/bin/esstra |
| 628 |
|
| 629 |
export DEB_BUILD_MAINT_OPTIONS = hardening=+all future=+lfs |
| 630 |
-export DEB_CFLAGS_MAINT_APPEND = -DOPENSSL_TLS_SECURITY_LEVEL=2 |
| 631 |
+export DEB_CFLAGS_MAINT_APPEND = -DOPENSSL_TLS_SECURITY_LEVEL=2 $(ESSTRA_CORE) |
| 632 |
|
| 633 |
SHELL=/bin/bash |
| 634 |
: |
| 635 |
(snip) |
| 636 |
: |
| 637 |
override_dh_shlibdeps: |
| 638 |
sed -i '/^udeb: libssl/s/libcrypto3-udeb/libssl3-udeb/' debian/libssl3/DEBIAN/shlibs |
| 639 |
dh_shlibdeps -a -L libssl3 |
| 640 |
|
| 641 |
+override_dh_strip: |
| 642 |
+ dh_strip |
| 643 |
+ $(ESSTRA_UTIL) rm -I `find debian/*/ -type f` |
| 644 |
+ for i in `find debian/.debhelper/*/dbgsym-root/ -name "*.debug"` ; do \ |
| 645 |
+ yaml=$${debug%.debug}.yaml ; \ |
| 646 |
+ ($(ESSTRA_UTIL) show --no-comments $$i > $$yaml && $(ESSTRA_UTIL) rm $$i) || rm -f $$yaml ; \ |
| 647 |
+ done |
| 648 |
``` |
| 649 |
|
| 650 |
## Discussion |
| 651 |
|
| 652 |
This list below outlines the points that need to be considered, discussed, and addressed in the |
| 653 |
future based on the content of this document: |
| 654 |
|
| 655 |
* Need to identify and fix The cause of the LTO issue in the ESSTRA Core. |
| 656 |
* In this demo, provenance information is separated into `.yaml` files, but it can also be keep |
| 657 |
within binaries or `.debug` files. |
| 658 |
* Including provenance information in binaries or `.debug` files increases file sizes. |
| 659 |
* Regardless of how you include provenance information, the package size will increase. |
| 660 |
* Therefore, need to determine the most preferable format to distribute provenance information |
| 661 |
from a distributor's viewpoint. |
| 662 |
* Also, need to define workflows and develop tools to utilize the distributed provenance |
| 663 |
information effectively. |
| 664 |
* Since the current ESSTRA Core supports only gcc/g++, need to establish ways to identify |
| 665 |
provenance information for other compilers and languages (e.g., LLVM, Rust, Go, Python) and |
| 666 |
develop a unified provenance information format. |
| 667 |
* Provenance information should make SBOM generation easier. Need to consider how to achieve |
| 668 |
this. |
| 669 |
* The current ESSTRA Core generates provenance information from the absolute path of the build |
| 670 |
environment, which includes personal information such as `/home/<username>/`. Need to remove |
| 671 |
such information. |
| 672 |
* Need to establish ways to apply the approach described in this document to other Linux |
| 673 |
distributions that are not Debian-based. |
| 674 |
|
| 675 |
## Summary and Conclusion |
| 676 |
|
| 677 |
In this document, we focused on Debian, one of the most popular Linux distributions, to |
| 678 |
demonstrate the practical application of ESSTRA. |
| 679 |
From the perspective of a Debian distributor, we illustrated a specific way to include |
| 680 |
provenance information obtained with ESSTRA in Debian debug packages. |
| 681 |
|
| 682 |
By modifying the `debian/rules` file of the source package to accomplish the following three |
| 683 |
points, the goal can be achieved: |
| 684 |
|
| 685 |
1. Add options to apply the ESSTRA Core to the options passed to gcc/g++. |
| 686 |
2. Override `dh_strip` to generate `.yaml` files containing provenance information to include |
| 687 |
in the debug package using the ESSTRA Utility. |
| 688 |
3. Remove unnecessary provenance information embedded in binary files and `.debug` files using |
| 689 |
the ESSTRA Utility. |
| 690 |
|
| 691 |
While we used **unzip** as an example to explain the process step-by-step, we also showed |
| 692 |
that this method is applicable to other software such as **bunzip2** and **openssl**. |
| 693 |
|
| 694 |
Finally, based on this study, we listed points for future discussion and resolution. |