Bionic. Christoph. Code analysis, quality and security overview. July 26 th 2017

Similar documents
MEASURE YOUR CODE USING CODE METRICS. CS 599 Software Metrics and Models Hana Alarifi

CSCE 548 Building Secure Software Buffer Overflow. Professor Lisa Luo Spring 2018

My name is Jesus Abelarde and I am Lead Systems Security Engineer for the MITRE Corporation. I currently work on multiple engineering domains that

Software Security: Buffer Overflow Attacks

DR. CHECKER. A Soundy Analysis for Linux Kernel Drivers. University of California, Santa Barbara. USENIX Security seclab

A brief introduction to C programming for Java programmers

Static Vulnerability Analysis

5) Attacker causes damage Different to gaining control. For example, the attacker might quit after gaining control.

Evolutionary Architecture and Design

This time. Defenses and other memory safety vulnerabilities. Everything you ve always wanted to know about gdb but were too afraid to ask

Cloud Essentials for Architects using OpenStack

Patterns and Practices for Embedded TDD in C and C++ How we introduced TDD into our company

Threat Modeling. Bart De Win Secure Application Development Course, Credits to

Don t Be the Developer Whose Rocket Crashes on Lift off LDRA Ltd

SANER 17. Klagenfurt, Austria

International Software & Systems Engineering Standards

Static Analysis in Practice

The SQALE Method (V1.0) for Managing Technical Debt. A 15 mn pres. June Jean-Louis Letouzey

Finding User/Kernel Pointer Bugs with Type Inference p.1

Static Analysis Alert Audits Lexicon And Rules David Svoboda, CERT Lori Flynn, CERT Presenter: Will Snavely, CERT

FOR0383 Software Quality Assurance

Towards automated detection of buffer overrun vulnerabilities: a first step. NDSS 2000 Feb 3, 2000

lpengfei Ding & Chenfu Bao lsecurity Researcher & Baidu X-Lab lfocused on Mobile, IoT and Linux kernel security

Architecture and Design Evolution

CSE 509: Computer Security

Introduction To Software Testing. Brian Nielsen. Center of Embedded Software Systems Aalborg University, Denmark CSS

CSE 127 Computer Security

[Sample] Quality Report: <<project>>

Software Security: Vulnerability Analysis

Automotive Software Security Testing

Automated Assessment Tools

DevOps, Continuous Integration & Automated Testing: Rule Them All

Demystifying Maintainability

CERT C++ COMPLIANCE ENFORCEMENT

Software Security and CISQ. Dr. Bill Curtis Executive Director

Application security : going quicker

Automated Assessment Tools

Test Driven Development (TDD), and Working with Legacy Code Using C# Workshop ( 4 days)

CS 161 Computer Security

Secure Software Development: Theory and Practice

Murray Goldschmidt. Chief Operating Officer Sense of Security Pty Ltd. Micro Services, Containers and Serverless PaaS Web Apps? How safe are you?

Lab 09 - Virtual Memory

Software Security II: Memory Errors - Attacks & Defenses

Refactoring and Rearchitecturing

Android Kernel Security

Software Security: Buffer Overflow Defenses and Miscellaneous

IS 2620: Developing Secure Systems. Building Security In Lecture 2

Keywords Static analysis tools; Software security; Software Development Life Cycle; Static Analysis; Vulnerabilities; Evaluation

Software security, secure programming

Static Analysis in Practice

Agenda. Security and Standard C Libraries. Martyn Lovell Visual C++ Libraries Microsoft Corporation

Brave New 64-Bit World. An MWR InfoSecurity Whitepaper. 2 nd June Page 1 of 12 MWR InfoSecurity Brave New 64-Bit World

Let's cyber: hacking, 0days and vulnerability research. PATROKLOS ARGYROUDIS CENSUS S.A.

Smartphone (in) Security

Honours/Master/PhD Thesis Projects Supervised by Dr. Yulei Sui

Three things you should know about Automated Refactoring. When planning an application modernization strategy

in memory: an evolution of attacks Mathias Payer Purdue University

CMPT 373 Software Development Methods. Design. Nick Sumner

Using Static Code Analysis to Find Bugs Before They Become Failures

Bradford J. Willke. 19 September 2007

COGNITIVE COMPLEXITY. sonarsource. A new way of measuring understandability. By G. Ann Campbell, Product Owner - SonarSource SA

Baseline Testing Services. Whitepaper Vx.x

AP COMPUTER SCIENCE JAVA CONCEPTS IV: RESERVED WORDS

Product Security Program

Debug your build by (s)tracing and reversing

How we implemented TDD in Embedded C & C++

CYSE 411/AIT681 Secure Software Engineering Topic #10. Secure Coding: Integer Security

2/9/18. Readings. CYSE 411/AIT681 Secure Software Engineering. Introductory Example. Secure Coding. Vulnerability. Introductory Example.

2/9/18. CYSE 411/AIT681 Secure Software Engineering. Readings. Secure Coding. This lecture: String management Pointer Subterfuge

IAGO ATTACKS: WHY THE SYSTEM CALL API IS A BAD UNTRUSTED RPC INTERFACE

RBS OpenEMR Multisite Setup Improper Access Restriction Remote Code Execution of 5

Software Security: Buffer Overflow Defenses

Lecture 08 Control-flow Hijacking Defenses

MEMORY SAFETY ATTACKS & DEFENSES

Achieving Continuous Delivery - Micro Services. - Vikram Gadang

One-Slide Summary. Lecture Outline. Language Security

Security Lab. Episode 6: Format String Vulnerabilities. Jan Nordholz, Matthias Petschick, Julian Vetter

Bug Finding with Under-approximating Static Analyses. Daniel Kroening, Matt Lewis, Georg Weissenbacher

Quality in Use: Achieving Stakeholder Needs for Quality

COSC Software Engineering. Lecture 16: Managing Memory Managers

McCa!"s Triangle of Quality

Container Deployment and Security Best Practices

CERT Secure Coding Initiative. Define security requirements. Model Threats 11/30/2010

Approaches, Techniques, and Tools for Identifying Important Code Changes to Help Code Reviewers

Advanced Software Development with MATLAB

goto considered not particularly harmful: defect analysis in a major numerical library"

Verification & Validation of Open Source

Adapting applications to exploit virtualization management knowledge

DDMD AND AUTOMATED CONVERSION FROM C++ TO D

Short Notes of CS201

Reply to Austin Group Concerns on PDTR 24731

Software Security Buffer Overflows more countermeasures. Erik Poll. Digital Security Radboud University Nijmegen

SECURITY TRAINING SECURITY TRAINING

Computer Components. Software{ User Programs. Operating System. Hardware

Java Embedded on ARM

IS 2620: Developing Secure Systems. Lecture 2 Sept 8, 2017

Cling: A Memory Allocator to Mitigate Dangling Pointers. Periklis Akritidis

CS201 - Introduction to Programming Glossary By

Constant-time programming in C

Transcription:

Bionic Code analysis, quality and security overview Christoph July 26 th 2017

stat /proc/self PhD on reflective OS architectures FOSS enthusiast (Linux fan since kernel 0.95) Tech support @ FraLUG (including making the coffee) IT Sec interests include: Social engineering Cognitive and behavioural psychology SDLC process optimizations and S/W quality Other assorted forms of witchcraft 2

Overview 1. Scope 2. ISO 9126 metrics 3. Attack surface analysis 4. Other observations 3

Executive summary What is it? Android runtime environment (similar to libc in standard Linux systems) Glue between kernel and remaining application stack (including Java VMs) Why is it important? Basis for all applications any security issues impact other userland What implication does this have? Attack surface analysis And mitigation 4

Android overview 5

Scope Assess Bionic code base: Against ISO 9126 maintainability aspects Identify high-level attack surface Additional findings based on further analysis Provide high-level mitigation advice 6

Assessment basis Tools: SonarQube RATS (Rough Auditing Tool for Security) Cppcheck Common sense and more than 30 years of software development expertise Various other forms of dark magic Codebase: As found on android.googlesource.com/platform/bionic.git 7

Summary Overall code quality: But: Some security risks due to insecure coding practices Also many code smells Extensive use of legacy code 8

ISO 9126 Internatonal standard for s/w quality evaluation ISO ISO 9126 9126 Functionality Usability Reliability Maintainability Analysability Changeability Stability Testability Efficiency Portability 9

Attributes of Maintainability Maintainability = Analysability: Easy to understand where and how to modify? 10 Changeability: Easy to perform modification? Stability: Easy to keep coherent when modifying? Testability: Easy to validate after modification? Maintain Analyse Change Stabilise Test 10

Simplified assessment model Analysability X X Changeability X X Stability Testability X 11

Volume Software Productivity: xloc Function points (FPs) Challenge: Expressiveness of different programming languages Approach: weigh xloc with industry-standard productivity factor Programming Languages Table 12

Volume (ctd.) Programming Languages Table: Language Level Avg. # of LOC per FP Perl 15 21 Smalltalk/V 15 21 Objective C 12 27 Haskell 8.5 38 C++ 6 53 Basic 3 107 C 2.5 128 Macro assembler 1.5 213 13

Volume (ctd.) Why this matters: Total cost Effort to rebuild overall code base Bionic volume metrics: Unit # Total LOCs 422,969 Files 3,981 Functions 5,597 Classes 9,336 Statements 63,664 14

Duplication Duplication of code reduces maintainability Substantial duplication implies high maintenance costs Substantial duplication makes bug fixing harder Substantial duplication makes testing harder 15

Duplication (ctd.) Bionic duplication metrics: Unit Total 0.9% Duplication Blocks 127 Files 49 16

Unit complexity Unit complexity is measured by McCabe s Cyclomatic Complexity Number of decision points (DPs) per unit (method/function/file) McCabe, IEEE Transactions on Software Engineering, 1976 Higher complexity makes units harder to test and change For C/C++/Objective C, increment DPs for: function definitions, while, do while, for, throw statements, return (except if it is the last statement of a function), switch, case, default, &&,,?, catch, break, continue, goto 17

Unit complexity (ctd.) Overview: Cyclomatic complexity Risk estimation 1-10 Clear code, small risk 11-20 Complex, medium risk 21-50 Very complex, high risk > 50 Not understandable, testability issues, very high risk 18

Unit complexity (ctd.) Bionic complexity metrics: Unit Complexity Function 3.4 Class 0.2 File 5.7 19

Conclusion Code analysis result: very good SQALE rating: A Est. technical debt: 17d But some security issues: Unit Occurences Vulnerabilities 1 Minor issues 74 Smells 1,634 (SQALE: Software Quality Assessment based on Lifecycle Expectations) 20

Attack surface analysis Good news: No major refactoring required Attack surface analysis: Only one major vulnerability Minor issues: Time of check / time of use issues Potential memory leaks Class initialization omissions 21

Attack surface analysis (ctd.) Attack surface analysis (ctd.): Smells: mostly string and buffer handling issues Primarily due to extensive reuse of legacy code Remedies: Extended code review Deploy static code analysis tools Fix coding issues 22

Attack surface analysis (ctd.) linker.cpp (#351): CWE-562, return of stack variable address static bool realpath_fd(int fd, std::string* realpath) { std::vector<char> buf(path_max), proc_self_fd(path_max); libc_format_buffer(&proc_self_fd[0], proc_self_fd.size(), "/proc/self/fd/%d", fd); if (readlink(&proc_self_fd[0], &buf[0], buf.size()) == -1) { PRINT("readlink(\"%s\") failed: %s [fd=%d]", &proc_self_fd[0], strerror(errno), fd); return false; } } *realpath = &buf[0]; return true; 23

Attack surface analysis (ctd.) Typical smells: libc/arch-mips/string/memcpy.c: no check on len memcpy (void *a, const void *b, size_t len) overloadable libc/arch-arm/bionic/atexit_legacy.c: nonconstant format string static char const warning[] = "WARNING: generic atexit() called from legacy shared library\n"; libc_format_log(android_log_warn, "libc", warning); fprintf(stderr, warning); 24

Overall remedies 1. Reduce attack surface by eliminating security risks (cf. previous slide) 2. Reduce complexity of selected modules 3. Reduce minor duplication by restructuring selected code base portions 4. Identify large volume units and restructure code base as applicable 25

Conclusion Sound code base despite legacy character Minimal attack surface requires no major refactoring Minor issues can be addressed without much effort Robust code base for remaining userland 26

Software sources Bionic source code: android.googlesource.com/platform/bionic.git Sonarqube: www.sonarqube.org/downloads Cppcheck: cppcheck.sourceforge.net RATS: code.google.com/archive/p/roughauditing-tool-for-security/downloads 27

Discussion / questions 28

Thank you! 2017 CC BY-SA Christoph monochromec@gmail.com 29