Operating Systems 2017F Lecture 16: Difference between revisions

From Soma-notes
No edit summary
No edit summary
Line 103: Line 103:
o Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.
o Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.


Additional notes:
'''Additional notes:'''
--> Warning: it's possible to destroy your entire system with 1 command. Solution: have good backups
--> Warning: it's possible to destroy your entire system with 1 command. Solution: have good backups
--> Core kernel functionality is implemented via modules
--> Core kernel functionality is implemented via modules

Revision as of 19:40, 7 November 2017

In Class Comp 3000 Lecture 16 Important notes: Tutorial 5: File system :  persistent data structure organized around blocks (which are fixed allocation units)  maps hierarchal names (keys) to values  provides a file-like API like open, read, write, close,etc What does it mean to “make” a file system?  Initializing a data structure.  “formatting” a disk Physical vs Logical : logical size of a file: the size your program see when accessing the file (bytes in a file) Physical : How much space it takes up on disk , in terms of blocks , fixed units of storage allocation

Physical :  By default or for multiple of files it is 1K blocks  Example : Ext4 has 4k blocks

Kernel Programing :  Warning: o If you use linux base , you may crash your whole system, just backup before you do so using “rsync”. Open Stack : log in through the terminal using your instance’s Ip address , but it failed to work . when you ssh to it you must write ssh “Address” –l Ubuntu  You are required to use sude to add a user name, so u can play around in root. What is a Kernel module ?  A way of splitting up kernel functionality so everything does not have to load at boot.  Modifies a kernel functionality  Runs in kernel space , is the key thing to think about o It is more powerful than root and it can do anything o Access to all kernel memory o And you can modify everything  If you miss anything in the kernel development your system will crash  Kernel machine provides you with a floppy by default which explains why it still exists in Anil’s terminal  Once you install a module , the module is unstrained Why do we use modules? Why don’t we load processes instead?  No new mechanisms  Increased security (restricted access)  Makes the kernel less smaller, microkernel design, o Putting in the functions that are supposed to be in the kernel into processes o Process do IPC rather than code talking in supervisor mode  Examples : • Filesystems • Drivers • Networking • Minix, QNX, GNU, hurd,  Why is Linux “monolithics” kernel ? o Switching between contexts are expensive (context switch) o How to make microkernels fast can be adopted by monolithics kernels to make them even faster o Unreal security benefits :  if you control the file system process, you can control everything




Rebuilding and changing the kernel:  1)Type “make” : more compilacted than 2401 o Kernel built  2)Make modules  3)Sudo make install  4) sudo make-modules install  5) Sudo shutdown –r now : for the vm to reboot  Which configuration would you use to build your own kernel ? o Don’t do configurations from scratch o Copy the configurations and use them o Make localmodconfig : output for ls mod and uses that for configuring your kernel o Requires time and effort  Why less /dev/ones doesn’t exist anymore? o Since reboot occurred o You must load the modules again o Head –c 100 /dev/ones to be able to use it again  Implementing the device file of dev 1 ?

o Implement the file API required o Teach the kernel what it means to do operations like read, etc Code from the tutorial ones.c:  Open ones_read code: file descriptor, file , buffer, amount of bytes to read and offset o Offset : position in the file o Fills the buffer with ones o Why don’t we just set it to 1 instead of putting put_user?  Char *buf : Pointer for a user space process, in order for the kernel to write to user spacer safely o Line 46: Why use printk and not printf? Since printf is not defined because the c library is not available in the kernel, how can you can c library when the c library depends on the kernel? Kernel is independent, does not depend on any libraries.


Commands: Man ls : to see different ls commands  Ls –las block  Cat /dev/ones |less : it is like dev u random , but instead of generating random number, it instead generates infinite of number 1  Ls –mod : displays all the moduls which are currently loaded on the virtual machine  IBM ps/2 : series of computers created to control PC, developed the interfaces to have a mouse and keyboard.  Less readme : to check instructions of how to do a make  Make menuconfig : options of kernel configurations  Cat/pro  Less .config : bad idea to go directly in it , use “make menuconfig “  /boot : where the kernel got installed. o Ls –lah : to see the size  Less/ etc/modules  Modul init: what function should be called when loaded and when it is unloaded  Modul exit:  Creating a device file : defining a file which has special semantics, define a struct and functions which should be called to explain each file operation, open , read, release(like closing but not really)  What happens if you start running to the file ? permission are read only, not writing o Override that? Still your permission is denied, you can only read since we didn’t write a function in the struct to write.

Additional notes: --> Warning: it's possible to destroy your entire system with 1 command. Solution: have good backups --> Core kernel functionality is implemented via modules --> use ls mod to see modules that are loaded --> In practice, you load modules all at once

Why do we need to load code into the kernel anyways? --> more secure, ability to restrict access

--> examples of microkernel: minix (predecessor to Linux), QNX, GNU hurd --> once you install a module, it's unrestrained

What is a monolithic kernel? --> a type of OS architecture where the entire OS is working in kernel space --> can dynamically load/unload modules at runtime

make localmodconfig: --> takes output of ls mod and configures your kernel

ones.c program:

/dev/ones: --> permissions are read only

file_operations ones_fops(): --> define what happens when you open a file, read from it, release tells you what happens when you're done with it (not the same thing as close)

ones_read(): --> len = number of bytes to read --> offset tells you where you are in the file --> put_user(): takes care of whatever needs to be done to write into that process properly

ones_release:

Why are we using printk instead of printf? --> printf is not yet defined (ie. C library is not available in the kernel) --> kernel doesn't depend on any libraries, all code belongs to the kernel itself --> printk is the kernel's own implementation of printf (outputs to the kernel log --> /var/log/kern.log)

vfs = virtual filesystem layer

How do we limit access to user space processes? --> Do a permission check

--> kernels need to be updated regularly to correct bugs that make the kernel vulnerable to programs trying to gain access to important user space processes --> unlikely() = tells you that this branch is not likely to be taken, optimize the current path

vfs_read:

file->f_op->read: --> this is how our read function will be called