<?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_12</id>
	<title>Operating Systems 2021F Lecture 12 - 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_12"/>
	<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_12&amp;action=history"/>
	<updated>2026-04-06T04:46:31Z</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_12&amp;diff=23420&amp;oldid=prev</id>
		<title>Soma: Created page with &quot;==Video==  Video from the lecture given on October 21, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec12-20211021.m4v...&quot;</title>
		<link rel="alternate" type="text/html" href="https://homeostasis.scs.carleton.ca/wiki/index.php?title=Operating_Systems_2021F_Lecture_12&amp;diff=23420&amp;oldid=prev"/>
		<updated>2021-10-22T03:04:20Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Video==  Video from the lecture given on October 21, 2021 is now available: * [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec12-20211021.m4v...&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 21, 2021 is now available:&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec12-20211021.m4v video]&lt;br /&gt;
* [https://homeostasis.scs.carleton.ca/~soma/os-2021f/lectures/comp3000-2021f-lec12-20211021.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 12&lt;br /&gt;
----------&lt;br /&gt;
 - midterm interviews will be after the break, will post schedule&lt;br /&gt;
   for sign-ups&lt;br /&gt;
     - either volunteer or sign up when asked&lt;br /&gt;
 - if you did badly, don&amp;#039;t worry&lt;br /&gt;
     - final exam can replace midterm grade (it is cumulative)&lt;br /&gt;
 - solutions will be posted once the midterm is graded (by the end of break, so by the end of the month)&lt;br /&gt;
&lt;br /&gt;
 - interview is a ~10 minute meeting&lt;br /&gt;
   - we go through your answers, discussing questions where&lt;br /&gt;
     you missed points or had a really good answer&lt;br /&gt;
   - really, it is a review to make sure it was properly graded&lt;br /&gt;
   - only time there would be an issue is if it became clear&lt;br /&gt;
     what you know != what is in your answers&lt;br /&gt;
   - about half the time I increase grades (I don&amp;#039;t decrease them&lt;br /&gt;
     if grading was too lenient)&lt;br /&gt;
   - if you want to appeal your grade on the midterm, do an interview&lt;br /&gt;
     (because the process is the same)&lt;br /&gt;
 - if you have concerns about any assignment grading, just message or email me, I will investigate&lt;br /&gt;
 &lt;br /&gt;
Tutorial 5&lt;br /&gt;
 - draft is posted now&lt;br /&gt;
 - will be adding eBPF-based content (need to add some opensnoop-based questions, maybe others)&lt;br /&gt;
&lt;br /&gt;
Tutorial 5 is all about how the login process works&lt;br /&gt;
 - when you log in, what happens?&lt;br /&gt;
 - LOTS is happening, we won&amp;#039;t cover it all&lt;br /&gt;
   - but you should get a mental model that lets you figure out&lt;br /&gt;
     details as you need to&lt;br /&gt;
&lt;br /&gt;
grep is the command line search program&lt;br /&gt;
  - searches through specified files&lt;br /&gt;
  - can you regular expressions, but can treat is just as searching for plain text&lt;br /&gt;
&lt;br /&gt;
What mental model should you have of what happens when you log in?&lt;br /&gt;
 - there&amp;#039;s a program waiting for logins (sshd, logind, or something else)&lt;br /&gt;
 - when you connect to it, it creates a child to handle the new session&lt;br /&gt;
    - parent goes back to waiting for new login attempts&lt;br /&gt;
    - (parent is normally a daemon of some kind)&lt;br /&gt;
 - daemon child gets user input, decides whether access is granted or not&lt;br /&gt;
 - if access is granted, it changes its privileges to be that&lt;br /&gt;
   of the requested user and then starts that user&amp;#039;s session&lt;br /&gt;
     - by execve&amp;#039;ing bash at some point, telling it to start a new session&lt;br /&gt;
&lt;br /&gt;
Users &amp;amp; groups in UNIX&lt;br /&gt;
 - associated with every file is a user and a group&lt;br /&gt;
    - actually a uid and a gid, they are numbers&lt;br /&gt;
 - associated with every process is a uid and potentially multiple gid&amp;#039;s.&lt;br /&gt;
    - but only one active gid&lt;br /&gt;
&lt;br /&gt;
Permissions in UNIX are (traditionally) all about looking at uid&amp;#039;s and gid&amp;#039;s and deciding what is allowed based on that.&lt;br /&gt;
&lt;br /&gt;
Root&amp;#039;s uid is 0&lt;br /&gt;
 - kernel normally treats uid 0 as maximally privileged, i.e., if a process with uid 0 asks to do something, the kernel says YES&lt;br /&gt;
    - unless it is just impossible to do&lt;br /&gt;
    - (there are more advanced security mechanisms that limit root&amp;#039;s privileges, but that is for much later in this class, if we have time)&lt;br /&gt;
&lt;br /&gt;
To the kernel, there are no &amp;quot;users&amp;quot;&lt;br /&gt;
 - there are just processes and files with uid and gid labels&lt;br /&gt;
 - kernel doesn&amp;#039;t have any concept of usernames&lt;br /&gt;
&lt;br /&gt;
A key idea in UNIX is that kernel implements mechanism, not policy&lt;br /&gt;
 - defers policy to userspace&lt;br /&gt;
 - allows kernel to be flexible&lt;br /&gt;
&lt;br /&gt;
Key questions&lt;br /&gt;
 - where are uid&amp;#039;s and gid&amp;#039;s stored for files?&lt;br /&gt;
 - where is the association between uid&amp;#039;s and usernames&lt;br /&gt;
   (and gid&amp;#039;s and group names) stored/maintained?&lt;br /&gt;
&lt;br /&gt;
In networked UNIX systems (i.e., ones where people can log into many systems as if they were one system), there can be complex ways to store username/group info&lt;br /&gt;
  - LDAP&lt;br /&gt;
  - kerberos/hesiod (and even MS Acive Directory)&lt;br /&gt;
  - yp/nis&lt;br /&gt;
(These are WAY outside the scope of this class, and&lt;br /&gt;
are actually increasingly irrelevant.)&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
But all of these systems are extensions to the classic UNIX mechanisms of user and group info files:&lt;br /&gt;
  /etc/passwd&lt;br /&gt;
  /etc/group&lt;br /&gt;
&lt;br /&gt;
(and /etc/shadow and /etc/gshadow)&lt;br /&gt;
&lt;br /&gt;
In your home directory, dot files configure your environment&lt;br /&gt;
 - hidden by default by ls because there can be a lot of them&lt;br /&gt;
&lt;br /&gt;
A user has access to all of the files in their directory&lt;br /&gt;
 - they can change them at will, and thus change their environment&lt;br /&gt;
&lt;br /&gt;
Remember dot files are normally text files&lt;br /&gt;
 - so you edit them like any text file!&lt;br /&gt;
&lt;br /&gt;
Passwords need to be stored, but not exactly&lt;br /&gt;
 - don&amp;#039;t want people to just read the password file and know their password&lt;br /&gt;
 - instead, store passwords &amp;quot;hashed&amp;quot;, one way function that can be used&lt;br /&gt;
   to verify the password&lt;br /&gt;
&lt;br /&gt;
To see how traditional UNIX systems stored passwords, run&lt;br /&gt;
  &amp;quot;shadowconfig off&amp;quot; as root&lt;br /&gt;
  - disables shadow passwords&lt;br /&gt;
&lt;br /&gt;
The passwd file needs to be world readable&lt;br /&gt;
 - so everyone can see what the uid&amp;lt;-&amp;gt;username mapping is,&lt;br /&gt;
   and so they can run finger&lt;br /&gt;
&lt;br /&gt;
But keeping password hashes accessible is a security risk&lt;br /&gt;
 - if I know your password hash, I can keep guessing&lt;br /&gt;
   until I figure it out&lt;br /&gt;
 - guessing passwords and testing password hashes is &amp;quot;password cracking&amp;quot;&lt;br /&gt;
   &lt;br /&gt;
So, how do we only allow privileged users to get password hashes?&lt;br /&gt;
 - move password hashes to /etc/shadow&lt;br /&gt;
 - do same for group passwords to /etc/gshadow&lt;br /&gt;
&lt;br /&gt;
For every file, three groups of permissions are stored&lt;br /&gt;
  user&lt;br /&gt;
  group&lt;br /&gt;
  other&lt;br /&gt;
&lt;br /&gt;
For each of these, we have three basic permissions&lt;br /&gt;
  read&lt;br /&gt;
  write&lt;br /&gt;
  execute&lt;br /&gt;
&lt;br /&gt;
so 3 bits for three fields: 9 bits&lt;br /&gt;
 (there&amp;#039;s a 4th bit for each, will discuss it later)&lt;br /&gt;
&lt;br /&gt;
When you do ls -l, the first field tells the kind of file&lt;br /&gt;
 &amp;quot;-&amp;quot;  regular file&lt;br /&gt;
 &amp;quot;d&amp;quot;  directory&lt;br /&gt;
 &amp;quot;c&amp;quot;  character device&lt;br /&gt;
 &amp;quot;b&amp;quot;  block device&lt;br /&gt;
 &amp;quot;l&amp;quot;  symbolic link&lt;br /&gt;
 &amp;quot;p&amp;quot;  named pipe&lt;br /&gt;
&lt;br /&gt;
We&amp;#039;ll explain each of these later, for now just focus on files and directories.&lt;br /&gt;
&lt;br /&gt;
The kernel is thus looking at each file&amp;#039;s permission bits and uid/gid&lt;br /&gt;
whenever an open system call is made&lt;br /&gt;
 - it decides whether the process making the open has the right privileges&lt;br /&gt;
 - note it doesn&amp;#039;t look at password hashes or anything like that,&lt;br /&gt;
   that is taken care of in userspace&lt;br /&gt;
&lt;br /&gt;
man chmod will tell you some about permission bits&lt;br /&gt;
&lt;br /&gt;
But how do we get the first user&amp;#039;s process?&lt;br /&gt;
 - the login process must create a child that &amp;quot;becomes&amp;quot; the user&lt;br /&gt;
    - the setuid, setgid system calls allow a process to change&lt;br /&gt;
      their user ID&lt;br /&gt;
    - of course these system calls are privileged&lt;br /&gt;
&lt;br /&gt;
This all works if a privileged process wants to become unprivileged.  But, what if I want to do a privileged operation as a regular user?&lt;br /&gt;
 - &amp;quot;setuid&amp;quot;: when you have owner execute and the setuid bit set,&lt;br /&gt;
   when you do an execve of the file, the process will run&lt;br /&gt;
   with the permissions of the file owner (and not of the uid&lt;br /&gt;
   of the process that did the execve)&lt;br /&gt;
 - &amp;quot;setuid root&amp;quot; - executable is owned by root and has the setuid bit set&lt;br /&gt;
&lt;br /&gt;
setuid executables, especially setuid root ones, are dangerous&lt;br /&gt;
 - can allow regular users to do things as root&lt;br /&gt;
 - if they aren&amp;#039;t programmed well, vulnerablities&lt;br /&gt;
   can then allow unprivileged users to become root&lt;br /&gt;
&lt;br /&gt;
So, then, how does sudo work?&lt;br /&gt;
 - it checks if the user is in the &amp;quot;sudo&amp;quot; group&lt;br /&gt;
 - if the user is, and they type in their password,&lt;br /&gt;
   run what they ask for as root (which it can, because&lt;br /&gt;
   sudo is setuid root)&lt;br /&gt;
(Complexity of sudo comes from being able to define rules&lt;br /&gt;
 on what commands can be run)&lt;br /&gt;
&lt;br /&gt;
When you login, nothing special really is happening&lt;br /&gt;
  - it is just a privileged process getting a request,&lt;br /&gt;
    deciding whether it is allowed,&lt;br /&gt;
    and then creating a child to handle the request&lt;br /&gt;
  - only tricky bit is the child has to change its uid, gid&lt;br /&gt;
    in order to be the limited requested user, not root&lt;br /&gt;
    - if you don&amp;#039;t drop privileges, you&amp;#039;re letting&lt;br /&gt;
      regular users become root&lt;br /&gt;
&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Soma</name></author>
	</entry>
</feed>