Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  2) /* Module signature checker
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  3)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  4)  * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  5)  * Written by David Howells (dhowells@redhat.com)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  6)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  8) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  9) #include <linux/errno.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/module_signature.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/verification.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <crypto/public_key.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include "module-internal.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)  * Verify the signature on a module.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) int mod_verify_sig(const void *mod, struct load_info *info)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) 	struct module_signature ms;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) 	size_t sig_len, modlen = info->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) 	int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) 	pr_devel("==>%s(,%zu)\n", __func__, modlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) 	if (modlen <= sizeof(ms))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) 		return -EBADMSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) 	memcpy(&ms, mod + (modlen - sizeof(ms)), sizeof(ms));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) 	ret = mod_check_sig(&ms, modlen, "module");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) 	if (ret)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) 		return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) 	sig_len = be32_to_cpu(ms.sig_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) 	modlen -= sig_len + sizeof(ms);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) 	info->len = modlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) 	return verify_pkcs7_signature(mod, modlen, mod + modlen, sig_len,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) 				      VERIFY_USE_SECONDARY_KEYRING,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) 				      VERIFYING_MODULE_SIGNATURE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) 				      NULL, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) }