<?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_2021F_Lecture_8</id>
	<title>Operating Systems 2021F Lecture 8 - 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_2021F_Lecture_8"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_8&amp;action=history"/>
	<updated>2026-04-06T04:46:33Z</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_2021F_Lecture_8&amp;diff=23369&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on October 5, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec08-20211005.m4v v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_8&amp;diff=23369&amp;oldid=prev"/>
		<updated>2021-10-05T17:29:49Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on October 5, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec08-20211005.m4v v...&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 October 5, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec08-20211005.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec08-20211005.cc.vtt auto-generated captions]&lt;br /&gt;
Video is also available through Brightspace (Resources-&amp;gt;Class zoom meetings-&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 8&lt;br /&gt;
---------&lt;br /&gt;
* Assignment 1 solutions released (will discuss at end)&lt;br /&gt;
* Tutorial 3 &amp;amp; gdb&lt;br /&gt;
* Tutorial 4&lt;br /&gt;
&lt;br /&gt;
Using gdb&lt;br /&gt;
---------&lt;br /&gt;
- To allow attaching to processes that aren&amp;#039;t gdb&amp;#039;s children, do the following:&lt;br /&gt;
&lt;br /&gt;
  sudo -i&lt;br /&gt;
  echo 0 &amp;gt; /proc/sys/kernel/yama/ptrace_scope&lt;br /&gt;
  exit    # to become a regular user again&lt;br /&gt;
&lt;br /&gt;
  (if you try doing the attach without doing this, you&amp;#039;ll get an error&lt;br /&gt;
   in gdb telling you about this file)&lt;br /&gt;
&lt;br /&gt;
- Compile with -g (to get debugging symbols) (keep -O)&lt;br /&gt;
- connect in two windows&lt;br /&gt;
- run the program you want to watch in one window&lt;br /&gt;
- in the other, find out its pid (eg using ps aux | grep)&lt;br /&gt;
- run gdb on the binary, then attach the PID (&amp;quot;attach &amp;lt;PID&amp;gt;&amp;quot;)&lt;br /&gt;
- set a breakpoint (probably at a function) so execution stops&lt;br /&gt;
  at a point of interest&lt;br /&gt;
- do &amp;quot;tui enable&amp;quot; to get a litle text-mode interface that shows you code&lt;br /&gt;
- note gdb will only follow one process at a time&lt;br /&gt;
   - so you have to decide whether you want to follow the parent or child&lt;br /&gt;
     on fork&lt;br /&gt;
   - by default, follows the parent&lt;br /&gt;
   - &amp;quot;set follow-fork-mode child&amp;quot; to follow child&lt;br /&gt;
- remember that gdb has extensive help and command completion&lt;br /&gt;
    - tab is your friend!&lt;br /&gt;
- n = next statement&lt;br /&gt;
  c = continue until next breakpoint/signal/program termination&lt;br /&gt;
  s = next statement, but going into functions&lt;br /&gt;
  print = view state of variables&lt;br /&gt;
  x = examine memory&lt;br /&gt;
  b = breakpoint (by line or function name)&lt;br /&gt;
  catch syscall = see every system call entered and exited (like strace but&lt;br /&gt;
                  slower)&lt;br /&gt;
&lt;br /&gt;
- you can&amp;#039;t run the program backwards&lt;br /&gt;
  (there are cool things that can, but not standard tools)&lt;br /&gt;
&lt;br /&gt;
GDB is a powerful tool, lots to play with and master&lt;br /&gt;
 - For this class I don&amp;#039;t care about you learning gdb per se&lt;br /&gt;
 - rather, it is a tool for you to understand how&lt;br /&gt;
   processes work&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Question: how does gdb actually work?&lt;br /&gt;
 - aren&amp;#039;t processes separate?&lt;br /&gt;
    - they each have their own address space&lt;br /&gt;
    - how is one process controlling another?&lt;br /&gt;
 - how can ltrace and strace watch another process?&lt;br /&gt;
 - ONLY WAY: ask the kernel for help&lt;br /&gt;
 - they use ptrace&lt;br /&gt;
 - ptrace can only follow one process at a time&lt;br /&gt;
 - it is also very intrusive, can change program behavior&lt;br /&gt;
   - you don&amp;#039;t want to use it when someone cares about the program&lt;br /&gt;
     continuing to work&lt;br /&gt;
 - you use ptrace-based tools to debug programs&lt;br /&gt;
   - but what if you want to debug in production?&lt;br /&gt;
&lt;br /&gt;
 - traditionally, to debug in production you&amp;#039;d just look at logs &amp;amp; crash dumps&lt;br /&gt;
 - but now we have something better: eBPF&lt;br /&gt;
 - &amp;quot;enhanced Berkeley Packet Filter&amp;quot; (name is almost meaningless now)&lt;br /&gt;
   - allows us to add code to the kernel safely to interact with the system&lt;br /&gt;
&lt;br /&gt;
 - if your vm does not have /usr/local/share/bpftrace/tools, you&amp;#039;re running the wrong VM (it should be the 2021 os VM)&lt;br /&gt;
    - this is the one I created for the class&lt;br /&gt;
&lt;br /&gt;
 - VM is all set for bpftrace except for one thing&lt;br /&gt;
    - WRONG KERNEL&lt;br /&gt;
    - kvm kernels (for some strange reason) don&amp;#039;t have full eBPF support&lt;br /&gt;
       - error in its configuration&lt;br /&gt;
    - so you need to install the generic kernel&lt;br /&gt;
       - instructions in Tutorial 4&lt;br /&gt;
    - if you have problems please let me know!&lt;br /&gt;
 - get the generic kernel running before doing Tutorial 4&lt;br /&gt;
    - check /proc/version that it says something like&lt;br /&gt;
        Linux version 5.11.0-37-generic&lt;br /&gt;
      NOT -kvm&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
 - unlike strace-based tools, eBPF-based ones must run as root&lt;br /&gt;
    - they can SEE ALL, so it makes sense&lt;br /&gt;
&lt;br /&gt;
 - what&amp;#039;s great about bpftrace is it lets you see what is happening anywhere on&lt;br /&gt;
   the system&lt;br /&gt;
     - so can watch specific system calls, who are making them and when&lt;br /&gt;
     - but can also watch function in userspace &amp;amp; kernelspace&lt;br /&gt;
&lt;br /&gt;
 - yes in an attacker&amp;#039;s hands this is potentially very bad&lt;br /&gt;
    - that&amp;#039;s why only root can do it&lt;br /&gt;
    - lots of other ways for root to get this kind of info,&lt;br /&gt;
      this is just crazy easy&lt;br /&gt;
 - I will add to the tutorial the header file with the system call numbers&lt;br /&gt;
   - so you can interpret the output of syscalls.bt&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
bpftrace works by attaching &amp;quot;probes&amp;quot; to specific tracepoints&lt;br /&gt;
 - events that can be monitored&lt;br /&gt;
 - a probe runs when the event happens&lt;br /&gt;
 - you can see a list of possible events with bpftrace -l&lt;br /&gt;
   - but you can also do uprobes of arbitrary&lt;br /&gt;
     userspace functions&lt;br /&gt;
   - run &amp;quot;sudo bpftrace -l | wc&amp;quot; to see how many, I see 50K+&lt;br /&gt;
      - use grep to search!&lt;br /&gt;
 - to see what probes are being used, run bpftrace -v&lt;br /&gt;
   (verbose)&lt;br /&gt;
&lt;br /&gt;
I don&amp;#039;t expect you to understand how bpftrace works&lt;br /&gt;
 - it is pretty magical&lt;br /&gt;
&lt;br /&gt;
But I do expect you to get an understanding of what it is showing you&lt;br /&gt;
 - files being opened, programs being run, signals being sent&lt;br /&gt;
 - perspective on everything we&amp;#039;ve covered up to now&lt;br /&gt;
&lt;br /&gt;
eBPF is a hot technology in the cloud today&lt;br /&gt;
 - major companies use all kinds of eBPF-based tools to monitor their&lt;br /&gt;
   infrastructure, track down bugs, and even secure systems&lt;br /&gt;
 - look up cilium.io to see the kinds of things being enabled with eBPF&lt;br /&gt;
&lt;br /&gt;
(bpftrace is just one eBPF-based tool by the way)&lt;br /&gt;
&lt;br /&gt;
Later you&amp;#039;ll try writing your own bpftrace scripts&lt;br /&gt;
 - but for now, if there is something you&amp;#039;d like to see, ask for&lt;br /&gt;
   it on Teams, I can try putting something together&lt;br /&gt;
&lt;br /&gt;
by default, a bpftrace scripts watches the whole system&lt;br /&gt;
  - you have to add logic to limit what you see&lt;br /&gt;
  &lt;br /&gt;
If you have time to spend learning bpftrace, go ahead, but it won&amp;#039;t be covered directly on the midterm&lt;br /&gt;
  - it is its own language, not fully documented&lt;br /&gt;
  - I want you to understand the output of the bpftrace scripts asked about&lt;br /&gt;
    in Tutorial 4&lt;br /&gt;
&lt;br /&gt;
Other cool things in eBPF:&lt;br /&gt;
  - bcc, the eBPF compiler collection (python + C)&lt;br /&gt;
  - cilium (cloud monitoring)&lt;br /&gt;
  - bpfcontain (William Findlay, my PhD student, doing container security)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;re going to use eBPF to learn how the kernel works later&lt;br /&gt;
 (after the midterm)&lt;br /&gt;
&lt;br /&gt;
eBPF is (a) tool you use to find out the overhead of other tools&lt;br /&gt;
&lt;br /&gt;
(Try running &amp;quot;gdb 3000shell&amp;quot; and then type &amp;quot;run&amp;quot; at the gdb prompt.  See how well things work)&lt;br /&gt;
&lt;br /&gt;
Midterm is not proctored, but I will do randomized &amp;amp; selected interviews after&lt;br /&gt;
 - online proctoring is ridiculous&lt;br /&gt;
 - you&amp;#039;ll submit a text file via brightspace&lt;br /&gt;
    - open book, open note, open internet, just NO COLLABORATION&lt;br /&gt;
      (you only have 80 minutes so collaboration would mean cheating,&lt;br /&gt;
       don&amp;#039;t do that)&lt;br /&gt;
 - you may volunteer for interviews&lt;br /&gt;
   (good way to make sure you got all the points you should)&lt;br /&gt;
     - I&amp;#039;ll post a schedule once midterms are graded&lt;br /&gt;
&lt;br /&gt;
A2 will be due by class time on the 14th, along with tutorials 3 &amp;amp; 4.&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>