-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lib: Validate metadata structure more consistently during pull
Previously we were doing e.g. `ot_util_filename_validate()` specifically inline in dirtree objects, but only *after* writing them into the staging directory (by default). In (non-default) cases such as not using a transaction, such an object could be written directly into the repo. A notable gap here is that `pull-local --untrusted` was *not* doing this verification, just checksums. We harden that (and also the static delta writing path, really *everything* that calls `ostree_repo_write_metadata()` to also do "structure" validation which includes path traversal checks. Basically, let's try hard to avoid having badly structured objects even in the repo. One thing that sucks in this patch is that we need to allocate a "bounce buffer" for metadata in the static delta path, because GVariant imposes alignment requirements, which I screwed up and didn't fulfill when designing deltas. It actually didn't matter before because we weren't parsing them, but now we are. In theory we could check alignment but ...eh, not worth it, at least not until we change the delta compiler to emit aligned metadata which actually may be quite tricky. (Big picture I doubt this really matters much right now but I'm not going to pull out a profiler yet for this) The pull test was extended to check we didn't even write a dirtree with path traversal into the staging directory. There's a bit of code motion in extracting `_ostree_validate_structureof_metadata()` from `fsck_metadata_object()`. Then `_ostree_verify_metadata_object()` builds on that to do checksum verification too. Closes: #1412 Approved by: jlebon
- Loading branch information
1 parent
f3ae36f
commit 8e6e64a
Showing
8 changed files
with
138 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2027,6 +2027,13 @@ ostree_repo_write_metadata (OstreeRepo *self, | |
if (!metadata_size_valid (objtype, g_variant_get_size (normalized), error)) | ||
return FALSE; | ||
|
||
/* For untrusted objects, verify their structure here */ | ||
if (expected_checksum) | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
cgwalters
Author
Member
|
||
{ | ||
if (!_ostree_validate_structureof_metadata (objtype, object, error)) | ||
return FALSE; | ||
} | ||
|
||
g_autoptr(GBytes) vdata = g_variant_get_data_as_bytes (normalized); | ||
if (!write_metadata_object (self, objtype, expected_checksum, | ||
vdata, out_csum, cancellable, error)) | ||
|
@@ -4101,6 +4108,7 @@ _ostree_repo_import_object (OstreeRepo *self, | |
&variant, error)) | ||
return FALSE; | ||
|
||
/* Note this one also now verifies structure in the !trusted case */ | ||
g_autofree guchar *real_csum = NULL; | ||
if (!ostree_repo_write_metadata (self, objtype, | ||
checksum, variant, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
#!/bin/bash | ||
# | ||
# Copyright (C) 2014 Alexander Larsson <[email protected]> | ||
# Copyright (C) 2018 Red Hat, Inc. | ||
# | ||
# This library is free software; you can redistribute it and/or | ||
# modify it under the terms of the GNU Lesser General Public | ||
|
@@ -22,7 +23,7 @@ set -euo pipefail | |
|
||
. $(dirname $0)/libtest.sh | ||
|
||
echo '1..3' | ||
echo '1..4' | ||
|
||
setup_test_repository "bare" | ||
|
||
|
@@ -60,10 +61,20 @@ else | |
fi | ||
|
||
rm -rf repo2 | ||
mkdir repo2 | ||
ostree_repo_init repo2 --mode="bare" | ||
if ${CMD_PREFIX} ostree --repo=repo2 pull-local --untrusted repo; then | ||
assert_not_reached "corrupted untrusted pull unexpectedly failed!" | ||
else | ||
echo "ok untrusted pull with corruption failed" | ||
fi | ||
|
||
|
||
cd ${test_tmpdir} | ||
tar xf ${test_srcdir}/ostree-path-traverse.tar.gz | ||
rm -rf repo2 | ||
ostree_repo_init repo2 --mode=archive | ||
if ${CMD_PREFIX} ostree --repo=repo2 pull-local --untrusted ostree-path-traverse/repo pathtraverse-test 2>err.txt; then | ||
fatal "pull-local unexpectedly succeeded" | ||
fi | ||
assert_file_has_content_literal err.txt 'Invalid / in filename ../afile' | ||
echo "ok untrusted pull-local path traversal" |
I stepped into this condition check while working on other metadata validation, and it left me slightly puzzled. Three questions on it:
expected_checksum
make it a trusted object?out_csum
instead? In the patch chunk below, I see there is atrusted
condition which is reflected to that instead.