aboutsummaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2013-02-25 18:41:43 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2013-02-25 18:41:43 -0500
commit9043a2650cd21f96f831a97f516c2c302e21fb70 (patch)
tree926720afb0acc7bad8cfcae537dc58de552f9249 /scripts
parentab7826595e9ec51a51f622c5fc91e2f59440481a (diff)
parentd9d8d7ed498ec65bea72dd24be7b9cd35af0c200 (diff)
Merge tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux
Pull module update from Rusty Russell: "The sweeping change is to make add_taint() explicitly indicate whether to disable lockdep, but it's a mechanical change." * tag 'modules-next-for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/rusty/linux: MODSIGN: Add option to not sign modules during modules_install MODSIGN: Add -s <signature> option to sign-file MODSIGN: Specify the hash algorithm on sign-file command line MODSIGN: Simplify Makefile with a Kconfig helper module: clean up load_module a little more. modpost: Ignore ARC specific non-alloc sections module: constify within_module_* taint: add explicit flag to show whether lock dep is still OK. module: printk message when module signature fail taints kernel.
Diffstat (limited to 'scripts')
-rw-r--r--scripts/mod/modpost.c2
-rwxr-xr-xscripts/sign-file134
2 files changed, 65 insertions, 71 deletions
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index ff36c508a10e..1c6fbb1a4f8e 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -830,6 +830,8 @@ static const char *section_white_list[] =
830 ".toc*", 830 ".toc*",
831 ".xt.prop", /* xtensa */ 831 ".xt.prop", /* xtensa */
832 ".xt.lit", /* xtensa */ 832 ".xt.lit", /* xtensa */
833 ".arcextmap*", /* arc */
834 ".gnu.linkonce.arcext*", /* arc : modules */
833 NULL 835 NULL
834}; 836};
835 837
diff --git a/scripts/sign-file b/scripts/sign-file
index 974a20b661b7..2b7c4484d46c 100755
--- a/scripts/sign-file
+++ b/scripts/sign-file
@@ -2,51 +2,45 @@
2# 2#
3# Sign a module file using the given key. 3# Sign a module file using the given key.
4# 4#
5# Format: 5
6# 6my $USAGE =
7# ./scripts/sign-file [-v] <key> <x509> <module> [<dest>] 7"Usage: scripts/sign-file [-v] <hash algo> <key> <x509> <module> [<dest>]\n" .
8# 8" scripts/sign-file [-v] -s <raw sig> <hash algo> <x509> <module> [<dest>]\n";
9# 9
10use strict; 10use strict;
11use FileHandle; 11use FileHandle;
12use IPC::Open2; 12use IPC::Open2;
13use Getopt::Std;
13 14
14my $verbose = 0; 15my %opts;
15if ($#ARGV >= 0 && $ARGV[0] eq "-v") { 16getopts('vs:', \%opts) or die $USAGE;
16 $verbose = 1; 17my $verbose = $opts{'v'};
17 shift; 18my $signature_file = $opts{'s'};
18}
19 19
20die "Format: ./scripts/sign-file [-v] <key> <x509> <module> [<dest>]\n" 20die $USAGE if ($#ARGV > 4);
21 if ($#ARGV != 2 && $#ARGV != 3); 21die $USAGE if (!$signature_file && $#ARGV < 3 || $signature_file && $#ARGV < 2);
22 22
23my $private_key = $ARGV[0]; 23my $dgst = shift @ARGV;
24my $x509 = $ARGV[1]; 24my $private_key;
25my $module = $ARGV[2]; 25if (!$signature_file) {
26my $dest = ($#ARGV == 3) ? $ARGV[3] : $ARGV[2] . "~"; 26 $private_key = shift @ARGV;
27}
28my $x509 = shift @ARGV;
29my $module = shift @ARGV;
30my ($dest, $keep_orig);
31if (@ARGV) {
32 $dest = $ARGV[0];
33 $keep_orig = 1;
34} else {
35 $dest = $module . "~";
36}
27 37
28die "Can't read private key\n" unless (-r $private_key); 38die "Can't read private key\n" if (!$signature_file && !-r $private_key);
39die "Can't read signature file\n" if ($signature_file && !-r $signature_file);
29die "Can't read X.509 certificate\n" unless (-r $x509); 40die "Can't read X.509 certificate\n" unless (-r $x509);
30die "Can't read module\n" unless (-r $module); 41die "Can't read module\n" unless (-r $module);
31 42
32# 43#
33# Read the kernel configuration
34#
35my %config = (
36 CONFIG_MODULE_SIG_SHA512 => 1
37 );
38
39if (-r ".config") {
40 open(FD, "<.config") || die ".config";
41 while (<FD>) {
42 if ($_ =~ /^(CONFIG_.*)=[ym]/) {
43 $config{$1} = 1;
44 }
45 }
46 close(FD);
47}
48
49#
50# Function to read the contents of a file into a variable. 44# Function to read the contents of a file into a variable.
51# 45#
52sub read_file($) 46sub read_file($)
@@ -321,73 +315,71 @@ my $id_type = 1; # Identifier type: X.509
321# 315#
322# Digest the data 316# Digest the data
323# 317#
324my ($dgst, $prologue) = (); 318my $prologue;
325if (exists $config{"CONFIG_MODULE_SIG_SHA1"}) { 319if ($dgst eq "sha1") {
326 $prologue = pack("C*", 320 $prologue = pack("C*",
327 0x30, 0x21, 0x30, 0x09, 0x06, 0x05, 321 0x30, 0x21, 0x30, 0x09, 0x06, 0x05,
328 0x2B, 0x0E, 0x03, 0x02, 0x1A, 322 0x2B, 0x0E, 0x03, 0x02, 0x1A,
329 0x05, 0x00, 0x04, 0x14); 323 0x05, 0x00, 0x04, 0x14);
330 $dgst = "-sha1";
331 $hash = 2; 324 $hash = 2;
332} elsif (exists $config{"CONFIG_MODULE_SIG_SHA224"}) { 325} elsif ($dgst eq "sha224") {
333 $prologue = pack("C*", 326 $prologue = pack("C*",
334 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09, 327 0x30, 0x2d, 0x30, 0x0d, 0x06, 0x09,
335 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04, 328 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x04,
336 0x05, 0x00, 0x04, 0x1C); 329 0x05, 0x00, 0x04, 0x1C);
337 $dgst = "-sha224";
338 $hash = 7; 330 $hash = 7;
339} elsif (exists $config{"CONFIG_MODULE_SIG_SHA256"}) { 331} elsif ($dgst eq "sha256") {
340 $prologue = pack("C*", 332 $prologue = pack("C*",
341 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09, 333 0x30, 0x31, 0x30, 0x0d, 0x06, 0x09,
342 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01, 334 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x01,
343 0x05, 0x00, 0x04, 0x20); 335 0x05, 0x00, 0x04, 0x20);
344 $dgst = "-sha256";
345 $hash = 4; 336 $hash = 4;
346} elsif (exists $config{"CONFIG_MODULE_SIG_SHA384"}) { 337} elsif ($dgst eq "sha384") {
347 $prologue = pack("C*", 338 $prologue = pack("C*",
348 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09, 339 0x30, 0x41, 0x30, 0x0d, 0x06, 0x09,
349 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02, 340 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x02,
350 0x05, 0x00, 0x04, 0x30); 341 0x05, 0x00, 0x04, 0x30);
351 $dgst = "-sha384";
352 $hash = 5; 342 $hash = 5;
353} elsif (exists $config{"CONFIG_MODULE_SIG_SHA512"}) { 343} elsif ($dgst eq "sha512") {
354 $prologue = pack("C*", 344 $prologue = pack("C*",
355 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09, 345 0x30, 0x51, 0x30, 0x0d, 0x06, 0x09,
356 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03, 346 0x60, 0x86, 0x48, 0x01, 0x65, 0x03, 0x04, 0x02, 0x03,
357 0x05, 0x00, 0x04, 0x40); 347 0x05, 0x00, 0x04, 0x40);
358 $dgst = "-sha512";
359 $hash = 6; 348 $hash = 6;
360} else { 349} else {
361 die "Can't determine hash algorithm"; 350 die "Unknown hash algorithm: $dgst\n";
362} 351}
363 352
364#
365# Generate the digest and read from openssl's stdout
366#
367my $digest;
368$digest = readpipe("openssl dgst $dgst -binary $module") || die "openssl dgst";
369
370#
371# Generate the binary signature, which will be just the integer that comprises
372# the signature with no metadata attached.
373#
374my $pid;
375$pid = open2(*read_from, *write_to,
376 "openssl rsautl -sign -inkey $private_key -keyform PEM") ||
377 die "openssl rsautl";
378binmode write_to;
379print write_to $prologue . $digest || die "pipe to openssl rsautl";
380close(write_to) || die "pipe to openssl rsautl";
381
382binmode read_from;
383my $signature; 353my $signature;
384read(read_from, $signature, 4096) || die "pipe from openssl rsautl"; 354if ($signature_file) {
385close(read_from) || die "pipe from openssl rsautl"; 355 $signature = read_file($signature_file);
356} else {
357 #
358 # Generate the digest and read from openssl's stdout
359 #
360 my $digest;
361 $digest = readpipe("openssl dgst -$dgst -binary $module") || die "openssl dgst";
362
363 #
364 # Generate the binary signature, which will be just the integer that
365 # comprises the signature with no metadata attached.
366 #
367 my $pid;
368 $pid = open2(*read_from, *write_to,
369 "openssl rsautl -sign -inkey $private_key -keyform PEM") ||
370 die "openssl rsautl";
371 binmode write_to;
372 print write_to $prologue . $digest || die "pipe to openssl rsautl";
373 close(write_to) || die "pipe to openssl rsautl";
374
375 binmode read_from;
376 read(read_from, $signature, 4096) || die "pipe from openssl rsautl";
377 close(read_from) || die "pipe from openssl rsautl";
378 waitpid($pid, 0) || die;
379 die "openssl rsautl died: $?" if ($? >> 8);
380}
386$signature = pack("n", length($signature)) . $signature, 381$signature = pack("n", length($signature)) . $signature,
387 382
388waitpid($pid, 0) || die;
389die "openssl rsautl died: $?" if ($? >> 8);
390
391# 383#
392# Build the signed binary 384# Build the signed binary
393# 385#
@@ -424,6 +416,6 @@ print FD
424 ; 416 ;
425close FD || die $dest; 417close FD || die $dest;
426 418
427if ($#ARGV != 3) { 419if (!$keep_orig) {
428 rename($dest, $module) || die $module; 420 rename($dest, $module) || die $module;
429} 421}