<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2020W_Lecture_15</id>
	<title>Operating Systems 2020W Lecture 15 - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://homeostasis.scs.carleton.ca/wiki/index.php?action=history&amp;feed=atom&amp;title=Operating_Systems_2020W_Lecture_15"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_15&amp;action=history"/>
	<updated>2026-06-02T22:26:50Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.42.1</generator>
	<entry>
		<id>https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_15&amp;diff=22580&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video for the lecture given on March 6, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec15-20200306.m4v is now available].  ==No...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2020W_Lecture_15&amp;diff=22580&amp;oldid=prev"/>
		<updated>2020-03-20T02:35:54Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video for the lecture given on March 6, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec15-20200306.m4v is now available].  ==No...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Video==&lt;br /&gt;
&lt;br /&gt;
Video for the lecture given on March 6, 2020 [https://homeostasis.scs.carleton.ca/~soma/os-2020w/lectures/comp3000-2020w-lec15-20200306.m4v is now available].&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 15&lt;br /&gt;
----------&lt;br /&gt;
&lt;br /&gt;
- midterms mostly graded, all should be done by end of weekend&lt;br /&gt;
- midterms will be returned through your TA&lt;br /&gt;
  - if you go over your midterm with your TA, you get 2 bonus marks&lt;br /&gt;
- solutions are posted, will go through them at a later date&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Kernel modules &amp;amp; eBPF&lt;br /&gt;
---------------------&lt;br /&gt;
&lt;br /&gt;
What do you do if system calls aren&amp;#039;t enough?&lt;br /&gt;
 - not fast enough&lt;br /&gt;
 - insufficient functionality&lt;br /&gt;
 - insufficient visibility&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Consider web browsers&lt;br /&gt;
 - web pages can do some things&lt;br /&gt;
 - browser extensions can do other things&lt;br /&gt;
&lt;br /&gt;
Browser extensions can be very dangerous&lt;br /&gt;
 - see every page you visit&lt;br /&gt;
 - change contents of any page&lt;br /&gt;
 - change interface elements -&amp;gt; change how your banking website works&lt;br /&gt;
 - send arbitrary data to other systems&lt;br /&gt;
   - spyware!&lt;br /&gt;
&lt;br /&gt;
Price for added functionality is more risk&lt;br /&gt;
&lt;br /&gt;
How can we extend the operating system, specifically the Linux kernel&lt;br /&gt;
&lt;br /&gt;
Firefox long had very powerful extensions, but more recently&lt;br /&gt;
adopted a much more restrictive extension interface&lt;br /&gt;
 - one reason: mostly compatible with Chrome&lt;br /&gt;
 - but big reason: much safer&lt;br /&gt;
 - also, made it hard to change the browser, because they&lt;br /&gt;
   had to preserve internal interfaces for external consumers&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Of course, any program running on a system &amp;quot;extends&amp;quot; it&lt;br /&gt;
 - but extensions make use of privileged APIs to allow for&lt;br /&gt;
   tighter integration&lt;br /&gt;
 - also, extensions tend to run in the same address space as&lt;br /&gt;
   the main program, so can manipulate main program state&lt;br /&gt;
&lt;br /&gt;
With extending the Linux kernel, we want code running in the kernel&lt;br /&gt;
 - so, in the address space of the kernel&lt;br /&gt;
 - but this means the code can mess with arbitrary parts of the kernel&lt;br /&gt;
   - so you can see and modify any process, act as any user&lt;br /&gt;
   - interact with any device in arbitrary ways&lt;br /&gt;
   - allocate any resources you want&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Classic bad thing to do with a kernel module: a rootkit&lt;br /&gt;
 - hide processes&lt;br /&gt;
 - hide files&lt;br /&gt;
 - add backdoors that allow you to bypass mainline authentication&lt;br /&gt;
    - think &amp;quot;joshua&amp;quot;&lt;br /&gt;
&lt;br /&gt;
How do we control what code gets loaded?&lt;br /&gt;
 - normally requires root privileges&lt;br /&gt;
 - on some systems, code must be signed&lt;br /&gt;
&lt;br /&gt;
Code running in the kernel IS NOT running as root!&lt;br /&gt;
 - root is the maximally privileged user&lt;br /&gt;
 - but root is just a label for processes&lt;br /&gt;
 - the kernel is what implements the process abstraction&lt;br /&gt;
&lt;br /&gt;
kernel modules have maximum flexibility and maximum pain&lt;br /&gt;
 - one coding error can lead to system crashes and corrupted devices&lt;br /&gt;
&lt;br /&gt;
But what about adding code to the kernel in a safer way?&lt;br /&gt;
&lt;br /&gt;
When you run code in a web browser, where does it run?&lt;br /&gt;
 - in the address space of the browser&lt;br /&gt;
 - (compiled JavaScript)&lt;br /&gt;
 - this is safe because code is &amp;quot;sandboxed&amp;quot;&lt;br /&gt;
 - (sandboxing is not a technical term, it is an aspiration)&lt;br /&gt;
&lt;br /&gt;
We don&amp;#039;t sandbox code loaded into a kernel&lt;br /&gt;
 - we already have processes&lt;br /&gt;
&lt;br /&gt;
But we can verify/check code to make sure it is safe (for some&lt;br /&gt;
approximation of safe)&lt;br /&gt;
&lt;br /&gt;
Standard kernel modules have no verification&lt;br /&gt;
&lt;br /&gt;
eBPF does!&lt;br /&gt;
&lt;br /&gt;
eBPF is based on the Berkeley Packet Filter (BPF), but extended&lt;br /&gt;
 - idea was to run code in the kernel to filter packets&lt;br /&gt;
&lt;br /&gt;
trace uses eBPF&lt;br /&gt;
strace, gdb uses ptrace (a system call)&lt;br /&gt;
 - designed for debugging one process at a time&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
eBPF is very fussy about the code it accepts&lt;br /&gt;
 - all loops must clearly terminate!&lt;br /&gt;
 - no arbitrary memory access&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 - eBPF code runs in kernel space, but is verified to make sure it is safe&lt;br /&gt;
   (supervisor mode on the CPU, in the kernel address space)&lt;br /&gt;
&lt;br /&gt;
 - kernel modules run in kernel space, and ARE NOT verified&lt;br /&gt;
    - but they may be signed (so inauthentic modules will be rejected)&lt;br /&gt;
    - supervisor mode on the CPU, in the kernel address space&lt;br /&gt;
&lt;br /&gt;
 - processes run in userspace, not verified but are &amp;quot;sandboxed&amp;quot; to a degree&lt;br /&gt;
    - user mode on CPU&lt;br /&gt;
    - own address space&lt;br /&gt;
 &lt;br /&gt;
 - eBPF is a new thing, separate from regular functionality we&amp;#039;ve covered&lt;br /&gt;
    - NOT used to implement system calls (at this time)&lt;br /&gt;
    - NOT used for device drivers&lt;br /&gt;
&lt;br /&gt;
eBPF is a safer way to add code to kernel space&lt;br /&gt;
&lt;br /&gt;
API exposed to userspace is stable&lt;br /&gt;
 - mainly system calls, but also device files&lt;br /&gt;
&lt;br /&gt;
but internal kernel APIs are not stable&lt;br /&gt;
 - kernel modules, eBPF programs have to be compiled anew for each&lt;br /&gt;
   new kernel&lt;br /&gt;
 - easier with eBPF, because designed to be compiled at runtime&lt;br /&gt;
&lt;br /&gt;
Monolithic vs microkernels&lt;br /&gt;
 - difference is in what runs in kernel vs user space&lt;br /&gt;
 - monolithic kernels runs most networking, filesystems, device drivers&lt;br /&gt;
   in kernel space&lt;br /&gt;
 - microkernels try to put these all in processes&lt;br /&gt;
&lt;br /&gt;
Advantage of microkernel&lt;br /&gt;
 - potentially more stable&lt;br /&gt;
 - easier to debug&lt;br /&gt;
 - most OS code is in processes, so can use conventional tools to debug&lt;br /&gt;
&lt;br /&gt;
Key disadvantage&lt;br /&gt;
 - performance&lt;br /&gt;
&lt;br /&gt;
(Security benefit of microkernels is quite arguable)&lt;br /&gt;
&lt;br /&gt;
Linux does have userspace drivers&lt;br /&gt;
 - NTFS for example (main Windows file system)&lt;br /&gt;
&lt;br /&gt;
eBPF reduces disadvantages of monolithic kernels &lt;br /&gt;
 - safe mechanism for extensions that is faster than processes&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>