All Topics  
Memory protection

 

   Email Print
   Bookmark   Link






 

Memory protection



 
 
Memory protection is a way to control memory usage on a computer, and is core to virtually every modern operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
. The main purpose of memory protection is to prevent a process
Process (computing)

In computing, a process is an Object of a computer program that is being sequentially executed by a computer system that has the ability to run several computer programs Concurrency ....
 running on an operating system from accessing memory beyond that allocated to it. This prevents a bug within the process from affecting other processes, and also prevents malicious software from gaining unauthorized access to the system.

lass="link1" onMouseover='showByLink("m1908223",this)' onMouseout='hide("m1908223")'href="http://www.absoluteastronomy.com/topics/Segmentation_%28memory%29">Segmentation
Segmentation (memory)

In computing, memory segmentation is one of the most common ways to achieve memory protection; another common one is paging. In a computer system using segmentation, an instruction operand that refers to a memory location includes a value that identifies a segment and an offset within that segment....
 refers to dividing a computer's memory into segments.

The x86 architecture
X86 architecture

The generic term x86 refers to the most commercially successful instruction set architecture in the history of personal computing. It derived from the model numbers, ending in "86", of the first few processor generations Backward compatibility with the original Intel 8086....
 has multiple segmentation features, which are useful for those who wish to use protected memory on this architecture.






Discussion
Ask a question about 'Memory protection'
Start a new discussion about 'Memory protection'
Answer questions from other users
Full Discussion Forum



Encyclopedia


Memory protection is a way to control memory usage on a computer, and is core to virtually every modern operating system
Operating system

An operating system is an interface between hardware and applications; it is responsible for the management and coordination of activities and the sharing of the limited resources of the computer....
. The main purpose of memory protection is to prevent a process
Process (computing)

In computing, a process is an Object of a computer program that is being sequentially executed by a computer system that has the ability to run several computer programs Concurrency ....
 running on an operating system from accessing memory beyond that allocated to it. This prevents a bug within the process from affecting other processes, and also prevents malicious software from gaining unauthorized access to the system.

Methods


Segmentation

Segmentation
Segmentation (memory)

In computing, memory segmentation is one of the most common ways to achieve memory protection; another common one is paging. In a computer system using segmentation, an instruction operand that refers to a memory location includes a value that identifies a segment and an offset within that segment....
 refers to dividing a computer's memory into segments.

The x86 architecture
X86 architecture

The generic term x86 refers to the most commercially successful instruction set architecture in the history of personal computing. It derived from the model numbers, ending in "86", of the first few processor generations Backward compatibility with the original Intel 8086....
 has multiple segmentation features, which are useful for those who wish to use protected memory on this architecture. On the x86 architecture, the Global Descriptor Table
Global Descriptor Table

The Global Descriptor Table or GDT is a data structure used by Intel x86-family processors starting with the 80286 in order to define the characteristics of the various memory areas used during program execution, for example the base address, the size and access privileges like executability and writability....
 and Local Descriptor Table
Local Descriptor Table

The Local Descriptor Table is a memory table used in the x86 architecture in protected mode and containing memory segment descriptors: start in linear memory, size, executability, writability, access privilege, actual presence in memory, etc....
s can be used to reference segments in the computer's memory. Pointers to memory segments on x86 processors can also be stored in the processor's segment registers. Initially x86 processors had 4 segment registers, CS (code segment), SS (stack segment), DS (data segment) and ES (extra segment); later another two segment registers were added – FS and GS.

Paging

In paging, the memory address space is divided into equal, small pieces, called pages
Page (computing)

In a context of computer virtual memory, a page, memory page, or virtual page is a fixed-length block of main memory, that is contiguous in both physical memory addressing and virtual memory addressing....
. Using a virtual memory
Virtual memory

Virtual memory is a computer system technique which gives an application program the impression that it has contiguous working memory , while in fact it may be physically fragmented and may even overflow on to disk storage....
 mechanism, each page can be made to reside in any location of the physical memory, or be flagged as being protected. Virtual memory makes it possible to have a linear virtual memory address space
Virtual address space

Virtual address space is a memory mapping mechanism available in modern operating systems such as OpenVMS, UNIX, Linux, and Windows NT. This is beneficial for different purposes, one is security through process isolation....
 and to use it to access blocks fragmented over physical memory address space.

Most computer architecture
Computer architecture

Computer architecture in computer engineering is the conceptual design and fundamental operational structure of a computer system. It is a blueprint and functional description of requirements and design implementations for the various parts of a computer, focusing largely on the way by which the central processing unit performs internally an...
s based on pages, most notably x86 architecture
X86 architecture

The generic term x86 refers to the most commercially successful instruction set architecture in the history of personal computing. It derived from the model numbers, ending in "86", of the first few processor generations Backward compatibility with the original Intel 8086....
, also use pages for memory protection.

A page table
Page table

A page table is the data structure used by a virtual memory system in a computer operating system to store the mapping between virtual addresses and physical addresses....
 is used for mapping virtual memory to physical memory. The page table is usually invisible to the process. Page tables make it easier to allocate new memory, as each new page can be allocated from anywhere in physical memory.

By such design, it is impossible for an application to access a page that has not been explicitly allocated to it, simply because any memory address, even a completely random one, that application may decide to use, either points to an allocated page, or generates a page fault
Page fault

In computer storage technology, a page is a fixed-length block of memory that is used as a unit of transfer between physical memory and external storage like a hard disk, and a page fault is an interrupt to the software raised by the hardware, when a program accesses a page that is mapped in address space, but not loaded in physical memory....
 (PF) error. Unallocated pages simply do not have any addresses from the application point of view.

As a side note, a PF may not be a fatal one. A PF is used not only for memory protection, but also in another interesting way: the OS may intercept PF, and may load a page that has been previously swapped out
Swapping

Swapping can mean:* Paging or thrash in computer systems* Swapping * Hot swapping* Book swappingSee also * Swap...
 to disk, and return to the application that caused page fault. This way, the application receives the memory page as needed. This scheme, known as swapping
Swapping

Swapping can mean:* Paging or thrash in computer systems* Swapping * Hot swapping* Book swappingSee also * Swap...
, allows in-memory data not currently in use to be moved to disk storage and back, in a way "invisible" for applications, to increase overall memory capacity.

Protection keys

A protection key mechanism divides physical memory up into blocks of a particular size (e.g. 2KB), each of which has an associated numerical value called a protection key. Each process also has a protection key value associated with it. On a memory access the hardware checks that the current process's protection key matches the value associated with the memory block being accessed; if not, an exception occurs. This mechanism was used in the System/360
System/360

The IBM System/360 is a mainframe computer system family announced by IBM on April 7, 1964. It was the first family of computers making a clear distinction between computer architecture and implementation, allowing IBM to release a suite of compatible designs at different price points....
 architecture.

The System/360 protection keys described above are associated with physical addresses. They should not be confused with the protection key mechanism used by processors such as the Intel Itanium
Itanium

Itanium is the brand name for 64-bit Intel microprocessors that implement the Intel Itanium architecture . Intel has released two processor families using the brand: the original Itanium and the Itanium 2....
 and the HP Precision Architecture (HP/PA, also known as PA-RISC), which are associated with virtual addresses, and which allow multiple keys per process.

In the Itanium and PA computer architectures, translations (TLB
Translation Lookaside Buffer

A Translation lookaside buffer is a Central processing unit CPU cache that is used by Memory management unit to improve the speed of virtual address translation....
 entries) have "keys" (Itanium) or "access ids" (PA) associated with them. A running process has several protection key registers - 16 for Itanium, 4 for HP PA. A translation selected by the virtual address has its key compared to each of the protection key registers. If any of them match (plus other possible checks), the access is permitted. If none match, a fault or exception is generated. The software fault handler can, if desired, check the missing key against a larger list of keys maintained by software; thus, the protection key registers inside the processor may be treated as a software managed cache of a larger list of keys associated with a process.

PA has 15-18 bits of key; Itanium mandates at least 18. Keys are usually associated with "protection domains", such as libraries, modules, etc.

Simulated segmentation

Simulation
Simulation

Simulation is the imitation of some real thing, state of affairs, or process. The act of simulating something generally entails representing certain key characteristics or behaviors of a selected physical or abstract system....
 is use of a monitoring
Monitoring

To monitor or monitoring generally means to be aware of the state of a system. Below are a couple of specific examples:* to observe a situation for any changes which may occur over time, using a monitor or measuring device of some sort:...
 program
Computer program

Computer programs are Instruction for a computer. A computer requires programs to function. Moreover, a computer program does not run unless its instructions are executed by a Central processing unit; however, a program may communicate an Algorithm#Formalization of algorithms to people without running....
 to interpret the machine code instructions of some computer. Such an Instruction Set Simulator
Instruction Set Simulator

An instruction set simulator is a simulation model , usually coded in a high-level programming language, which mimics the behavior of a mainframe or microprocessor by "reading" instructions and maintaining internal variables which represent the processor's registers....
 can provide memory protection by using a segmentation-like scheme and validating the target address and length of each instruction in real time before actually executing them. The simulator must calculate the target address and length and compare this against a list of valid address ranges that it holds concerning the thread
Thread (computer science)

In computer science, a thread of execution is a Fork of a computer program into two or more Concurrency running task s. The implementation of threads and process es differs from one operating system to another, but in most cases, a thread is contained inside a process....
's environment, such as any dynamic memory
Memory

In psychology, memory is an organism's mental ability to store, retain and recall information. Traditional studies of memory began in the fields of philosophy, including techniques of mnemonic....
 blocks acquired since the thread's inception plus any valid shared static memory slots. The meaning of "valid" may change throughout the thread's life depending upon context: it may sometimes be allowed to alter a static block of storage, and sometimes not, depending upon the current mode of execution which may or may not depend on a storage key or supervisor state.

It is generally not advisable to use this method of memory protection where adequate facilities exist on a CPU, as this takes valuable processing power from the computer. However it is generally used for debugging and testing purposes to provide an extra fine level of granularity to otherwise generic storage violation
Storage violation

A storage violation occurs when a task modifies computer storage that it does not own....
s and can indicate precisely which instruction is attempting to overwrite the particular section of storage which may have the same storage key as unprotected storage. Early IBM
IBM

International Business Machines Corporation, abbreviated IBM and nicknamed "Big Blue" , is a multinational corporation computer technology and consulting corporation headquartered in Armonk, New York, New York, United States....
 teleprocessing systems such as CICS
CICS

CICS is a transaction server that runs primarily on IBM mainframe systems under z/OS and z/VSE.CICS is a transaction manager designed for rapid, high-volume online processing....
, for example, multi-threaded commercial transactions in shared and unprotected storage for around 20 years.

Capability-based addressing

Capability-based addressing
Capability-based addressing

In computer science, capability-based addressing is a scheme used by some computers to control access to memory. Under a capability-based addressing scheme, pointer s are replaced by protected objects that can only be created through the use of privilege instructions which may only be executed by the kernel ....
 is an interesting scheme for memory protection, albeit unused in modern computers. Under this scheme, pointers are replaced by protected objects (called capabilities) that can only be created through the use of privileged instructions which may only be executed by the kernel (or some other process authorized to do so). This effectively allows the kernel to control which processes may access which objects in memory without the need to use separate address spaces and without the need of context switch
Context switch

A context switch is the computing process of storing and restoring the State of a Central processing unit such that multiple Process es can share a single CPU resource....
es.

Measures

A useful estimation of the protection level of a particular implementation, is to measure how closely it adheres to the principle of minimum privilege.

Memory protection in different operating systems

There are very few operating systems that do not use some form of memory protection. Most 1970s and 1980s home computer
Home computer

A home computer was a class of personal computer entering the market in 1977 and becoming common during the 1980s. They were marketed to consumers as accessible personal computers, more capable than video game consoles....
 operating systems, CP/M
CP/M

CP/M is an operating system originally created for Intel 8080/Intel 8085 based microcomputers by Gary Kildall of Digital Research. Initially confined to single tasking on 8-bit processors and no more than 64 kilobytes of memory, later versions of CP/M added multi-user variations, and were migrated to 16-bit processors....
, and all variants of MS-DOS
MS-DOS

MS-DOS is an operating system commercialized by Microsoft. It was the most commonly used member of the DOS family of operating systems and was the main operating system for personal computers during the 1980s....
 lacked it, since they were designed for computers that did not offer the necessary hardware support. Even then, versions of Microsoft Windows beginning with Windows 2.1x
Windows 2.1x

Windows 2.1x is a family of Microsoft Windows graphical user interface-based operating environments.Less than a year after the release of Windows 2.0, Windows/286 2.10 and Windows/386 2.10 were released on 27 May 1988....
 implemented memory protection on top of DOS when run on an Intel 80286
Intel 80286

The Intel 286, introduced on February 1, 1982, was an x86 16-bit microprocessor with 134,000 transistors.It was widely used in IBM PC compatible computers during the mid 1980s to early 1990s....
 or better processor.

Some operating systems that do implement memory protection include

  • Microsoft Windows
    Microsoft Windows

    Microsoft Windows is a series of software operating systems and graphical user interfaces produced by Microsoft. Microsoft first introduced an operating environment named Windows in November 1985 as an add-on to MS-DOS in response to the growing interest in graphical user interfaces ....
     family
  • most Unix-like
    Unix-like

    A Unix-like operating system is one that behaves in a manner similar to a Unix system, while not necessarily conforming to or being certified to any version of the Single UNIX Specification....
     systems, including
    • Solaris
    • Linux
      Linux

      Linux is a generic term referring to Unix-like computer operating systems based on the Linux kernel. Their development is one of the most prominent examples of free and open source software collaboration; typically all the underlying source code can be used, freely modified, and redistributed by anyone under the terms of the GNU GPL license...
    • BSD
    • Mac OS X
      Mac OS X

      Mac OS X is a line of computer operating systems developed, marketed, and sold by Apple Inc., and since 2002 has been included with all new Macintosh computer systems....
       (earlier Mac OSes had limited memory protection)


See also

  • Storage violation
    Storage violation

    A storage violation occurs when a task modifies computer storage that it does not own....
    , for violation of memory protection
  • Separation of protection and security
    Separation of protection and security

    In computer sciences the separation of Protection mechanism and Computer security is a computer design choice. Wulf et al identified protection as a Mechanism and security as a policy, therefore making the protection-security distinction as a particular case of the separation of mechanism and policy principle....


External links

  • - in-depth information on memory protection for Intel based architectures.