mirror of
https://github.com/Fishwaldo/Star64_linux.git
synced 2025-06-22 22:51:37 +00:00
MODSIGN: Move the magic string to the end of a module and eliminate the search
Emit the magic string that indicates a module has a signature after the signature data instead of before it. This allows module_sig_check() to be made simpler and faster by the elimination of the search for the magic string. Instead we just need to do a single memcmp(). This works because at the end of the signature data there is the fixed-length signature information block. This block then falls immediately prior to the magic number. From the contents of the information block, it is trivial to calculate the size of the signature data and thus the size of the actual module data. Signed-off-by: David Howells <dhowells@redhat.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
b6bb324dbd
commit
caabe24057
4 changed files with 27 additions and 30 deletions
|
@ -2421,25 +2421,17 @@ static inline void kmemleak_load_module(const struct module *mod,
|
|||
|
||||
#ifdef CONFIG_MODULE_SIG
|
||||
static int module_sig_check(struct load_info *info,
|
||||
const void *mod, unsigned long *len)
|
||||
const void *mod, unsigned long *_len)
|
||||
{
|
||||
int err = -ENOKEY;
|
||||
const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
|
||||
const void *p = mod, *end = mod + *len;
|
||||
unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
|
||||
unsigned long len = *_len;
|
||||
|
||||
/* Poor man's memmem. */
|
||||
while ((p = memchr(p, MODULE_SIG_STRING[0], end - p))) {
|
||||
if (p + markerlen > end)
|
||||
break;
|
||||
|
||||
if (memcmp(p, MODULE_SIG_STRING, markerlen) == 0) {
|
||||
const void *sig = p + markerlen;
|
||||
/* Truncate module up to signature. */
|
||||
*len = p - mod;
|
||||
err = mod_verify_sig(mod, *len, sig, end - sig);
|
||||
break;
|
||||
}
|
||||
p++;
|
||||
if (len > markerlen &&
|
||||
memcmp(mod + len - markerlen, MODULE_SIG_STRING, markerlen) == 0) {
|
||||
/* We truncate the module to discard the signature */
|
||||
*_len -= markerlen;
|
||||
err = mod_verify_sig(mod, _len);
|
||||
}
|
||||
|
||||
if (!err) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue