Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[memory hardware isolation] Add session content #11

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

cristian-vijelie
Copy link
Contributor

No description provided.

@cristian-vijelie cristian-vijelie changed the title [hardware_computing] Add session content [hardware isolation] Add session content Apr 15, 2023
@cristian-vijelie cristian-vijelie changed the title [hardware isolation] Add session content [memory hardware isolation] Add session content Jun 25, 2023
Copy link
Collaborator

@StefanJum StefanJum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks really nice @cristian-vijelie, see the few comments.
Also, will the hardware-isolation directory be used for something else? If not we should just remove it.

Comment on lines 10 to 11
You have encountered (hopefully) the main protection mechanism that the hardware uses to ensure memory isolation: pages.
There are other less-known mechanisms for ensuring memory isolation, through which we will go this session: segments, privilege rings, memory protection keys.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
You have encountered (hopefully) the main protection mechanism that the hardware uses to ensure memory isolation: pages.
There are other less-known mechanisms for ensuring memory isolation, through which we will go this session: segments, privilege rings, memory protection keys.
You have encountered (hopefully) the main protection mechanism that the hardware uses to ensure memory isolation: [pages](...).
There are other less-known mechanisms for ensuring memory isolation, through which we will go this session: [segments](...), [privilege rings](...), [memory protection keys](...).

Leave links to some relevant pages about the topics.

hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Show resolved Hide resolved
hardware-memory-isolation/README.md Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
Comment on lines 3 to 7
all:
make -C /home/cristi/WSL2-Linux-Kernel M=$(shell pwd) modules

clean:
make -C /home/cristi/WSL2-Linux-Kernel M=$(shell pwd) clean
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
all:
make -C /home/cristi/WSL2-Linux-Kernel M=$(shell pwd) modules
clean:
make -C /home/cristi/WSL2-Linux-Kernel M=$(shell pwd) clean
all:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules
clean:
make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Besides this, ask people somewhere in the session to install the kernel header files.

$ apt-cache search linux-headers-`uname -r`
$ sudo apt install linux-headers.....

Also ask them to run this from inside a virtual machine.


##### Tutorial: Reading the GDT of the Linux Kernel

Go to the [`read-gdt`](./activities/read-gdt/) folder.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comments on the Makefile.

Copy link
Member

@teodutu teodutu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this session. There are places where it could use some improvements. See my comments.

hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
We have the following scenario:
an application wants to change an area of its memory from read-write to read-only, for reasons.
To do this it will call `mprotect` on that area.
What will happen behind the scenes will be that the OS will change permissions for each page that is part of the memory area, then it will flush the TLB.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The TLB appears out of nowhere here. Add the concept of MMU + TLB as a prerequisite altogether, together with paging in general.

hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Show resolved Hide resolved
This allows an application to allocate its pages to a `protection domain`.
When accessing a page, instead of checking only the page permissions, the MMU will also check the protection domain permissions.

Let's take a practical example:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is too much text. Try to make a practical example out of this somehow (hopefully via a tutorial that modifies the PKRU). You can draw some inspiration from here.

Copy link
Collaborator

@mariasfiraiala mariasfiraiala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cristian-vijelie, this looks nice. See my comments below.

hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved

#### Segmentation

Segmentation is the x86 CPU feature that allows assigning permissions and ownership to a certain memory zone, using segments.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a bit more detail as to what segments represent. They can be easily confused with pages by novices.

hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
hardware-memory-isolation/README.md Outdated Show resolved Hide resolved
But wait, don't we have the `Stack Canary` for the last one?
The main problem with that solution is that the canary is placed on the same memory zone as the return address.
If we can modify the return address, what is stopping someone from reading the canary first, then modifying the return address, while keeping the canary intact?
The shadow stack places a copy of the return address in a separate memory zone, that can be accessed using only some special instructions.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to show how this can be achieved hardware wise. There are already some compiler enforced mechanism similar to this, that were however, deemed not as efficient (ShadowCallStack, SafeStack).


#### Indirect Branch Tracking

The main idea behind some attacks is to chain small pieces of code (gadgets), in order to call a system function, usually, in a certain way.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually, in a certain way

This is quite vague

Copy link
Member

@teodutu teodutu Jun 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd suggest referring to the ROP session of the Binary track for this since it's beyond the scope of the Hardware track.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants