1079 Commits

Author SHA1 Message Date
Valentin David
5fb7dccc36 boot: prune some bootchains that should not happen (#13750)
We are supposed to update on disk from the back of the boot chain to
the beginning. That means and old shim should not be expected to
install a new grub.

We can reduce the list of possible boot chains we give to secboot.
When we will switch to secboot master, secboot will fail if
it sees boot chains that cannot work. So we should make sure not
to pass them.

There is still a bug where we update the seed partition before boot
partition. But here we assume the bug is fixed.
2024-04-03 23:31:49 +02:00
Miguel Pires
79c5ac14b2 many: remove usages of deprecated io/ioutil package (#13768)
* many: remove usages of deprecated io/ioutil package

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* .golangci.yml: remove errcheck ignore rule for io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

* run-checks: prevent new usages of io/ioutil

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>

---------

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2024-04-03 23:23:24 +02:00
Valentin David
0c73e7ddac boot: do not sort list of hashes for boot assets
This is needed to re-merge #13402.

Hashes for boot assets are in a list that is already predictable: if
there is only one hash, then the asset is not modified; if there are 2
hashes, then the first one is the old asset, and the second is the new
asset.

There is no need to re-sort the hashes. And we lose the semantic if we
do. We want to keep that semantic so we can prune impossible boot chains.
2024-03-22 13:18:20 +01:00
Valentin David
2091704c97 boot/seal_test.go: add cases where
As we are reverting some old behavior because of an ordering bug we
need to reintroduce some cases in a refactored test. If the shim and
grub do not change of path, we need to accept the chain new shim ->
old grub. This is because we get confused and mix up old and new grub
somewhere else that has not been fixed yet.
2024-03-15 13:11:11 +01:00
Valentin David
f43f9601c4 boot: revert bb7d327a36
This reverts #13402.

`tests/nested/manual/uc-update-assets-secure-add-sbat` shows some
failures from time to time. It is possible in some context, the wrong
hashes are pruned when resealing.
2024-03-15 13:11:11 +01:00
Valentin David
3424bc3959 boot/seal_test.go: test ResealKeyToModeenv against changes of boot chains 2024-03-13 12:41:32 +01:00
Valentin David
cdec736475 boot/seal_test.go: test run mode boot chains 2024-03-13 12:41:32 +01:00
Valentin David
b248f6c7f7 bootloader/grub.go: add new boot chain binary paths 2024-03-13 12:41:32 +01:00
Valentin David
9edec0a419 bootloader/grub.go: return all possible boot chains
We need to resolve the boot chains another place based on the trusted
assets we encountered to be installed. At this point it could be any chain.
We will need to discover later what the correct chain is.

Also make TrustedAssets return an unsorted data structure to make sure
we do not use the order like the comments claimed.
2024-03-13 12:41:32 +01:00
Valentin David
bb7d327a36 boot: prune some bootchains that should not happen (#13402)
* boot: prune some bootchains that should not happen

We are supposed to update on disk from the back of the boot chain to
the beginning. That means and old shim should not be expected to
install a new grub.

We can reduce the list of possible boot chains we give to secboot.
When we will switch to secboot master, secboot will fail if
it sees boot chains that cannot work. So we should make sure not
to pass them.

There is still a bug where we update the seed partition before boot
partition. But here we assume the bug is fixed.

* fixup! boot: prune some bootchains that should not happen

* fixup! boot: prune some bootchains that should not happen

* fixup! boot: prune some bootchains that should not happen

* fixup! boot: prune some bootchains that should not happen
2024-02-19 09:03:40 +01:00
Andrew Phelps
4f59ae0fa2 boot: add UnmarkRecoveryCapableSystem function for undoing creation of a recovery system (#13459) 2024-01-10 16:30:18 -05:00
Miguel Pires
e3c52850d5 boot: fix more slices missing types
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-12-12 14:09:56 +01:00
Miguel Pires
f8e260ecca boot: fix missing type in asset list
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-12-12 11:54:54 +01:00
Valentin David
7e3b1bb83e boot: lock the modeenv while reading revisions
`ubuntu-core-20-64:tests/core/system-snap-refresh` fails because
of this.
2023-10-26 16:20:07 +01:00
Valentin David
0954b5ac79 gadget: add kernel command-line remove filter to gadget yaml 2023-10-26 09:34:20 +02:00
Valentin David
597529deac gadget: add kernel parameters from "append" in gadget yaml 2023-10-26 09:34:20 +02:00
Valentin David
7ab5e25a69 boot: update cmdline variables also when updating gadget
Since the cmdline variable will contain default arguments for
the edition, we need to update the variable if we change of edition.
2023-10-18 11:20:15 +02:00
Valentin David
33f5a54f40 boot: only use variable snapd_full_cmdline_args
We know what are the default the default command line so that we can
compute measurement, so there is not much reason to use
`snapd_extra_cmdline_args`. Always using `snapd_full_cmdline_args`
will allow us to filter part of the default command line.

There is a potential bug when filtering all arguments, `grub.cfg` will
just revert to the all the default. We will need to fix it when we
introduce the filtering.
2023-10-18 11:20:15 +02:00
Valentin David
d4128c8754 boot: unlock snapd state when sealing keys 2023-10-13 12:36:44 +02:00
Miguel Pires
29c9752d66 many: s/ioutil.WriteFile/os.WriteFile (#13217)
Replace ioutil.WriteFile with os.WriteFile since the former has been
deprecated since go1.16 and simply calls the latter.

Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-09-26 11:38:46 +01:00
Miguel Pires
671119293e boot: fix formatting
Signed-off-by: Miguel Pires <miguel.pires@canonical.com>
2023-09-25 12:18:18 +01:00
Samuele Pedroni
d0cfb81163 boot,o/devicestate: protect with a mutex modifying modeeenv and sealing/releasing (#13185)
this should allow to release the global state lock while doing resealing/sealing proper as those are slow operations in fact

* boot: use loadModeenv a bit more consistently and some XXXs

* boot: take a lock around read modeenv/modify(/reaseal) etc

* boot: do not seal without the modeenv associated lock

* boot: do not reseal without the modeenv associated lock

* boot,o/devicestate: introduce Unlocker to unlock global state

have boot.DeviceChange make use of it for a start

* boot: explain a bit more modeenvMu

* overlord: introduce state.Unlocker convenience method

* boot: check that the lock is taken also in bootStateUpdate20.commit
2023-09-20 18:26:12 +02:00
Samuele Pedroni
8a9fd7239e boot: MakeRunnableStandaloneSystem doc was missing "not" 2023-09-06 09:56:07 +02:00
Valentin David
d9e4ab8c5e osutil/kcmdline: simplify names 2023-07-31 16:40:56 +02:00
Valentin David
c9bbf25300 osutil: extract kcmdline to its own package 2023-07-31 16:40:56 +02:00