]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
core: refuse credentials with invalid names matching with glob 33916/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 3 Aug 2024 05:25:16 +0000 (14:25 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 3 Aug 2024 05:25:35 +0000 (14:25 +0900)
Even if the glob pattern is valid, the pattern may match credentials
with invalid names. So, we need to check the names of the found
credentials.

Follow-up for 947c4d3952e30604b97f657dca08f93a0a8f4bae.

src/core/exec-credential.c
test/units/TEST-54-CREDS.sh

index e1b09f671893a5fcd1fb468df92a5e034d53c6f2..45cb7f5ce22948bf68a3eb3846ac93234a1a0d25 100644 (file)
@@ -502,6 +502,11 @@ static int load_credential_glob(
                                 free_and_replace(fn, renamed);
                         }
 
+                        if (!credential_name_valid(fn)) {
+                                log_debug("Skipping credential with invalid name: %s", fn);
+                                continue;
+                        }
+
                         if (faccessat(write_dfd, fn, F_OK, AT_SYMLINK_NOFOLLOW) >= 0) {
                                 log_debug("Skipping credential with duplicated ID %s at %s", fn, *p);
                                 continue;
index f0e69328258882379ed5738f2dc4ab395dd0873b..29b789d36166de0b4d50470061f239b40d0e9b65 100755 (executable)
@@ -279,6 +279,24 @@ echo -n ignored >/run/credstore/test.creds.second
 mkdir -p /etc/credstore
 echo -n b >/etc/credstore/test.creds.second
 echo -n c >/etc/credstore/test.creds.third
+# Credential name cannot contain ':'
+echo -n hoge >/etc/credstore/test.creds.hoge:invalid
+
+# Check if credentials with invalid names are not imported.
+systemd-run -p "ImportCredential=test.creds.*" \
+            --unit=test-54-ImportCredential.service \
+            -p DynamicUser=1 \
+            --wait \
+            --pipe \
+            test ! -e '${CREDENTIALS_DIRECTORY}/test.creds.hoge:invalid'
+
+# Check if credentials with invalid names are not imported (with renaming).
+systemd-run -p "ImportCredentialEx=test.creds.*:renamed.creds." \
+            --unit=test-54-ImportCredential.service \
+            -p DynamicUser=1 \
+            --wait \
+            --pipe \
+            test ! -e '${CREDENTIALS_DIRECTORY}/renamed.creds.hoge:invalid'
 
 # Check that all valid credentials are imported.
 systemd-run -p "ImportCredential=test.creds.*" \