65
Secure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016

Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

  • Upload
    others

  • View
    10

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Secure Programming Lecture 1:Introduction

David Aspinall, Informatics @ Edinburgh

12th January 2016

Page 2: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Orientation

É This course is Secure Programming.É Aimed at Informatics 4th year and MSc studentsÉ Primarily: those anticipating a career in software

É programming: architects, developers, testers, dotsÉ security: pentesters, malware/reverse engineersÉ researchers: verification, compilers, language

design, dots

É It is taught by David Aspinall.É I am a Reader in the School of Informatics at the

University of Edinburgh.

Page 3: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Outline

Recent motivations

Course syllabus

Software security overview

Practicalities

Structure of course

An example: overflow in X server

Summary

Page 4: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Heartbleed (2014)

Page 5: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Shellshock (2014)

Page 6: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Attacks can cause physical damage (2014)

Page 7: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Nobody can keep online records safe (2015)

Page 8: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Known good practice ignored (2015)

Page 9: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Why does this happen?

Ostensibly, many security failures are due tosoftware vulnerabilities.

Are they inevitable?

Many surrounding questions. Can we:

É find vulnerabilities (before attacks)?É detect exploits in-the-wild?É repair vulnerabilities (routinely/automatically)?É program better to avoid vulnerabilities?É measure risk associated with software?É design or verify to prevent them?É develop new technology to help the above?

Page 10: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Outline

Recent motivations

Course syllabus

Software security overview

Practicalities

Structure of course

An example: overflow in X server

Summary

Page 11: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

What is this course about?Mainly: building software that’s more secure

É finding security flaws in existing softwareÉ avoiding flaws in new softwareÉ techniques, tools and understanding to do this

also infrastructure around software:

É language, libraries, run-time; other programsÉ data storage, distribution, protocols and APIsÉ development methodologies

and in the first place, policies for security

É what should be protectedÉ who/what is trustedÉ risk assessment: cost of defences.

Page 12: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Target audience

É Aimed at 4th year UGs, MSc by permissionÉ Should have passed 3rd year Computer Security

É Basic crypto, protocols, secure prog ideas

É Programming practiceÉ should be confident in programmingÉ necessarily will use a range of languagesÉ . . . including some CÉ but don’t have be “master hacker”

É Programming theoryÉ interest in PL concepts and designÉ knowledge of compilers usefulÉ also software engineering, esp, testingÉ theory courses helpful, semantics

Page 13: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Why should you take this course?

Want to work in the cyber security industry?

É security appraisal, system and code reviewingÉ pen-testing, ethical hackingÉ malware analysis, reverse engineeringÉ operations and response (SOCs)É innovation: start-ups, spin-outsÉ cyber defence, attack, espionageÉ Want to work in security research?É academic (conceptual advances, fixing, breaking)É commercial (breaking, fixing, defending)

(Hopefully): you think it’s fun and interesting!

Page 14: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Why should you not take this course?

É None of the previous points applyÉ You don’t have the right background (see next slide)É You don’t want to risk a relatively new course

É second time to run (2013/14 first time)É still “bedding in”É honest, constructive feedback is very welcome

Page 15: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Learning outcomes

Here is the list from the Course Catalogue Entry:

1. Know how to respond to security alerts (concerningsoftware)

2. Identify possible security programming errors whenconducting code reviews in languages such as Java,C or Python

3. Define a methodology for security testing and useappropriate tools in its implementation

4. Apply new security-enhanced programming modelsand tools which help ensure security goals, e.g., withaccess control, information flow tracking, protocolimplementation, or atomicity enforcement.

Page 16: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Learning outcomes

Here is the list from the Course Catalogue Entry:

1. Know how to respond to security alerts (concerningsoftware)

2. Identify possible security programming errors whenconducting code reviews in languages such as Java,C or Python

3. Define a methodology for security testing and useappropriate tools in its implementation

4. Apply new security-enhanced programming modelsand tools which help ensure security goals, e.g., withaccess control, information flow tracking, protocolimplementation, or atomicity enforcement.

Page 17: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Learning outcomes

Here is the list from the Course Catalogue Entry:

1. Know how to respond to security alerts (concerningsoftware)

2. Identify possible security programming errors whenconducting code reviews in languages such as Java,C or Python

3. Define a methodology for security testing and useappropriate tools in its implementation

4. Apply new security-enhanced programming modelsand tools which help ensure security goals, e.g., withaccess control, information flow tracking, protocolimplementation, or atomicity enforcement.

Page 18: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Learning outcomes

Here is the list from the Course Catalogue Entry:

1. Know how to respond to security alerts (concerningsoftware)

2. Identify possible security programming errors whenconducting code reviews in languages such as Java,C or Python

3. Define a methodology for security testing and useappropriate tools in its implementation

4. Apply new security-enhanced programming modelsand tools which help ensure security goals, e.g., withaccess control, information flow tracking, protocolimplementation, or atomicity enforcement.

Page 19: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Outline

Recent motivations

Course syllabus

Software security overview

Practicalities

Structure of course

An example: overflow in X server

Summary

Page 20: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Safety versus security

Safety is concerned with ensuring bad things don’thappen accidently. For example, aeroplanes don’t fallout of the sky because maintenance checks areforgotten.

Security is concerned with with ensuring that badthings don’t happen because of malicious actions byothers. For example, terrorists cannot drive bombs intoairport departure halls.

The distinction is sometimes blurred, and the twointeract in intriguing ways. (Q. why?)

Page 21: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

The challenge of software security

Software artefacts are among the most complex built.

É Design flaws are likely

É Bugs seem inevitable

Flaws and bugs lead to vulnerabilities which areexploited by attackers.

Often to learn secrets, obtain money. But many otherreasons: a security risk assessment for a system shouldconsider different attackers and their motives.

Page 22: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

The challenge of software security

Software artefacts are among the most complex built.

É Design flaws are likelyÉ Bugs seem inevitable

Flaws and bugs lead to vulnerabilities which areexploited by attackers.

Often to learn secrets, obtain money. But many otherreasons: a security risk assessment for a system shouldconsider different attackers and their motives.

Page 23: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

The challenge of software security

Software artefacts are among the most complex built.

É Design flaws are likelyÉ Bugs seem inevitable

Flaws and bugs lead to vulnerabilities which areexploited by attackers.

Often to learn secrets, obtain money. But many otherreasons: a security risk assessment for a system shouldconsider different attackers and their motives.

Page 24: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

The challenge of software security

Software artefacts are among the most complex built.

É Design flaws are likelyÉ Bugs seem inevitable

Flaws and bugs lead to vulnerabilities which areexploited by attackers.

Often to learn secrets, obtain money. But many otherreasons: a security risk assessment for a system shouldconsider different attackers and their motives.

Page 25: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Cost estimates are difficult

Page 26: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

But it’s agreed they’re increasing. . .

Page 27: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Cyber warfare is real

Page 28: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Privacy is being eroded

Page 29: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Why isn’t software security better?

Page 30: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Why (else) isn’t software security better?

É Asymmetry: attackers have the advantageÉ just need to find one viable attack routeÉ defenders have to anticipate all

É Attackers focus on weakest links:É since 1990s, network defences vastly improvedÉ rise of insider threats

É Current penetrate-and-patch approach is brokenÉ understandable by managers (“show me the

problem!”)É but no substitute for secure design

Page 31: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

What’s the outlook?

New frontiers:

É PCs in decline, but connected devices increasingÉ Mobile new target point (convergence, mobility)É Internet of Things: repeating same mistakes!É Cloud storage: storage providers, protocolsÉ Cyber resilience: speedy, automatic recoveryÉ Data sharing and its limits: privacy

New solutions:

É More and easier-to-use secure programmingÉ Defensive technologies continuing to evolveÉ New cryptographic, verification techniquesÉ Old ideas re-appear: MLS, containment, isolationÉ Updates: automatic, pushed patching

Page 32: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Outline

Recent motivations

Course syllabus

Software security overview

Practicalities

Structure of course

An example: overflow in X server

Summary

Page 33: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Delivery and assessment

We will have

É 16 lectures covering core course topics

É 3 lab sessionsÉ 1 coursework contributing 30% of final markÉ 1 written exam contributing 70% of final mark

Lecture slides will be made available in several formats.

They have numerous embedded links to useful resources(the links are more noticeable in the online versions).

Page 34: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Delivery and assessment

We will have

É 16 lectures covering core course topicsÉ 3 lab sessions

É 1 coursework contributing 30% of final markÉ 1 written exam contributing 70% of final mark

Lecture slides will be made available in several formats.

They have numerous embedded links to useful resources(the links are more noticeable in the online versions).

Page 35: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Delivery and assessment

We will have

É 16 lectures covering core course topicsÉ 3 lab sessionsÉ 1 coursework contributing 30% of final mark

É 1 written exam contributing 70% of final mark

Lecture slides will be made available in several formats.

They have numerous embedded links to useful resources(the links are more noticeable in the online versions).

Page 36: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Delivery and assessment

We will have

É 16 lectures covering core course topicsÉ 3 lab sessionsÉ 1 coursework contributing 30% of final markÉ 1 written exam contributing 70% of final mark

Lecture slides will be made available in several formats.

They have numerous embedded links to useful resources(the links are more noticeable in the online versions).

Page 37: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Delivery and assessment

We will have

É 16 lectures covering core course topicsÉ 3 lab sessionsÉ 1 coursework contributing 30% of final markÉ 1 written exam contributing 70% of final mark

Lecture slides will be made available in several formats.

They have numerous embedded links to useful resources(the links are more noticeable in the online versions).

Page 38: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Delivery and assessment

We will have

É 16 lectures covering core course topicsÉ 3 lab sessionsÉ 1 coursework contributing 30% of final markÉ 1 written exam contributing 70% of final mark

Lecture slides will be made available in several formats.

They have numerous embedded links to useful resources(the links are more noticeable in the online versions).

Page 39: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Lab sessions

Three 3hrs lab sessions.

Scheduled TBC.

É Week 4É Week 6É Week 8

Each session will examine some software vulnerabilities:why they exist, how they can be discovered, exploited,and repaired.

Labs may start with a short guided introduction.

Working together is encouraged. We want to fostera supportive learning environment. Students who haveprior knowledge or expertise are especially welcome.

Page 40: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Formative feedback during Labs

One reason to introduce labs in this course is to allow usto give face-to-face formative feedback on yourlearning. medskip

We will do this by reviewing the results from one labsession at the next lab session. To do this effectively wewill ask that you submit your work and/or discuss itwith us during the lab sessions. bigskip

Lab sessions will be run by me together with the courseTAs, who are Joseph Hallett and Arthur Chan.

Page 41: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Coursework

The coursework will be an assignment following a similarpattern to the lab exercises: discover, exploit thenrepair.

1. as usual: your work should be your own2. no publication, please do not publish solutions

even after the deadline

(at least two reasons for last point).

The coursework deadline is scheduled for Week 8.

Page 42: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

An ethical point (reminder)

Nothing in this course is intended as incitementto crack into running systems!

É Breaking into systems to “demonstrate” securityproblems at best causes a headache to overworkedsysadmins, at worst compromises systems for manyusers and could lead to prosecution

É If you spot a security hole in a running system,don’t exploit it, instead contact the relevantadministrators or developers confidentially.

É To experiment with security holes, play with yourown machine, or better, your own privatenetwork of machines.

Page 43: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Communications

É New, evolving course:É honest, constructive feedback is very welcome

É As with any course, I welcomeÉ questions after lecturesÉ questions by email

Shall we have a course-wide online facility? Open toclass opinion:

1. University forum (private in UoE)2. University VLE tool (Learn)3. Piazza for questions, discussion (signup)4. None, but FAQs sent to class list sp-students by

email

Piazza is ready to use.

Page 44: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Exam

Will follow the common format:

É Choose 2 questions to answer from 3É Two hours allowed

Towards the end of the course I will provide:

É a list of topics and concepts that may be examinedÉ a hint about the format of the questions

There is some guidance on the web along with a samplequestion.

Page 45: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Outline

Recent motivations

Course syllabus

Software security overview

Practicalities

Structure of course

An example: overflow in X server

Summary

Page 46: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Dimensions: practice and theoryPractice

É Programming securely, identifying security issuesÉ Mistakes in language, APIs, crypto, comms. . .É Ultimately: detailed, highly specific knowledge

Theory

É Understand reasons for failure, ways to mitigateÉ Understand advanced techniques, automated toolsÉ In general: transferable concepts and methods.

This is not really a “vocational” course. I hope it will giveyou the foundation to allow you to rapidly developdetailed specific knowledge needed later. There are anumber of certification schemes for building practicalknowledge.

Page 47: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Overview of topics

General organisation:

1. Threats2. Vulnerabilities3. Defences4. Processes5. Emerging Methods

We’ll look at details under each of these headings (invarious orders).

Page 48: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

1. Threats

É What attackers want, can doÉ Types of bad code: malware, spyware, PUPsÉ How bad code gets inÉ Classification of vulnerabilities and weaknesses,

CVE/CWEs

Page 49: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

2. Vulnerabilities

É Overflows – example nextÉ InjectionsÉ Race conditionsÉ Information leaks

Page 50: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

3. Defences

É Protection mechanismsÉ Avoidance by secure codingÉ Trade-offs in adding protection mechanisms

Page 51: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

4. Processes

É Secure design principlesÉ Testing and reviewing to find vulnerabilitiesÉ Assessing/measuring security of code

Page 52: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

5. Emerging methods

É Methods and tools to find problemsÉ Detecting buggy patterns automaticallyÉ Building security in, methodology and technology

Page 53: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Outline

Recent motivations

Course syllabus

Software security overview

Practicalities

Structure of course

An example: overflow in X server

Summary

Page 54: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

1. Threats

General aim: services running on Unix systems shouldbe robust against local and remote attackers.

Otherwise: attackers may exploit a service to cause aDoS attack, gain access to a system, etc.

For a specific system, a threat analysis would considerthe kinds of attackers and their motives (local? remote?what is being protected?) and then all the servicesrunning on the system.

Question. What’s the easiest form of defence?

Page 55: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

2. Vulnerability

A security review should first discover (and thenmonitor) relevant published security advisories.

For high value situations (and application code),dedicated review may be needed.

Jan. 7, 2014 - Stack buffer overflow in parsing of BDFfont files in libXfontCVE-2013-6462: An authenticated X client can causean X server to read a font file that overflows a buffer onthe stack in the X server, potentially leading to crashand/or privilege escalation in setuid servers. The fix isincluded in libXfont 1.4.7. See the advisory for moredetails.

Page 56: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

What is a BDF file?

STARTFONT 2.1COMMENTCOMMENT Copyright (c) 1999, Thomas A. FineCOMMENT...FONT -atari-smallSIZE 11 75 75FONTBOUNDINGBOX 4 8 0 -1STARTCHAR C000ENCODING 0SWIDTH 1 0DWIDTH 4 0BBX 4 8 0 -1BITMAP0000...

É BDF = Bitmap Distribution FormatÉ A (mostly) obsolete font format by Adobe

Page 57: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Advisory: DescriptionScanning of the libXfont sources with the cppcheck staticanalyzer included a report:

[lib/libXfont/src/bitmap/bdfread.c:341]: (warning)scanf without field width limits can crash...

Evaluation of this report by X.Org developers concludedthat a BDF font file containing a longer than expectedstring could overflow the buffer on the stack.Testing in X servers built with Stack Protector resulted inan immediate crash when reading a user-providedspecially crafted font.

As libXfont is used to read user-specified font files in all Xservers distributed by X.Org, including the Xorg serverwhich is often run with root privileges or as setuid-root inorder to access hardware, this bug may lead to anunprivileged user acquiring root privileges insome systems.

Page 58: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Advisory: Affected Versions

This bug appears to have been introduced in the initialRCS version 1.1 checked in on 1991/05/10, and isthus believed to be present in every X11 releasestarting with X11R5 up to the current libXfont 1.4.6.(Manual inspection shows it is present in the sourcesfrom the X11R5 tarballs, but not in those from the X11R4tarballs.)

Page 59: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

The vulnerability in the code

338 char charName[100];339 int ignore;340

341 if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) {342 bdfError("bad character name in BDF filen");343 goto BAILOUT; /* bottom of function, free and return error */344 }

Page 60: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

The vulnerability in the code338 char charName[100];339 int ignore;340

341 if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) {342 bdfError("bad character name in BDF filen");343 goto BAILOUT; /* bottom of function, free and return error */344 }

SYNOPSIS

#include <stdio.h>

int sscanf(const char *str, const char*format, ...);

DESCRIPTION

sscanf() scans input from the character string pointedto by str, according to format string. This may containconversions; results are stored in locations pointed to bythe pointer arguments that follow format.

Page 61: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Advisory: Fix

diff --git a/src/bitmap/bdfread.c b/src/bitmap/bdfread.cindex e2770dc..e11c5d2 100644--- a/src/bitmap/bdfread.c+++ b/src/bitmap/bdfread.c@@ -338,7 +338,7 @@ bdfReadCharacters(FontFilePtr file, FontPtr pFont, bdfFileState *pState,

char charName[100];int ignore;

- if (sscanf((char *) line, "STARTCHAR %s", charName) != 1) {+ if (sscanf((char *) line, "STARTCHAR %99s", charName) != 1) {

bdfError("bad character name in BDF filen");goto BAILOUT; /* bottom of function, free and return error */

}

The text above is an example of a context diff which shows thedifference between two file versions. The patch command can be

used to update the older file given this text. You need to know howto make and apply patches for this course.

Page 62: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Defences

Options:

É Disable serviceÉ Repair service: downstream updatesÉ Mitigate impact of attack

In running systems:

É Have there been past attacks?É Can we check for future ones?

Page 63: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Outline

Recent motivations

Course syllabus

Software security overview

Practicalities

Structure of course

An example: overflow in X server

Summary

Page 64: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

Review questions

Safety versus Security

É Explain the difference between these two, and whyensuring security may be harder.

Security flaws and their impact on society.

É Explain some recent secure programming flaws thatmade the news and explain what the underlyingproblems were.

É Discuss the fundamental reasons that softwaresecurity fails and the wider questions around cybersecurity.

Page 65: Secure Programming Lecture 1: IntroductionSecure Programming Lecture 1: Introduction David Aspinall, Informatics @ Edinburgh 12th January 2016 Orientation É This course is Secure

References and reading

The slides contain links which you can click on to findreferenced or connected material.

References and reading will also be given for eachlecture in a separate web page for that lecture. For thislecture, see here.

There is no single recommended course textbook,although a few books will be mentioned. See the pageabove for pointers.