From 3941378c4f463b3c27bc3fa5ed5b96cc0a0976e3 Mon Sep 17 00:00:00 2001 From: relyt871 <104436315+relyt871@users.noreply.github.com> Date: Fri, 16 Jun 2023 22:13:10 +0800 Subject: [PATCH] notes --- W12D2.md | 38 ++++++++++++++++++++++++++++++++++++++ W4D2.md | 38 ++++++++++++++++++++++++++++++++++++++ W8D2.md | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 W12D2.md create mode 100644 W4D2.md create mode 100644 W8D2.md diff --git a/W12D2.md b/W12D2.md new file mode 100644 index 0000000..05c096d --- /dev/null +++ b/W12D2.md @@ -0,0 +1,38 @@ +# W12D2 + +## Distributed Shared Memory + +Q: Addressing + +- Message + - packet + - document + - file (page) +- Shared Memory (OS does it) + - directory (translation) + + + +#### DHT(Chord) + +Background: distributed searching + +Basic: any content $K_i = Hash(...)$ + +- machine $i$ has file A.mpg: $Hash(A.mpg) = 1$, then let machine 1 hold the information that A.mpg is owned by $i$ +- query A.mpg: Hash = 1 $\to$ ask machine 1 for the owner $\to$ go to owner $i$ + +Challenge: some machine may be offline + +- $succ(i)$: $i$'s next online machine +- finger table: for each online machine, maintain $succ$ of $s+2^k,k=0,1,2,...$ on machine $s$ +- every time a machine becomes online: broadcast, other machines update finger table + + + +#### Distributed Systems + +- Chip: SoC (System on Chip) +- Board: SMP (Symmetric Pultiprocessing) recall: reentrant functions +- LAN: Cluster +- Internet: Grid $\to$ Cloud \ No newline at end of file diff --git a/W4D2.md b/W4D2.md new file mode 100644 index 0000000..ceff85e --- /dev/null +++ b/W4D2.md @@ -0,0 +1,38 @@ +# W4D2 + +## Memory Management + +#### Concepts + +- No Memory Abstraction + - reallocation (static/dynamic) + - swapping +- Virutal Memory + - need to run programs that are too large to fit in memory + - no explicit swapping -> OS does it +- Page Replacement Algorithm + - Optimal algorithm (based on the future) + - NRU (not recently used) algorithm + - Referenced bit and Modified bit + - class0: not R not M + - class 1: not R, M + - class 2: R, not M + - class 3: R and M + - FIFO algorithm + - Second-chance algorithm + - Clock algorithm + - optimize the queue: only the clock ptr needs to move + - LRU (least recently used) algorithm + - complex for hardware + - simulating LRU in software: aging algorithm + - Working set algorithm + - each process focus on a set of pages + - WSClock algorithm + +##### Physical Memory Management + +- Buddy System (UNIX) + - allocate $2^m$ continual physical pages(frames) + - free_areas[] (list head) + - buddy: $2k*2^n$ and $(2k+1)*2^n$ + - used in Linux since 1970s. why efficient? \ No newline at end of file diff --git a/W8D2.md b/W8D2.md new file mode 100644 index 0000000..7ba4a09 --- /dev/null +++ b/W8D2.md @@ -0,0 +1,53 @@ +# W8D2 + +#### Buffer Overflow + +- Architecture level mechanism: data area not executable (page table: DEP) + +- Stack Canary + + - compiler adds canary in stack and check whether canary is modified + + - eg: + + ```c + foo() { + //compiler: add code to insert canary + char s[128]; + get(s); + //compiler: add code to check canary + } + ``` + + + +#### Code Reuse Attacks (Return to libc) + +```c +system("/bin/sh"); += +fork(); +execve("/bin/sh"); +``` + +- use instructions in libc to build useful functions (including stack overflow) + + + +#### Format String Attack + +format string: + +```c +printf("Hello, %s", name); +printf("%x add %x equals %x", a, b, c); +``` + +- if not enough args provided: + - compiler will reserve space for these args + - can be used to either leak information or modify registers + + + +#### Back Doors +