#endif
#ifdef CONFIG_MODULE_SIG
- static int module_sig_check(struct load_info *info,
- const void *mod, unsigned long *_len)
+ static int module_sig_check(struct load_info *info)
{
int err = -ENOKEY;
- unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
- unsigned long len = *_len;
+ const unsigned long markerlen = sizeof(MODULE_SIG_STRING) - 1;
+ const void *mod = info->hdr;
- const void *p = mod, *end = mod + info->len;
++ unsigned long len = info->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. */
- info->len = p - mod;
- err = mod_verify_sig(mod, info->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);
++ info->len -= markerlen;
++ err = mod_verify_sig(mod, &info->len);
}
if (!err) {