SlideShare a Scribd company logo
1 of 37
Download to read offline
Multi-signed Kernel Module
SUSE Labs Conference 2020, Virtual
edition
October 8, 2020
2 Copyright © SUSE 2020
Agenda
01 Structure of kernel
module signature
02 Producing a CMS
message
03 Producing a multiple
signer CMS message
04 Re-signing a CMS
05 Conclusion
06 Q&A
LINUX KERNEL
3 Copyright © SUSE 2020
Structure of
kernel module
signature
Copyright © SUSE 20204
Kernel module signature verification
LINUX KERNEL
* The kernel module signing facility cryptographically signs modules during
installation and then checks the signature upon loading the module. [1]
CONFIG_MODULE_SIG
* History in Kernel
- v3.7: Kernel module signature verification be introduced
- Using a specific structure for module signature
- v3.17: PKCS#7 parser be introduced
CONFIG_PKCS7_MESSAGE_PARSER
- v4.3: The format of module signature be switched to PKCS#7/CMS message
5 Copyright © SUSE 2020
Signature of
Kernel Module
LINUX KERNEL
Module Data
ms->sig_len
struct module_signature
u8 id_type;
__be32 sig_len;
PKCS#7 / CMS
message
MODULE_SIG_STRING
12 bytes
markerlen
ModuleSignature
6 Copyright © SUSE 2020
Structure of
module signature
LINUX KERNEL
7 Copyright © SUSE 2020
Example of module signature
LINUX KERNEL
PKCS#7 type sig_len = 0x1ea = 0x1e6 + 4
0x10b31 – 0x1ea + 1 = 0x10948
CMS message
ASN.1 tag:
Type: 30 = _tag(UNIV, CONS, SEQ)
0x82 = 10000002 = 2 subsequent octet
Length = 0x1e6
Copyright © SUSE 20208
Cryptographic Message Syntax (CMS)
LINUX KERNEL
* ietf.org RFC 5652
* The CMS is derived from PKCS #7 version 1.5, which is documented in RFC 2315
[PKCS#7].
* The CMS describes an encapsulation syntax for data protection. It supports digital
signatures and encryption. [2]
* The CMS values are generated using ASN.1 [X.208-88], using BER-encoding (Basic
Encoding Rules) [X.209-88]. Values are typically represented as octet strings. [2]
* CMS be supported by openssl-1.0.0 or newer. [1]
Copyright © SUSE 20209
Signed-data Content Type
LINUX KERNEL
* The CMS is general enough to support many different content types. [2]
* An implementation that conforms to this specification MUST implement the
protection content, ContentInfo, and MUST implement the data, signed-data, and
enveloped-data content types. [2]
* Kernel module signature uses signed-data conent type.
* openssl cms -sign command can generate signed-data content type.
10 Copyright © SUSE 2020
CMS message
LINUX KERNEL
ContentType
SignedData (a.k.a content)
version
digestAlgorithms
EncapsulatedContentInfo
eContentType
eContent
certificates
crls
SignerInfos
SignerInfo
version
signerIdentifier
digestAlgorithm
signedAttrs (a.k.a. authAttrs)
contentType
messageDigest
signatureAlgorithm
signature (a.k.a. encryptedDigest)
unsignedAttrs
CMSmessage(a.k.a.ContentInfo)
SignerInfo
Module Data
struct module_signature
PKCS#7 / CMS
message
MODULE_SIG_STRING
11 Copyright © SUSE 2020
Producing a CMS
message
Copyright © SUSE 202012
scripts/sign-file.c
LINUX KERNEL
* A tool in kernel for signing a module file using the given key. [1]
* It relies on openssl
- Before openssl-1.0.0: old PKCS#7
- openssl-1.0.0 or newer: CMS message
* Signing a module:
scripts/sign-file [-dp] <hash algo> <key> <x509> <module> [<dest>]
* Attaching a raw signature on module:
scripts/sign-file -s <raw sig> <hash algo> <x509> <module> [<dest>]
13 Copyright © SUSE 2020
Example for using sign-file tool
LINUX KERNEL
* Signing a kernel module
- Using the key automatically generated by the kernel:
../scripts/sign-file sha256 ../certs/signing_key.pem ../certs/signing_key.x509 
./acer-wmi.ko ./acer-wmi-signed.ko
* Generating .p7s signature file of a kernel module
- A acer-wmi.ko.p7s file be generated:
../scripts/sign-file -dp sha256 ../certs/signing_key.pem 
../certs/signing_key.x509 ./acer-wmi.ko
- openSSL can dump .p7s signature file:
openssl asn1parse -i -dump -inform der -in acer-wmi.ko.p7s | less
14 Copyright © SUSE 2020
ContentType
SignedData
SignerInfos
version
digestAlgorithms
encapContentInfo:eContentType
SignerInfo:version
1: SignerIdentifier = issuerAndSerialNumber
3: SignerIdentifier = subjectKeyIdentifier
sid:issuer
15 Copyright © SUSE 2020
SignedData
SignerInfos
sid:issuer
sid:serialNumber
SignerInfo:digestAlgorithm
SignerInfo:signatureAlgorithm
SignerInfo:signature
(aka encryptedDigest)
SignerInfo:version
1: SignerIdentifier = issuerAndSerialNumber
3: SignerIdentifier = subjectKeyIdentifier
16 Copyright © SUSE 2020
Generating CMS by openssl command
LINUX KERNEL
* Target: Create a CMS by openssl command that the result is the same with sign-file
tool.
* Looking at the CMS code in sign-file.c
- Looks that those flags are for reducing the size of signature.
* Add corresponding options to openssl command for generating CMS message:
openssl cms -sign -signer ../certs/signing_key.pem -binary -in ./acer-wmi.ko 
-outform DER -out acer-wmi.ko.cms -nocerts -noattr -nosmimecap
17 Copyright © SUSE 2020
Attach raw CMS message by sign-file
LINUX KERNEL
* Use sign-file to attach a raw CMS message on a kernel module:
../scripts/sign-file -s ./acer-wmi.ko.cms sha256  ../certs/signing_key.x509 
acer-wmi.ko acer-wmi-signed.ko
* Loading signed kernel module for testing:
- Kernel should be tainted when verification failed:
[ 57.394922] acer_wmi: module verification failed: signature and/or required
key missing - tainting kernel
- Or enabling lock-down mode for testing:
# echo integrity > /sys/kernel/security/lockdown
# insmod acer-wmi-signed.ko
insmod: ERROR: could not insert module acer-wmi-signed.ko: Operation not
permitted
18 Copyright © SUSE 2020
Producing a
multiple signer
CMS message
Copyright © SUSE 202019
Add multiple signer by openssl
LINUX KERNEL
* Target: Create a multiple signer CMS message by openssl command.
* Add two signer keys in openssl command for generating two signers CMS message:
openssl cms -sign -signer ../certs/signing_key.pem –signer 
../certs/signing_key1.pem -binary -in ./acer-wmi.ko -outform DER -out 
acer-wmi.ko.cms -nocerts -noattr -nosmimecap
* The sign-file tool can still be used to attach the multi-signer CMS message on
kernel module.
* Result: The multi-signed kernel module can pass the verification on both two
kernels. And third kernel (SLE kernel) rejected it.
20 Copyright © SUSE 2020
SignerInfo 2
SignerInfo2:signature
SignerInfo2:serialNumber
21 Copyright © SUSE 2020
SignerInfo 1
SignerInfo2:signature
SignerInfo1:signature
SignerInfo1:serialNumber
22 Copyright © SUSE 2020
Re-signing a CMS
message
Copyright © SUSE 202023
Re-signing a CMS message
LINUX KERNEL
* The openssl cms -sign command can be used to generate a multiple signers CMS
message. But it also means that the signer should hosts multiple private keys.
* Target: Is it possible that we can re-sign a signed CMS message?
Copyright © SUSE 202024
Try openssl cms -resign
LINUX KERNEL
* Using -sign command generates a single signer CMS message:
openssl cms -sign -signer ../certs/signing_key.pem -binary -in ./acer-wmi.ko 
-outform DER -out acer-wmi.ko.cms -nocerts -noattr -nosmimecap
* Then using -resign command re-signs the single signer CMS message:
openssl cms -resign -signer ../certs/signing_key1.pem -inform DER 
-in ./acer- wmi.ko.cms -outform DER -out acer-wmi.ko.cms2 -nocerts -noattr 
-nosmimecap
* Result: The second signature is lost.
25 Copyright © SUSE 2020
SignerInfo 2
SignerInfo 1
SignerInfo1:signature
SignerInfo2:signature is Lost!
26 Copyright © SUSE 2020
LINUX KERNEL
The openssl cms -resign uses signedAttrs
* -resign
- resign a message: take an existing message and one or more new signers.
- The -resign option uses an existing message digest when adding a new signer.
This means that attributes must be present in at least one existing signer using
the same message digest or this operation will fail. [3]
* -noattr
- normally when a message is signed a set of attributes are included which include
the signing time and supported symmetric algorithms. With this option they are
not included. [3]
* The openssl cms -resign command follows signedAttrs approach
The -noattr option can not be used with -resign
27 Copyright © SUSE 2020
LINUX KERNEL
Message Digest Calculation for CMS
* The message digest calculation process computes a message digest on either the
content being signed or the content together with the signed attributes. [2]
* Content together with the signed attributes:
- The complete DER encoding of the SignedAttrs value contained in the signedAttrs
field. it MUST contain:
- content-type
- message-digest
* Content being signed:
- encapContentInfo eContent OCTEST STRING
* External signatures (when no signedAttrs, no eContent):
- SingerInfo:signature SignatureValue
increased size of CMS
28 Copyright © SUSE 2020
Content,
Digest and
Signature
in CMS
LINUX KERNEL
ContentType
SignedData (a.k.a content)
version
digestAlgorithms
EncapsulatedContentInfo
eContentType
eContent
certificates
crls
SignerInfos
SignerInfo
version
signerIdentifier
digestAlgorithm
signedAttrs (a.k.a. authAttrs)
contentType
messageDigest
signatureAlgorithm
signature (a.k.a. encryptedDigest)
unsignedAttrs
CMSmessage(a.k.a.ContentInfo)
SignerInfo
a. RSA encrypted digest of
signedAttrs or eContent
b. External signature when
no signedAttrs, no eContent
OPTIONAL
OPTIONAL
29 Copyright © SUSE 2020
LINUX KERNEL
Removed -noattr when re-signing
* Using -sign command generates a single signer CMS message:
openssl cms -sign -signer ../certs/signing_key.pem -binary -in ./acer-wmi.ko 
-outform DER -out acer-wmi.ko.cms -nocerts -nosmimecap
* Then using -resign command re-signs the single signer CMS message:
openssl cms -resign -signer ../certs/signing_key1.pem -inform DER 
-in ./acer-wmi.ko.cms -outform DER -out acer-wmi.ko.cms2 -nocerts 
-nosmimecap
* Result:
- Kernel raised: [200547.294895] PKCS7: Missing required AuthAttr
- CMS: Adding signers should gen a content type attribute
https://github.com/openssl/openssl/pull/8944
30 Copyright © SUSE 2020
SignerInfo 2
SignerInfo2:contentType is Lost!
patch: openssl#8944
SignerInfo 1
SignerInfo1:contentType
31 Copyright © SUSE 2020
Update openssl
to 1.1.1g
LINUX KERNEL
* The openssl 1.1.1g includes #8944
patches.
- The contentType in second
SignerInfo be generated.
* Kernel raised: [ 249.579675] PKCS7:
Invalid module sig (has authattrs)
* The authattrs can not be used in kernel
module signature.
32 Copyright © SUSE 2020
Conclusion
Copyright © SUSE 202033
Conclusion
LINUX KERNEL
* The kernel module signature verification does support multi-signed modules
, but authAttrs can not be used in CMS message. Kernel can only work with
a multiple external signature CMS message.
* The openssl cms -sign function can be used to generate an available multiple
signerinfo CMS message for kernel module verification. The premise is that the
signer hosts multiple private keys.
* Current openssl cms -resign function can not produce an available multiple
signerinfo CMS message for kernel module verification. Because kernel doesn’t
support authAttrs approach.
Copyright © SUSE 202034
TODO
LINUX KERNEL
* Use Cases?
* Improve sing-file tool to support multiple private keys?
* Find a way to produce multiple external signatures CMS message for re-signing a
CMS message?
- RFC 5652 does not define re-signing process for CMS message.
35 Copyright © SUSE 2020
Q&A
Copyright © SUSE 202036
References
LINUX KERNEL
* [1] Linux Kernel v5.9-rc6
* [2] RFC5652 Cryptographic Message Syntax (CMS), September 2009
* [3] man page of openssl-cms command
Thank you.
© 2020 SUSE LLC. All Rights Reserved. SUSE and the
SUSE logo are registered trademarks of SUSE LLC in the
United States and other countries. All third-party
trademarks are the property of their respective owners.
For more information, contact SUSE at:
+1 800 796 3700 (U.S./Canada)
+49 (0)911-740 53-0 (Worldwide)
SUSE
Maxfeldstrasse 5
90409 Nuremberg
www.suse.com

More Related Content

What's hot

6 stages of linux boot process
6 stages of linux boot process6 stages of linux boot process
6 stages of linux boot process
Hari Shankar
 
Linux Porting to a Custom Board
Linux Porting to a Custom BoardLinux Porting to a Custom Board
Linux Porting to a Custom Board
Patrick Bellasi
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitch
Sim Janghoon
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
Macpaul Lin
 

What's hot (20)

Vmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is bootedVmlinux: anatomy of bzimage and how x86 64 processor is booted
Vmlinux: anatomy of bzimage and how x86 64 processor is booted
 
Intro to Linux Shell Scripting
Intro to Linux Shell ScriptingIntro to Linux Shell Scripting
Intro to Linux Shell Scripting
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introductionLinux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
 
Platform Drivers
Platform DriversPlatform Drivers
Platform Drivers
 
Jagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratchJagan Teki - U-boot from scratch
Jagan Teki - U-boot from scratch
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototyping
 
U-Boot presentation 2013
U-Boot presentation  2013U-Boot presentation  2013
U-Boot presentation 2013
 
6 stages of linux boot process
6 stages of linux boot process6 stages of linux boot process
6 stages of linux boot process
 
Summary of linux kernel security protections
Summary of linux kernel security protectionsSummary of linux kernel security protections
Summary of linux kernel security protections
 
Architecture Of The Linux Kernel
Architecture Of The Linux KernelArchitecture Of The Linux Kernel
Architecture Of The Linux Kernel
 
Spi drivers
Spi driversSpi drivers
Spi drivers
 
Linux Porting to a Custom Board
Linux Porting to a Custom BoardLinux Porting to a Custom Board
Linux Porting to a Custom Board
 
Decompressed vmlinux: linux kernel initialization from page table configurati...
Decompressed vmlinux: linux kernel initialization from page table configurati...Decompressed vmlinux: linux kernel initialization from page table configurati...
Decompressed vmlinux: linux kernel initialization from page table configurati...
 
Virtualized network with openvswitch
Virtualized network with openvswitchVirtualized network with openvswitch
Virtualized network with openvswitch
 
Spectrum Scale Best Practices by Olaf Weiser
Spectrum Scale Best Practices by Olaf WeiserSpectrum Scale Best Practices by Olaf Weiser
Spectrum Scale Best Practices by Olaf Weiser
 
Study on Android Emulator
Study on Android EmulatorStudy on Android Emulator
Study on Android Emulator
 
U boot porting guide for SoC
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
 
Physical Memory Management.pdf
Physical Memory Management.pdfPhysical Memory Management.pdf
Physical Memory Management.pdf
 
Physical Memory Models.pdf
Physical Memory Models.pdfPhysical Memory Models.pdf
Physical Memory Models.pdf
 
The basic concept of Linux FIleSystem
The basic concept of Linux FIleSystemThe basic concept of Linux FIleSystem
The basic concept of Linux FIleSystem
 

Similar to Multi-signed Kernel Module

Cohesive Networks Support Docs: VNS3 Configuration for AWS EC2 Classic
Cohesive Networks Support Docs: VNS3 Configuration for AWS EC2 ClassicCohesive Networks Support Docs: VNS3 Configuration for AWS EC2 Classic
Cohesive Networks Support Docs: VNS3 Configuration for AWS EC2 Classic
Cohesive Networks
 
Module 4 Enumeration
Module 4   EnumerationModule 4   Enumeration
Module 4 Enumeration
leminhvuong
 
Datasheet_Embedded_Security_Shield
Datasheet_Embedded_Security_ShieldDatasheet_Embedded_Security_Shield
Datasheet_Embedded_Security_Shield
David Cozens
 
Dominating Industrie 4.0 with Secure Software Licensing
Dominating Industrie 4.0 with Secure Software LicensingDominating Industrie 4.0 with Secure Software Licensing
Dominating Industrie 4.0 with Secure Software Licensing
team-WIBU
 

Similar to Multi-signed Kernel Module (20)

Code Factory avec GitLab CI et Rancher
Code Factory avec GitLab CI et RancherCode Factory avec GitLab CI et Rancher
Code Factory avec GitLab CI et Rancher
 
Code Factory avec GitLab CI et Rancher
Code Factory avec GitLab CI et RancherCode Factory avec GitLab CI et Rancher
Code Factory avec GitLab CI et Rancher
 
Cohesive Networks Support Docs: VNS3 Configuration Guide
Cohesive Networks Support Docs: VNS3 Configuration Guide Cohesive Networks Support Docs: VNS3 Configuration Guide
Cohesive Networks Support Docs: VNS3 Configuration Guide
 
Cohesive Networks Support Docs: VNS3 Configuration for CenturyLink Cloud
Cohesive Networks Support Docs: VNS3 Configuration for CenturyLink Cloud Cohesive Networks Support Docs: VNS3 Configuration for CenturyLink Cloud
Cohesive Networks Support Docs: VNS3 Configuration for CenturyLink Cloud
 
MuleSoft Meetup Roma - Runtime Fabric Series (From Zero to Hero) - Sessione 2
MuleSoft Meetup Roma - Runtime Fabric Series (From Zero to Hero) - Sessione 2MuleSoft Meetup Roma - Runtime Fabric Series (From Zero to Hero) - Sessione 2
MuleSoft Meetup Roma - Runtime Fabric Series (From Zero to Hero) - Sessione 2
 
Cohesive Networks Support Docs: VNS3 Configuration for GCE
Cohesive Networks Support Docs: VNS3 Configuration for GCE Cohesive Networks Support Docs: VNS3 Configuration for GCE
Cohesive Networks Support Docs: VNS3 Configuration for GCE
 
IBM MQ in containers MQTC 2017
IBM MQ in containers MQTC 2017IBM MQ in containers MQTC 2017
IBM MQ in containers MQTC 2017
 
Cohesive Networks Support Docs: VNS3 Configuration for AWS EC2 Classic
Cohesive Networks Support Docs: VNS3 Configuration for AWS EC2 ClassicCohesive Networks Support Docs: VNS3 Configuration for AWS EC2 Classic
Cohesive Networks Support Docs: VNS3 Configuration for AWS EC2 Classic
 
Module 4 Enumeration
Module 4   EnumerationModule 4   Enumeration
Module 4 Enumeration
 
LCJ2010-KaiGai-Memcached
LCJ2010-KaiGai-MemcachedLCJ2010-KaiGai-Memcached
LCJ2010-KaiGai-Memcached
 
Cohesive Networks Support Docs: VNS3:turret NIDS Guide
Cohesive Networks Support Docs: VNS3:turret NIDS GuideCohesive Networks Support Docs: VNS3:turret NIDS Guide
Cohesive Networks Support Docs: VNS3:turret NIDS Guide
 
Install websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bitsInstall websphere message broker 8 RHEL 6 64 bits
Install websphere message broker 8 RHEL 6 64 bits
 
Datasheet_Embedded_Security_Shield
Datasheet_Embedded_Security_ShieldDatasheet_Embedded_Security_Shield
Datasheet_Embedded_Security_Shield
 
Security @ Windows 10 Partner Technical Bootcamp Microsoft Norway October 2015
Security @ Windows 10 Partner Technical Bootcamp Microsoft Norway October 2015Security @ Windows 10 Partner Technical Bootcamp Microsoft Norway October 2015
Security @ Windows 10 Partner Technical Bootcamp Microsoft Norway October 2015
 
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
Ivan Zhuravel and Ihor Khlaponin "DC/OS vs Kubernetes. Let the Fight Begin!"
 
Dominating Industrie 4.0 with Secure Software Licensing
Dominating Industrie 4.0 with Secure Software LicensingDominating Industrie 4.0 with Secure Software Licensing
Dominating Industrie 4.0 with Secure Software Licensing
 
Confidential compute with hyperledger fabric .v17
Confidential compute with hyperledger fabric .v17Confidential compute with hyperledger fabric .v17
Confidential compute with hyperledger fabric .v17
 
Rancher Rodéo France
Rancher Rodéo FranceRancher Rodéo France
Rancher Rodéo France
 
Ibm mq with c# sending and receiving messages
Ibm mq with c# sending and receiving messagesIbm mq with c# sending and receiving messages
Ibm mq with c# sending and receiving messages
 
Cohesive Networks Support Docs: Welcome to VNS3 3.5
Cohesive Networks Support Docs: Welcome to VNS3 3.5 Cohesive Networks Support Docs: Welcome to VNS3 3.5
Cohesive Networks Support Docs: Welcome to VNS3 3.5
 

More from SUSE Labs Taipei

Develop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build ServiceDevelop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build Service
SUSE Labs Taipei
 

More from SUSE Labs Taipei (19)

Locked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernelLocked down openSUSE Tumbleweed kernel
Locked down openSUSE Tumbleweed kernel
 
ACPI Debugging from Linux Kernel
ACPI Debugging from Linux KernelACPI Debugging from Linux Kernel
ACPI Debugging from Linux Kernel
 
Profiling the ACPICA Namespace and Event Handing
Profiling the ACPICA Namespace and Event HandingProfiling the ACPICA Namespace and Event Handing
Profiling the ACPICA Namespace and Event Handing
 
The bright future of SUSE and openSUSE
The bright future of SUSE and openSUSEThe bright future of SUSE and openSUSE
The bright future of SUSE and openSUSE
 
EFI Secure Key
EFI Secure KeyEFI Secure Key
EFI Secure Key
 
eBPF maps 101
eBPF maps 101eBPF maps 101
eBPF maps 101
 
Convert your package to multibuild on Open Build Service
Convert your package to multibuild on Open Build ServiceConvert your package to multibuild on Open Build Service
Convert your package to multibuild on Open Build Service
 
Ixgbe internals
Ixgbe internalsIxgbe internals
Ixgbe internals
 
Linux Linux Traffic Control
Linux Linux Traffic ControlLinux Linux Traffic Control
Linux Linux Traffic Control
 
Looking into trusted and encrypted keys
Looking into trusted and encrypted keysLooking into trusted and encrypted keys
Looking into trusted and encrypted keys
 
Use bonding driver with ethernet
Use bonding driver with ethernetUse bonding driver with ethernet
Use bonding driver with ethernet
 
Use build service API in your program
Use build service API in your programUse build service API in your program
Use build service API in your program
 
Hands-on ethernet driver
Hands-on ethernet driverHands-on ethernet driver
Hands-on ethernet driver
 
eBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to UserspaceeBPF Trace from Kernel to Userspace
eBPF Trace from Kernel to Userspace
 
S4 sig-check-lpc-20130918
S4 sig-check-lpc-20130918S4 sig-check-lpc-20130918
S4 sig-check-lpc-20130918
 
openSUSE12.2 Review
openSUSE12.2 ReviewopenSUSE12.2 Review
openSUSE12.2 Review
 
oS KDE Repos & MM
oS KDE Repos & MMoS KDE Repos & MM
oS KDE Repos & MM
 
Develop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build ServiceDevelop and Maintain a Distro with Open Build Service
Develop and Maintain a Distro with Open Build Service
 
Coscup 2012-urfkill
Coscup 2012-urfkillCoscup 2012-urfkill
Coscup 2012-urfkill
 

Recently uploaded

CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Recently uploaded (20)

Unlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language ModelsUnlocking the Future of AI Agents with Large Language Models
Unlocking the Future of AI Agents with Large Language Models
 
VTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learnVTU technical seminar 8Th Sem on Scikit-learn
VTU technical seminar 8Th Sem on Scikit-learn
 
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
Shapes for Sharing between Graph Data Spaces - and Epistemic Querying of RDF-...
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 
AI & Machine Learning Presentation Template
AI & Machine Learning Presentation TemplateAI & Machine Learning Presentation Template
AI & Machine Learning Presentation Template
 
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
Direct Style Effect Systems -The Print[A] Example- A Comprehension AidDirect Style Effect Systems -The Print[A] Example- A Comprehension Aid
Direct Style Effect Systems - The Print[A] Example - A Comprehension Aid
 
Right Money Management App For Your Financial Goals
Right Money Management App For Your Financial GoalsRight Money Management App For Your Financial Goals
Right Money Management App For Your Financial Goals
 
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
The Real-World Challenges of Medical Device Cybersecurity- Mitigating Vulnera...
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdfAzure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
Azure_Native_Qumulo_High_Performance_Compute_Benchmarks.pdf
 
Optimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTVOptimizing AI for immediate response in Smart CCTV
Optimizing AI for immediate response in Smart CCTV
 
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected WorkerHow To Troubleshoot Collaboration Apps for the Modern Connected Worker
How To Troubleshoot Collaboration Apps for the Modern Connected Worker
 
Exploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdfExploring the Best Video Editing App.pdf
Exploring the Best Video Editing App.pdf
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICECHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
CHEAP Call Girls in Pushp Vihar (-DELHI )🔝 9953056974🔝(=)/CALL GIRLS SERVICE
 
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdfThe Ultimate Test Automation Guide_ Best Practices and Tips.pdf
The Ultimate Test Automation Guide_ Best Practices and Tips.pdf
 
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
call girls in Vaishali (Ghaziabad) 🔝 >༒8448380779 🔝 genuine Escort Service 🔝✔️✔️
 
10 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 202410 Trends Likely to Shape Enterprise Technology in 2024
10 Trends Likely to Shape Enterprise Technology in 2024
 
Software Quality Assurance Interview Questions
Software Quality Assurance Interview QuestionsSoftware Quality Assurance Interview Questions
Software Quality Assurance Interview Questions
 
Diamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with PrecisionDiamond Application Development Crafting Solutions with Precision
Diamond Application Development Crafting Solutions with Precision
 

Multi-signed Kernel Module

  • 1. Multi-signed Kernel Module SUSE Labs Conference 2020, Virtual edition October 8, 2020
  • 2. 2 Copyright © SUSE 2020 Agenda 01 Structure of kernel module signature 02 Producing a CMS message 03 Producing a multiple signer CMS message 04 Re-signing a CMS 05 Conclusion 06 Q&A LINUX KERNEL
  • 3. 3 Copyright © SUSE 2020 Structure of kernel module signature
  • 4. Copyright © SUSE 20204 Kernel module signature verification LINUX KERNEL * The kernel module signing facility cryptographically signs modules during installation and then checks the signature upon loading the module. [1] CONFIG_MODULE_SIG * History in Kernel - v3.7: Kernel module signature verification be introduced - Using a specific structure for module signature - v3.17: PKCS#7 parser be introduced CONFIG_PKCS7_MESSAGE_PARSER - v4.3: The format of module signature be switched to PKCS#7/CMS message
  • 5. 5 Copyright © SUSE 2020 Signature of Kernel Module LINUX KERNEL Module Data ms->sig_len struct module_signature u8 id_type; __be32 sig_len; PKCS#7 / CMS message MODULE_SIG_STRING 12 bytes markerlen ModuleSignature
  • 6. 6 Copyright © SUSE 2020 Structure of module signature LINUX KERNEL
  • 7. 7 Copyright © SUSE 2020 Example of module signature LINUX KERNEL PKCS#7 type sig_len = 0x1ea = 0x1e6 + 4 0x10b31 – 0x1ea + 1 = 0x10948 CMS message ASN.1 tag: Type: 30 = _tag(UNIV, CONS, SEQ) 0x82 = 10000002 = 2 subsequent octet Length = 0x1e6
  • 8. Copyright © SUSE 20208 Cryptographic Message Syntax (CMS) LINUX KERNEL * ietf.org RFC 5652 * The CMS is derived from PKCS #7 version 1.5, which is documented in RFC 2315 [PKCS#7]. * The CMS describes an encapsulation syntax for data protection. It supports digital signatures and encryption. [2] * The CMS values are generated using ASN.1 [X.208-88], using BER-encoding (Basic Encoding Rules) [X.209-88]. Values are typically represented as octet strings. [2] * CMS be supported by openssl-1.0.0 or newer. [1]
  • 9. Copyright © SUSE 20209 Signed-data Content Type LINUX KERNEL * The CMS is general enough to support many different content types. [2] * An implementation that conforms to this specification MUST implement the protection content, ContentInfo, and MUST implement the data, signed-data, and enveloped-data content types. [2] * Kernel module signature uses signed-data conent type. * openssl cms -sign command can generate signed-data content type.
  • 10. 10 Copyright © SUSE 2020 CMS message LINUX KERNEL ContentType SignedData (a.k.a content) version digestAlgorithms EncapsulatedContentInfo eContentType eContent certificates crls SignerInfos SignerInfo version signerIdentifier digestAlgorithm signedAttrs (a.k.a. authAttrs) contentType messageDigest signatureAlgorithm signature (a.k.a. encryptedDigest) unsignedAttrs CMSmessage(a.k.a.ContentInfo) SignerInfo Module Data struct module_signature PKCS#7 / CMS message MODULE_SIG_STRING
  • 11. 11 Copyright © SUSE 2020 Producing a CMS message
  • 12. Copyright © SUSE 202012 scripts/sign-file.c LINUX KERNEL * A tool in kernel for signing a module file using the given key. [1] * It relies on openssl - Before openssl-1.0.0: old PKCS#7 - openssl-1.0.0 or newer: CMS message * Signing a module: scripts/sign-file [-dp] <hash algo> <key> <x509> <module> [<dest>] * Attaching a raw signature on module: scripts/sign-file -s <raw sig> <hash algo> <x509> <module> [<dest>]
  • 13. 13 Copyright © SUSE 2020 Example for using sign-file tool LINUX KERNEL * Signing a kernel module - Using the key automatically generated by the kernel: ../scripts/sign-file sha256 ../certs/signing_key.pem ../certs/signing_key.x509 ./acer-wmi.ko ./acer-wmi-signed.ko * Generating .p7s signature file of a kernel module - A acer-wmi.ko.p7s file be generated: ../scripts/sign-file -dp sha256 ../certs/signing_key.pem ../certs/signing_key.x509 ./acer-wmi.ko - openSSL can dump .p7s signature file: openssl asn1parse -i -dump -inform der -in acer-wmi.ko.p7s | less
  • 14. 14 Copyright © SUSE 2020 ContentType SignedData SignerInfos version digestAlgorithms encapContentInfo:eContentType SignerInfo:version 1: SignerIdentifier = issuerAndSerialNumber 3: SignerIdentifier = subjectKeyIdentifier sid:issuer
  • 15. 15 Copyright © SUSE 2020 SignedData SignerInfos sid:issuer sid:serialNumber SignerInfo:digestAlgorithm SignerInfo:signatureAlgorithm SignerInfo:signature (aka encryptedDigest) SignerInfo:version 1: SignerIdentifier = issuerAndSerialNumber 3: SignerIdentifier = subjectKeyIdentifier
  • 16. 16 Copyright © SUSE 2020 Generating CMS by openssl command LINUX KERNEL * Target: Create a CMS by openssl command that the result is the same with sign-file tool. * Looking at the CMS code in sign-file.c - Looks that those flags are for reducing the size of signature. * Add corresponding options to openssl command for generating CMS message: openssl cms -sign -signer ../certs/signing_key.pem -binary -in ./acer-wmi.ko -outform DER -out acer-wmi.ko.cms -nocerts -noattr -nosmimecap
  • 17. 17 Copyright © SUSE 2020 Attach raw CMS message by sign-file LINUX KERNEL * Use sign-file to attach a raw CMS message on a kernel module: ../scripts/sign-file -s ./acer-wmi.ko.cms sha256 ../certs/signing_key.x509 acer-wmi.ko acer-wmi-signed.ko * Loading signed kernel module for testing: - Kernel should be tainted when verification failed: [ 57.394922] acer_wmi: module verification failed: signature and/or required key missing - tainting kernel - Or enabling lock-down mode for testing: # echo integrity > /sys/kernel/security/lockdown # insmod acer-wmi-signed.ko insmod: ERROR: could not insert module acer-wmi-signed.ko: Operation not permitted
  • 18. 18 Copyright © SUSE 2020 Producing a multiple signer CMS message
  • 19. Copyright © SUSE 202019 Add multiple signer by openssl LINUX KERNEL * Target: Create a multiple signer CMS message by openssl command. * Add two signer keys in openssl command for generating two signers CMS message: openssl cms -sign -signer ../certs/signing_key.pem –signer ../certs/signing_key1.pem -binary -in ./acer-wmi.ko -outform DER -out acer-wmi.ko.cms -nocerts -noattr -nosmimecap * The sign-file tool can still be used to attach the multi-signer CMS message on kernel module. * Result: The multi-signed kernel module can pass the verification on both two kernels. And third kernel (SLE kernel) rejected it.
  • 20. 20 Copyright © SUSE 2020 SignerInfo 2 SignerInfo2:signature SignerInfo2:serialNumber
  • 21. 21 Copyright © SUSE 2020 SignerInfo 1 SignerInfo2:signature SignerInfo1:signature SignerInfo1:serialNumber
  • 22. 22 Copyright © SUSE 2020 Re-signing a CMS message
  • 23. Copyright © SUSE 202023 Re-signing a CMS message LINUX KERNEL * The openssl cms -sign command can be used to generate a multiple signers CMS message. But it also means that the signer should hosts multiple private keys. * Target: Is it possible that we can re-sign a signed CMS message?
  • 24. Copyright © SUSE 202024 Try openssl cms -resign LINUX KERNEL * Using -sign command generates a single signer CMS message: openssl cms -sign -signer ../certs/signing_key.pem -binary -in ./acer-wmi.ko -outform DER -out acer-wmi.ko.cms -nocerts -noattr -nosmimecap * Then using -resign command re-signs the single signer CMS message: openssl cms -resign -signer ../certs/signing_key1.pem -inform DER -in ./acer- wmi.ko.cms -outform DER -out acer-wmi.ko.cms2 -nocerts -noattr -nosmimecap * Result: The second signature is lost.
  • 25. 25 Copyright © SUSE 2020 SignerInfo 2 SignerInfo 1 SignerInfo1:signature SignerInfo2:signature is Lost!
  • 26. 26 Copyright © SUSE 2020 LINUX KERNEL The openssl cms -resign uses signedAttrs * -resign - resign a message: take an existing message and one or more new signers. - The -resign option uses an existing message digest when adding a new signer. This means that attributes must be present in at least one existing signer using the same message digest or this operation will fail. [3] * -noattr - normally when a message is signed a set of attributes are included which include the signing time and supported symmetric algorithms. With this option they are not included. [3] * The openssl cms -resign command follows signedAttrs approach The -noattr option can not be used with -resign
  • 27. 27 Copyright © SUSE 2020 LINUX KERNEL Message Digest Calculation for CMS * The message digest calculation process computes a message digest on either the content being signed or the content together with the signed attributes. [2] * Content together with the signed attributes: - The complete DER encoding of the SignedAttrs value contained in the signedAttrs field. it MUST contain: - content-type - message-digest * Content being signed: - encapContentInfo eContent OCTEST STRING * External signatures (when no signedAttrs, no eContent): - SingerInfo:signature SignatureValue increased size of CMS
  • 28. 28 Copyright © SUSE 2020 Content, Digest and Signature in CMS LINUX KERNEL ContentType SignedData (a.k.a content) version digestAlgorithms EncapsulatedContentInfo eContentType eContent certificates crls SignerInfos SignerInfo version signerIdentifier digestAlgorithm signedAttrs (a.k.a. authAttrs) contentType messageDigest signatureAlgorithm signature (a.k.a. encryptedDigest) unsignedAttrs CMSmessage(a.k.a.ContentInfo) SignerInfo a. RSA encrypted digest of signedAttrs or eContent b. External signature when no signedAttrs, no eContent OPTIONAL OPTIONAL
  • 29. 29 Copyright © SUSE 2020 LINUX KERNEL Removed -noattr when re-signing * Using -sign command generates a single signer CMS message: openssl cms -sign -signer ../certs/signing_key.pem -binary -in ./acer-wmi.ko -outform DER -out acer-wmi.ko.cms -nocerts -nosmimecap * Then using -resign command re-signs the single signer CMS message: openssl cms -resign -signer ../certs/signing_key1.pem -inform DER -in ./acer-wmi.ko.cms -outform DER -out acer-wmi.ko.cms2 -nocerts -nosmimecap * Result: - Kernel raised: [200547.294895] PKCS7: Missing required AuthAttr - CMS: Adding signers should gen a content type attribute https://github.com/openssl/openssl/pull/8944
  • 30. 30 Copyright © SUSE 2020 SignerInfo 2 SignerInfo2:contentType is Lost! patch: openssl#8944 SignerInfo 1 SignerInfo1:contentType
  • 31. 31 Copyright © SUSE 2020 Update openssl to 1.1.1g LINUX KERNEL * The openssl 1.1.1g includes #8944 patches. - The contentType in second SignerInfo be generated. * Kernel raised: [ 249.579675] PKCS7: Invalid module sig (has authattrs) * The authattrs can not be used in kernel module signature.
  • 32. 32 Copyright © SUSE 2020 Conclusion
  • 33. Copyright © SUSE 202033 Conclusion LINUX KERNEL * The kernel module signature verification does support multi-signed modules , but authAttrs can not be used in CMS message. Kernel can only work with a multiple external signature CMS message. * The openssl cms -sign function can be used to generate an available multiple signerinfo CMS message for kernel module verification. The premise is that the signer hosts multiple private keys. * Current openssl cms -resign function can not produce an available multiple signerinfo CMS message for kernel module verification. Because kernel doesn’t support authAttrs approach.
  • 34. Copyright © SUSE 202034 TODO LINUX KERNEL * Use Cases? * Improve sing-file tool to support multiple private keys? * Find a way to produce multiple external signatures CMS message for re-signing a CMS message? - RFC 5652 does not define re-signing process for CMS message.
  • 35. 35 Copyright © SUSE 2020 Q&A
  • 36. Copyright © SUSE 202036 References LINUX KERNEL * [1] Linux Kernel v5.9-rc6 * [2] RFC5652 Cryptographic Message Syntax (CMS), September 2009 * [3] man page of openssl-cms command
  • 37. Thank you. © 2020 SUSE LLC. All Rights Reserved. SUSE and the SUSE logo are registered trademarks of SUSE LLC in the United States and other countries. All third-party trademarks are the property of their respective owners. For more information, contact SUSE at: +1 800 796 3700 (U.S./Canada) +49 (0)911-740 53-0 (Worldwide) SUSE Maxfeldstrasse 5 90409 Nuremberg www.suse.com