Blame SOURCES/kmod-signature-do-not-report-wrong-data-for-pkc-7-signatu.patch

068827
From a11057201ed326a9e65e757202da960735e45799 Mon Sep 17 00:00:00 2001
068827
From: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
068827
Date: Fri, 16 Nov 2018 10:56:34 +0200
068827
Subject: [PATCH] signature: do not report wrong data for pkc#7 signature
068827
068827
when PKC#7 signing method is used the old structure doesn't contain
068827
any useful data, but the data are encoded in the certificate.
068827
068827
The info getting/showing code is not aware of that at the moment and
068827
since 0 is a valid constant, shows, for example, wrong "md4" for the
068827
hash algo.
068827
068827
The patch splits the 2 mothods of gethering the info and reports
068827
"unknown" for the algo.
068827
068827
Signed-off-by: Yauheni Kaliuta <yauheni.kaliuta@redhat.com>
068827
---
068827
 libkmod/libkmod-module.c    |  2 +-
068827
 libkmod/libkmod-signature.c | 56 +++++++++++++++++++++++++------------
068827
 2 files changed, 39 insertions(+), 19 deletions(-)
068827
068827
diff --git a/libkmod/libkmod-module.c b/libkmod/libkmod-module.c
068827
index ee420f4ec2bf..889f26479a98 100644
068827
--- a/libkmod/libkmod-module.c
068827
+++ b/libkmod/libkmod-module.c
068827
@@ -2273,7 +2273,7 @@ KMOD_EXPORT int kmod_module_get_info(const struct kmod_module *mod, struct kmod_
068827
 	struct kmod_elf *elf;
068827
 	char **strings;
068827
 	int i, count, ret = -ENOMEM;
068827
-	struct kmod_signature_info sig_info;
068827
+	struct kmod_signature_info sig_info = {};
068827
 
068827
 	if (mod == NULL || list == NULL)
068827
 		return -ENOENT;
068827
diff --git a/libkmod/libkmod-signature.c b/libkmod/libkmod-signature.c
068827
index 1f3e26dea203..429ffbd8a957 100644
068827
--- a/libkmod/libkmod-signature.c
068827
+++ b/libkmod/libkmod-signature.c
068827
@@ -92,6 +92,38 @@ struct module_signature {
068827
 	uint32_t sig_len;    /* Length of signature data (big endian) */
068827
 };
068827
 
068827
+static bool fill_default(const char *mem, off_t size,
068827
+			 const struct module_signature *modsig, size_t sig_len,
068827
+			 struct kmod_signature_info *sig_info)
068827
+{
068827
+	size -= sig_len;
068827
+	sig_info->sig = mem + size;
068827
+	sig_info->sig_len = sig_len;
068827
+
068827
+	size -= modsig->key_id_len;
068827
+	sig_info->key_id = mem + size;
068827
+	sig_info->key_id_len = modsig->key_id_len;
068827
+
068827
+	size -= modsig->signer_len;
068827
+	sig_info->signer = mem + size;
068827
+	sig_info->signer_len = modsig->signer_len;
068827
+
068827
+	sig_info->algo = pkey_algo[modsig->algo];
068827
+	sig_info->hash_algo = pkey_hash_algo[modsig->hash];
068827
+	sig_info->id_type = pkey_id_type[modsig->id_type];
068827
+
068827
+	return true;
068827
+}
068827
+
068827
+static bool fill_unknown(const char *mem, off_t size,
068827
+			 const struct module_signature *modsig, size_t sig_len,
068827
+			 struct kmod_signature_info *sig_info)
068827
+{
068827
+	sig_info->hash_algo = "unknown";
068827
+	sig_info->id_type = pkey_id_type[modsig->id_type];
068827
+	return true;
068827
+}
068827
+
068827
 #define SIG_MAGIC "~Module signature appended~\n"
068827
 
068827
 /*
068827
@@ -112,7 +144,6 @@ bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signat
068827
 	const struct module_signature *modsig;
068827
 	size_t sig_len;
068827
 
068827
-
068827
 	size = kmod_file_get_size(file);
068827
 	mem = kmod_file_get_contents(file);
068827
 	if (size < (off_t)strlen(SIG_MAGIC))
068827
@@ -134,21 +165,10 @@ bool kmod_module_signature_info(const struct kmod_file *file, struct kmod_signat
068827
 	    size < (int64_t)(modsig->signer_len + modsig->key_id_len + sig_len))
068827
 		return false;
068827
 
068827
-	size -= sig_len;
068827
-	sig_info->sig = mem + size;
068827
-	sig_info->sig_len = sig_len;
068827
-
068827
-	size -= modsig->key_id_len;
068827
-	sig_info->key_id = mem + size;
068827
-	sig_info->key_id_len = modsig->key_id_len;
068827
-
068827
-	size -= modsig->signer_len;
068827
-	sig_info->signer = mem + size;
068827
-	sig_info->signer_len = modsig->signer_len;
068827
-
068827
-	sig_info->algo = pkey_algo[modsig->algo];
068827
-	sig_info->hash_algo = pkey_hash_algo[modsig->hash];
068827
-	sig_info->id_type = pkey_id_type[modsig->id_type];
068827
-
068827
-	return true;
068827
+	switch (modsig->id_type) {
068827
+	case PKEY_ID_PKCS7:
068827
+		return fill_unknown(mem, size, modsig, sig_len, sig_info);
068827
+	default:
068827
+		return fill_default(mem, size, modsig, sig_len, sig_info);
068827
+	}
068827
 }
068827
-- 
068827
2.20.1
068827