Homework 1 – due Friday Lab1 – due next Wednesday Section
- will talk about gdb, etc.
Assignments Homework 1 due Friday Lab1 due next Wednesday - - PowerPoint PPT Presentation
Assignments Homework 1 due Friday Lab1 due next Wednesday Section - will talk about gdb, etc. Approaches to Fin inding Security Bugs 2 Runtime Monitoring Black-box Testing Static Analysis From Coverity 3
2
3
ash Causing using Defects ects
l pointer nter der eref efere erence nce
e after er free ee
uble free ee
ray index dexing ing error rors
smatched ed arr rray ay new/ w/delete delete
Potent ential ial stack ack over errun un
ential ial heap ap ove verrun run
urn point inters ers to lo loca cal var ariables iables
gically inconsistent consistent code de
nitial ialized ized var ariables iables
valid id use e of negat gative ive values lues
Pass ssing ing large ge param rameters eters by value lue
der-all allocat
ions s of dynam namic ic data
mory ry leaks aks
ndle e leaks ks
work k res esourc
e leak aks
used values lues
handled led retur urn codes des
e of inva valid id itera rators
5
Some coding patterns and
some vulnerabilities are specific to the code base
Issues that apply to the Linux
kernel are unlikely to apply in application software
6
7 Prototype for open() syscall: Typical mistake: Force setting explicit file perm
rmissions!
Check: Look for oflags == O_CREAT without mode
argument
int open(const char *path, int oflag, /* mode_t mode */...);
fd = open(“file”, O_CREAT);
Goal: confine process to a “jail” on the filesystem
chroot() changes filesystem root for a process
Problem
chroot() itself does not change current working
directory
chroot() chdir(“/”)
Error if open before chdir
9
Linux: 125 errors, 24 false; BSD: 12 errors, 4 false
array[v] while(i < v) … v.clean
Use(v)
v.tainted Syscall param Network packet copyin(&v, p, len) memcpy(p, q, v) copyin(p,q,v) copyout(p,q,v)
ERROR
Warn when unchecked integers from untrusted sources reach trusting sinks
11 11
12 12
d is read from the user Signed integer d.idx is upper-bound checked but not lower-bound checked d.used is unchecked, allowing 2GB of user data to be copied into the kernel
/* 2.4.5/drivers/char/drm/i810_dma.c */ if(copy_from_user(&d, arg, sizeof(arg))) return –EFAULT; if(d.idx > dma->buf_count) return –EINVAL; buf = dma->buflist[d.idx]; Copy_from_user(buf_priv->virtual, d.address, d.used);
13 13
msg points to arbitrary network data This can be used to overflow cmd and write data
/* 2.4.9/drivers/isdn/act2000/capi.c:actcapi_dispatch */ isdn_ctrl cmd; ... while ((skb = skb_dequeue(&card->rcvq))) { msg = skb->data; ... memcpy(cmd.parm.setup.phone, msg->msg.connect_ind.addr.num, msg->msg.connect_ind.addr.len - 1);
We would want to
15 15
atoi main exit free malloc printf fgets say_hello
16 16
char * buf[8]; if (a) b = new char [5]; if (a && b) buf[8] = a; delete [] b; *b = ‘x’; END *a = *b; a !a a && b !(a && b)
17 17
Represent logical structure of code in graph form
char * buf[8]; if (a) b = new char [5]; if (a && b) buf[8] = a; delete [] b; *b = ‘x’; END *a = *b; a !a a && b !(a && b)
18 18
Conceptually: Analyze each path through control graph separately Actually Perform some checking computation once per node; combine paths at merge nodes Conceptually Actually
char * buf[8]; if (a) if (a && b) delete [] b; *b = ‘x’; END *a = *b; !a !(a && b)
19 19
Null ll po poin inters Use Use aft fter fr free Arr Array over errun
See how three checkers are run for this path
transitions and error states Checker
previous point, program actions
Run Checker
char * buf[8]; if (a) if (a && b) delete [] b; *b = ‘x’; END *a = *b; !a !(a && b)
20 20
Null pointers Use after free Array overrun “buf is 8 bytes”
char * buf[8]; if (a) if (a && b) delete [] b; *b = ‘x’; END *a = *b; !a !(a && b)
21 21
Null pointers Use after free Array overrun “buf is 8 bytes” “a is null”
char * buf[8]; if (a) if (a && b) delete [] b; *b = ‘x’; END *a = *b; !a !(a && b)
22 22
Null pointers Use after free Array overrun “buf is 8 bytes” “a is null” Already knew a was null
char * buf[8]; if (a) if (a && b) delete [] b; *b = ‘x’; END *a = *b; !a !(a && b)
23 23
Null pointers Use after freeArray overrun “buf is 8 bytes” “a is null” “b is deleted”
char * buf[8]; if (a) if (a && b) delete [] b; *b = ‘x’; END *a = *b; !a !(a && b)
24 24
Null pointers Use after free Array overrun “buf is 8 bytes” “a is null” “b is deleted” “b dereferenced!”
char * buf[8]; if (a) if (a && b) delete [] b; *b = ‘x’; END *a = *b; !a !(a && b)
25 25
Null pointers Use after free Array overrun “buf is 8 bytes” “a is null” “b is deleted” “b dereferenced!”
No more errors reported for b
26 26 What is a bug? Something the user will fix. Many sources of false positives
False paths Idioms Execution environment assumptions Killpaths Conditional compilation “third party code” Analysis imprecision …
char * buf[8]; if (a) b = new char [5]; if (a && b) buf[8] = a; delete [] b; *b = ‘x’; END *a = *b; a !a a && b !(a && b)
27 27
char * buf[8]; if (a) if (a && b) buf[8] = a; END !a a && b
28 28
Integer Range Disequality Branch
char * buf[8]; if (a) if (a && b) buf[8] = a; END !a a && b
29 29
“a in [0,0]” “a == 0 is true” Integer Range Disequality Branch
char * buf[8]; if (a) if (a && b) buf[8] = a; END !a a && b
30 30
“a in [0,0]” “a == 0 is true” “a != 0” Integer Range Disequality Branch
char * buf[8]; if (a) if (a && b) buf[8] = a; END !a a && b
31 31
“a in [0,0]” “a == 0 is true” “a != 0”
Impossible
Integer Range Disequality Branch
32 32
Stanford research project Ken Ashcraft and Dawson Engler, Using
Used modified compiler to find over 100 security
33 33
Gain control of system 18 15 3 3 Corrupt memory 43 17 2 2 Read arbitrary memory 19 14 7 7 Denial of service 17 5 0 0 Minor 28 1 0 0 Total 125 52 12 12 Linux BSD Violation Bug Fixed Bug Fixed