📄 Page
1
Building Secure Firmware Armoring the Foundation of the Platform — Jiewen Yao Vincent Zimmer
📄 Page
2
Building Secure Firmware Armoring the Foundation of the Platform Jiewen Yao Vincent Zimmer
📄 Page
3
Building Secure Firmware: Armoring the Foundation of the Platform ISBN-13 (pbk): 978-1-4842-6105-7 ISBN-13 (electronic): 978-1-4842-6106-4 https://doi.org/10.1007/978-1-4842-6106-4 Copyright © 2020 by Jiewen Yao and Vincent Zimmer This work is subject to copyright. All rights are reserved by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed. Trademarked names, logos, and images may appear in this book. Rather than use a trademark symbol with every occurrence of a trademarked name, logo, or image we use the names, logos, and images only in an editorial fashion and to the benefit of the trademark owner, with no intention of infringement of the trademark. The use in this publication of trade names, trademarks, service marks, and similar terms, even if they are not identified as such, is not to be taken as an expression of opinion as to whether or not they are subject to proprietary rights. While the advice and information in this book are believed to be true and accurate at the date of publication, neither the authors nor the editors nor the publisher can accept any legal responsibility for any errors or omissions that may be made. The publisher makes no warranty, express or implied, with respect to the material contained herein. Managing Director, Apress Media LLC: Welmoed Spahr Acquisitions Editor: Susan McDermott Development Editor: Laura Berendson Coordinating Editor: Jessica Vakili Distributed to the book trade worldwide by Springer Science+Business Media New York, 233 Spring Street, 6th Floor, New York, NY 10013. Phone 1-800-SPRINGER, fax (201) 348-4505, e-mail orders-ny@springer- sbm.com, or visit www.springeronline.com. Apress Media, LLC is a California LLC and the sole member (owner) is Springer Science + Business Media Finance Inc (SSBM Finance Inc). SSBM Finance Inc is a Delaware corporation. For information on translations, please e-mail booktranslations@springernature.com; for reprint, paperback, or audio rights, please e-mail bookpermissions@springernature.com. Apress titles may be purchased in bulk for academic, corporate, or promotional use. eBook versions and licenses are also available for most titles. For more information, reference our Print and eBook Bulk Sales web page at http://www.apress.com/bulk-sales. Any source code or other supplementary material referenced by the author in this book is available to readers on GitHub via the book’s product page, located at www.apress.com/978-1-4842-6105-7. For more detailed information, please visit http://www.apress.com/source-code. Printed on acid-free paper Jiewen Yao Shanghai, China Vincent Zimmer Issaquah, WA, USA
📄 Page
4
To my lovely wife, Wenjun Zeng. Thank you for your constant encouragement and unconditional support! —Jiewen Yao To my parents; to my wife, Jan; and to my daughters, Ally and Zoe. Your support and love are rays of sunshine that warm my days. —Vincent Zimmer
📄 Page
5
v Table of Contents Part I: Overview ���������������������������������������������������������������������������������������������� 1 Chapter 1: Introduction to Firmware ������������������������������������������������������������������������ 3 Similarity Between Firmware and Software ��������������������������������������������������������������������������������� 3 Distinction Between Firmware and Software ������������������������������������������������������������������������������� 5 Introduction to Firmware Security ������������������������������������������������������������������������������������������������ 6 Firmware Resiliency ���������������������������������������������������������������������������������������������������������������� 7 Firmware Measurement and Attestation ��������������������������������������������������������������������������������� 8 Secure Device Communication ������������������������������������������������������������������������������������������������ 8 Introduction to Variants of Host Firmware ������������������������������������������������������������������������������������ 9 Industry Standards ���������������������������������������������������������������������������������������������������������������������� 10 Boot Flow and Phased Handoff ��������������������������������������������������������������������������������������������������� 11 Introduction to Non-host Firmware ��������������������������������������������������������������������������������������������� 13 Introduction to Device Firmware ������������������������������������������������������������������������������������������������� 14 Summary������������������������������������������������������������������������������������������������������������������������������������� 14 References ���������������������������������������������������������������������������������������������������������������������������������� 15 About the Authors ���������������������������������������������������������������������������������������������������xix About the Technical Reviewer ��������������������������������������������������������������������������������xxi Organization and What Is Covered �����������������������������������������������������������������������xxiii Acknowledgments �������������������������������������������������������������������������������������������������xxv Preface ����������������������������������������������������������������������������������������������������������������xxvii Foreword ��������������������������������������������������������������������������������������������������������������xxix
📄 Page
6
vi Chapter 2: Proactive Firmware Security Development ������������������������������������������� 17 Requirement Phase ��������������������������������������������������������������������������������������������������������������������� 17 Security Requirements ���������������������������������������������������������������������������������������������������������� 17 Threat Model and Architecture Phase ����������������������������������������������������������������������������������������� 18 Threat Model Analysis ����������������������������������������������������������������������������������������������������������� 18 Security Architecture and Design ������������������������������������������������������������������������������������������ 31 Real Example ������������������������������������������������������������������������������������������������������������������������� 36 Development Phase �������������������������������������������������������������������������������������������������������������������� 49 Secure Coding Practice ��������������������������������������������������������������������������������������������������������� 49 Security Unit Test ������������������������������������������������������������������������������������������������������������������� 49 Security Code Review ������������������������������������������������������������������������������������������������������������ 49 Test Phase ����������������������������������������������������������������������������������������������������������������������������������� 55 Fuzzing ���������������������������������������������������������������������������������������������������������������������������������� 55 Static Code Analysis �������������������������������������������������������������������������������������������������������������� 56 Dynamic Code Analysis ��������������������������������������������������������������������������������������������������������� 56 Vulnerability Scan ������������������������������������������������������������������������������������������������������������������ 57 Release and Maintenance Phase ������������������������������������������������������������������������������������������������ 57 Security Incidence Response ������������������������������������������������������������������������������������������������ 57 People Education ������������������������������������������������������������������������������������������������������������������������ 58 Before the Project Starts ������������������������������������������������������������������������������������������������������� 58 After the Project Release ������������������������������������������������������������������������������������������������������� 58 Fallacy and Pitfall ������������������������������������������������������������������������������������������������������������������������ 58 Security Technology��������������������������������������������������������������������������������������������������������������� 58 Security Process �������������������������������������������������������������������������������������������������������������������� 59 Summary������������������������������������������������������������������������������������������������������������������������������������� 60 References ���������������������������������������������������������������������������������������������������������������������������������� 61 Part II: Security Architecture ������������������������������������������������������������������������ 65 Chapter 3: Firmware Resiliency: Protection ����������������������������������������������������������� 67 Resiliency Building Block ������������������������������������������������������������������������������������������������������������ 67 Immutable ROM �������������������������������������������������������������������������������������������������������������������������� 69 Table of ConTenTs
📄 Page
7
vii Integrity ��������������������������������������������������������������������������������������������������������������������������������� 69 Confidentiality������������������������������������������������������������������������������������������������������������������������ 69 Case Study ����������������������������������������������������������������������������������������������������������������������������� 70 Attack and Mitigation ������������������������������������������������������������������������������������������������������������ 72 Updatable Firmware �������������������������������������������������������������������������������������������������������������������� 73 Authenticated Update Mechanism ���������������������������������������������������������������������������������������� 73 Case Study ����������������������������������������������������������������������������������������������������������������������������� 74 Integrity Protection ���������������������������������������������������������������������������������������������������������������� 93 Case Study ����������������������������������������������������������������������������������������������������������������������������� 94 Non-bypassability ������������������������������������������������������������������������������������������������������������������ 94 Attack and Mitigation ������������������������������������������������������������������������������������������������������������ 94 Configurable Data ��������������������������������������������������������������������������������������������������������������������� 108 Case Study ��������������������������������������������������������������������������������������������������������������������������� 108 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 110 Summary����������������������������������������������������������������������������������������������������������������������������������� 111 References �������������������������������������������������������������������������������������������������������������������������������� 111 Chapter 4: Firmware Resiliency: Detection ���������������������������������������������������������� 115 Secure Boot������������������������������������������������������������������������������������������������������������������������������� 115 Detectability ������������������������������������������������������������������������������������������������������������������������ 115 Version ��������������������������������������������������������������������������������������������������������������������������������� 117 Policy Revocation ���������������������������������������������������������������������������������������������������������������� 117 Non-bypassability ���������������������������������������������������������������������������������������������������������������� 117 Additional Capability ������������������������������������������������������������������������������������������������������������ 118 Case Study ��������������������������������������������������������������������������������������������������������������������������� 118 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 149 Secure Configuration ���������������������������������������������������������������������������������������������������������������� 155 Detectability ������������������������������������������������������������������������������������������������������������������������ 156 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 157 Summary����������������������������������������������������������������������������������������������������������������������������������� 158 References �������������������������������������������������������������������������������������������������������������������������������� 158 Table of ConTenTs
📄 Page
8
viii Chapter 5: Firmware Resiliency: Recovery ����������������������������������������������������������� 163 Image Recovery ������������������������������������������������������������������������������������������������������������������������ 163 RTRec Selection and Recovery Policy ��������������������������������������������������������������������������������� 163 Recovery Image Selection ��������������������������������������������������������������������������������������������������� 165 Recovery Image Location ���������������������������������������������������������������������������������������������������� 165 Case Study ��������������������������������������������������������������������������������������������������������������������������� 166 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 177 Configuration Recovery ������������������������������������������������������������������������������������������������������������� 178 Recovery Configuration Selection ��������������������������������������������������������������������������������������� 178 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 180 Watchdog ���������������������������������������������������������������������������������������������������������������������������������� 181 Summary����������������������������������������������������������������������������������������������������������������������������������� 182 References �������������������������������������������������������������������������������������������������������������������������������� 182 Chapter 6: OS Resiliency �������������������������������������������������������������������������������������� 185 Protection ���������������������������������������������������������������������������������������������������������������������������������� 186 Automated Update ��������������������������������������������������������������������������������������������������������������� 186 Detection ����������������������������������������������������������������������������������������������������������������������������������� 186 Image Signing ���������������������������������������������������������������������������������������������������������������������� 186 Case Study ��������������������������������������������������������������������������������������������������������������������������� 186 Recovery ����������������������������������������������������������������������������������������������������������������������������������� 193 Automated Recovery ����������������������������������������������������������������������������������������������������������� 193 Case Study ��������������������������������������������������������������������������������������������������������������������������� 193 Summary����������������������������������������������������������������������������������������������������������������������������������� 195 References �������������������������������������������������������������������������������������������������������������������������������� 195 Chapter 7: Trusted Boot ���������������������������������������������������������������������������������������� 197 Static Root-of-Trust for Measurement (SRTM) �������������������������������������������������������������������������� 198 Trusted Platform Module (TPM) ������������������������������������������������������������������������������������������� 198 TPM Device Type������������������������������������������������������������������������������������������������������������������ 201 Measurement Report ����������������������������������������������������������������������������������������������������������� 202 Attestation ��������������������������������������������������������������������������������������������������������������������������� 203 Table of ConTenTs
📄 Page
9
ix S3 Resume �������������������������������������������������������������������������������������������������������������������������� 206 Device Identifier Composition Engine (DICE) ����������������������������������������������������������������������� 207 Case Study ��������������������������������������������������������������������������������������������������������������������������� 210 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 224 Dynamic Root-of-Trust for Measurement (DRTM) ��������������������������������������������������������������������� 226 CPU-Based Dynamic Root-of-Trust �������������������������������������������������������������������������������������� 227 S3 Resume �������������������������������������������������������������������������������������������������������������������������� 229 DEC’s Execution Environment ���������������������������������������������������������������������������������������������� 230 Hot Plug ������������������������������������������������������������������������������������������������������������������������������� 231 Case Study ��������������������������������������������������������������������������������������������������������������������������� 232 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 237 TCG Memory Overwrite ������������������������������������������������������������������������������������������������������������� 242 Secure MOR ������������������������������������������������������������������������������������������������������������������������� 244 MOR for Storage ������������������������������������������������������������������������������������������������������������������ 244 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 245 TCG Physical Presence Configuration ��������������������������������������������������������������������������������������� 246 TCG Storage ������������������������������������������������������������������������������������������������������������������������������ 246 Summary����������������������������������������������������������������������������������������������������������������������������������� 246 References �������������������������������������������������������������������������������������������������������������������������������� 246 Chapter 8: Device Security ����������������������������������������������������������������������������������� 257 Device Firmware Resiliency ������������������������������������������������������������������������������������������������������ 257 Secure Device Communication ������������������������������������������������������������������������������������������������� 258 Authentication and Measurement ��������������������������������������������������������������������������������������� 258 Secure Communication Channel ����������������������������������������������������������������������������������������� 259 Device Identifier Composition Engine (DICE) ����������������������������������������������������������������������� 260 Case Study ��������������������������������������������������������������������������������������������������������������������������� 260 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 267 Device Attack Prevention ���������������������������������������������������������������������������������������������������������� 268 Device Identifier Data ���������������������������������������������������������������������������������������������������������� 268 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 269 Direct Memory Access (DMA) ���������������������������������������������������������������������������������������������� 270 Table of ConTenTs
📄 Page
10
x Case Study ��������������������������������������������������������������������������������������������������������������������������� 275 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 283 Message Signaled Interrupt (MSI) ��������������������������������������������������������������������������������������� 286 Case Study ��������������������������������������������������������������������������������������������������������������������������� 291 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 297 Server RAS (Reliability, Availability, and Serviceability) ������������������������������������������������������� 300 Case Study ��������������������������������������������������������������������������������������������������������������������������� 301 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 305 Summary����������������������������������������������������������������������������������������������������������������������������������� 307 References �������������������������������������������������������������������������������������������������������������������������������� 307 Chapter 9: S3 Resume ������������������������������������������������������������������������������������������ 313 Threat Model ����������������������������������������������������������������������������������������������������������������������������� 315 LockBox ������������������������������������������������������������������������������������������������������������������������������������ 317 Case Study ��������������������������������������������������������������������������������������������������������������������������� 319 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 332 Summary����������������������������������������������������������������������������������������������������������������������������������� 333 References �������������������������������������������������������������������������������������������������������������������������������� 333 Chapter 10: Access Control ���������������������������������������������������������������������������������� 335 Boot Access Control ������������������������������������������������������������������������������������������������������������������ 337 What a User Knows: Password �������������������������������������������������������������������������������������������� 337 What a User Has: Token ������������������������������������������������������������������������������������������������������� 342 What a User Is: Biometrics �������������������������������������������������������������������������������������������������� 342 Other Considerations ����������������������������������������������������������������������������������������������������������� 342 Case Study ��������������������������������������������������������������������������������������������������������������������������� 343 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 345 TEE Access Control ������������������������������������������������������������������������������������������������������������������� 347 Feature Configuration Control ��������������������������������������������������������������������������������������������������� 347 User Physical Presence ������������������������������������������������������������������������������������������������������� 347 UEFI Variable ������������������������������������������������������������������������������������������������������������������������ 347 Case Study ��������������������������������������������������������������������������������������������������������������������������� 348 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 349 Table of ConTenTs
📄 Page
11
xi Device Configuration Control ���������������������������������������������������������������������������������������������������� 349 Physical Presence ��������������������������������������������������������������������������������������������������������������� 350 Secure Console �������������������������������������������������������������������������������������������������������������������� 350 Case Study ��������������������������������������������������������������������������������������������������������������������������� 351 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 355 Storage Access Control ������������������������������������������������������������������������������������������������������������� 356 Hard Drive Password ����������������������������������������������������������������������������������������������������������� 356 Fast Boot Impact ����������������������������������������������������������������������������������������������������������������� 357 Unlock in a Warm Reset ������������������������������������������������������������������������������������������������������ 357 Auto Unlock in S3 ���������������������������������������������������������������������������������������������������������������� 357 Runtime D3 impact �������������������������������������������������������������������������������������������������������������� 358 Password Update ����������������������������������������������������������������������������������������������������������������� 359 User Password vs� Master Password ���������������������������������������������������������������������������������� 359 Retry Count �������������������������������������������������������������������������������������������������������������������������� 359 Hard Drive Freeze ���������������������������������������������������������������������������������������������������������������� 359 Secure Console �������������������������������������������������������������������������������������������������������������������� 359 Case Study ��������������������������������������������������������������������������������������������������������������������������� 360 Attack & Mitigation �������������������������������������������������������������������������������������������������������������� 371 Network Access Control ������������������������������������������������������������������������������������������������������������ 372 Case Study ��������������������������������������������������������������������������������������������������������������������������� 372 Attack & Mitigation �������������������������������������������������������������������������������������������������������������� 374 Device Access Control ��������������������������������������������������������������������������������������������������������������� 375 Case Study ��������������������������������������������������������������������������������������������������������������������������� 375 Attack & Mitigation �������������������������������������������������������������������������������������������������������������� 377 Summary����������������������������������������������������������������������������������������������������������������������������������� 378 References �������������������������������������������������������������������������������������������������������������������������������� 378 Chapter 11: Configuration������������������������������������������������������������������������������������� 383 UEFI Variables ��������������������������������������������������������������������������������������������������������������������������� 383 Integrity Protection �������������������������������������������������������������������������������������������������������������� 384 Availability Protection ���������������������������������������������������������������������������������������������������������� 406 Confidentiality Protection ���������������������������������������������������������������������������������������������������� 416 Table of ConTenTs
📄 Page
12
xii Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 421 UEFI PI Firmware Volume ���������������������������������������������������������������������������������������������������� 427 UEFI PI PCD (Platform Configuration Data) �������������������������������������������������������������������������������� 427 Summary����������������������������������������������������������������������������������������������������������������������������������� 429 References �������������������������������������������������������������������������������������������������������������������������������� 430 Chapter 12: Security Model ���������������������������������������������������������������������������������� 433 Confidentiality ��������������������������������������������������������������������������������������������������������������������������� 433 Bell-LaPadula ���������������������������������������������������������������������������������������������������������������������� 434 Integrity ������������������������������������������������������������������������������������������������������������������������������������� 436 Biba Model ��������������������������������������������������������������������������������������������������������������������������� 436 Clark-Wilson Model ������������������������������������������������������������������������������������������������������������� 438 Others ��������������������������������������������������������������������������������������������������������������������������������������� 440 Application �������������������������������������������������������������������������������������������������������������������������������� 441 Trusted Computing Group Security Model ��������������������������������������������������������������������������� 441 Firmware Resiliency (Protection, Detection, Recovery) ������������������������������������������������������� 443 Summary����������������������������������������������������������������������������������������������������������������������������������� 456 References �������������������������������������������������������������������������������������������������������������������������������� 456 Chapter 13: Virtual Firmware ������������������������������������������������������������������������������� 459 New Threats in the Guest Domain ��������������������������������������������������������������������������������������������� 460 Case Study ��������������������������������������������������������������������������������������������������������������������������� 461 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 473 Device Interface ������������������������������������������������������������������������������������������������������������������������ 476 Case Study ��������������������������������������������������������������������������������������������������������������������������� 477 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 481 Special Feature ������������������������������������������������������������������������������������������������������������������������� 482 Case Study ��������������������������������������������������������������������������������������������������������������������������� 483 Summary����������������������������������������������������������������������������������������������������������������������������������� 487 References �������������������������������������������������������������������������������������������������������������������������������� 487 Table of ConTenTs
📄 Page
13
xiii Part III: Security Development �������������������������������������������������������������������� 493 Chapter 14: Firmware Secure Coding Practice ����������������������������������������������������� 495 Basic Security Practice ������������������������������������������������������������������������������������������������������������� 495 Secure Coding Practice ������������������������������������������������������������������������������������������������������� 495 Secure Design Practice ������������������������������������������������������������������������������������������������������� 517 Boot Firmware Secure Design Practice ������������������������������������������������������������������������������� 522 Advanced Secure Coding Topic ������������������������������������������������������������������������������������������������� 525 Side Channel Attack ������������������������������������������������������������������������������������������������������������ 525 Fault Injection ���������������������������������������������������������������������������������������������������������������������� 545 High-Risk Area in Firmware ������������������������������������������������������������������������������������������������������ 551 External Input ���������������������������������������������������������������������������������������������������������������������� 552 Race Condition �������������������������������������������������������������������������������������������������������������������� 553 Hardware Input �������������������������������������������������������������������������������������������������������������������� 554 Secret Handling ������������������������������������������������������������������������������������������������������������������� 555 Register Lock ����������������������������������������������������������������������������������������������������������������������� 556 Secure Configuration ����������������������������������������������������������������������������������������������������������� 556 Replay/Rollback ������������������������������������������������������������������������������������������������������������������� 557 Cryptography ����������������������������������������������������������������������������������������������������������������������� 558 Summary����������������������������������������������������������������������������������������������������������������������������������� 559 References �������������������������������������������������������������������������������������������������������������������������������� 559 Chapter 15: Compiler Defensive Technology �������������������������������������������������������� 571 Break the Exploit ����������������������������������������������������������������������������������������������������������������������� 573 Stack Check ������������������������������������������������������������������������������������������������������������������������� 573 Code Protection ������������������������������������������������������������������������������������������������������������������� 577 Address Space Layout Randomization �������������������������������������������������������������������������������� 579 Control Flow Guard �������������������������������������������������������������������������������������������������������������� 580 Hardware-Based Control Flow Guard ���������������������������������������������������������������������������������� 589 Speculative Load Hardening ������������������������������������������������������������������������������������������������ 594 Eliminate the Vulnerability �������������������������������������������������������������������������������������������������������� 598 Static Analyzer ��������������������������������������������������������������������������������������������������������������������� 598 Address Sanitizer ���������������������������������������������������������������������������������������������������������������� 598 Table of ConTenTs
📄 Page
14
xiv Hardware-Based Address Sanitizer ������������������������������������������������������������������������������������� 605 Uninitialized Data Check ������������������������������������������������������������������������������������������������������ 608 Arithmetic Check ����������������������������������������������������������������������������������������������������������������� 613 Summary����������������������������������������������������������������������������������������������������������������������������������� 618 References �������������������������������������������������������������������������������������������������������������������������������� 618 Chapter 16: The Kernel ����������������������������������������������������������������������������������������� 625 Break the Exploitation ��������������������������������������������������������������������������������������������������������������� 628 Code Protection ������������������������������������������������������������������������������������������������������������������� 628 Address Space Layout Randomization �������������������������������������������������������������������������������� 634 Control Flow Guard �������������������������������������������������������������������������������������������������������������� 642 Address Sanitizer ���������������������������������������������������������������������������������������������������������������� 644 Contain the Damage ������������������������������������������������������������������������������������������������������������������ 654 User Mode/Supervisor Mode ����������������������������������������������������������������������������������������������� 654 Virtual Machine Monitor ������������������������������������������������������������������������������������������������������ 659 Trusted Execution Environment ������������������������������������������������������������������������������������������� 669 System Partitioning ������������������������������������������������������������������������������������������������������������� 670 Summary����������������������������������������������������������������������������������������������������������������������������������� 672 References �������������������������������������������������������������������������������������������������������������������������������� 672 Chapter 17: Trusted Execution Environment �������������������������������������������������������� 681 CPU-Based TEE ������������������������������������������������������������������������������������������������������������������������� 681 X86 SMM ����������������������������������������������������������������������������������������������������������������������������� 681 ARM TrustZone��������������������������������������������������������������������������������������������������������������������� 707 Intel SGX ������������������������������������������������������������������������������������������������������������������������������ 716 AMD SEV ������������������������������������������������������������������������������������������������������������������������������ 718 Intel TDX ������������������������������������������������������������������������������������������������������������������������������ 719 IBM Z ����������������������������������������������������������������������������������������������������������������������������������� 719 RISC-V Keystone ������������������������������������������������������������������������������������������������������������������ 719 RISC-V/ARM-M MultiZone ���������������������������������������������������������������������������������������������������� 720 Standards, Frameworks, and SDKs ������������������������������������������������������������������������������������� 721 Summary ����������������������������������������������������������������������������������������������������������������������������� 722 Table of ConTenTs
📄 Page
15
xv Coprocessor-Based TEE ������������������������������������������������������������������������������������������������������������ 723 Intel Converged Security and Management Engine (CSME) ������������������������������������������������ 724 Apple Secure Enclave Processor (SEP) �������������������������������������������������������������������������������� 727 Google Titan ������������������������������������������������������������������������������������������������������������������������� 727 Microsoft Azure Sphere: Pluton ������������������������������������������������������������������������������������������� 728 Summary����������������������������������������������������������������������������������������������������������������������������������� 729 References �������������������������������������������������������������������������������������������������������������������������������� 732 Chapter 18: Silicon Secure Configuration ������������������������������������������������������������� 745 Flash Lock ��������������������������������������������������������������������������������������������������������������������������������� 745 BIOS Write Protection ���������������������������������������������������������������������������������������������������������� 745 BIOS Region Selection ��������������������������������������������������������������������������������������������������������� 747 SPI Region Lock ������������������������������������������������������������������������������������������������������������������� 749 SPI Region Access Control ��������������������������������������������������������������������������������������������������� 750 SMM Lock ���������������������������������������������������������������������������������������������������������������������������� 751 SMRAM Address Alias Lock ������������������������������������������������������������������������������������������������� 754 SMRR ����������������������������������������������������������������������������������������������������������������������������������� 759 SMM Code Access Check ���������������������������������������������������������������������������������������������������� 759 Global SMI Lock ������������������������������������������������������������������������������������������������������������������� 760 IOMMU �������������������������������������������������������������������������������������������������������������������������������������� 761 IOMMU Protection for DRAM ������������������������������������������������������������������������������������������������ 762 IOMMU Protection for SRAM ������������������������������������������������������������������������������������������������ 762 Silicon Support for DMA Prevention ������������������������������������������������������������������������������������ 762 Summary����������������������������������������������������������������������������������������������������������������������������������� 764 References �������������������������������������������������������������������������������������������������������������������������������� 765 Chapter 19: Cryptography ������������������������������������������������������������������������������������ 767 Modern Cryptography ��������������������������������������������������������������������������������������������������������������� 767 Cryptography Usage in the Firmware ���������������������������������������������������������������������������������� 770 Algorithm Recommendation ������������������������������������������������������������������������������������������������ 772 Some Concepts�������������������������������������������������������������������������������������������������������������������� 772 Challenge in the Firmware �������������������������������������������������������������������������������������������������� 787 Attack and Mitigation ���������������������������������������������������������������������������������������������������������� 790 Table of ConTenTs
📄 Page
16
xvi Quantum Safe Cryptography ����������������������������������������������������������������������������������������������������� 792 Security Challenge��������������������������������������������������������������������������������������������������������������� 792 Quantum Safe Algorithm ����������������������������������������������������������������������������������������������������� 794 Quantum Cryptography�������������������������������������������������������������������������������������������������������� 805 Algorithm Recommendation ������������������������������������������������������������������������������������������������ 809 Preparation for the Future ��������������������������������������������������������������������������������������������������� 811 Summary����������������������������������������������������������������������������������������������������������������������������������� 813 References �������������������������������������������������������������������������������������������������������������������������������� 814 Chapter 20: Programming Language �������������������������������������������������������������������� 825 Assembly Language ������������������������������������������������������������������������������������������������������������������ 825 C Language ������������������������������������������������������������������������������������������������������������������������������� 828 Rust ������������������������������������������������������������������������������������������������������������������������������������������� 828 Rust Security Solution ��������������������������������������������������������������������������������������������������������� 830 Unsafe Code ������������������������������������������������������������������������������������������������������������������������ 847 Current Project �������������������������������������������������������������������������������������������������������������������� 850 Limitation ����������������������������������������������������������������������������������������������������������������������������� 851 Others ��������������������������������������������������������������������������������������������������������������������������������������� 852 Summary����������������������������������������������������������������������������������������������������������������������������������� 852 References �������������������������������������������������������������������������������������������������������������������������������� 852 Part IV: Security Test ���������������������������������������������������������������������������������� 855 Chapter 21: Security Unit Test ������������������������������������������������������������������������������ 857 Security Unit Testing Plan ��������������������������������������������������������������������������������������������������������� 857 Advanced Security Unit Testing ������������������������������������������������������������������������������������������������� 860 Fuzzing �������������������������������������������������������������������������������������������������������������������������������� 861 Symbolic Execution ������������������������������������������������������������������������������������������������������������� 866 Formal Verification �������������������������������������������������������������������������������������������������������������� 868 Design for Security Test ������������������������������������������������������������������������������������������������������������ 870 Summary����������������������������������������������������������������������������������������������������������������������������������� 872 References �������������������������������������������������������������������������������������������������������������������������������� 872 Table of ConTenTs
📄 Page
17
xvii Chapter 22: Security Validation and Penetration Test ������������������������������������������ 875 Security Validation Plan ������������������������������������������������������������������������������������������������������������ 875 Penetration Test Plan ���������������������������������������������������������������������������������������������������������������� 886 Summary����������������������������������������������������������������������������������������������������������������������������������� 888 References �������������������������������������������������������������������������������������������������������������������������������� 889 Chapter 23: Maintenance ������������������������������������������������������������������������������������� 891 Mitigation Strategy and Tactics ������������������������������������������������������������������������������������������������� 891 Supply Chain for the Firmware Components ���������������������������������������������������������������������������� 894 Firmware Component Certificate and Manifest ������������������������������������������������������������������� 894 Firmware Attestation Data ��������������������������������������������������������������������������������������������������� 896 Vulnerable Firmware Detection ������������������������������������������������������������������������������������������������� 899 Antivirus for Firmware �������������������������������������������������������������������������������������������������������������� 900 Firmware Update ���������������������������������������������������������������������������������������������������������������������� 900 Summary����������������������������������������������������������������������������������������������������������������������������������� 901 References �������������������������������������������������������������������������������������������������������������������������������� 902 Index ��������������������������������������������������������������������������������������������������������������������� 907 Table of ConTenTs
📄 Page
18
xix About the Authors Jiewen Yao is a principal engineer in the Intel Architecture, Graphics, and Software Group. He has been engaged as a firmware developer for over 15 years. He is a member of the UEFI Security Sub-Team (USST) and the Trusted Computing Group (TCG) PC Client sub-working group. He has presented at industry events such as the Intel Developer Forum, UEFI Plugfest, and RSA Conference. He worked with coauthor Vincent Zimmer to publish 30 “A Tour Beyond BIOS” technical papers for tianocore.org and firmware.intel. com. He holds 40 US patents. Vincent Zimmer is a senior principal engineer in the Intel Architecture, Graphics, and Software Group. He has been engaged as a firmware developer for over 25 years and leads the UEFI Security Sub-Team. He has presented at industry events such as the Open Source Firmware Conference, LinuxFest Northwest, Intel Developer Forum, UEFI Plugfest, Open Compute Project Summit, Black Hat Las Vegas, BSides Seattle, ToorCon, and CanSecWest. In addition to collaborating with Jiewen Yao on many whitepapers, he has coauthored several books on firmware, papers, and over 400 issued US patents.
📄 Page
19
xxi About the Technical Reviewer Tim Lewis is the CTO and head of the Office of Security and Trust for Insyde Software. With over 30 years of BIOS experience, he has served on the UEFI board of directors and chaired the UEFI Security Sub-Team (USST). He is an active member of his local CS2AI chapter near his home in Folsom, California.
📄 Page
20
xxiii Organization and What Is Covered Currently, we already have books to separately introduce the topics of firmware and security. The purpose of this book is to link these areas together and provide the best practices in the security development of firmware. The whole book consists of four parts: Part I: Overview Chapter 1 includes a brief overview of the firmware in a system. Chapter 2 describes a proactive development lifecycle for the firmware. We will introduce a general threat model for the firmware and use a real example to demonstrate how to do threat model analysis. Part II: Security Architecture Chapter 3 describes the first aspect of the firmware resiliency – protection. Chapter 4 describes the second aspect of the firmware resiliency – detection. Chapter 5 describes the third aspect of the firmware resiliency – recovery. Chapter 6 extends the resiliency concept from the firmware to the operating system (OS). Chapter 7 introduces the trusted boot concept, besides the firmware resiliency in Chapters 3, 4, and 5. Chapter 8 focuses on the security aspects of the device firmware, including secure device communication and device attack prevention. Chapter 9 discusses S3 resume – a special boot path in the system firmware. Chapter 10 presents the access control technology in the firmware, including boot access control, device access control, feature configuration control, and so on. Chapter 11 examines the confidentiality, integrity, and availability of the firmware configuration data. Chapter 12 provides a brief introduction for the security model and maps the Clark- Wilson model to existing firmware features. Chapter 13 explains the virtual firmware, which may include a new threat model.