Pointer Authentication, ASLR, and Intro to Cryptography
CS 161 Spring 2022 - Lecture 6
Computer Science 161
Nicholas Weaver
Announcements
2
Computer Science 161
Nicholas Weaver
Mitigation: Pointer Authentication
3
Textbook Chapter 4.10
Computer Science 161
Nicholas Weaver
Recall: Putting Together an Attack
We can defend against memory safety vulnerabilities by making each of these steps more difficult (or impossible)!
4
Computer Science 161
Nicholas Weaver
Reminder: 32-Bit and 64-Bit Processors
5
Computer Science 161
Nicholas Weaver
Pointer Authentication
6
Computer Science 161
Nicholas Weaver
Pointer Authentication: Properties of the PAC
7
Computer Science 161
Nicholas Weaver
Subverting Pointer Authentication
8
Computer Science 161
Nicholas Weaver
Defenses Against Pointer Reuse
9
Computer Science 161
Nicholas Weaver
Pointer Authentication on ARM v8.3 (e.g. Apple M1)
10
Computer Science 161
Nicholas Weaver
Pointer Authentication on ARM v8.3 (e.g. Apple M1)
11
foo:
# Prologue: Store canary on stack
la t0, CANARY_ADDR
lw t0, 0(t0)
sw t0, 12(sp)
...
# Epilogue: Check canary on stack
la t0, CANARY_ADDR
lw t0, 0(t0)
lw t1, 12(sp)
bne t0, t0, CANARY_FAILED
Before: Stack canaries
foo:
# Prologue: Auth ra using IA secret
pacia ra
...
# Epilogue: Check ra using IA secret
autia ra
After: Pointer auth (using RISC-V syntax)
Computer Science 161
Nicholas Weaver
Pointer Authentication on ARM
12
Computer Science 161
Nicholas Weaver
Pointer Authentication on ARM
13
Computer Science 161
Nicholas Weaver
Mitigation: Address Space Layout Randomization (ASLR)
14
Textbook Chapter 4.11 & 4.12
Computer Science 161
Nicholas Weaver
Recall: Putting Together an Attack
We can defend against memory safety vulnerabilities by making each of these steps more difficult (or impossible)!
15
Computer Science 161
Nicholas Weaver
Recall: x86 Memory Layout
16
Higher addresses
Lower addresses
Stack |
|
Heap |
Data |
Code |
Grows upwards
In theory, x86 memory layout looks like this...
Grows downwards
Computer Science 161
Nicholas Weaver
Recall: x86 Memory Layout
17
Higher addresses
Lower addresses
Stack |
|
Heap |
Data |
Code |
Grows downwards
Grows upwards
In theory, x86 memory layout looks like this...
Higher addresses
Lower addresses
Unused |
Stack |
Unused |
Heap |
Unused |
Data |
Unused |
Code |
Unused |
...but in practice, it usually looks like this (mostly empty)!
Computer Science 161
Nicholas Weaver
Recall: x86 Memory Layout
18
Higher addresses
Lower addresses
|
Stack |
|
Heap |
|
Data |
|
Code |
|
Idea: Put each segment of memory in a different location each time the program is run
|
Heap |
|
Data |
|
Code |
|
Stack |
|
Computer Science 161
Nicholas Weaver
Address Space Layout Randomization
19
Computer Science 161
Nicholas Weaver
ASLR: Efficiency
20
Computer Science 161
Nicholas Weaver
Subverting ASLR
21
Computer Science 161
Nicholas Weaver
Relative Addresses
22
void vulnerable(char *dest) {
// Format string vulnerability
printf(dest);
}
int main(void) {
int secret = 42;� char buf[20];
fgets(buf, 20, stdin);
vulnerable(buf);
}
... | ... | ... | ... |
... | ... | ... | ... |
... | ... | ... | ... |
RIP of main | |||
SFP of main | |||
secret = 42 | |||
buf | |||
buf | |||
buf | |||
buf | |||
buf | |||
dest (arg to vulnerable) | |||
RIP of vulnerable | |||
SFP of vulnerable | |||
format (arg to printf) |
We know that the SFP is a pointer to the stack. How would you print the value of the SFP?
secret is 4 bytes below where the SFP points, so its address is 0xbfff0404!
Input:
'%x'
If the output is bfff0408, what is the address of secret?
Computer Science 161
Nicholas Weaver
Combining Mitigations
23
Textbook Chapter 4.13
Computer Science 161
Nicholas Weaver
Combining Mitigations
24
Computer Science 161
Nicholas Weaver
Combining Mitigations
25
Computer Science 161
Nicholas Weaver
Enabling Mitigations
26
Computer Science 161
Nicholas Weaver
Enabling Mitigations: CISCO
27
Computer Science 161
Nicholas Weaver
Enabling Mitigations: Internet of Things
Takeaway: Many (most?) IoT devices don’t enable basic mitigations
28
Qualys Security Blog | |
CVE-2021-3156: Heap-Based Buffer Overflow in Sudo (Baron Samedit) | |
Animesh Jain | January 26, 2021 |
The Qualys Research Team has discovered a heap overflow vulnerability in sudo, a near-ubiquitous utility available on major Unix-like operating systems. Any unprivileged user can gain root privileges on a vulnerable host using a default sudo configuration by exploiting this vulnerability. |
Computer Science 161
Nicholas Weaver
Summary: Memory Safety Mitigations
29
Computer Science 161
Nicholas Weaver
Summary: Memory Safety Mitigations
30
Computer Science 161
Nicholas Weaver
Next Unit: Cryptography
31
Computer Science 161
Nicholas Weaver
What is cryptography?
32
Textbook Chapter 5.1
Computer Science 161
Nicholas Weaver
What is cryptography?
33
Computer Science 161
Nicholas Weaver
Don’t try this at home!
34
This appears when someone makes a small mistake in cryptography and breaks everything.
Computer Science 161
Nicholas Weaver
Don’t try this at home!
35
Computer Science 161
Nicholas Weaver
Definitions
36
Textbook Chapter 5.3–5.9
Computer Science 161
Nicholas Weaver
Meet Alice, Bob, Eve, and Mallory
37
Computer Science 161
Nicholas Weaver
Meet Alice, Bob, Eve, and Mallory
38
Computer Science 161
Nicholas Weaver
Three Goals of Cryptography
39
Computer Science 161
Nicholas Weaver
Keys
40
Computer Science 161
Nicholas Weaver
Security Principle: Kerckhoff’s Principle
41
Computer Science 161
Nicholas Weaver
Confidentiality
42
Message
Key
Lock
Message in locked box
Key
Unlock
Message
Alice
Bob
Insecure Channel
Computer Science 161
Nicholas Weaver
Confidentiality
43
Message
Key
Encryption Algorithm
Encrypted Message
Key
Decryption Algorithm
Message
Alice
Bob
Insecure Channel
Computer Science 161
Nicholas Weaver
Confidentiality
44
Plaintext
Key
Encryption Algorithm
Ciphertext
Key
Decryption Algorithm
Plaintext
Alice
Bob
Insecure Channel
Computer Science 161
Nicholas Weaver
Integrity (and Authenticity)
45
Message
Key
Create Seal
Message
Key
Check Seal
Message
Alice
Bob
Insecure Channel
Seal
Computer Science 161
Nicholas Weaver
Integrity (and Authenticity)
46
Message
Key
Create Tag
Message
Key
Check Tag
Message
Alice
Bob
Insecure Channel
Tag
Computer Science 161
Nicholas Weaver
Threat Models
47
| Can Eve trick Alice into encrypting messages of Eve’s choosing? | Can Eve trick Bob into decrypting messages of Eve’s choosing? |
Ciphertext-only | No | No |
Chosen-plaintext | Yes | No |
Chosen-ciphertext | No | Yes |
Chosen plaintext-ciphertext | Yes | Yes |
Computer Science 161
Nicholas Weaver
Threat Models
48
| Can Eve trick Alice into encrypting messages of Eve’s choosing? | Can Eve trick Bob into decrypting messages of Eve’s choosing? |
Ciphertext-only | No | No |
Chosen-plaintext | Yes | No |
Chosen-ciphertext | No | Yes |
Chosen plaintext-ciphertext | Yes | Yes |
Computer Science 161
Nicholas Weaver
A Brief History of Cryptography
49
Textbook Chapter 5.2
Computer Science 161
Nicholas Weaver
Cryptography by Hand: Caesar Cipher
50
K = 3 | |||
M | C | M | C |
A | D | N | Q |
B | E | O | R |
C | F | P | S |
D | G | Q | T |
E | H | R | U |
F | I | S | V |
G | J | T | W |
H | K | U | X |
I | L | V | Y |
J | M | W | Z |
K | N | X | A |
L | O | Y | B |
M | P | Z | C |
Computer Science 161
Nicholas Weaver
Cryptography by Hand: Attacks on the Caesar Cipher
51
+1 IBJM DBFTBS
+2 HAIL CAESAR
+3 GZHK BZDRZQ
+4 FYGJ AYCQYP
+5 EXFI ZXBPXO
+6 DWEH YWAOWN
+7 CVDG XVZNVM
+8 BUCF WUYMUL
+9 ATBE VTXLTK
+10 ZSAD USWKSJ
+11 YRZC TRVJRI
+12 XQYB SQUIQH
+13 WPXA RPTHPG
+14 VOWZ QOSGOF
+15 UNVY PNRFNE
+16 TMUX OMQEMD
+17 SLTW NLPDLC
+18 RKSV MKOCKB
+19 QJRU LJNBJA
+20 PIQT KIMAIZ
+21 OHPS JHLZHY
+22 NGOR IGKYGX
+23 MFNQ HFJXFW
+24 LEMP GEIWEV
+25 KDLO FDHVDU
Computer Science 161
Nicholas Weaver
Cryptography by Hand: Attacks on the Caesar Cipher
52
Computer Science 161
Nicholas Weaver
Cryptography by Hand: Substitution Cipher
53
K | |||
M | C | M | C |
A | N | N | G |
B | Q | O | P |
C | L | P | T |
D | Z | Q | A |
E | K | R | J |
F | R | S | O |
G | V | T | D |
H | U | U | I |
I | E | V | C |
J | S | W | F |
K | B | X | M |
L | W | Y | X |
M | Y | Z | H |
Computer Science 161
Nicholas Weaver
Cryptography by Hand: Attacks on Substitution Ciphers
54
K | |||
M | C | M | C |
A | N | N | G |
B | Q | O | P |
C | L | P | T |
D | Z | Q | A |
E | K | R | J |
F | R | S | O |
G | V | T | D |
H | U | U | I |
I | E | V | C |
J | S | W | F |
K | B | X | M |
L | W | Y | X |
M | Y | Z | H |
Computer Science 161
Nicholas Weaver
Takeaways
55
Computer Science 161
Nicholas Weaver
Cryptography by Machines: Enigma
56
Plugboard
Rotors
Computer Science 161
Nicholas Weaver
Enigma Operating Principle: Rotor Machine
57
Computer Science 161
Nicholas Weaver
Cryptography by Machines: Enigma
58
Computer Science 161
Nicholas Weaver
Cryptography by Machines: Attack on Enigma
59
BOMBE machine
Computer Science 161
Nicholas Weaver
Cryptography by Machines: Legacy of Enigma
60
Alan Turing
Computer Science 161
Nicholas Weaver
Cryptography by Computers
61
One of these is Diffie, and the other one is Hellman.
Computer Science 161
Nicholas Weaver
Cryptography Roadmap
62
| Symmetric-key | Asymmetric-key |
Confidentiality |
|
|
Integrity,�Authentication |
|
|
Computer Science 161
Nicholas Weaver