Software Security

Memory Model

0xFFFFFFFF0x00000000textdataheapstackstores variables,return address,argumentsflexible, dynamic memoryglobal / static datacode

Stack Buffer Overflows

old frame pointerframe pointerarguments, ra, vars...stack pointer...

When a new function is called, the current position of the frame pointer is saved in the stack, and the frame pointer changes to point at its location. The stack pointer decreases (because the stack grows downward) to “allocate” more memory. When the function ends, the stack pointer is changed to match the frame pointer, and the frame pointer takes the value of the old frame pointer.

What happens if we try to write to more memory than allocated?

void func(char *str){
	char buf[128];
	strcpy(buf, str);
	use(buf);
}

strcpy will copy the contents of the string until it reaches a \0. If it contains more than 128 chars, then there will be a buffer overflow, and the attacker will be able to write code to the stack. By overwriting the return address, it is possible to make the program run code that was not intended.

Heap Buffer Overflow

Similar to stack buffer overflows, but, since it depends on dynamic memory allocation, it can vary across OS and hardware, so exploiting it is much harder. Candidate targets can include function pointers, exception handlers, ...

Data Execution Prevention (DEP) and Address Space Layout Randomization (ASLR)

Systems Security

Fundamental Principles

Reference Monitor

To cause critical damage, a user-mode process has to invoke a system call. So, implementing monitoring mechanisms that control the security perimeter can prevent attacks. It has to always be present, if it terminates, then all monitored processes have to be terminated (fail-safe defaults). It also has to be simple, to make it easier to analyze without validating the whole system (economy of mechanism).

System Calls

application program...pid = getpid();...library functiongetpid() { ... syscall ... return;}1user modesystem callsys_getpid(){ return current->pid;}kernelentry_SYSCALL_64 ... call sys_call_table ... sysretqkernel mode2345

B
C (talvez A)

A

A
A
B
A
A
D
A
B
C
B

A
D
D
A
A
D
B
B
B

B
D
C
B
D

#REsit 1

A
C
D
B

C
A (d se o prof n fumasse)
C
A
A
D
A

C
C

A
D
D
A
A
D
B
D
C
C

B
D
C
C
A
B