Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0+
0002 /*
0003  * Module signature checker
0004  *
0005  * Copyright (C) 2012 Red Hat, Inc. All Rights Reserved.
0006  * Written by David Howells (dhowells@redhat.com)
0007  */
0008 
0009 #include <linux/errno.h>
0010 #include <linux/printk.h>
0011 #include <linux/module_signature.h>
0012 #include <asm/byteorder.h>
0013 
0014 /**
0015  * mod_check_sig - check that the given signature is sane
0016  *
0017  * @ms:     Signature to check.
0018  * @file_len:   Size of the file to which @ms is appended.
0019  * @name:   What is being checked. Used for error messages.
0020  */
0021 int mod_check_sig(const struct module_signature *ms, size_t file_len,
0022           const char *name)
0023 {
0024     if (be32_to_cpu(ms->sig_len) >= file_len - sizeof(*ms))
0025         return -EBADMSG;
0026 
0027     if (ms->id_type != PKEY_ID_PKCS7) {
0028         pr_err("%s: not signed with expected PKCS#7 message\n",
0029                name);
0030         return -ENOPKG;
0031     }
0032 
0033     if (ms->algo != 0 ||
0034         ms->hash != 0 ||
0035         ms->signer_len != 0 ||
0036         ms->key_id_len != 0 ||
0037         ms->__pad[0] != 0 ||
0038         ms->__pad[1] != 0 ||
0039         ms->__pad[2] != 0) {
0040         pr_err("%s: PKCS#7 signature info has unexpected non-zero params\n",
0041                name);
0042         return -EBADMSG;
0043     }
0044 
0045     return 0;
0046 }