Bug 905947 - signing boot binaries encapsulates timestamp
Summary: signing boot binaries encapsulates timestamp
Status: NEW
: 906160 (view as bug list)
Alias: None
Product: openSUSE Tumbleweed
Classification: openSUSE
Component: Basesystem (show other bugs)
Version: 201411*
Hardware: Other Other
: P5 - None : Normal (vote)
Target Milestone: ---
Assignee: Gary Ching-Pang Lin
QA Contact: E-mail List
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-11-18 13:56 UTC by Olaf Hering
Modified: 2020-06-04 12:28 UTC (History)
6 users (show)

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olaf Hering 2014-11-18 13:56:03 UTC
build-compare will fail for vmlinuz and xen.efi because these binaries contain some timestamp. Hopefully such timestamp is not part of the protocol.
Not sure what the rest of the noise is.

/boot/vmlinuz-3.12.31-@RELEASE_SHORT@-default differs ( Linux/x86 Kernel, Setup Version 0x20c, bzImage, Version 3.12.31-3.olh_sle12-default (geeko@buildhost) #1 SMP Wed Oct 29, RO-rootFS, swap_dev 0x4, Normal VGA)
--- /dev/shm/tmp.Ecj0vBjCyx     2014-11-18 14:55:22.650551820 +0100
+++ /dev/shm/tmp.JneR5NguZW     2014-11-18 14:55:24.350508995 +0100
@@ -305048,26 +305048,26 @@
 004a9b20  48 86 f7 0d 01 09 0f 31  02 30 00 30 19 06 09 2a  |H......1.0.0...*|
 004a9b30  86 48 86 f7 0d 01 09 03  31 0c 06 0a 2b 06 01 04  |.H......1...+...|
 004a9b40  01 82 37 02 01 04 30 1c  06 09 2a 86 48 86 f7 0d  |..7...0...*.H...|
-004a9b50  01 09 05 31 0f 17 0d 31  34 31 31 31 37 31 36 31  |...1...141117161|
-004a9b60  30 35 38 5a 30 2f 06 09  2a 86 48 86 f7 0d 01 09  |058Z0/..*.H.....|
+004a9b50  01 09 05 31 0f 17 0d 31  34 31 31 31 38 30 38 31  |...1...141118081|
+004a9b60  30 31 39 5a 30 2f 06 09  2a 86 48 86 f7 0d 01 09  |019Z0/..*.H.....|
 004a9b70  04 31 22 04 20 a4 60 be  8b 98 7f aa 19 dd db 7c  |.1". .`........||
 004a9b80  91 9e 7c fc 5f 19 22 18  aa f4 62 12 a6 1e 8a 55  |..|._."...b....U|
 004a9b90  7b 62 65 a3 de 30 0d 06  09 2a 86 48 86 f7 0d 01  |{be..0...*.H....|
-004a9ba0  01 01 05 00 04 82 01 00  3a fd 22 b0 66 54 ed f3  |........:.".fT..|
-004a9bb0  10 9e 92 b8 31 07 66 90  8b e2 b0 47 e1 32 73 3a  |....1.f....G.2s:|
-004a9bc0  6e b4 60 c2 88 83 71 37  ad 45 67 b8 89 d4 d2 cf  |n.`...q7.Eg.....|
-004a9bd0  3c bf d3 e9 98 eb d7 ca  3b f7 9d 4d 98 9d 0f 28  |<.......;..M...(|
-004a9be0  b4 09 08 c8 84 79 db 91  87 94 10 da eb 77 6c 82  |.....y.......wl.|
-004a9bf0  b4 30 91 ef 64 20 7d 78  c5 a8 3d 81 35 c4 c7 76  |.0..d }x..=.5..v|
-004a9c00  87 d6 ca 5e a5 d6 f7 03  3a ba 33 b7 5c f9 74 56  |...^....:.3.\.tV|
-004a9c10  c5 e1 10 78 a2 44 23 10  0f d5 9d 13 80 b3 ba 3d  |...x.D#........=|
-004a9c20  e9 0d ef 72 71 5f 29 0d  ea ec f1 06 98 ad 27 4e  |...rq_).......'N|
-004a9c30  eb ce 5c 37 a4 b6 56 94  d0 4b 43 a0 0d 2a 34 b2  |..\7..V..KC..*4.|
-004a9c40  ab bd 6a bf aa fe a1 4e  d7 c2 4b d4 59 0b 03 56  |..j....N..K.Y..V|
-004a9c50  c4 00 0a fa 6b 37 0f c7  9c 99 8d 06 6e 43 c2 72  |....k7......nC.r|
-004a9c60  21 4d 8a 1f 90 f3 47 e5  cf 7b 88 07 22 43 72 92  |!M....G..{.."Cr.|
-004a9c70  36 ce 44 99 64 98 ab 21  21 51 a6 03 fc bc 7d fc  |6.D.d..!!Q....}.|
-004a9c80  06 14 46 e0 48 29 e8 15  56 c8 38 19 4e 08 78 68  |..F.H)..V.8.N.xh|
-004a9c90  2d bc 07 16 8a 23 a9 98  c1 36 f9 ee e8 99 d7 f7  |-....#...6......|
-004a9ca0  80 c2 2f 25 55 cd ce cc                           |../%U...|
+004a9ba0  01 01 05 00 04 82 01 00  77 59 a5 e9 75 31 f2 84  |........wY..u1..|
+004a9bb0  92 39 ee c4 ef 9b 05 f1  3c 9c 04 ae c3 5f 77 21  |.9......<...._w!|
+004a9bc0  2e 7f b0 80 2b 06 b2 56  79 72 ac 06 4c 2b df e9  |....+..Vyr..L+..|
+004a9bd0  5b d6 36 ad c1 e8 d2 01  04 4b 42 d6 95 0e ef 32  |[.6......KB....2|
+004a9be0  b9 43 22 0d 09 3c 7f 55  00 1d 1f 12 93 d3 51 17  |.C"..<.U......Q.|
+004a9bf0  6a 39 ea ef 2b b5 6a 39  ad 52 45 0b 6c ee 21 09  |j9..+.j9.RE.l.!.|
+004a9c00  a4 80 c4 40 7f 0c 94 cf  3f 21 62 9f f1 5c 5e 4e  |...@....?!b..\^N|
+004a9c10  1c a4 17 c4 24 66 74 f6  ac 6b 96 eb 89 bd c5 15  |....$ft..k......|
+004a9c20  b2 2d db 97 3a 5e cf e1  c2 c4 6b 0d 3d 25 8f 5c  |.-..:^....k.=%.\|
+004a9c30  5d fc c8 79 5c 05 11 d6  a3 7a 57 65 97 ca 7c 6a  |]..y\....zWe..|j|
+004a9c40  78 89 13 22 48 ab a9 1e  ff d4 86 f2 68 04 0a 51  |x.."H.......h..Q|
+004a9c50  df b5 2a 86 68 86 32 0f  ba 82 98 d7 be 85 17 26  |..*.h.2........&|
+004a9c60  44 1d 1b 83 04 55 2a 4e  b5 05 1b 5f 00 49 3b cf  |D....U*N..._.I;.|
+004a9c70  27 e7 ed a5 58 3f 31 b5  2d 73 6a 28 fd 5c 06 ac  |'...X?1.-sj(.\..|
+004a9c80  ec 19 48 fd 2a 1d d3 9a  02 5f 4f 2f f5 20 a7 fe  |..H.*...._O/. ..|
+004a9c90  23 92 79 a3 5a 2f 11 79  3a 66 a7 ad af e2 50 15  |#.y.Z/.y:f....P.|
+004a9ca0  e8 90 91 ef b3 1b ec 28                           |.......(|
 004a9ca8
Comment 1 Stephan Kulow 2014-11-18 23:16:29 UTC
I have no idea about signing, but I know someone who does :)
Comment 2 Gary Ching-Pang Lin 2014-11-19 03:49:49 UTC
The timestamp marked when the EFI image was signed, and the "noise" is a part of the signature.
Comment 3 Gary Ching-Pang Lin 2014-11-19 07:49:46 UTC
If you want to strip the signature, use the following command:

$ pesign -r -u 0 -i <input> -o <output>

then you can compare the real binary contents.
Comment 4 Olaf Hering 2014-11-19 07:52:38 UTC
Do we want to strip the signature? I think its important to republish if the signature happens to differ. 

Hopefully there is a way to provide stable input to get stable output.
Comment 5 Gary Ching-Pang Lin 2014-11-19 08:13:08 UTC
(In reply to Olaf Hering from comment #4)
> Do we want to strip the signature? I think its important to republish if the
> signature happens to differ. 
> 
The problem is if you want the signature to be the same, you have to "fake" the signing time.

> Hopefully there is a way to provide stable input to get stable output.
The other way I know is to compare the hash of the binaries. The hash can be generated with "pesign -h -i <input>". This will be easier than comparing the binaries.
Comment 6 Olaf Hering 2014-11-19 08:20:23 UTC
the kernel binary packages (and soon xen) already use a fixed timestamp for building. So I'm sure pesign (or whatever tool is used) can do the very same. Would that lead to identical binaries if the timestamp is always the same?
Comment 7 Gary Ching-Pang Lin 2014-11-19 08:33:21 UTC
(In reply to Olaf Hering from comment #6)
> the kernel binary packages (and soon xen) already use a fixed timestamp for
> building. So I'm sure pesign (or whatever tool is used) can do the very
> same. Would that lead to identical binaries if the timestamp is always the
> same?
I think so.
Comment 8 Olaf Hering 2014-11-19 17:46:32 UTC
Then this might be the place to fix it. There needs to be a way to pass a timestamp from the main pkg.spec to pesign-repackage.spec.
Comment 9 Gary Ching-Pang Lin 2014-11-20 02:44:28 UTC
I was thinking about adding a new option to pesign to specify the timestamp so we don't have to fiddle with the binary.
Comment 10 Michal Marek 2014-11-26 09:21:31 UTC
Copying from email:

IMO this is more complicated than it needs to be. The rpm signatures are
not checked by the build-compare script, so there is little point in
checking the EFI singnatures byte-by-byte. The build-compare script
should be taught to only check the binary itself plus maybe the ID of
the key used to sign it.
Comment 11 Olaf Hering 2014-11-26 09:32:47 UTC
(In reply to Michal Marek from comment #10)
> Copying from email:
> 
> IMO this is more complicated than it needs to be. The rpm signatures are
> not checked by the build-compare script, so there is little point in
> checking the EFI singnatures byte-by-byte. The build-compare script
> should be taught to only check the binary itself plus maybe the ID of
> the key used to sign it.

What exactly should it do to compare old/foo.ko new/foo.ko?
Comment 12 Gary Ching-Pang Lin 2014-12-04 09:34:42 UTC
(In reply to Olaf Hering from comment #11)
> (In reply to Michal Marek from comment #10)
> > Copying from email:
> > 
> > IMO this is more complicated than it needs to be. The rpm signatures are
> > not checked by the build-compare script, so there is little point in
> > checking the EFI singnatures byte-by-byte. The build-compare script
> > should be taught to only check the binary itself plus maybe the ID of
> > the key used to sign it.
> 
> What exactly should it do to compare old/foo.ko new/foo.ko?

I am not aware of any tool to strip the signature of the kernel modules, but the structure of the signature is not complicated, so you could do it with a script.

The structure of a signed ko file is like this:

[module content][signer name][key identifier][signature][info][magic number]

Since you are going to compare the old and new ko files, [module content] is definitely the thing you want to keep. It's also good to keep [signer name] and [key identifier]. Those two come from the signer key and shouldn't change if the modules are signed by the same key. [magic number] is always "~Module signature appended~\n". Now the problem becomes how to remove [signature].

Before removing [signature], you have to parse [info]. [info] is packed by the sign-file perl script with "CCCCCxxxN". Just ignore the first 8 bytes. The last 4 bytes of [info] is the size of [signature] in the big endian order. The size is 258 under our current configuration.

In short, all you have to do is to remove the last 258+12+28 bytes. Of course, it's safer to check the size instead of using 258 directly.

For reference, the sign-file script:
https://git.kernel.org/cgit/linux/kernel/git/torvalds/linux.git/tree/scripts/sign-file
Comment 13 Michal Marek 2015-01-22 13:09:18 UTC
*** Bug 906160 has been marked as a duplicate of this bug. ***
Comment 14 Michal Marek 2015-01-22 13:14:24 UTC
Please do not assume that the signature has a givent lenght. Parsing the information is rather simple, have a look e.g. at the kernel-sign-file script in pesign-obs-integration:

my $unsigned_module = read_file($module);

my $magic_number = "~Module signature appended~\n";
my $magic_len = length($magic_number);
my $info_len = 12;

# Truncate existing signarure, if any
if (substr($unsigned_module, -$magic_len) eq $magic_number) {
	my $info = substr($unsigned_module, -$magic_len - $info_len, $info_len);
	my ($name_len, $key_len, $sig_len) = unpack("xxxCCxxxN", $info);
	my $subtract = $name_len + $key_len + $sig_len + $info_len + $magic_len;
	if ($subtract > length($unsigned_module)) {
		die "$module: Existing signature is malformed\n";
	}
	$unsigned_module = substr($unsigned_module, 0,
		length($unsigned_module) - $subtract);
}

To keep the name and key id, only truncate $sig_len + $info_len + $magic_len bytes.