Commit Graph

4059 Commits

Author SHA1 Message Date
472d9d493a curl: Assert that curl_multi_assign worked
ref https://github.com/ostreedev/ostree/issues/3299

This won't fix that issue, but *if* this assertion triggers
it should give us a better idea of the possible codepaths
where it is happening.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-09-18 13:22:55 -04:00
508a8b61ac bootloader/grub2: Handle empty static configs
In #3205, we introduced a check to skip re-generating the GRUB config if
we detect that static configs are in used by looking at bootupd's state.

Unfortunately this check is incomplete and does not account for present
but null entries in the JSON state file.

A proper fix would be to parse the JSON but this requires a larger code
change.

Fixes: https://github.com/ostreedev/ostree/issues/3295
Fixes: https://github.com/ostreedev/ostree/pull/3205
2024-09-14 00:34:24 +02:00
81867f0444 Merge pull request #3287 from cgwalters/fix-memleak
lib/traverse: Fix minor memory leak
2024-09-07 01:30:25 +01:00
413b0ad00e Merge pull request #3292 from dbnicholson/var-slave-shared
switchroot: Stop making /sysroot mount private
2024-09-06 19:35:19 -04:00
bd5b4adccd lib/traverse: Fix minor memory leak
I was trying to check something with `-fsanitize=address`
and it warned about this memory leak. It's...subtle, basically
we were leaking when the same commit was added to the hash table.

But unfortunately fixing that then complicates ownership
over the return value; what we really want to use here is
`g_hash_table_steal_all_keys` but RHEL 9.4 is still rocking
`glib2-2.68.4` so we can't use it.

(Rust would mean we wouldn't have leaked anything here in the
 first place...)

Signed-off-by: Colin Walters <walters@verbum.org>
2024-09-06 18:52:33 -04:00
2973ec5910 switchroot: Stop making /sysroot mount private
Back in 2b8d586c5, /sysroot was changed to be a private mount so that
submounts of /var do not propagate back to the stateroot /var. That's
laudible, but it makes /sysroot different than every other shared mount
in the root namespace. In particular, it means that submounts of
/sysroot do not propagate into separate mount namespaces.

Rather than make /sysroot private, make /var a slave+shared mount so
that it receives mount events from /sysroot but not vice versa. That
achieves the same effect of preventing /var submount events from
propagating back to /sysroot while allowing /sysroot mount events to
propagate forward like every other system mount. See
mount_namespaces(7)[1] and the linux shared subtrees[2] documentation
for details on slave+shared mount propagation.

When /var is mounted in the initramfs, this is accomplished with
mount(2) syscalls. When /var is mounted after switching to the real
root, the mount propagation flags are applied as options in the
generated var.mount unit. This depends on a mount(8) feature that has
been present since util-linux 2.23. That's available in RHEL 7 and every
non-EOL Debian and Ubuntu release. Applying the propagation from
var.mount fixes a small race, too. Previously, if a /var submount was
added before /sysroot was made private, it would have propagated back
into /sysroot. That was possible since ostree-remount.service orders
itself after var.mount but not before any /var submounts.

1. https://man7.org/linux/man-pages/man7/mount_namespaces.7.html
2. https://docs.kernel.org/filesystems/sharedsubtree.html

Fixes: #2086
2024-09-06 15:49:49 -06:00
cdbe93dc9b grub2: Show output when run in systemd by default
xref https://github.com/coreos/rpm-ostree/issues/5071

Hiding errors by default is painful. At least as of
recently in Fedora it looks like the command is nice
and quiet by default, I only see

```
Generating grub configuration file ...
Adding boot menu entry for UEFI Firmware Settings ...
done
```

Signed-off-by: Colin Walters <walters@verbum.org>
2024-09-03 08:55:35 -04:00
2b01c93cd9 Merge pull request #3283 from cgwalters/fix-more-coverity-dirname
sysroot: Make coverity happy with dirname+strdup
2024-08-16 00:26:52 -04:00
7683eb5aa4 commit/payload-link: Ensure we don't overrun target_checksum size
This is another warning from recently changed code from Coverity:

```
1. Defect type: OVERRUN
16. libostree-2024.7/src/libostree/ostree-repo-commit.c:823:7: overrun-buffer-arg: Overrunning array "target_checksum" of 65 bytes by passing it to a function which accesses it at byte offset 258 using argument "size" (which evaluates to 259). [Note: The source code implementation of the function has been overridden by a builtin model.]
```

I think this can only happen if the repository is corrupt; the
data shouldn't be that long. But fix this by passing the max
length we expect; this will ignore the rest currently.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-08-15 12:15:50 -04:00
70430fe02b sysroot: Make coverity happy with dirname+strdup
Similar to d528083cae - I don't
believe we actually had a leak here because `dirname` always
returns the same start pointer, but this makes Coverity
happy.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-08-15 11:29:22 -04:00
3d07a808ce deploy: Log to journal for boot space, not stderr
bootc doesn't run as a systemd unit, and this pollutes stderr.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-08-14 09:09:15 -04:00
f08cea998e repo: NUL terminate readlinkat result
Coverity was correctly complaining about this.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-07-29 17:14:12 -04:00
4941d9cd0d Release 2024.7
Signed-off-by: Colin Walters <walters@verbum.org>
2024-07-18 17:55:21 -04:00
e226c87614 prepare-root: Add ostree.prepare-root.composefs
We have a use case for overriding the composefs state via
the kernel commandline; see e.g.
https://gitlab.com/fedora/bootc/tracker/-/issues/27

Signed-off-by: Colin Walters <walters@verbum.org>
2024-07-11 17:04:09 -04:00
65ff404195 prepare-root: Gather kernel cmdline early
Prep for parsing the composefs config from the kernel cmdline.
No functional changes intended.
2024-07-10 17:52:28 -04:00
26abca7126 keyfile-utils: Add API to parse tristate strings
Prep for using this in multiple places. Add unit tests.
2024-07-10 17:52:28 -04:00
97fb11127b Merge pull request #3275 from ueno/wip/dueno/glib-2.44
libostree: Remove compatibility code with GLib < 2.44
2024-07-10 08:27:45 -04:00
a0bd18945f libostree: Remove compatibility code with GLib < 2.44
As the build system has required GLib 2.44 since commit
eb09207e1a, the manual expansion of
G_DECLARE_INTERFACE and G_DECLARE_FINAL_TYPE is no longer necessary.

Signed-off-by: Daiki Ueno <dueno@redhat.com>
2024-07-10 10:22:07 +09:00
772801faf0 sysroot: Use journal rather than printf()
Fix the TODO here; this was making some bootc output
ugly.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-07-08 07:52:39 -04:00
e99693c787 prepare: Create global var for tmp_sysroot_etc
Coverity points out that ""/sysroot.tmp/etc"" could be a copy-paste
error. This is mistake from coverity, but to supress the warning,
we create a global var, tmp_sysroot_etc, which replaces all
instances of TMP_SYSROOT "/etc".
2024-06-20 15:09:11 -04:00
d528083cae repo: Fix dir_or_file_path memory leak
Coverity points out that we have a memory leak from
`g_strdup(dir_or_file_path)`. Make the duplication of the string a
temporary variable that is freed using `g_autofree`.
2024-06-20 15:09:11 -04:00
20d5bc8453 commit: Null terminate target_buf var
Coverity points out that we are passing an unterminated string to
sprintf(). Fix by using snprintf() which stores the content as a C
string.
2024-06-20 15:09:11 -04:00
dc9eaef1e5 tree: Fix name memory leak
Coverity points out that we have a memory leak from `g_strdup(name)`.
`insert_child_mtree()` takes a const char * and duplicates it.
`name` can be passed directly to `insert_child_mtree()`.
2024-06-20 15:09:11 -04:00
0ea7d2e326 Merge pull request #3269 from cgwalters/fix-ordering
remount: Drop `Before=systemd-sysusers.service`
2024-06-20 11:54:23 -04:00
b0ab531e08 remount: Drop Before=systemd-sysusers.service
This created an ordering cycle, and I merged over red CI
for bad reasons.
2024-06-20 09:18:08 -04:00
371540f9ab repo: Remove leftover OpenSSL includes
This removes OpenSSL includes for PKCS#7, previously used to generate
fs-verity builtin signatures.

Signed-off-by: Daiki Ueno <dueno@redhat.com>
2024-06-20 15:06:49 +09:00
e25ca8099f remount: ignore ENOENT error during SELinux relabeling
Ignore ENOENT error in selinux_restorecon to avoid failures when
temporary files created by systemd-sysusers in /etc are missing during
relabeling. This prevents errors such as:

  "Failed to relabel /etc/.#gshadowJzu4Rx: No such file or directory"

and allows the process to continue.

Co-Authored-By: Alexander Larsson <alexl@redhat.com>
Signed-off-by: Eric Curtin <ecurtin@redhat.com>
2024-06-18 18:43:51 +01:00
e19f732481 core: Validate that xattr names aren't empty
In the ostree-ext codebase the test fixture was generating xattrs
without the trailing NUL byte.  This caused confusing errors
later.  Change the dirmeta validator to catch this.

The way GVariant represents bytestrings, the trailing NUL is there
on wire/disk so it can be there in memory too, but `g_variant_get_bytestring()`
will just return an empty `""` string if actually the value
has a missing NUL.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-06-01 14:46:23 -04:00
b605230635 Merge pull request #3253 from cgwalters/prepare-comments
prepare-root: Cleanup comments
2024-05-23 16:52:32 +02:00
f041e0253f prepare-root: Cleanup comments
Mainly we can now drop the TODO for mounting `/` readonly - that's
handled by composefs.  Add a few other comments, typo fixes
while we're here.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-05-22 21:08:32 -04:00
c0a715f1e2 checkout: Add API to directly checkout composefs
We were missing the simple, obvious API and CLI to go
from ostree commit -> composefs.

Internally, we had `ostree_repo_checkout_composefs`
with the right "shape" mostly, except it had more code
in the deploy path to turn that into a composefs.

Add a straightforward public API that does what
the deploy code did before, and then the old
API becomes an explicitly internal helper with an `_`
prefix.

Goals:

- Lead towards a composefs-oriented future
- This makes the composefs logic more testable directly

Signed-off-by: Colin Walters <walters@verbum.org>
2024-05-22 20:38:24 -04:00
664116f03a Merge pull request #3244 from alexlarsson/fix-fsverity-supported
Fix _ostree_ensure_fsverity reporting of supports in early exit
2024-05-15 13:15:05 -04:00
083eacd6de Fix _ostree_ensure_fsverity reporting of supports in early exit
If supported_out is passed to _ostree_ensure_fsverity and we
successfully exit early, for example because the file is a symlink, then
*supported_out is not initialized.

This is problematic in the case of ostree_sysroot_update_post_copy(),
because it passes in an uninitialized supported, and on successfull
return of _ostree_ensure_fsverity() it assumes that it is iniialized.

In case supported happened to be initialized to non-zero it will take
this branch:

      if (!supported)
        break; /* If not supported, skip rest */

Which means *all* further objects will not get fs-verity enabled.
2024-05-15 17:31:09 +02:00
ee066d799d sysroot: Handle /ostree/deploy having epoch 0
Ironically we break if the timestamp there is zero.

Closes: https://github.com/ostreedev/ostree/issues/3022
Signed-off-by: Colin Walters <walters@verbum.org>
2024-05-15 09:59:50 -04:00
cb70e4063f ostree-sysroot-deploy: check if deployments are in the same stateroot. 2024-05-03 19:57:31 -04:00
a33c7d23d6 ci: Only run clang-format on ubuntu-stable GH runner
Previously we were running clang-format across multiple operating
system versions and hence clang versions, and it turns out
clang has changed the preferred formatting multiple times.

We could *probably* dig in and try to pin things more strongly
but eh...for now let's arbitrarily just use whatever's in
the default GH Action ubuntu-latest runner as that should
be equally painful for everyone.

Signed-off-by: Colin Walters <walters@verbum.org>
2024-05-01 20:35:32 -04:00
60f4592b2c repo: Make summary and signature mtime match
HTTP servers derive Last-Modified from the modification time of the
file. When used in combination with a Cache-Control max-age value,
having the modification times match means that caches will consider them
expired at the same time. This helps make it more likely that clients
won't receive a cached summary and fresh signature or vice versa.

This makes more sense to do now that the summary and signature are
created in a temporary directory and renamed into place. In the old days
where they were created directly in the repo root, it would be strange
to change the summary mtime when it wasn't actually modified.
2024-04-25 09:38:50 -06:00
6ac8c49a83 prepare-root: Handle non-AB aboot properly
otcore_get_ostree_target() should set is_aboot for android boot
systems, but currently it only does this on A/B boot systems, not
single-boot-partition systems. Fix this by setting it in the second
case.
2024-04-15 20:09:34 +02:00
74a3d2da9c init-fs: Add --epoch=2
We want to start switching things so that the toplevel `/ostree`
repository is mode 0700, to close off unprivileged code
from being able to access it.  Previous deployment roots
may have setuid binaries, etc.  The `/var/lib/containers/storage`
directory is mode 0700 for this reason I believe.

Closes: https://github.com/ostreedev/ostree/issues/3211
2024-04-12 16:10:36 -04:00
38f6b9b3ab init-fs: Add --epoch
I want to add another variant here, and `--modern` is now old.  Let's
acknowledge that we may want to make even more changes in the
future.  So `--modern == --epoch=1` but I will add `--epoch=2` after
this.
2024-04-12 08:56:13 -04:00
374fb05d0e _ostree_ensure_fsverity: Properly check for errors
If fs_verity_wanted == _OSTREE_FEATURE_YES we should fail if
!suported, but we were checking !supported where supported is a
pointer, not a boolean. This caused us to miss errors when the kernel
didn't support fs-verity that lead to lots of debugging.
2024-04-08 17:05:23 +02:00
05b3b66275 ostree-prepare-root.service: add OnFailureJobMode=isolate
This is stronger than the default (`replace`) because it tells systemd
to *stop everything* and go to `emergency.target`. In other codebases,
this has definitely helped me with the problem of "systemd keeps going
even after a failure".

Likely addresses #3219.

See also e.g. 3d2e165f97.
2024-03-21 12:19:32 -04:00
dc4d4b5592 Merge pull request #3218 from cgwalters/policy-allow-none
sepolicy: Add missing `(nullable)`
2024-03-19 12:28:54 -04:00
45453b73e5 sepolicy: Add missing (nullable)
This can return NULL if there's no real policy.

Now obviously we need to update the Rust bindings too but...
I am having trouble doing that, we're pretty out of date with
upstream.
2024-03-19 10:23:43 -04:00
76ab862188 curl: Also map HTTP errors for retries
When we added the retry logic, the intention here was definitely
to do it not just for network errors but also e.g. HTTP 500s and
the like.

xref https://pagure.io/releng/issue/11439
where we rather painfully debugged that this was missing.
2024-03-15 18:45:22 -04:00
756e2dade0 Merge pull request #3214 from cgwalters/checkout-overwrite-force
checkout: Always replace existing content with overlay mode
2024-03-13 16:05:23 -04:00
bb6dfd3ab0 checkout: Always replace existing content in overlay mode
The combination of the "honor whiteout" and "union" flags
are intended to basically be "merge trees like overlayfs does".
But we were missing this case in order to support e.g. replacing
a symlink with a directory.
2024-03-13 14:07:54 -04:00
4efb44f35a deploy: Ensure boot directory is open before accessing it
This fixes a bug in the (early) deployment pruning function which before
tried to access the boot directory without opening it first.

Signed-off-by: Rogerio Guerra Borin <rogerio.borin@toradex.com>
2024-03-12 17:29:35 -03:00
abc7d5b9a0 kargs: parse spaces in kargs input and keep quotes
According to Jonathan's suggestion, should fix the code from
ostree repo.

With this patch:
- kargs input like "init_on_alloc=1 init_on_free=1", will be
parsed as 2 seperated args `init_on_alloc=1` and `init_on_free=1`,
instead of whole;
- According to https://www.kernel.org/doc/html/v4.14/admin-guide/kernel-parameters.html,
need to keep spaces in double-quotes, like `param="spaces in here"`
will be parsed as whole instead of 3.

Fixes https://github.com/coreos/rpm-ostree/issues/4821
2024-03-08 10:01:06 +08:00
2fb7a04838 sysroot: Turn on bootloader-naming-2 by default
I think it's about time we flipped this on by default;
like the bootprefix I was a bit too chicken.  We still have
a `bootloader-naming-1` that can be flipped on in case of
some regression.

Closes: https://github.com/ostreedev/ostree/issues/2961
2024-02-28 09:40:34 -05:00