1
0
mirror of https://github.com/systemd/systemd synced 2026-03-04 12:14:46 +01:00

Compare commits

..

No commits in common. "b3a2444ba57c90b93b5f76cc7f62b84acb7adec8" and "db1689e69cbb25c5e24d845601088897bf3df5d7" have entirely different histories.

14 changed files with 60 additions and 79 deletions

View File

@ -11,7 +11,6 @@ SUBSYSTEMS=="platform", ENV{ID_BUS}="platform"
SUBSYSTEMS=="i2c", ENV{ID_BUS}="i2c" SUBSYSTEMS=="i2c", ENV{ID_BUS}="i2c"
SUBSYSTEMS=="rmi4", ENV{ID_BUS}="rmi" SUBSYSTEMS=="rmi4", ENV{ID_BUS}="rmi"
SUBSYSTEMS=="serio", ENV{ID_BUS}="i8042" SUBSYSTEMS=="serio", ENV{ID_BUS}="i8042"
SUBSYSTEMS=="spi", ENV{ID_BUS}="spi"
SUBSYSTEMS=="usb", ENV{ID_BUS}=="", IMPORT{builtin}="usb_id" SUBSYSTEMS=="usb", ENV{ID_BUS}=="", IMPORT{builtin}="usb_id"

View File

@ -6,8 +6,8 @@
ACTION=="remove", GOTO="integration_end" ACTION=="remove", GOTO="integration_end"
ENV{ID_BUS}=="", GOTO="integration_end" ENV{ID_BUS}=="", GOTO="integration_end"
# ACPI, platform, PS/2, I2C, RMI, SPI and PCI devices: Internal by default. # ACPI, platform, PS/2, I2C, RMI and PCI devices: Internal by default.
ENV{ID_BUS}=="acpi|platform|i8042|i2c|rmi|spi|pci", ENV{ID_INTEGRATION}="internal" ENV{ID_BUS}=="acpi|platform|i8042|i2c|rmi|pci", ENV{ID_INTEGRATION}="internal"
# Bluetooth devices: External by default. # Bluetooth devices: External by default.
ENV{ID_BUS}=="bluetooth", ENV{ID_INTEGRATION}="external" ENV{ID_BUS}=="bluetooth", ENV{ID_INTEGRATION}="external"

View File

@ -1020,7 +1020,7 @@ static int pe_find_uki_sections(
} }
/* Permit "masking" of sections in the base profile */ /* Permit "masking" of sections in the base profile */
if (le32toh(found->VirtualSize) == 0) if (found->VirtualSize == 0)
continue; continue;
r = pe_read_section_data(fd, found, PE_SECTION_SIZE_MAX, (void**) t->data, /* ret_size= */ NULL); r = pe_read_section_data(fd, found, PE_SECTION_SIZE_MAX, (void**) t->data, /* ret_size= */ NULL);

View File

@ -883,7 +883,7 @@ int image_find(RuntimeScope scope,
.type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR), .type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR),
.basename = name, .basename = name,
.architecture = _ARCHITECTURE_INVALID, .architecture = _ARCHITECTURE_INVALID,
.suffix = suffix, .suffix = STRV_MAKE(suffix),
}; };
_cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL; _cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL;
@ -1100,7 +1100,7 @@ int image_discover(
.type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR), .type_mask = endswith(suffix, ".raw") ? (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK) : (UINT32_C(1) << DT_DIR),
.basename = pretty, .basename = pretty,
.architecture = _ARCHITECTURE_INVALID, .architecture = _ARCHITECTURE_INVALID,
.suffix = suffix, .suffix = STRV_MAKE(suffix),
}; };
_cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL; _cleanup_(pick_result_done) PickResult result = PICK_RESULT_NULL;

View File

@ -336,7 +336,7 @@ static int hash_file(int fd, EVP_MD_CTX *md_ctx, uint64_t offset, uint64_t size)
} }
static int section_offset_cmp(const IMAGE_SECTION_HEADER *a, const IMAGE_SECTION_HEADER *b) { static int section_offset_cmp(const IMAGE_SECTION_HEADER *a, const IMAGE_SECTION_HEADER *b) {
return CMP(le32toh(ASSERT_PTR(a)->PointerToRawData), le32toh(ASSERT_PTR(b)->PointerToRawData)); return CMP(ASSERT_PTR(a)->PointerToRawData, ASSERT_PTR(b)->PointerToRawData);
} }
int pe_hash(int fd, int pe_hash(int fd,
@ -384,7 +384,7 @@ int pe_hash(int fd,
return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "Failed to allocate message digest."); return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "Failed to allocate message digest.");
/* Everything from beginning of file to CheckSum field in PE header */ /* Everything from beginning of file to CheckSum field in PE header */
p = (uint64_t) le32toh(dos_header->e_lfanew) + p = (uint64_t) dos_header->e_lfanew +
offsetof(PeHeader, optional.CheckSum); offsetof(PeHeader, optional.CheckSum);
r = hash_file(fd, mdctx, 0, p); r = hash_file(fd, mdctx, 0, p);
if (r < 0) if (r < 0)
@ -392,7 +392,7 @@ int pe_hash(int fd,
p += sizeof(le32_t); p += sizeof(le32_t);
/* Everything between the CheckSum field and the Image Data Directory Entry for the Certification Table */ /* Everything between the CheckSum field and the Image Data Directory Entry for the Certification Table */
q = (uint64_t) le32toh(dos_header->e_lfanew) + q = (uint64_t) dos_header->e_lfanew +
PE_HEADER_OPTIONAL_FIELD_OFFSET(pe_header, DataDirectory[IMAGE_DATA_DIRECTORY_INDEX_CERTIFICATION_TABLE]); PE_HEADER_OPTIONAL_FIELD_OFFSET(pe_header, DataDirectory[IMAGE_DATA_DIRECTORY_INDEX_CERTIFICATION_TABLE]);
r = hash_file(fd, mdctx, p, q - p); r = hash_file(fd, mdctx, p, q - p);
if (r < 0) if (r < 0)
@ -400,7 +400,7 @@ int pe_hash(int fd,
q += sizeof(IMAGE_DATA_DIRECTORY); q += sizeof(IMAGE_DATA_DIRECTORY);
/* The rest of the header + the section table */ /* The rest of the header + the section table */
p = le32toh(pe_header->optional.SizeOfHeaders); p = pe_header->optional.SizeOfHeaders;
if (p < q) if (p < q)
return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "SizeOfHeaders too short."); return log_debug_errno(SYNTHETIC_ERRNO(EBADMSG), "SizeOfHeaders too short.");
r = hash_file(fd, mdctx, q, p - q); r = hash_file(fd, mdctx, q, p - q);
@ -411,19 +411,19 @@ int pe_hash(int fd,
typesafe_qsort(sections, le16toh(pe_header->pe.NumberOfSections), section_offset_cmp); typesafe_qsort(sections, le16toh(pe_header->pe.NumberOfSections), section_offset_cmp);
FOREACH_ARRAY(section, sections, le16toh(pe_header->pe.NumberOfSections)) { FOREACH_ARRAY(section, sections, le16toh(pe_header->pe.NumberOfSections)) {
r = hash_file(fd, mdctx, le32toh(section->PointerToRawData), le32toh(section->SizeOfRawData)); r = hash_file(fd, mdctx, section->PointerToRawData, section->SizeOfRawData);
if (r < 0) if (r < 0)
return r; return r;
p += le32toh(section->SizeOfRawData); p += section->SizeOfRawData;
} }
if ((uint64_t) st.st_size > p) { if ((uint64_t) st.st_size > p) {
if ((uint64_t) st.st_size - p < le32toh(certificate_table->Size)) if (st.st_size - p < certificate_table->Size)
return log_debug_errno(errno, "No space for certificate table, refusing."); return log_debug_errno(errno, "No space for certificate table, refusing.");
r = hash_file(fd, mdctx, p, st.st_size - p - le32toh(certificate_table->Size)); r = hash_file(fd, mdctx, p, st.st_size - p - certificate_table->Size);
if (r < 0) if (r < 0)
return r; return r;
@ -560,13 +560,13 @@ int uki_hash(int fd,
if (EVP_DigestInit_ex(mdctx, md, NULL) != 1) if (EVP_DigestInit_ex(mdctx, md, NULL) != 1)
return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "Failed to allocate message digest."); return log_debug_errno(SYNTHETIC_ERRNO(ENOTRECOVERABLE), "Failed to allocate message digest.");
r = hash_file(fd, mdctx, le32toh(section->PointerToRawData), MIN(le32toh(section->VirtualSize), le32toh(section->SizeOfRawData))); r = hash_file(fd, mdctx, section->PointerToRawData, MIN(section->VirtualSize, section->SizeOfRawData));
if (r < 0) if (r < 0)
return r; return r;
if (le32toh(section->SizeOfRawData) < le32toh(section->VirtualSize)) { if (section->SizeOfRawData < section->VirtualSize) {
uint8_t zeroes[1024] = {}; uint8_t zeroes[1024] = {};
size_t remaining = le32toh(section->VirtualSize) - le32toh(section->SizeOfRawData); size_t remaining = section->VirtualSize - section->SizeOfRawData;
while (remaining > 0) { while (remaining > 0) {
size_t sz = MIN(sizeof(zeroes), remaining); size_t sz = MIN(sizeof(zeroes), remaining);

View File

@ -13,6 +13,7 @@
#include "recurse-dir.h" #include "recurse-dir.h"
#include "stat-util.h" #include "stat-util.h"
#include "string-util.h" #include "string-util.h"
#include "strv.h"
#include "vpick.h" #include "vpick.h"
void pick_result_done(PickResult *p) { void pick_result_done(PickResult *p) {
@ -85,6 +86,8 @@ static int format_fname(
if (FLAGS_SET(flags, PICK_TRIES) || !filter->version) /* Underspecified? */ if (FLAGS_SET(flags, PICK_TRIES) || !filter->version) /* Underspecified? */
return -ENOEXEC; return -ENOEXEC;
if (strv_length(filter->suffix) > 1) /* suffix is not deterministic? */
return -ENOEXEC;
/* The format for names we match goes like this: /* The format for names we match goes like this:
* *
@ -136,8 +139,8 @@ static int format_fname(
return -ENOMEM; return -ENOMEM;
} }
if (!isempty(filter->suffix)) if (!strv_isempty(filter->suffix))
if (!strextend(&fn, filter->suffix)) if (!strextend(&fn, filter->suffix[0]))
return -ENOMEM; return -ENOMEM;
if (!filename_is_valid(fn)) if (!filename_is_valid(fn))
@ -404,8 +407,8 @@ static int make_choice(
} else } else
e = dname; e = dname;
if (!isempty(filter->suffix)) { if (!strv_isempty(filter->suffix)) {
char *sfx = endswith(e, filter->suffix); char *sfx = endswith_strv(e, filter->suffix);
if (!sfx) if (!sfx)
continue; continue;
@ -508,6 +511,7 @@ static int path_pick_one(
PickResult *ret) { PickResult *ret) {
_cleanup_free_ char *filter_bname = NULL, *dir = NULL, *parent = NULL, *fname = NULL; _cleanup_free_ char *filter_bname = NULL, *dir = NULL, *parent = NULL, *fname = NULL;
char * const *filter_suffix_strv = NULL;
const char *filter_suffix = NULL, *enumeration_path; const char *filter_suffix = NULL, *enumeration_path;
uint32_t filter_type_mask; uint32_t filter_type_mask;
int r; int r;
@ -565,13 +569,11 @@ static int path_pick_one(
return -ENOMEM; return -ENOMEM;
/* Chop off suffix, if specified */ /* Chop off suffix, if specified */
if (!isempty(filter->suffix)) { char *f = endswith_strv(filter_bname, filter->suffix);
char *f = endswith(filter_bname, filter->suffix);
if (f) if (f)
*f = 0; *f = 0;
}
filter_suffix = filter->suffix; filter_suffix_strv = filter->suffix;
filter_type_mask = filter->type_mask; filter_type_mask = filter->type_mask;
enumeration_path = path; enumeration_path = path;
@ -631,7 +633,7 @@ static int path_pick_one(
.basename = filter_bname, .basename = filter_bname,
.version = filter->version, .version = filter->version,
.architecture = filter->architecture, .architecture = filter->architecture,
.suffix = filter_suffix, .suffix = filter_suffix_strv ?: STRV_MAKE(filter_suffix),
}, },
flags, flags,
ret); ret);
@ -788,7 +790,7 @@ const PickFilter pick_filter_image_raw[1] = {
{ {
.type_mask = (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK), .type_mask = (UINT32_C(1) << DT_REG) | (UINT32_C(1) << DT_BLK),
.architecture = _ARCHITECTURE_INVALID, .architecture = _ARCHITECTURE_INVALID,
.suffix = ".raw", .suffix = STRV_MAKE(".raw"),
}, },
}; };

View File

@ -17,7 +17,7 @@ typedef struct PickFilter {
const char *basename; /* Can be overridden by search pattern */ const char *basename; /* Can be overridden by search pattern */
const char *version; const char *version;
Architecture architecture; Architecture architecture;
const char *suffix; /* Can be overridden by search pattern */ char * const *suffix; /* Can be overridden by search pattern */
} PickFilter; } PickFilter;
typedef struct PickResult { typedef struct PickResult {

View File

@ -44,7 +44,7 @@ TEST(path_pick) {
PickFilter filter = { PickFilter filter = {
.architecture = _ARCHITECTURE_INVALID, .architecture = _ARCHITECTURE_INVALID,
.suffix = ".raw", .suffix = STRV_MAKE(".raw"),
}; };
if (IN_SET(native_architecture(), ARCHITECTURE_X86, ARCHITECTURE_X86_64)) { if (IN_SET(native_architecture(), ARCHITECTURE_X86, ARCHITECTURE_X86_64)) {

View File

@ -245,7 +245,7 @@ static int run(int argc, char *argv[]) {
.basename = arg_filter_basename, .basename = arg_filter_basename,
.version = arg_filter_version, .version = arg_filter_version,
.architecture = arg_filter_architecture, .architecture = arg_filter_architecture,
.suffix = arg_filter_suffix, .suffix = STRV_MAKE(arg_filter_suffix),
.type_mask = arg_filter_type_mask, .type_mask = arg_filter_type_mask,
}, },
/* n_filters= */ 1, /* n_filters= */ 1,

View File

@ -37,7 +37,13 @@ trap at_exit EXIT
# For unprivileged tests # For unprivileged tests
loginctl enable-linger testuser loginctl enable-linger testuser
if machine_supports_verity_keyring; then # Requires kernel built with certain kconfigs, as listed in README:
# https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=DM_VERITY_VERIFY_ROOTHASH_SIG&config=DM_VERITY_VERIFY_ROOTHASH_SIG_SECONDARY_KEYRING&config=DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING&config=IMA_ARCH_POLICY&config=INTEGRITY_MACHINE_KEYRING
if grep -q "$(openssl x509 -noout -subject -in /usr/share/mkosi.crt | sed 's/^.*CN=//')" /proc/keys && \
( . /etc/os-release; [ "$ID" != "centos" ] || systemd-analyze compare-versions "$VERSION_ID" ge 10 ) && \
( . /etc/os-release; [ "$ID" != "debian" ] || [ -z "${VERSION_ID:-}" ] || systemd-analyze compare-versions "$VERSION_ID" ge 13 ) && \
( . /etc/os-release; [ "$ID" != "ubuntu" ] || systemd-analyze compare-versions "$VERSION_ID" ge 24.04 ) && \
systemd-analyze compare-versions "$(cryptsetup --version | sed 's/^cryptsetup \([0-9]*\.[0-9]*\.[0-9]*\) .*/\1/')" ge 2.3.0; then
export VERITY_SIG_SUPPORTED=1 export VERITY_SIG_SUPPORTED=1
else else
export VERITY_SIG_SUPPORTED=0 export VERITY_SIG_SUPPORTED=0

View File

@ -54,17 +54,8 @@ DIGEST_MEASURED2="$(echo -n "schnurz" | openssl dgst -sha256 -hex -r | cut -d' '
DIGEST_EXPECTED2="$(echo "$DIGEST_EXPECTED$DIGEST_MEASURED2" | tr '[:lower:]' '[:upper:]' | basenc --base16 -d | openssl dgst -sha256 -hex -r | cut -d' ' -f1)" DIGEST_EXPECTED2="$(echo "$DIGEST_EXPECTED$DIGEST_MEASURED2" | tr '[:lower:]' '[:upper:]' | basenc --base16 -d | openssl dgst -sha256 -hex -r | cut -d' ' -f1)"
test "$DIGEST_ACTUAL2" = "$DIGEST_EXPECTED2" test "$DIGEST_ACTUAL2" = "$DIGEST_EXPECTED2"
mkdir -p /tmp/nvpcr/tree mkdir /tmp/nvpcr
touch /tmp/nvpcr/tree/file
if machine_supports_verity_keyring; then
SYSTEMD_REPART_OVERRIDE_FSTYPE=squashfs \
systemd-repart -P \
-s /tmp/nvpcr/tree \
--certificate=/usr/share/mkosi.crt \
--private-key=/usr/share/mkosi.key \
/var/tmp/nvpcr.raw
else
OPENSSL_CONFIG="/tmp/nvpcr/opensslconfig" OPENSSL_CONFIG="/tmp/nvpcr/opensslconfig"
# Unfortunately OpenSSL insists on reading some config file, hence provide one with mostly placeholder contents # Unfortunately OpenSSL insists on reading some config file, hence provide one with mostly placeholder contents
cat >"${OPENSSL_CONFIG:?}" <<EOF cat >"${OPENSSL_CONFIG:?}" <<EOF
@ -86,6 +77,9 @@ EOF
-x509 -sha256 -nodes -days 365 -newkey rsa:4096 \ -x509 -sha256 -nodes -days 365 -newkey rsa:4096 \
-keyout /tmp/nvpcr/test-70-nvpcr.key -out /tmp/nvpcr/test-70-nvpcr.crt -keyout /tmp/nvpcr/test-70-nvpcr.key -out /tmp/nvpcr/test-70-nvpcr.crt
mkdir /tmp/nvpcr/tree
touch /tmp/nvpcr/tree/file
SYSTEMD_REPART_OVERRIDE_FSTYPE=squashfs \ SYSTEMD_REPART_OVERRIDE_FSTYPE=squashfs \
systemd-repart -P \ systemd-repart -P \
-s /tmp/nvpcr/tree \ -s /tmp/nvpcr/tree \
@ -95,7 +89,6 @@ EOF
mkdir -p /run/verity.d mkdir -p /run/verity.d
cp /tmp/nvpcr/test-70-nvpcr.crt /run/verity.d/ cp /tmp/nvpcr/test-70-nvpcr.crt /run/verity.d/
fi
cp /run/log/systemd/tpm2-measure.log /tmp/nvpcr/log-before cp /run/log/systemd/tpm2-measure.log /tmp/nvpcr/log-before

View File

@ -5,11 +5,6 @@ set -o pipefail
export SYSTEMD_LOG_LEVEL=debug export SYSTEMD_LOG_LEVEL=debug
if ! systemd-analyze has-tpm2; then
echo "Full TPM2 support not available, skipping the test"
exit 0
fi
bootctl bootctl
CURRENT_UKI=$(bootctl --print-stub-path) CURRENT_UKI=$(bootctl --print-stub-path)

View File

@ -84,7 +84,7 @@ timer2=$(systemctl show -P NextElapseUSecRealtime upgrade_timer_test.timer)
# FIXME: See https://github.com/systemd/systemd/pull/39293 # FIXME: See https://github.com/systemd/systemd/pull/39293
systemctl stop systemd-networkd-resolve-hook.socket || true systemctl stop systemd-networkd-resolve-hook.socket || true
dnf downgrade --no-gpgchecks -y --allowerasing --disablerepo '*' "$pkgdir"/distro/*.rpm dnf downgrade -y --allowerasing --disablerepo '*' "$pkgdir"/distro/*.rpm
# Some distros don't ship networkd, so the test will always fail # Some distros don't ship networkd, so the test will always fail
if command -v networkctl >/dev/null; then if command -v networkctl >/dev/null; then
@ -105,7 +105,7 @@ fi
check_sd check_sd
# Finally test the upgrade # Finally test the upgrade
dnf -y upgrade --no-gpgchecks --disablerepo '*' "$pkgdir"/devel/*.rpm dnf -y upgrade --disablerepo '*' "$pkgdir"/devel/*.rpm
# TODO: sanity checks # TODO: sanity checks
check_sd check_sd

View File

@ -285,20 +285,6 @@ kernel_supports_lsm() {
return 1 return 1
} }
machine_supports_verity_keyring() {
# Requires kernel built with certain kconfigs, as listed in README:
# https://oracle.github.io/kconfigs/?config=UTS_RELEASE&config=DM_VERITY_VERIFY_ROOTHASH_SIG&config=DM_VERITY_VERIFY_ROOTHASH_SIG_SECONDARY_KEYRING&config=DM_VERITY_VERIFY_ROOTHASH_SIG_PLATFORM_KEYRING&config=IMA_ARCH_POLICY&config=INTEGRITY_MACHINE_KEYRING
if grep -q "$(openssl x509 -noout -subject -in /usr/share/mkosi.crt | sed 's/^.*CN=//')" /proc/keys && \
( . /etc/os-release; [ "$ID" != "centos" ] || systemd-analyze compare-versions "$VERSION_ID" ge 10 ) && \
( . /etc/os-release; [ "$ID" != "debian" ] || [ -z "${VERSION_ID:-}" ] || systemd-analyze compare-versions "$VERSION_ID" ge 13 ) && \
( . /etc/os-release; [ "$ID" != "ubuntu" ] || systemd-analyze compare-versions "$VERSION_ID" ge 24.04 ) && \
systemd-analyze compare-versions "$(cryptsetup --version | sed 's/^cryptsetup \([0-9]*\.[0-9]*\.[0-9]*\) .*/\1/')" ge 2.3.0; then
return 0
fi
return 1
}
install_extension_images() { install_extension_images() {
local os_release local os_release
os_release="$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os-release)" os_release="$(test -e /etc/os-release && echo /etc/os-release || echo /usr/lib/os-release)"