# US 2017/0255780 A1 · Methods and systems for securely executing untrusted software

> Agents: this data is available as JSON from the patentgrep API and MCP server — see https://patentgrep.com/llms.txt

- Number: US 2017/0255780 A1
- Document ID: US20170255780A1
- Status: Published application
- Kind: A1
- Application number: 15/275,000
- Filed: 2016-09-23
- Published: 2017-09-07
- Earliest claimed: 2016-03-02
- Assignees: Apple Inc.
- Applicants: Apple Inc.
- Inventors: Gregory D. Hughes; Ivan Krstic; Oliver J. Hunt
- Web page: https://patentgrep.com/patent/US20170255780A1

## CPC

- G06F 21/575: {Secure boot}
- G06F 3/0622: {in relation to access}
- G06F 3/0631: {by allocating resources to storage systems}
- G06F 3/0634: {by changing the state or mode of one or more devices}
- G06F 3/065: {Replication mechanisms}
- G06F 9/4552: {Involving translation to a different instruction set architecture, e.g. just-in-time translation in a JVM}
- G06F 12/10: Address translation
- G06F 21/53: by executing in a restricted environment, e.g. sandbox or secure virtual machine
- G06F 2212/1052: Security improvement
- G06F 2221/033: Test or assess software
- G06F: ELECTRIC DIGITAL DATA PROCESSING (computer systems based on specific computational models G06N)

## Abstract

Methods and systems for securely executing untrusted software are described. In one embodiment, two virtual memory mappings are used (one readable/writeable-RW and the other readable/executable-RX). In one embodiment, compiled software is used at run time through pointers to the RX virtual memory space and a compiler causes the storage of the compiled software in the RW virtual memory space through the use of an executable function (e.g. a memory copy like function) stored in an executable only memory region.

## Claims

### Claim 1

A non-transitory machine readable medium storing executable instructions which when executed cause a method for executing code in a data processing system, the code compiled by a compiler, the method comprising:
creating a first virtual memory mapping from a readable and executable (RX) virtual memory space to physical memory, the physical memory being designated for use in storing code and data produced by the compiler;
creating a second virtual memory mapping from a readable and writeable (RW) virtual memory space to the physical memory, the RW virtual memory space for storing data used in one or more processes resulting from execution of software stored in the RX virtual memory space;
allocating a memory region in one or more pages of memory, the memory region being at least writeable;
writing into the memory region an executable function configured to copy input data into the RW virtual memory space at a specified offset;
converting the memory region, after the writing, into an execute only memory region having an execute only privilege;
storing a pointer to the memory region, the pointer being used during a write operation that uses the executable function;
compiling the code to create compiled software and storing the compiled software in the physical memory by using the pointer to call for the execution of the executable function to cause the compiled software to be written, through the RW virtual memory space to physical memory mapping, to the physical memory.

### Claim 2 (depends on 1)

The medium as in claim 1, wherein the compiler is a Just-In-Time (JIT) compiler and the code is unsigned and the JIT compiler compiles the code at run time to create the compiled software.

### Claim 3 (depends on 2)

The medium as in claim 2 wherein the JIT compiler is run in a web browser that processes web pages and the code is associated with one or more web pages, and wherein the RW virtual memory space is located at a random address and the memory region is located at a random address, and wherein an operating system allocates memory for the web browser and the physical memory designated for use in storing code and data produced by the JIT compiler is located within the memory allocated for the web browser.

### Claim 4 (depends on 3)

The medium as in claim 3 wherein the JIT compiler is signed code and the web browser is signed code and the operating system has a set of components each of which is signed code and wherein the operating system performs a secure boot up procedure which verifies code signatures in a chain of trust starting from a boot Read-Only-Memory (ROM).

### Claim 5 (depends on 4)

The medium as in claim 4 wherein the operating system controls access to memory based on access privileges which include: RW, RX and execute only.

### Claim 6 (depends on 5)

The medium as in claim 5 wherein all executable software on the data processing system is signed code except for the unsigned code compiled by the JIT compiler.

### Claim 7 (depends on 1)

The medium as in claim 1, wherein the compiler is a Just-In-Time (JIT) compiler and the JIT compiler compiles the code at run time to create the compiled software and wherein the call for the execution of the executable function uses a call that refers to the compiled software and also includes the specified offset which is an offset from a location in the RW virtual memory space and wherein pointers to addresses in the RX virtual memory space are used at run time during execution of the compiled software to invoke one or more functions in the compiled software.

### Claim 8 (depends on 7)

The medium as in claim 7 wherein the executable function is a memory copy function in which the destination address of the memory copy function is the RW virtual memory space at the specified offset.

### Claim 9 (depends on 7)

The medium as in claim 7 wherein the physical memory for use in storing executable software and data produced by the JIT compiler is a JIT physical memory and wherein the memory region is stored in the JIT physical memory and wherein the RX virtual memory space and the RW virtual memory space share the same physical memory.

### Claim 10 (depends on 7)

The medium as in claim 7, the method further comprising zeroing out all pointers or references to the RW virtual memory space after storing the pointer to the memory region and wherein the allocating, the writing, the converting and the storing are performed by the JIT compiler and not by the compiled software.

### Claim 11

A method for executing code in a data processing system, the code compiled by a compiler, the method comprising:
creating a first virtual memory mapping from a readable and executable (RX) virtual memory space to physical memory, the physical memory being designated for use in storing code and data produced by the compiler;
creating a second virtual memory mapping from a readable and writeable (RW) virtual memory space to the physical memory, the RW virtual memory space for storing data used in one or more processes resulting from execution of software stored in the RX virtual memory space;
allocating a memory region in one or more pages of memory, the memory region being at least writeable;
writing into the memory region an executable function configured to copy input data into the RW virtual memory space at a specified offset;
converting the memory region, after the writing, into an execute only memory region having an execute only privilege;
storing a pointer to the memory region, the pointer being used during a write operation that uses the executable function;
compiling the code to create compiled software and storing the compiled software in the physical memory by using the pointer to call for the execution of the executable function to cause the compiled software to be written, through the RW virtual memory space to physical memory mapping, to the physical memory.

### Claim 12 (depends on 11)

The method as in claim 11, wherein the compiler is a Just-In-Time (JIT) compiler and the code is unsigned and the JIT compiler compiles the code at run time to create the compiled software.

### Claim 13 (depends on 12)

The method as in claim 12 wherein the JIT compiler is run in a web browser that processes web pages and the code is associated with one or more web pages, and wherein the RW virtual memory space is located at a random address and the memory region is located at a random address, and wherein an operating system allocates memory for the web browser and the physical memory designated for use in storing code and data produced by the JIT compiler is located within the memory allocated for the web browser.

### Claim 14 (depends on 13)

The method as in claim 13 wherein the JIT compiler is signed code and the web browser is signed code and the operating system has a set of components each of which is signed code and wherein the operating system performs a secure boot up procedure which verifies code signatures in a chain of trust starting from a boot Read-Only-Memory (ROM).

### Claim 15 (depends on 14)

The method as in claim 14 wherein the operating system controls access to memory based on access privileges which include: RW, RX and execute only.

### Claim 16 (depends on 15)

The method as in claim 15 wherein all executable software on the data processing system is signed code except for the unsigned code compiled by the JIT compiler.

### Claim 17 (depends on 11)

The method as in claim 11, wherein the compiler is a Just-In-Time (JIT) compiler and the JIT compiler compiles the code at run time to create the compiled software and wherein the call for the execution of the executable function uses a call that refers to the compiled software and also includes the specified offset which is an offset from a location in the RW virtual memory space and wherein pointers to addresses in the RX virtual memory space are used at run time during execution of the compiled software to invoke one or more functions in the compiled software.

### Claim 18 (depends on 17)

The method as in claim 17 wherein the executable function is a memory copy function in which the destination address of the memory copy function is the RW virtual memory space at the specified offset.

### Claim 19 (depends on 17)

The method as in claim 17 wherein the physical memory for use in storing executable software and data produced by the JIT compiler is a JIT physical memory and wherein the memory region is stored in the JIT physical memory and wherein the RX virtual memory space and the RW virtual memory space share the same physical memory.

### Claim 20 (depends on 17)

The method as in claim 17, the method further comprising zeroing out pointers or references to the RW virtual memory space after storing the pointer to the memory region and wherein the allocating, the writing, the converting and the storing are performed by the JIT compiler and not by the compiled software.

### Claim 21

A non-transitory machine readable medium storing executable program instructions which when executed by a data processing system cause the data processing system to perform a method comprising:
compiling, by a compiler prior to run time, software code to create compiled software, the compiled software to be stored in a readable and executable (RX) virtual memory address space at run time, the RX virtual memory address space to be mapped to physical memory by a first virtual memory address mapping;
creating, by the compiler, an executable function to be stored in a memory region which is at least writeable when the executable function is written to the memory region at run time, wherein the executable function is configured to copy at run time input data into a readable and writeable (RW) virtual memory address space at a specified offset, the RW virtual memory address space to be mapped to the physical memory by a second virtual memory address mapping at run time;
creating, by the compiler, executable software which at run time converts the memory region into an execute only memory region and stores a pointer to the converted memory region, the pointer being used during a write operation, at run time, by one or more processes resulting from execution of the compiled software in the RX virtual memory address space, wherein at run time, when a request from the one or more processes requires writing first data, the pointer is used to call the executable function to cause the first data to be written, through the RW virtual memory address space, to the physical memory.

### Claim 22

A non-transitory machine readable medium storing executable instructions which when executed cause a method for executing code in a data processing system, the method comprising:
obtaining a memory region in one or more pages of memory, the memory region being at least writeable;
writing into the memory region an executable function configured to write one or more functions or data into a writeable virtual memory space;
converting the memory region, after the writing, into an execute only memory region having an execute only privilege;
storing a pointer to the memory region, the pointer being used during a write operation that uses the executable function;
receiving a request, from one or more processes, which requires writing functions or data, and using the pointer, calling the execution of the executable function to cause the functions or data to be written, through the writeable virtual memory space to physical memory mapping, to the physical memory.

### Claim 23 (depends on 22)

The medium as in claim 22, wherein the method is performed at least in part by a Just-In-Time (JIT) compiler and the code is unsigned and the JIT compiler compiles the code at run time to create the compiled software and wherein the functions or data is compiled code that has been compiled by the JIT compiler and wherein the method further comprises:
creating a first virtual memory mapping from a readable and executable (RX) virtual memory space to physical memory, the physical memory being designated for use in storing code and data;
creating a second virtual memory mapping from a readable and writeable (RW) virtual memory space to the physical memory, the RW virtual memory space for storing data used in one or more processes resulting from execution of software stored in the RX virtual memory space.

### Claim 24 (depends on 23)

The medium as in claim 23 wherein the JIT compiler is run in a web browser that processes web pages and the code is associated with one or more web pages, and wherein the RW virtual memory space is located at a random address and the memory region is located at a random address, and wherein an operating system allocates memory for the web browser and the physical memory designated for use in storing code and data produced by the JIT compiler is located within the memory allocated for the web browser and wherein the web browser and the JIT compiler are signed.

### Claim 25 (depends on 24)

The medium as in claim 24, the method further comprising zeroing out pointers or references to the RW virtual memory space after storing the pointer to the memory region, and wherein pointers to addresses in the RX virtual memory space are used at run time during execution of the compiled software to invoke one or more functions in the compiled software.

### Claim 26 (depends on 22)

The medium as in claim 22 wherein the method is performed at least in part by signed software code and wherein the one or more functions that are written by the executable function are software that is not signed.

### Claim 27

A non-transitory machine readable medium storing executable instructions which when executed cause a method for executing code in a data processing system, the method comprising:
obtaining a memory region in one or more pages of memory, the memory region being at least writeable;
writing into the memory region an executable function configured to perform a cryptographic function;
converting the memory region, after the writing, into an execute only memory region having an execute only privilege;
storing a pointer to the memory region, the pointer being used in response to a request to perform the cryptographic function;
receiving a request, from one or more processes, which requires use of the cryptographic function, and using the pointer, calling the execution of the cryptographic function.

### Claim 28 (depends on 27)

The medium as in claim 27 wherein the method further comprises:
creating a first virtual memory mapping from a readable and executable (RX) virtual memory space to physical memory, the physical memory being designated for use in storing code and data;
creating a second virtual memory mapping from a readable and writeable (RW) virtual memory space to the physical memory, the RW virtual memory space for storing data used in one or more processes resulting from execution of software stored in the RX virtual memory space.

### Claim 29 (depends on 28)

The medium as in claim 28, the method further comprising zeroing out pointers or references to the RW virtual memory space after storing the pointer to the memory region, and wherein pointers to addresses in the RX virtual memory space are used at run time during execution to invoke the cryptographic function, and wherein the cryptographic function performs a digital rights management function.
