1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Module signature checker
4 * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
8 #include <linux/kernel.h>
9 #include <linux/errno.h>
10 #include <linux/module.h>
11 #include <linux/module_signature.h>
12 #include <linux/string.h>
13 #include <linux/verification.h>
14 #include <crypto/public_key.h>
15 #include "module-internal.h"
18 * Verify the signature on a module.
20 int mod_verify_sig(const void *mod, struct load_info *info)
22 struct module_signature ms;
23 size_t sig_len, modlen = info->len;
26 pr_devel("==>%s(,%zu)\n", __func__, modlen);
28 if (modlen <= sizeof(ms))
31 memcpy(&ms, mod + (modlen - sizeof(ms)), sizeof(ms));
33 ret = mod_check_sig(&ms, modlen, "module");
37 sig_len = be32_to_cpu(ms.sig_len);
38 modlen -= sig_len + sizeof(ms);
41 return verify_pkcs7_signature(mod, modlen, mod + modlen, sig_len,
42 VERIFY_USE_SECONDARY_KEYRING,
43 VERIFYING_MODULE_SIGNATURE,