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