SlideShare a Scribd company logo
1 of 41
Signature verification ofSignature verification of
kernel module and kexeckernel module and kexec
October, 2016, openSUSE.Asia 2016, YogyakartaOctober, 2016, openSUSE.Asia 2016, Yogyakarta
Joey Lee, SUSE Labs Taipei
2
Agenda
• Kernel module signing
– How to enable it
– Sign kernel module
– The mechanism of verification
• kexec: Verify signature of PE signed bzImage
– How to enable it
– Sign kernel PE binary for loading with kexec-file
– The mechanism of kexec-file syscall
• Q&A
Kernel module signingKernel module signing
4
Kernel Module Signing Facility
• Introduced since v3.7-rc1 kernel
• Author: David Howells
– https://lkml.org/lkml/2012/9/24/631
– crypto algorithm: RSA
– Key identifier type: X.509
• The kernel module signing facility cryptographically signs
modules during installation and then checks the signature
upon loading the module.
• This allows increased kernel security by disallowing the
loading of unsigned modules or modules signed with an
invalid key. [1]
5
How to enable modsign
• CONFIG_MODULE_SIG=y
– Module signature verification
• CONFIG_MODULE_SIG_FORCE
– Require modules to be validly signed
• CONFIG_MODULE_SIG_ALL
– Automatically sign all modules
• CONFIG_MODULE_SIG_SHA*
– which hash algorithm the installation phase will sign the
modules with
– e.g. CONFIG_MODULE_SIG_SHA512
6
How to enable modsign (cont.)
• CONFIG_MODULE_SIG_KEY
– File name or PKCS#11 URI of module signing key
– Default: certs/signing_key.pem
• CONFIG_SYSTEM_TRUSTED_KEYS
– Additional X.509 keys for default system keyring
• CONFIG_MODULE_SIG_UEFI=y (SUSE)
– Load certificate from db, dbx, mok and mokx
7
module signing key
• CONFIG_MODULE_SIG_KEY
– File name or PKCS#11 URI of module signing key
– Default:
● CONFIG_MODULE_SIG_KEY="certs/signing_key.p
em"
● certs/signing_key.pem (private key + public key)
● certs/signing_key.x509 (only public key)
8
module signing key (cont.)
9
module signing key (cont.)
• Show private key
– openssl rsa -in certs/signing_key.pem -noout -text | less
10
module signing key (cont.)
• Show certificate (includes public key)
– openssl x509 -in certs/signing_key.pem -inform PEM -noout -text | less
– openssl x509 -in certs/signing_key.x509 -inform DER -noout -text | less
11
x509.genkey
• During the building of vmlinux (the public part of the key needs to be built into
vmlinux) using parameters in the:
certs/x509.genkey
• This file is also generated if it does not already exist [1]
• Most notably, in the x509.genkey file, the req_distinguished_name section
• should be altered from the default:
– [ req_distinguished_name ]
#O = Unspecified company
CN = Build time autogenerated kernel key
#emailAddress = unspecified.user@unspecified.company
• The generated RSA key size can also be set with:
[ req ]
default_bits = 4096
12
x509.genkey (cont.)
13
sign module
• scripts/sign-file
– ./scripts/sign-file sha1 certs/signing_key.pem certs/signing_key.x509
drivers/platform/x86/acer-wmi.ko ~/acer-wmi-signed.ko
• CONFIG_MODULE_SIG_ALL=y
– Automatically sign all modules when “make
modules_install”
14
Require modules to be validly signed
• CONFIG_MODULE_SIG_FORCE=y
– insmod: ERROR: could not insert module acer-wmi-unsign.ko: Required
key not available
•
• CONFIG_MODULE_SIG_FORCE not set
– module verification failed: signature and/or required key missing -
tainting kernel
– Taint kernel by 'E' flag
15
Signature of module
16
marker string
17
module_signature
18
PKEY_ID_X509 type (before v3.18)
19
PKEY_ID_PKCS7 type (after v3.18)
20
21
MOKutil
• Import your certificate to machine owner key(MOK) variable.
• Linux kernel loads certificate from MOK to verify kernel module.
• # mokutil --root-pw --import certs/signing_key.x509
22
MOKutil (cont.)
kexec: verify signaturekexec: verify signature
24
kexec: Verify signature of PE signed bzImage
• Introduced since v3.7-rc1 kernel
• Author: Vivek Goyal
– https://lkml.org/lkml/2014/7/3/749
– x86_64 only
– Base on:
● kexec: A new system call to allow in kernel loading
● PKCS7 signature support
• Now kexec bzImage loader calls into pefile parser and
passes the PE signed bzImage for signature verification.
25
How to enable kexec verify
• CONFIG_KEXEC_FILE=y
– kexec file based system call
• CONFIG_KEXEC_VERIFY_SIG=y
– Verify kernel signature during kexec_file_load() syscall
• CONFIG_KEXEC_BZIMAGE_VERIFY_SIG=y
– Enable bzImage signature verification support
26
The EFI Boot Stub
• On the x86 and ARM platforms, a kernel zImage/bzImage can
masquerade as a PE/COFF image, thereby convincing EFI
firmware loaders to load it as an EFI executable. [2]
• CONFIG_EFI_STUB=y
• The bzImage located in arch/x86/boot/bzImage must be copied
to the EFI System Partition (ESP) and renamed with the
extension ".efi".
• Using EFI shell to execute EFI stub kernel
• Grub2 supports kernel x86 boot protocol 2.11 (since v3.6)
– Protocol 2.11: (Kernel 3.6) Added a field for offset of EFI handover
protocol entry point. [5]
– With linuxefi/initrdefi grub2 module
27
Key was rejected by service
28
sign your bzImage
• set CONFIG_MODULE_SIG=y to generate signing_key.*
– Or using your own key-pair
• Enroll certificate to MOK to shim for kernel verification
– mokutil --root-pw --import certs/signing_key.x509
• Install mozilla-nss-tools, openssl and pesign
– zypper in mozilla-nss-tools openssl pesign
29
sign your bzImage (cont.)
• Create certificate database for signing (certdb)
– mkdir $WORKSPACE
– cp $KERNEL_SOURCE/certs/signing_key.* ./
– mkdir certdb
– certutil -d certdb/ -A -i signing_key.x509 -n cert -t CT,CT,CT
• Hierarchy
/root/kexec-sign/:
certdb signing_key.pem signing_key.x509
/root/kexec-sign/certdb:
cert8.db key3.db secmod.db
30
sign your bzImage (cont.)
• Using pesign to sign kernel
– pesign -n certdb/ -i /boot/"$TARGET_KERNEL"
-E ./"$TARGET_KERNEL".sattrs
– openssl dgst -sha256 -sign signing_key.pem ./"$TARGET_KERNEL".sattrs
> ./"$TARGET_KERNEL".sattrs.sig
– pesign -n certdb/ -c cert -i /boot/"$TARGET_KERNEL"
-R ./"$TARGET_KERNEL".sattrs.sig -I ./"$TARGET_KERNEL".sattrs
-o ./"$TARGET_KERNEL".signed
– pesign -S -i ./"$TARGET_KERNEL".signed
• Help script: kexec-sign-test.sh
– https://github.com/joeyli/hackweek/blob/master/kexec-sign-test/kexec-sign-test.sh
– kexec-sign-test.sh init ~/kernel-source.nfs
– kexec-sign-test.sh sign vmlinuz-4.4.21-default+
31
Load signed kernel
• Load signed kernel with kexec-file system call for testing
– /sbin/kexec -s -p ./$SIGNED_KERNEL --append="ro quiet
elevator=deadline sysrq=yes reset_devices acpi_no_memhotplug
cgroup_disable=memory irqpoll nr_cpus=1 disable_cpu_apicid=0 noefi
acpi_rsdp=0xdfbfe014 panic=1"
• Copy signed kernel to /boot folder to replace the unsigned
kernel:
– # cp /root/kexec-sign/vmlinuz-4.4.21-default+.signed /boot/vmlinuz-
4.4.21-default+
• Reboot and check the kdump status:
– # systemctl status kdump -l
32
Load crash kernel success
33
Kernel signature hexdump
34
Embedded signatures of PE/COFF
• CONFIG_EFI_STUB=y
– On the x86 and ARM platforms, a kernel zImage/bzImage can
masquerade as a PE/COFF image, thereby convincing EFI firmware
loaders to load it as an EFI executable.
• Authenticode signature format [4]
– Authenticode® is a digital signature format that is used to determine the
origin and integrity of software binaries.
– Authenticode is based on Public-Key Cryptography Standards
(PKCS) #7 signed data and X.509 certificates to bind an Authenticode-
signed binary to the identity of a software publisher.
35
Embedded signatures of PE/COFF (cont.)
36
Q&AQ&A
Terima Kasih!Terima Kasih!
謝謝謝謝 !!
Thank you!Thank you!
39
References
• [1] Documentation/module-signing.txt
– https://www.kernel.org/doc/Documentation/module-signing.tx
• [2] Documentation/efi-stub.txt
– https://www.kernel.org/doc/Documentation/efi-stub.txt
• [3] Unified Extensible Firmware Interface Specification,
Version 2.6, January 2016
• [4] Windows Authenticode Portable Executable Signature
Format
• [5] Documentation/x86/boot.txt
40
Join us on:
www.opensuse.org
41

More Related Content

What's hot

from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu WorksZhen Wei
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation Jiann-Fuh Liaw
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)shimosawa
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototypingYan Vugenfirer
 
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 HandingSUSE Labs Taipei
 
Multi-signed Kernel Module
Multi-signed Kernel ModuleMulti-signed Kernel Module
Multi-signed Kernel ModuleSUSE Labs Taipei
 
Linux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisPaul V. Novarese
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...Adrian Huang
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelAdrian Huang
 
Physical Memory Management.pdf
Physical Memory Management.pdfPhysical Memory Management.pdf
Physical Memory Management.pdfAdrian Huang
 
Virtualization Support in ARMv8+
Virtualization Support in ARMv8+Virtualization Support in ARMv8+
Virtualization Support in ARMv8+Aananth C N
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Adrian Huang
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelAdrian Huang
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux KernelAdrian Huang
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectYen-Chin Lee
 

What's hot (20)

from Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Worksfrom Binary to Binary: How Qemu Works
from Binary to Binary: How Qemu Works
 
QEMU - Binary Translation
QEMU - Binary Translation QEMU - Binary Translation
QEMU - Binary Translation
 
Linux Initialization Process (2)
Linux Initialization Process (2)Linux Initialization Process (2)
Linux Initialization Process (2)
 
Qemu device prototyping
Qemu device prototypingQemu device prototyping
Qemu device prototyping
 
Introduction to Perf
Introduction to PerfIntroduction to Perf
Introduction to Perf
 
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
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
Multi-signed Kernel Module
Multi-signed Kernel ModuleMulti-signed Kernel Module
Multi-signed Kernel Module
 
Linux Crash Dump Capture and Analysis
Linux Crash Dump Capture and AnalysisLinux Crash Dump Capture and Analysis
Linux Crash Dump Capture and Analysis
 
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
qemu + gdb: The efficient way to understand/debug Linux kernel code/data stru...
 
Userspace networking
Userspace networkingUserspace networking
Userspace networking
 
Reverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux KernelReverse Mapping (rmap) in Linux Kernel
Reverse Mapping (rmap) in Linux Kernel
 
Physical Memory Management.pdf
Physical Memory Management.pdfPhysical Memory Management.pdf
Physical Memory Management.pdf
 
Virtualization Support in ARMv8+
Virtualization Support in ARMv8+Virtualization Support in ARMv8+
Virtualization Support in ARMv8+
 
Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...Process Address Space: The way to create virtual address (page table) of user...
Process Address Space: The way to create virtual address (page table) of user...
 
Memory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux KernelMemory Mapping Implementation (mmap) in Linux Kernel
Memory Mapping Implementation (mmap) in Linux Kernel
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Qemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System EmulationQemu JIT Code Generator and System Emulation
Qemu JIT Code Generator and System Emulation
 
Linux-Internals-and-Networking
Linux-Internals-and-NetworkingLinux-Internals-and-Networking
Linux-Internals-and-Networking
 
Build your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto projectBuild your own embedded linux distributions by yocto project
Build your own embedded linux distributions by yocto project
 

Similar to Signature verification of kernel module and kexec

Introduction to InSpec and 1.0 release update
Introduction to InSpec and 1.0 release updateIntroduction to InSpec and 1.0 release update
Introduction to InSpec and 1.0 release updateAlex Pop
 
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLESQuick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLESJan Kalcic
 
Upgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with SecurebootUpgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with SecurebootJonathan MICHEL-VILLAZ
 
Continuous Security
Continuous SecurityContinuous Security
Continuous SecuritySysdig
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldDevOps.com
 
Open SSL and MS Crypto API EKON21
Open SSL and MS Crypto API EKON21Open SSL and MS Crypto API EKON21
Open SSL and MS Crypto API EKON21Max Kleiner
 
DevOpsDays InSpec Workshop
DevOpsDays InSpec WorkshopDevOpsDays InSpec Workshop
DevOpsDays InSpec WorkshopMandi Walls
 
CI / CD / CS - Continuous Security in Kubernetes
CI / CD / CS - Continuous Security in KubernetesCI / CD / CS - Continuous Security in Kubernetes
CI / CD / CS - Continuous Security in KubernetesSysdig
 
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)Codemotion
 
Road to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoopsRoad to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoopsGianluca Varisco
 
K2000 Scripted Installations
K2000 Scripted InstallationsK2000 Scripted Installations
K2000 Scripted InstallationsDell World
 
InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017Mandi Walls
 
InSpec Workshop at Velocity London 2018
InSpec Workshop at Velocity London 2018InSpec Workshop at Velocity London 2018
InSpec Workshop at Velocity London 2018Mandi Walls
 
kubernetes - minikube - getting started
kubernetes - minikube - getting startedkubernetes - minikube - getting started
kubernetes - minikube - getting startedMunish Mehta
 
CERN OpenStack Cloud Control Plane - From VMs to K8s
CERN OpenStack Cloud Control Plane - From VMs to K8sCERN OpenStack Cloud Control Plane - From VMs to K8s
CERN OpenStack Cloud Control Plane - From VMs to K8sBelmiro Moreira
 
Docker Runtime Security
Docker Runtime SecurityDocker Runtime Security
Docker Runtime SecuritySysdig
 
DockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with DockerDockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with DockerDocker, Inc.
 
Pro2516 10 things about oracle and k8s.pptx-final
Pro2516   10 things about oracle and k8s.pptx-finalPro2516   10 things about oracle and k8s.pptx-final
Pro2516 10 things about oracle and k8s.pptx-finalMichel Schildmeijer
 
XPDDS17: EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...
XPDDS17:  EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...XPDDS17:  EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...
XPDDS17: EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...The Linux Foundation
 

Similar to Signature verification of kernel module and kexec (20)

Introduction to InSpec and 1.0 release update
Introduction to InSpec and 1.0 release updateIntroduction to InSpec and 1.0 release update
Introduction to InSpec and 1.0 release update
 
EFI Secure Key
EFI Secure KeyEFI Secure Key
EFI Secure Key
 
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLESQuick-and-Easy Deployment of a Ceph Storage Cluster with SLES
Quick-and-Easy Deployment of a Ceph Storage Cluster with SLES
 
Upgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with SecurebootUpgrade Ubuntu 18.04 Security with Secureboot
Upgrade Ubuntu 18.04 Security with Secureboot
 
Continuous Security
Continuous SecurityContinuous Security
Continuous Security
 
The Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote WorldThe Future of Security and Productivity in Our Newly Remote World
The Future of Security and Productivity in Our Newly Remote World
 
Open SSL and MS Crypto API EKON21
Open SSL and MS Crypto API EKON21Open SSL and MS Crypto API EKON21
Open SSL and MS Crypto API EKON21
 
DevOpsDays InSpec Workshop
DevOpsDays InSpec WorkshopDevOpsDays InSpec Workshop
DevOpsDays InSpec Workshop
 
CI / CD / CS - Continuous Security in Kubernetes
CI / CD / CS - Continuous Security in KubernetesCI / CD / CS - Continuous Security in Kubernetes
CI / CD / CS - Continuous Security in Kubernetes
 
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
Gianluca Varisco - DevOoops (Increase awareness around DevOps infra security)
 
Road to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoopsRoad to Opscon (Pisa '15) - DevOoops
Road to Opscon (Pisa '15) - DevOoops
 
K2000 Scripted Installations
K2000 Scripted InstallationsK2000 Scripted Installations
K2000 Scripted Installations
 
InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017InSpec For DevOpsDays Amsterdam 2017
InSpec For DevOpsDays Amsterdam 2017
 
InSpec Workshop at Velocity London 2018
InSpec Workshop at Velocity London 2018InSpec Workshop at Velocity London 2018
InSpec Workshop at Velocity London 2018
 
kubernetes - minikube - getting started
kubernetes - minikube - getting startedkubernetes - minikube - getting started
kubernetes - minikube - getting started
 
CERN OpenStack Cloud Control Plane - From VMs to K8s
CERN OpenStack Cloud Control Plane - From VMs to K8sCERN OpenStack Cloud Control Plane - From VMs to K8s
CERN OpenStack Cloud Control Plane - From VMs to K8s
 
Docker Runtime Security
Docker Runtime SecurityDocker Runtime Security
Docker Runtime Security
 
DockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with DockerDockerCon EU 2015: Trading Bitcoin with Docker
DockerCon EU 2015: Trading Bitcoin with Docker
 
Pro2516 10 things about oracle and k8s.pptx-final
Pro2516   10 things about oracle and k8s.pptx-finalPro2516   10 things about oracle and k8s.pptx-final
Pro2516 10 things about oracle and k8s.pptx-final
 
XPDDS17: EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...
XPDDS17:  EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...XPDDS17:  EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...
XPDDS17: EFI Secure Boot, Shim and Xen: Current Status and Developments - Da...
 

Recently uploaded

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)OPEN KNOWLEDGE GmbH
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackVICTOR MAESTRE RAMIREZ
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio, Inc.
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfPower Karaoke
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number SystemsJheuzeDellosa
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxTier1 app
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureDinusha Kumarasiri
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataBradBedford3
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsMehedi Hasan Shohan
 

Recently uploaded (20)

Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)Der Spagat zwischen BIAS und FAIRNESS (2024)
Der Spagat zwischen BIAS und FAIRNESS (2024)
 
Cloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStackCloud Management Software Platforms: OpenStack
Cloud Management Software Platforms: OpenStack
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed DataAlluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
Alluxio Monthly Webinar | Cloud-Native Model Training on Distributed Data
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
The Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdfThe Evolution of Karaoke From Analog to App.pdf
The Evolution of Karaoke From Analog to App.pdf
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
What is Binary Language? Computer Number Systems
What is Binary Language?  Computer Number SystemsWhat is Binary Language?  Computer Number Systems
What is Binary Language? Computer Number Systems
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptxKnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
KnowAPIs-UnknownPerf-jaxMainz-2024 (1).pptx
 
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Naraina Delhi 💯Call Us 🔝8264348440🔝
 
Implementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with AzureImplementing Zero Trust strategy with Azure
Implementing Zero Trust strategy with Azure
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer DataAdobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
Adobe Marketo Engage Deep Dives: Using Webhooks to Transfer Data
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
XpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software SolutionsXpertSolvers: Your Partner in Building Innovative Software Solutions
XpertSolvers: Your Partner in Building Innovative Software Solutions
 

Signature verification of kernel module and kexec

  • 1. Signature verification ofSignature verification of kernel module and kexeckernel module and kexec October, 2016, openSUSE.Asia 2016, YogyakartaOctober, 2016, openSUSE.Asia 2016, Yogyakarta Joey Lee, SUSE Labs Taipei
  • 2. 2 Agenda • Kernel module signing – How to enable it – Sign kernel module – The mechanism of verification • kexec: Verify signature of PE signed bzImage – How to enable it – Sign kernel PE binary for loading with kexec-file – The mechanism of kexec-file syscall • Q&A
  • 4. 4 Kernel Module Signing Facility • Introduced since v3.7-rc1 kernel • Author: David Howells – https://lkml.org/lkml/2012/9/24/631 – crypto algorithm: RSA – Key identifier type: X.509 • The kernel module signing facility cryptographically signs modules during installation and then checks the signature upon loading the module. • This allows increased kernel security by disallowing the loading of unsigned modules or modules signed with an invalid key. [1]
  • 5. 5 How to enable modsign • CONFIG_MODULE_SIG=y – Module signature verification • CONFIG_MODULE_SIG_FORCE – Require modules to be validly signed • CONFIG_MODULE_SIG_ALL – Automatically sign all modules • CONFIG_MODULE_SIG_SHA* – which hash algorithm the installation phase will sign the modules with – e.g. CONFIG_MODULE_SIG_SHA512
  • 6. 6 How to enable modsign (cont.) • CONFIG_MODULE_SIG_KEY – File name or PKCS#11 URI of module signing key – Default: certs/signing_key.pem • CONFIG_SYSTEM_TRUSTED_KEYS – Additional X.509 keys for default system keyring • CONFIG_MODULE_SIG_UEFI=y (SUSE) – Load certificate from db, dbx, mok and mokx
  • 7. 7 module signing key • CONFIG_MODULE_SIG_KEY – File name or PKCS#11 URI of module signing key – Default: ● CONFIG_MODULE_SIG_KEY="certs/signing_key.p em" ● certs/signing_key.pem (private key + public key) ● certs/signing_key.x509 (only public key)
  • 9. 9 module signing key (cont.) • Show private key – openssl rsa -in certs/signing_key.pem -noout -text | less
  • 10. 10 module signing key (cont.) • Show certificate (includes public key) – openssl x509 -in certs/signing_key.pem -inform PEM -noout -text | less – openssl x509 -in certs/signing_key.x509 -inform DER -noout -text | less
  • 11. 11 x509.genkey • During the building of vmlinux (the public part of the key needs to be built into vmlinux) using parameters in the: certs/x509.genkey • This file is also generated if it does not already exist [1] • Most notably, in the x509.genkey file, the req_distinguished_name section • should be altered from the default: – [ req_distinguished_name ] #O = Unspecified company CN = Build time autogenerated kernel key #emailAddress = unspecified.user@unspecified.company • The generated RSA key size can also be set with: [ req ] default_bits = 4096
  • 13. 13 sign module • scripts/sign-file – ./scripts/sign-file sha1 certs/signing_key.pem certs/signing_key.x509 drivers/platform/x86/acer-wmi.ko ~/acer-wmi-signed.ko • CONFIG_MODULE_SIG_ALL=y – Automatically sign all modules when “make modules_install”
  • 14. 14 Require modules to be validly signed • CONFIG_MODULE_SIG_FORCE=y – insmod: ERROR: could not insert module acer-wmi-unsign.ko: Required key not available • • CONFIG_MODULE_SIG_FORCE not set – module verification failed: signature and/or required key missing - tainting kernel – Taint kernel by 'E' flag
  • 20. 20
  • 21. 21 MOKutil • Import your certificate to machine owner key(MOK) variable. • Linux kernel loads certificate from MOK to verify kernel module. • # mokutil --root-pw --import certs/signing_key.x509
  • 23. kexec: verify signaturekexec: verify signature
  • 24. 24 kexec: Verify signature of PE signed bzImage • Introduced since v3.7-rc1 kernel • Author: Vivek Goyal – https://lkml.org/lkml/2014/7/3/749 – x86_64 only – Base on: ● kexec: A new system call to allow in kernel loading ● PKCS7 signature support • Now kexec bzImage loader calls into pefile parser and passes the PE signed bzImage for signature verification.
  • 25. 25 How to enable kexec verify • CONFIG_KEXEC_FILE=y – kexec file based system call • CONFIG_KEXEC_VERIFY_SIG=y – Verify kernel signature during kexec_file_load() syscall • CONFIG_KEXEC_BZIMAGE_VERIFY_SIG=y – Enable bzImage signature verification support
  • 26. 26 The EFI Boot Stub • On the x86 and ARM platforms, a kernel zImage/bzImage can masquerade as a PE/COFF image, thereby convincing EFI firmware loaders to load it as an EFI executable. [2] • CONFIG_EFI_STUB=y • The bzImage located in arch/x86/boot/bzImage must be copied to the EFI System Partition (ESP) and renamed with the extension ".efi". • Using EFI shell to execute EFI stub kernel • Grub2 supports kernel x86 boot protocol 2.11 (since v3.6) – Protocol 2.11: (Kernel 3.6) Added a field for offset of EFI handover protocol entry point. [5] – With linuxefi/initrdefi grub2 module
  • 27. 27 Key was rejected by service
  • 28. 28 sign your bzImage • set CONFIG_MODULE_SIG=y to generate signing_key.* – Or using your own key-pair • Enroll certificate to MOK to shim for kernel verification – mokutil --root-pw --import certs/signing_key.x509 • Install mozilla-nss-tools, openssl and pesign – zypper in mozilla-nss-tools openssl pesign
  • 29. 29 sign your bzImage (cont.) • Create certificate database for signing (certdb) – mkdir $WORKSPACE – cp $KERNEL_SOURCE/certs/signing_key.* ./ – mkdir certdb – certutil -d certdb/ -A -i signing_key.x509 -n cert -t CT,CT,CT • Hierarchy /root/kexec-sign/: certdb signing_key.pem signing_key.x509 /root/kexec-sign/certdb: cert8.db key3.db secmod.db
  • 30. 30 sign your bzImage (cont.) • Using pesign to sign kernel – pesign -n certdb/ -i /boot/"$TARGET_KERNEL" -E ./"$TARGET_KERNEL".sattrs – openssl dgst -sha256 -sign signing_key.pem ./"$TARGET_KERNEL".sattrs > ./"$TARGET_KERNEL".sattrs.sig – pesign -n certdb/ -c cert -i /boot/"$TARGET_KERNEL" -R ./"$TARGET_KERNEL".sattrs.sig -I ./"$TARGET_KERNEL".sattrs -o ./"$TARGET_KERNEL".signed – pesign -S -i ./"$TARGET_KERNEL".signed • Help script: kexec-sign-test.sh – https://github.com/joeyli/hackweek/blob/master/kexec-sign-test/kexec-sign-test.sh – kexec-sign-test.sh init ~/kernel-source.nfs – kexec-sign-test.sh sign vmlinuz-4.4.21-default+
  • 31. 31 Load signed kernel • Load signed kernel with kexec-file system call for testing – /sbin/kexec -s -p ./$SIGNED_KERNEL --append="ro quiet elevator=deadline sysrq=yes reset_devices acpi_no_memhotplug cgroup_disable=memory irqpoll nr_cpus=1 disable_cpu_apicid=0 noefi acpi_rsdp=0xdfbfe014 panic=1" • Copy signed kernel to /boot folder to replace the unsigned kernel: – # cp /root/kexec-sign/vmlinuz-4.4.21-default+.signed /boot/vmlinuz- 4.4.21-default+ • Reboot and check the kdump status: – # systemctl status kdump -l
  • 34. 34 Embedded signatures of PE/COFF • CONFIG_EFI_STUB=y – On the x86 and ARM platforms, a kernel zImage/bzImage can masquerade as a PE/COFF image, thereby convincing EFI firmware loaders to load it as an EFI executable. • Authenticode signature format [4] – Authenticode® is a digital signature format that is used to determine the origin and integrity of software binaries. – Authenticode is based on Public-Key Cryptography Standards (PKCS) #7 signed data and X.509 certificates to bind an Authenticode- signed binary to the identity of a software publisher.
  • 35. 35 Embedded signatures of PE/COFF (cont.)
  • 36. 36
  • 38. Terima Kasih!Terima Kasih! 謝謝謝謝 !! Thank you!Thank you!
  • 39. 39 References • [1] Documentation/module-signing.txt – https://www.kernel.org/doc/Documentation/module-signing.tx • [2] Documentation/efi-stub.txt – https://www.kernel.org/doc/Documentation/efi-stub.txt • [3] Unified Extensible Firmware Interface Specification, Version 2.6, January 2016 • [4] Windows Authenticode Portable Executable Signature Format • [5] Documentation/x86/boot.txt
  • 41. 41

Editor's Notes

  1. CN: Common Name Organization (O)
  2. Terima kasih. 得理媽嘎西
  3. Theory Mathematics