The KEYCTL_DH_COMPUTE key payloads are interpreted as MPI-formatted numbers. Even though the generic DH algorithm implementation doesn't look at the actual values when setting the parameters (and probably only validates them later when doing the actual operation), this isn't necessarily true for other implementations. Specifically, the Intel QAT driver checks if the prime size is one of 1536, 2048, 3072, or 4096 bits, causing the KEYCTL_DH_COMPUTE operation to fail with -EINVAL. While it is questionable if the QAT implementation should reject unusual prime sizes (it should use a fallback to generic instead), let's just make sure we pass valid numbers to avoid similar validation errors. I verified on a machine with an Intel QAT device that this patch makes the testsuite pass there. Fixes: 2d7aad8a1f8c ("selinux-testsuite: Add keys tests") Signed-off-by: Ondrej Mosnacek <omosnace@xxxxxxxxxx> --- tests/keys/keyctl.c | 8 ++++---- tests/keys/keyring_service.c | 8 ++++---- tests/keys/keys_common.h | 28 +++++++++++++++++++++++++--- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/tests/keys/keyctl.c b/tests/keys/keyctl.c index 5aff8d8..e13c655 100644 --- a/tests/keys/keyctl.c +++ b/tests/keys/keyctl.c @@ -72,15 +72,15 @@ int main(int argc, char *argv[]) * required by the keyctl(KEYCTL_DH_COMPUTE, ..) function. * These require key { create write } permissions. */ - private = add_key("user", "private", payload, strlen(payload), - KEY_SPEC_PROCESS_KEYRING); + private = add_key("user", "private", payload_private, + sizeof(payload_private), KEY_SPEC_PROCESS_KEYRING); if (private < 0) { fprintf(stderr, "Failed add_key(private): %s\n", strerror(errno)); exit(5); } - prime = add_key("user", "prime", payload, strlen(payload), + prime = add_key("user", "prime", payload_prime, sizeof(payload_prime), KEY_SPEC_PROCESS_KEYRING); if (prime < 0) { fprintf(stderr, "Failed add_key(prime): %s\n", @@ -88,7 +88,7 @@ int main(int argc, char *argv[]) exit(5); } - base = add_key("user", "base", payload, strlen(payload), + base = add_key("user", "base", payload_base, sizeof(payload_base), KEY_SPEC_PROCESS_KEYRING); if (base < 0) { fprintf(stderr, "Failed add_key(base): %s\n", diff --git a/tests/keys/keyring_service.c b/tests/keys/keyring_service.c index e5dcab0..9913653 100644 --- a/tests/keys/keyring_service.c +++ b/tests/keys/keyring_service.c @@ -91,15 +91,15 @@ int main(int argc, char **argv) printf("\tKEYCTL_JOIN_SESSION_KEYRING newkey ID: 0x%x\n", newring); - private = add_key("user", "private", payload, strlen(payload), - KEY_SPEC_SESSION_KEYRING); + private = add_key("user", "private", payload_private, + sizeof(payload_private), KEY_SPEC_SESSION_KEYRING); if (private < 0) { fprintf(stderr, "Failed add_key(private): %s\n", strerror(errno)); exit(6); } - prime = add_key("user", "prime", payload, strlen(payload), + prime = add_key("user", "prime", payload_prime, sizeof(payload_prime), KEY_SPEC_SESSION_KEYRING); if (prime < 0) { fprintf(stderr, "Failed add_key(prime): %s\n", @@ -107,7 +107,7 @@ int main(int argc, char **argv) exit(6); } - base = add_key("user", "base", payload, strlen(payload), + base = add_key("user", "base", payload_base, sizeof(payload_base), KEY_SPEC_SESSION_KEYRING); if (base < 0) { fprintf(stderr, "Failed add_key(base): %s\n", diff --git a/tests/keys/keys_common.h b/tests/keys/keys_common.h index df15280..55cc4eb 100644 --- a/tests/keys/keys_common.h +++ b/tests/keys/keys_common.h @@ -11,6 +11,28 @@ #include <selinux/selinux.h> #include <selinux/context.h> -/* This is used as the payload for each add_key() */ -static const char payload[] = - " -----BEGIN PUBLIC KEY-----\nMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDN4FHsPjlJf03r9KfNt1Ma9/D6\nQDEiR/cfhZrNUPgHRresult+E4dj52VJSonPFJ6HaLlUi5pZq2t1LqPNrMfFKCNn12m+\nWw4aduBJM7u1RUPSNxrlfDAJZkdtNALOO/ds3U93hZrxOYNetzbnjILDu5JT1nbI\n4aC60SkdlCw1TxmvXwIDAQAB\n-----END PUBLIC KEY-----\n"; +/* dummy values - the prime was genearted using `openssl dhparam -C` */ +static const unsigned char payload_prime[] = { + 0x96, 0xC1, 0xFA, 0xA4, 0xD4, 0xAB, 0xD6, 0x6D, 0x6F, 0x99, + 0x3A, 0xCC, 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static const unsigned char payload_base[] = { 0x02 }; +static const unsigned char payload_private[] = { 42 }; -- 2.26.2