Memory Protection: Kernel and User Address Spaces Andy Wang Operating Systems COP 4610 / CGS 5765.

Slides:



Advertisements
Similar presentations
More on Processes Chapter 3. Process image _the physical representation of a process in the OS _an address space consisting of code, data and stack segments.
Advertisements

Memory Protection: Kernel and User Address Spaces  Background  Address binding  How memory protection is achieved.
Chapter 6 Limited Direct Execution
CSC 501 Lecture 2: Processes. Von Neumann Model Both program and data reside in memory Execution stages in CPU: Fetch instruction Decode instruction Execute.
Thursday, June 08, 2006 The number of UNIX installations has grown to 10, with more expected. The UNIX Programmer's Manual, 2nd Edition, June, 1972.
3.5 Interprocess Communication Many operating systems provide mechanisms for interprocess communication (IPC) –Processes must communicate with one another.
3.5 Interprocess Communication
OS Spring’03 Introduction Operating Systems Spring 2003.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
1 Last Class: Introduction Operating system = interface between user & architecture Importance of OS OS history: Change is only constant User-level Applications.
1 Process Description and Control Chapter 3 = Why process? = What is a process? = How to represent processes? = How to control processes?
OS Spring’04 Introduction Operating Systems Spring 2004.
1 OS & Computer Architecture Modern OS Functionality (brief review) Architecture Basics Hardware Support for OS Features.
CSE 451: Operating Systems Autumn 2013 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Computer Organization
System Calls 1.
Protection and the Kernel: Mode, Space, and Context.
CSC 501 Lecture 2: Processes. Process Process is a running program a program in execution an “instantiation” of a program Program is a bunch of instructions.
Three fundamental concepts in computer security: Reference Monitors: An access control concept that refers to an abstract machine that mediates all accesses.
Operating Systems ECE344 Ashvin Goel ECE University of Toronto OS-Related Hardware.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
CE Operating Systems Lecture 3 Overview of OS functions and structure.
Processes and Process Control 1. Processes and Process Control 2. Definitions of a Process 3. Systems state vs. Process State 4. A 2 State Process Model.
Lecture Topics: 10/29 Architectural support for operating systems –timers –kernel mode –system calls –protected instructions.
We will focus on operating system concepts What does it do? How is it implemented? Apply to Windows, Linux, Unix, Solaris, Mac OS X. Will discuss differences.
Operating Systems Engineering Based on MIT (2012, lec3) Recitation 2: OS Organization.
Concurrency, Processes, and System calls Benefits and issues of concurrency The basic concept of process System calls.
Processes and Virtual Memory
Efficient Software-Based Fault Isolation Authors: Robert Wahbe Steven Lucco Thomas E. Anderson Susan L. Graham Presenter: Gregory Netland.
Interrupts and Exception Handling. Execution We are quite aware of the Fetch, Execute process of the control unit of the CPU –Fetch and instruction as.
Chapter 6 Limited Direct Execution Chien-Chung Shen CIS/UD
CS703 - Advanced Operating Systems By Mr. Farhan Zaidi.
Introduction to Operating Systems Concepts
Computer Organization & Design 计算机组成与设计
Introduction to Operating Systems
Non Contiguous Memory Allocation
Processes and threads.
Memory Protection: Kernel and User Address Spaces
Protection and OS Structure
Mechanism: Limited Direct Execution
CS 3305 System Calls Lecture 7.
Intro to Processes CSSE 332 Operating Systems
Modularity and Memory Clearly, programs must have access to memory
Concurrency: Threads, Address Spaces, and Processes
Introduction to Operating Systems
Lecture 28: Virtual Memory-Address Translation
Memory Protection: Kernel and User Address Spaces
Memory Protection: Kernel and User Address Spaces
Memory Protection: Kernel and User Address Spaces
Computer System Overview
Concurrency: Threads, Address Spaces, and Processes
CSE 451: Operating Systems Spring 2012 Module 6 Review of Processes, Kernel Threads, User-Level Threads Ed Lazowska 570 Allen.
Lecture Topics: 11/1 General Operating System Concepts Processes
Architectural Support for OS
CSE 451: Operating Systems Autumn 2005 Memory Management
Translation Buffers (TLB’s)
CSE 451: Operating Systems Autumn 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 596 Allen Center 1.
Prof. Leonardo Mostarda University of Camerino
CSE 451: Operating Systems Autumn 2001 Lecture 2 Architectural Support for Operating Systems Brian Bershad 310 Sieg Hall 1.
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
CSE 451: Operating Systems Winter 2007 Module 2 Architectural Support for Operating Systems Brian Bershad 562 Allen Center 1.
Operating Systems: A Modern Perspective, Chapter 6
CSE 451: Operating Systems Autumn 2003 Lecture 9 Memory Management
Chapter 9: Main Memory.
CSE 451: Operating Systems Winter 2003 Lecture 2 Architectural Support for Operating Systems Hank Levy 412 Sieg Hall 1.
Architectural Support for OS
Contact Information Office: 225 Neville Hall Office Hours: Monday and Wednesday 12:00-1:00 and by appointment. Phone:
Review What are the advantages/disadvantages of pages versus segments?
Memory Protection: Kernel and User Address Spaces
Concurrency: Threads, Address Spaces, and Processes
Presentation transcript:

Memory Protection: Kernel and User Address Spaces Andy Wang Operating Systems COP 4610 / CGS 5765

Up to This Point  Threads provide the illusion of an infinite number of CPUs  On a single processor machine  Memory management provides a different set of illusions  Protected memory  Infinite amount of memory  Transparent sharing

Physical vs. Virtual Memory Physical memory Virtual memory No protection Each process isolated from others and from OS Limited size Illusion of infinite memory Sharing visible to processes Each process cannot tell if memory is shared

Memory Organizations  Simplest: uniprogramming without memory protection  Each application runs within a hardwired range of physical memory addresses  One application runs at a time  Application can use the same physical addresses every time, across reboots

Uniprogramming Without Memory Protection  Applications typically use the lower memory addresses  An OS uses the higher memory addresses  An application can address any physical memory location ffffff Physical memory ApplicationOperating system

Multiprogramming Without Memory Protection  When a program is copied into memory, a linker-loader alters the code of the program (e.g., loads, stores, and jumps)  To use the address of where the program lands in memory

Multiprogramming Without Memory Protection  Bugs in any program can cause other programs to crash, even the OS ffffff Physical memory Application 1Operating systemApplication 2

Multiprogrammed OS With Memory Protection  Memory protection keeps user programs from crashing one another and the OS  Two hardware-supported mechanisms  Address translation  Dual-mode operation

Address Translation  Each process is associated with an address space, or all the physical addresses a process can touch  However, each process believes that it owns the entire memory, starting with the virtual address 0  The missing piece is a translation table  Translate every memory reference from virtual to physical addresses

Address Translation Visualized Virtual addresses Physical addresses Translation table Data reads or writes (untranslated)

More on Address Translations  Translation provides protection  Processes cannot talk about other processes’ addresses, nor about the OS addresses  OS uses physical addresses directly  No translations

Dual-mode Operation Revisited  Translation tables offer protection if they cannot be altered by applications  An application can only touch its address space under the user mode  HW requires the CPU to be in the kernel mode to modify the address translation tables

Details of Dual-mode Operations  How the CPU is shared between the kernel and user processes  How processes interact among themselves

Switching from the Kernel to User Mode  To run a user program, the kernel  Creates a process and initialize the address space  Loads the program into the memory  Initializes translation tables  Sets the HW pointer to the translation table  Sets the CPU to user mode  Jumps to the entry point of the program

To Run a Program User level Kernel level Translation table Hardware pointer user mode PC

Switching from User Mode to Kernel Mode  Voluntary  System calls: a user process asks the OS to do something on the process’s behalf  Involuntary  Hardware interrupts (e.g., I/O)  Program exceptions (e.g., segmentation fault)

Switching from User Mode to Kernel Mode  For all cases, hardware atomically performs the following steps  Sets the CPU to kernel mode  Saves the current program counter  Jumps to the handler in the kernel  The handler saves old register values

Switching from User Mode to Kernel Mode  Unlike context switching among threads, to switch among processes  Need to save and restore pointers to translation tables  To resume process execution  Kernel reloads old register values  Sets CPU to user mode  Jumps to the old program counter

User  Kernel User level Kernel level set kernel mode PC handler trusted code register valuestranslation tables (for processes)

Kernel  User User level Kernel level set kernel mode PC handler trusted code register valuestranslation tables (for processes)

Kernel  User User level Kernel level PC handler trusted code register valuestranslation tables (for processes) user mode

Communication Between Address Spaces  Processes communicate among address spaces via interprocess communication (IPC)  Byte stream (e.g., pipe )  Message passing (send/receive)  File system (e.g., read and write files)  Shared memory  Bugs can propagate from one process to another

Interprocess Communication  Direct  send(P 1, message);  receive(P 2, message);  One-to-one communication  Indirect  Mailboxes or ports  send(mailbox_A, message);  receive(mailbox_A, message);  Many-to-many communication

Protection Without HW Support  HW-supported protection can be slow  Requires applications be separated into address spaces to achieve fault isolation  What if your apps are built by multiple vendors? (e.g., Firefox plug-ins)  Can we run two programs in the same address space, with safety guarantees?

Protection via Strong Typing  Programming languages may disallow the misuse of data structures (casting)  e.g., LISP and Java  Java has its own virtual machines  A Java program can run on different HW and OSes - Need to learn a new language

Protection via Software Fault Isolation  Compilers generate code that is provably safe  e.g., a pointer cannot reference illegal addresses  With aggressive optimizations, the overhead can be as low as 5%

 A malicious user cannot jump to the last line and do damage, since safe is a legal address Protection via Software Fault Isolation Original instruction Compiler-modified version st r2, (r1) safe = a legal address safe = r1 Check safe is still legal st r2, (safe)