<?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_2022F_Lecture_17</id>
	<title>Operating Systems 2022F Lecture 17 - 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_2022F_Lecture_17"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_17&amp;action=history"/>
	<updated>2026-04-05T22:41:57Z</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_2022F_Lecture_17&amp;diff=24144&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on November 15, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec17-20221115.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec17-20221115.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&gt;Zoom meeting-&gt;Cloud Recordings tab)  ==Notes==  &lt;pre&gt; Lecture 17 ----------  - midterms, A2 are graded    - fee...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2022F_Lecture_17&amp;diff=24144&amp;oldid=prev"/>
		<updated>2022-11-16T02:05:21Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on November 15, 2022 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec17-20221115.m4v video] * [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec17-20221115.cc.vtt auto-generated captions] Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&amp;gt;Cloud Recordings tab)  ==Notes==  &amp;lt;pre&amp;gt; Lecture 17 ----------  - midterms, A2 are graded    - fee...&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 from the lecture given on November 15, 2022 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec17-20221115.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2022f/lectures/comp3000-2022f-lec17-20221115.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Zoom meeting-&amp;gt;Cloud Recordings tab)&lt;br /&gt;
&lt;br /&gt;
==Notes==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
Lecture 17&lt;br /&gt;
----------&lt;br /&gt;
 - midterms, A2 are graded&lt;br /&gt;
   - feedback under Progress-&amp;gt;Class Progress&lt;br /&gt;
   - hopefully you got notifications?&lt;br /&gt;
&lt;br /&gt;
Also, there are now midterm interviews!&lt;br /&gt;
 - I&amp;#039;ve made a spreadsheet in the annoucements channel, see the Interviews tab&lt;br /&gt;
 - you can just sign up if you want to volunteer&lt;br /&gt;
 - I will add slots as they fill up, or if people tell me they want&lt;br /&gt;
   to sign up but can&amp;#039;t make any of the available slots&lt;br /&gt;
 - this afternoon I&amp;#039;ll be sending out messages regarding randomized/selected interviews&lt;br /&gt;
&lt;br /&gt;
If you want to discuss your midterm grade, sign up for an interview&lt;br /&gt;
&lt;br /&gt;
Class average for the midterm was around 67% (so C+), which isn&amp;#039;t bad&lt;br /&gt;
 - but there was a huge spread&lt;br /&gt;
 &lt;br /&gt;
The final exam can substitute for the midterm, and I change the weights of assignments, tutorials at the end with different grading schemes&lt;br /&gt;
 - so there is still a chance to bring your grade up&lt;br /&gt;
 - but the material doesn&amp;#039;t get any easier!&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
So now let&amp;#039;s talk about the kernel&lt;br /&gt;
&lt;br /&gt;
First, when doing the tutorial, if you see a message about &amp;quot;system restart required&amp;quot;, run &amp;quot;sudo reboot&amp;quot; to reboot your VM&lt;br /&gt;
  - after doing a backup!&lt;br /&gt;
&lt;br /&gt;
Because that means there&amp;#039;s a new kernel to be run, so if you build modules they won&amp;#039;t necessarily load until you reboot&lt;br /&gt;
 - and while you are at it, run as root:&lt;br /&gt;
     apt update; apt -y dist-upgrade; apt clean; apt autoremove&lt;br /&gt;
     &lt;br /&gt;
For tutorial 8, for the simple module:&lt;br /&gt;
  - download the code to the VM using wget&lt;br /&gt;
  - unzip, cd into new dir, run &amp;quot;make&amp;quot;&lt;br /&gt;
  - then install the module using insmod, e.g. &amp;quot;sudo insmod simple.ko&amp;quot;&lt;br /&gt;
  - to see results, look in the kernel log, /var/log/kern.log&lt;br /&gt;
&lt;br /&gt;
When I did this just now, I got these messages in the log:&lt;br /&gt;
&lt;br /&gt;
Nov 15 12:02:06 comp3000 kernel: [  122.454585] simple: loading out-of-tree module taints kernel.&lt;br /&gt;
Nov 15 12:02:06 comp3000 kernel: [  122.454932] simple: module verification failed: signature and/or required key missing - tainting kernel&lt;br /&gt;
Nov 15 12:02:06 comp3000 kernel: [  122.455765] Hello kernel world!&lt;br /&gt;
&lt;br /&gt;
Last one came from the code itself, but the other two are warnings&lt;br /&gt;
&lt;br /&gt;
&amp;quot;Tainting&amp;quot; the kernel means that unverified code has been loaded&lt;br /&gt;
  - so the kernel may have been corrupted&lt;br /&gt;
  - because remember a module can do essentially ANYTHING to the kernel&lt;br /&gt;
&lt;br /&gt;
How would you avoid this tainting message?&lt;br /&gt;
 - module would have to be digitally signed by a key that is trusted by the kernel&lt;br /&gt;
 - in practice, you&amp;#039;d need to build an entire kernel on your own and then&lt;br /&gt;
   build modules, with all of them being signed using the same key&lt;br /&gt;
&lt;br /&gt;
Signed modules are part of a &amp;quot;trusted boot&amp;quot; system&lt;br /&gt;
 - that all OS and application code come from an authorized source&lt;br /&gt;
 - good side: make sure rootkits and other malware can&amp;#039;t run on your system&lt;br /&gt;
 - bad side: enforces DRM&lt;br /&gt;
&lt;br /&gt;
On phones, signatures are checked on boot and strictly enforced&lt;br /&gt;
 - you can&amp;#039;t install an OS on a device unless it is properly signed&lt;br /&gt;
 - exception: unlocked bootloaders (which many devices don&amp;#039;t allow)&lt;br /&gt;
&lt;br /&gt;
PCs also have the same mechanisms&lt;br /&gt;
 - default config on many systems is to only allow booting of trusted bootloaders (from trusted operating systems)&lt;br /&gt;
 - who has the keys for this?  Microsoft!&lt;br /&gt;
 - you can turn off trusted boot to allow any OS to be installed&lt;br /&gt;
 - many Linux distributions can be installed on PCs with trusted&lt;br /&gt;
   boot enabled&lt;br /&gt;
     - either by installing your own keys, or...&lt;br /&gt;
     - because Microsoft has signed the Linux distribution&amp;#039;s bootloader&lt;br /&gt;
&lt;br /&gt;
You can leave trusted boot enabled and run custom kernels...but you need to add your own keys to your PC&amp;#039;s EFI so it will trust your kernel&lt;br /&gt;
&lt;br /&gt;
In looking at the code for simple.c, note a few things:&lt;br /&gt;
 - the #include&amp;#039;s aren&amp;#039;t for standard libraries&lt;br /&gt;
    - in fact, the C library ISN&amp;#039;T AVAILABLE for kernel code&lt;br /&gt;
       - because you can&amp;#039;t even make system calls in kernel modules!&lt;br /&gt;
       - makes sense if you realize the kernel is what implements&lt;br /&gt;
         system calls&lt;br /&gt;
       - and, you really don&amp;#039;t want to switch from user mode to&lt;br /&gt;
         supervisor mode when you&amp;#039;re already in supervisor mode&lt;br /&gt;
       - so instead of doing a system call, the kernel just&lt;br /&gt;
         calls the right functions (but the API is more complex and delicate,&lt;br /&gt;
	 because the kernel code assumes it is working on behalf of a process,&lt;br /&gt;
	 not the kernel itself)&lt;br /&gt;
 - always need to have init and exit function&lt;br /&gt;
    - designated by module_init() and module_exit()&lt;br /&gt;
    - init can potentially fail, it should return 0 on success&lt;br /&gt;
    - exit has no return value, assumed to always work&lt;br /&gt;
&lt;br /&gt;
 - the pr_info are macros for printk&amp;#039;s (NOT printf&amp;#039;s!)&lt;br /&gt;
    - how the kernel writes log messages&lt;br /&gt;
    - the &amp;quot;info&amp;quot; part designates the importance of the log message&lt;br /&gt;
      (can be warn, others)&lt;br /&gt;
&lt;br /&gt;
There is no main function in a kernel module, just init&lt;br /&gt;
  - remember, a module doesn&amp;#039;t continuously run, instead&lt;br /&gt;
    it adds code to the kernel that is run when certain conditions occur&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Pro tip: remove modules when you are done with them&lt;br /&gt;
 - class modules may interfere with each other&lt;br /&gt;
 - if things seem weird, reboot your VM&lt;br /&gt;
&lt;br /&gt;
Go to a Linux cross reference website to look at the Linux kernel source&lt;br /&gt;
 - that&amp;#039;s how I figured out how to build kernel modules&lt;br /&gt;
 - there are also random web pages, but they are often out of date&lt;br /&gt;
   - the authoritative source is the Linux kernel source code&lt;br /&gt;
 - you can see system calls defined in the source with SYSCALL_DEFINE?&lt;br /&gt;
   where ? is the number of arguments the system call takes&lt;br /&gt;
&lt;br /&gt;
The Linux kernel is the Linux kernel&lt;br /&gt;
 - all that varies are the options it is built with, what modules are included&lt;br /&gt;
 - embedded systems use the same kernel, just maybe with fewer modules,&lt;br /&gt;
   some different features enabled/disabled, but it is mostly the same&lt;br /&gt;
    - userland is very different, is much more compact&lt;br /&gt;
&lt;br /&gt;
Remember that kernel modules are tied to a specific version of the Linux kernel&lt;br /&gt;
 - when you install a new version of the kernel, new modules must accompany it&lt;br /&gt;
 - this is because the internals of the kernel change all the time, and&lt;br /&gt;
   Linux, by design, has no stable internal interfaces&lt;br /&gt;
     - the stable interface is the system call interface!&lt;br /&gt;
&lt;br /&gt;
the ones module installs a custom device&lt;br /&gt;
a device is just a &amp;quot;file&amp;quot; that has custom file operations&lt;br /&gt;
  - when you do a read or a write to this file, you are running special&lt;br /&gt;
    functions, not just reading data from a device&lt;br /&gt;
  - those functions *could* get data from an outside source, but&lt;br /&gt;
    they can just make it up (fill buffers with 1&amp;#039;s)&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>