diff options
author | David Howells <dhowells@redhat.com> | 2012-10-19 20:19:29 -0400 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2012-10-19 20:30:40 -0400 |
commit | caabe240574aec05b2f5667414ce80f9075c2ba1 (patch) | |
tree | d92bf96b009bd0b0caec44c21348812b06805909 /kernel/module_signing.c | |
parent | b6bb324dbddd704b4b9a85971e1f7ae79abb2e1d (diff) |
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>
Diffstat (limited to 'kernel/module_signing.c')
-rw-r--r-- | kernel/module_signing.c | 24 |
1 files changed, 15 insertions, 9 deletions
diff --git a/kernel/module_signing.c b/kernel/module_signing.c index 6b09f6983ac0..d492a23df99c 100644 --- a/kernel/module_signing.c +++ b/kernel/module_signing.c | |||
@@ -183,27 +183,33 @@ static struct key *request_asymmetric_key(const char *signer, size_t signer_len, | |||
183 | /* | 183 | /* |
184 | * Verify the signature on a module. | 184 | * Verify the signature on a module. |
185 | */ | 185 | */ |
186 | int mod_verify_sig(const void *mod, unsigned long modlen, | 186 | int mod_verify_sig(const void *mod, unsigned long *_modlen) |
187 | const void *sig, unsigned long siglen) | ||
188 | { | 187 | { |
189 | struct public_key_signature *pks; | 188 | struct public_key_signature *pks; |
190 | struct module_signature ms; | 189 | struct module_signature ms; |
191 | struct key *key; | 190 | struct key *key; |
192 | size_t sig_len; | 191 | const void *sig; |
192 | size_t modlen = *_modlen, sig_len; | ||
193 | int ret; | 193 | int ret; |
194 | 194 | ||
195 | pr_devel("==>%s(,%lu,,%lu,)\n", __func__, modlen, siglen); | 195 | pr_devel("==>%s(,%lu)\n", __func__, modlen); |
196 | 196 | ||
197 | if (siglen <= sizeof(ms)) | 197 | if (modlen <= sizeof(ms)) |
198 | return -EBADMSG; | 198 | return -EBADMSG; |
199 | 199 | ||
200 | memcpy(&ms, sig + (siglen - sizeof(ms)), sizeof(ms)); | 200 | memcpy(&ms, mod + (modlen - sizeof(ms)), sizeof(ms)); |
201 | siglen -= sizeof(ms); | 201 | modlen -= sizeof(ms); |
202 | 202 | ||
203 | sig_len = be32_to_cpu(ms.sig_len); | 203 | sig_len = be32_to_cpu(ms.sig_len); |
204 | if (sig_len >= siglen || | 204 | if (sig_len >= modlen) |
205 | siglen - sig_len != (size_t)ms.signer_len + ms.key_id_len) | ||
206 | return -EBADMSG; | 205 | return -EBADMSG; |
206 | modlen -= sig_len; | ||
207 | if ((size_t)ms.signer_len + ms.key_id_len >= modlen) | ||
208 | return -EBADMSG; | ||
209 | modlen -= (size_t)ms.signer_len + ms.key_id_len; | ||
210 | |||
211 | *_modlen = modlen; | ||
212 | sig = mod + modlen; | ||
207 | 213 | ||
208 | /* For the moment, only support RSA and X.509 identifiers */ | 214 | /* For the moment, only support RSA and X.509 identifiers */ |
209 | if (ms.algo != PKEY_ALGO_RSA || | 215 | if (ms.algo != PKEY_ALGO_RSA || |