Okay, and let's start recording
Okay, Good morning, everyone. we've we're at near the end here, as you can see from the
You can see from the schedule here we're right now on we have lecture today.
We have lecture Thursday. you have until class time on Thursday.
Yes. so all the last tutorials 7, 8, 9 are due along with assignment, for I basically do Thursday for class.
We really should try to finish it by the end of Wednesday, but you can turn it in.
Get the done before class. but you know, keep mind when office hours are, and stuff so, and all depends on idea.
So we're so hopefully assignment so right now what i'm happy to do, is answer questions so today.
So this is this is my plan right now, because this is basically this week is reviewing stuff and discussing things for the final Exam: Because Oh, where are you expected to receive assignment?
3 grades. Oh, it's almost completely graded I think there's one question that is great.
I'll get that up for you ac grades Oh, sorry I should have got that.
I should have followed up on that yesterday. but I well, right now.
So in terms of new material. I mean I certainly if there's time i'm happy to discuss other things.
But there's so much material I could still cover but we've kind of run out of time.
And we've got you know this you know we've got the 4 assignments here, and you know you will have I'm happy to answer other questions and discuss things.
But really, you know, last week so but anyway, so let's Co.
So
Okay, So I i've got a question here about assignment for so Yeah.
So please do ask me questions. This is Come on.
How's my wish come wiki been slow
There we go. No, that's not okay so requirements
Yeah, Okay, So what you should say when you run this command?
Is it? number of it should lock up like it? should not, this command should not finish.
Yeah, So this should lock up and then you won't see everything that you see for question.
3 so i'll just say that but then you know tell me what's going on with that?
So. That was a question about that other questions about assignment for i'm happy to discuss anything a question.
Yep. no, it means intermediate lookups. Is it talking about like the Pmd. any other?
This stuff you're talking about 9 Oh, intermittent.
Yeah, yeah, exactly what what i'm talking about intermediate lookups.
What i'm literally talking about is deans all these addresses That's what you want to the pud pmd heat, though you want to report all of those that's. What you wanna do do you us explain why the lockout happens for
a exploit get basically explain what's happening and then track it down as much as you can.
I mean it's i'm not expecting so so just to be clear.
I'm sorry with with this assignment I expect the questions.
Yeah. One through 4, I think, are pretty much run. and observe, I think these are mostly gimme points.
5 and 6 requires a little bit of, you know.
Thought and experimentation. but again they aren't too hard sevens hmm!
A little more. A little thought, but again but 8, 9, 8 9.
Those those take some work. Yeah. So 8 9 or the rest of the assignment should be relatively straightforward.
8 and 9 is what's actually the hard work
So So what streaming? Yeah, Well, depends on how you the actual solution for 9.
Is not that hard? As long as you figure out how to.
Yeah, I told you basically how to do it. so. but you actually have to code for Oh, I think Tag is not going
So the question about difference between K. malik and getting a page.
The big difference between K-mart and gang. A page is K.
Malloc gang of page only gets you. One page came. Malloc gets you a bunch of pages actually contiguous in the kernels virtual virtual address space.
Maybe can I think actually, maybe contiguous in physical address space, too.
Actually, I think that I I know is contiguous in both.
But i'm not i'd have to you know check that.
But basically it's you know get paid just one page other other questions on the on question assigned for So on Thursday I will be going through the full solutions for this Yeah, 5 5 exactly that that's Exactly.
What you do for 5 and 7. you should do do some experiments and make some reasonable guesses about what's happening.
You know that that I mean that that really to do 5, 6, and 7, you should be doing some experiment.
But for all these things you should be doing experiments.
If you just try searching online for the answers it's mostly useless, you know you're not I mean you'll may find a few things, but you're not gonna find the you know directly understanding what the code is doing we
should be doing experiments. Oh, man.
Come here, come here.
Tab is so So Now you've got a little scene here right here.
Tab is trying to play with Roche, and Rosie just wants to sleep, anyway.
Why is Q* Mark? why excuse me, One mark I feel like you should worth more marks.
The amount of work it takes to answer.
6 is not hard to do. You literally remove the line, rebuild the module and run it.
You know, if you run it and look at the output of it versus, you know, before it's.
Yeah, Yeah, you have to look at the Yeah. Exactly. Look at the output.
It is. Yeah, 7 should not it's like 6 should not be hard, but you you we can look at it, so we don't
Well, I mean the purpose. I mean something breaks Okay, something breaks.
Yeah, you have to look at what the yeah that's true that the the log does help to.
Yeah, the log. the log also helps, but
Hi! there!
I don't today? we've got a cap here just wants to Can I get there? camera?
But you can't quite zoom. Okay, okay, gonna pick you up here, and you'll get well.
People think about questions.
For questions. This you need to move the module, Then call in smart again.
Definitely, if you don't remove the module yeah if you don't remove the module you're running the old version of the module.
Oh, and this is what he does. He bites me. Nope.
Now you are
Yeah, make only rebuilds the code. You have to load it
So just be clear what i'm doing right now. is Oh, yes, that's review for the final exam is basically today and Thursday, because now i'm gonna talk about assignment 3.
So what is on the final exam, I can say very simply, You final exam is based on the midterm assignment.
3 and assignment 4, so let's talk about assignment 3
I see what's any other questions Okay, there's no producer consumer on a* that you'd be tested on.
I the the
I the The The final exam is based on is based literally on assignment.
3 assignment for and that's true there's not I didn't put so much producer consumer on here, but it shows up in the and you're asking assignment for you'll see some hints of of actually a
pretty the presenter I don't basically the exams on the 2 tutorials directly, because the tutorial material is always bigger and I haven't actually given you answers or tested you on it so But
let's just let's go through the solutions here
So assigned 3 solutions, so download inspect the thing.
Is there a risk of data loss or writing the script?
So what I was looking for here let's what's
Download the code here, Because
Okay.
So So the question is what's the data loss that you get from here.
So while I was basically just kind of look through this and kind of look what's dangerous, i'm like okay here we're assigning things.
You know these are variables was here here, we do it echo that's not dangerous.
Oh, Rm: That's potentially dangerous so here. you know you could talk like, Okay, this is deleting, but it's just lean.
What specific file Fs image what would be called that that's our own thing.
We're not the meeting you know there here we're here. We're overriding the image.
File. You could have talked about Osama. Look at the Rm.
Demands Here, there's an rm rf that could be potentially dangerous.
But again, that's of the mount point which is 3,000 Fs.
So again, why should there be anything important in there? Because we made that directory?
And you know, overriding things. So so what I was looking for here was how, whether there's an arm of the script that you create.
So mostly. if the script is keeping to itself it's just dealing with the files and directories it created.
So as long as you, if you change it, You, of course, could make one character change and make it a race, because you race your entire drive.
But as it's written it's relatively safe
Yeah, Yeah, Exactly. Well, yeah, it's like if you as named the Rm. commands. Yeah.
But I was looking. I was looking for you to make some assessment of risk.
That's really what i'm you know kind of interesting here. So then, let's go through 2 words so.
And so yeah, I used to talk about the particular Rm.
Command. So those are the ones that really want to delete things.
And then. Now number 2 run 3,000 contain sh so so so what's the concept i'm looking at?
Is. Do you know, how do you decide whether something is dangerous or not?
What are these things doing You know the fact that we're working in a directory?
And because we're working in this directory we're not going to really mess with anything else outside of it, unless we're following symbolic links, and that would let outside of it.
We're kind of confined just by the directory structure, So then, what?
Yeah, okay, in the sugars record, Actually, how do you get back to the contain environments?
So here it was just about you know, realizing that the thing that puts you into the confined environment is this command right here. now. An advanced version of this would actually change this line to save the State.
There, there's a way to save the contact like giving it a I think a file. and then, if you go into there using the same file name, it will actually you'll get back in the same shared.
Context. But I would. You run this, and if you run again, you get into the new environment.
The reason I mentioned that other things, because technically, when you rerun this, you get a new confined environment that just happens to be the same directory as opposed to a new one.
If you put pseudo change route at 3,000 fs you at most get partial credit. Yeah.
So. yeah, So no, that was definitely our change it was definitely not the correct answer.
Because it's you don't have the confined semantics. Yeah, you you can find the directory. But change it was what the answer was last year.
That that's not that's not the answer this year 3?
How does the output of Ps differ when run inside the contained environment versus outside?
So the big difference is, P. is Ps. looks very different.
You get like pid one is the bash process that you're running.
And then you basically get another pid for the ps command so you don't see the process.
Ids of the rest of the system, you have a whole new set of process ids, and, in fact, there the option here.
I think it's a p is one that gets the new pit space.
And now notice, when you exit and you come back, you get a whole new pit space.
You have to do some special match to get the same one.
But since we weren't having anything be persistent it didn't matter
For question. 2. Oh, if you, if you if you said yeah, I if you change the directory that's perfectly fine. yeah, the yeah.
So say for question 2 you did unsure. Dash is really close.
3,000 fs. Yeah, that actually perfectly fine got that that's because this this you have to CD into the directory, and otherwise you didn't that's actually a better answer
Are. What does Lion, you know? So so what does line 50 at 3,000 contain?
Do? What does it run? So here this is about. Do you understand?
The semantics of what's happening with these lines so here.
This is just stuff. Funny way of getting, you know the term environment.
You make a directory, you copy it. These 4 lines create a shell, script with these contents, and then we run it with this change root command.
So So this was asking out, line 58, which is busy, box install.
So this is running in the confined environment, and it it makes all the hard links from all the commands that appear in there.
And so, if you don't so what that line is so on its own.
It just depends. You know, this line causes hard links.
So. and then for 5. so for 5, I was just what I really wanted you to do was do an experiment inside the confined environment.
And then just try to make a really big file, And you should have seen Now, now, if you kept running the command and got multiple copies of 3,000 fs in the mouth, you might actually using a different image.
So when you start putting things that you wouldn't if they see the changes occur.
Well, I don't think we'll think of too much for that.
But what should be have I mean I get there's there's what you see happening, and then what should happen according to your mental model, these things can get out of Sync.
And then you have to understand what's going on but here you the size of the file, that you will create is determined by the size of the you know what determines it.
It's this Dvd command this dd command you know block size, time, number of blocks, or 60 out.
That's the size of the image and then when you do make Fs ext 4 that's gonna be the Mac that's like the size of the virtual disk.
We're creating it's gonna have some over it because there's file system overhead, and then there's the files we copied into it, and then there's reserve space. But then the rest is whatever is for us to be able to make a
file. So I was looking for you to kind of do some experiments and try to figure out why is the size smaller than what you might think?
Theoretically, and if you get at least some of that, you should be fine
For question 3. we said Ps. apple was different, due to one Ps.
Coming from busybox and the main shell using bash.
No the answer for for 3 if you just said that it's Ps.
Because of the Yeah, because it's a different version of Ps.
Now that I mean I mean you could. you can mention that as a separate thing.
But the basic output is the same. Yeah, the formatting is different.
But
Because the reason why I say that is because the outputs very different in terms of the processes that are shown.
So the formatting is really secondary, could mention it.
But then, if you fill up the disk space in the host system, how will it change the amount of data that can be stored in the confined environment?
Does this depend on you know, previously stored, you know, in the confinement.
So the idea here is when you run this command. the physical size on disc will be large, will be, you know, equal to, or larger than the logicals size, because Dd.
This will allocate all the blocks, but when you run, make Fs.
Ext 4. This is going to free up a lot of the blocks, is it for everything that's not explicitly needed for file system metadata?
It will throw away those box, so your physical size will be significantly smaller than logical size, and as you right to the disk more and more of what will be used
Now this but this is now the yeah. You would actually get a couple of different ways of this.
So what what happens when you when you fill up the disc on your on your virtual machine disc, and then try to do it there.
What what you'll find is that the so on disk if you have it allocated all the blocks of the file system.
So cause like this thing is you know, deallocated most of them. and if you later need them, what happens so you're actually going to get errors in the host systems kernel log saying that I can't allocate
those blocks, but depending on your state of your system, you may, this is may actually work fine like you may be able to save stuff to the files and then retrieve them, and everything seems fine.
But you get these errors in the kernel log and that's because what's happening is everything is being cached in memory. and if the whole file system is cached in memory, you can read and write to it and we're not
saying went to disk. but everything will be fine until you reboot the system, the more you reboot the system you try to get in, that data will have been lost.
It won't have been written to the virtual disks or whatever written to the real disk. and so you won't have that data.
But it may work for as long as systems up the experiment would.
I did it first. I didn't see I got outright errors.
I actually got discounts, and then, when I tried to read from the disk, I there was nothing there.
I later did some experiments, and I read it to.
You know I got the same errors, but when I tried reading from the disc the data that i'd written was there like I did a Dd.
From Dev Random, and then did a read from it like. Then the data was there that I rebooted, and then, of course, the data was gone.
So, because because there's 4 GB of ram, and this is like 400 MB or something, so it can cash the entire virtual disk in ram so, if you But if you
said something along those like you saw something and realize that you know things are not actually getting written to disk.
Then you'd be fine is it casting round it depends on it, Sometimes it's cash ram Sometimes it isn't you're you're in this failure condition the in the confined environment.
You don't see any problems or you might see problems if you know if the data gets lost.
But from the outside it's not able to write a disc It notices that. but there shows up almost like disc errors.
That's what it looks like they look like disk errors, even though what's happening is it's just the disk is full.
But for the virtual disc you have errors. and what the question is, how does this respond?
And if it and cash it's not doesn't have to cash it.
What it can cache it so It will depend so I i've seen both behaviors.
It's definitely not being written in this
Okay.
So maybe the Conf. many files in our confined environment referred to the same inode.
What was the original name for the sign node well busybox it's not 7.
So what was kind of a give me give me? because 7 is really a different version of 4.
If you understood what for was doing like you kind of got 7.
So that wasn't quite orthogonal in in my questioning.
But you know it's me again are you what understanding how the script works what it's actually doing.
Then 8 make Nano work in the environment.
So here. what i'm really out is you understand what the heck these lines are so.
This is making all the directories for all the direct things you want.
This copy of busy Box. Busy boxes, stackly linked so there's no libraries.
It depends on Bash is dynamically linked. So you copy, bask in order for it to work.
You need all its dependencies. So this is how we find all the dependencies as we copy.
You know, you need to copy this library. Yeah. Well, actually, we first had the copy, the dynamic linker here.
Then we copy everything needed by Ld config again.
Maybe this dynamic linker we copy the dynamic Linkers configuration files, So that's also a dot linker.
And then we copy the dynamic libraries. That bash depends upon using this little bit of magic.
So this is running Ld. and then a just grabs the right column of it.
So we actually have the library files file names and then that's what we copy over to and fine environment.
So if you understood that, then you basically did exactly the same. We use how to basically do a version of this in order to get Nano to work.
But I think also you may have had to copy. that was all you have to do.
I did copy the library, but I just like for I know what the library I needed was, and copy that directly.
That's fine. Yeah, if you just found what the libraries that you needed. Were in.
Copy them directly that's perfect fine. Okay, so in fact, if you were looked at the last.
Few things that was the same. That question was the same. Question 9.
How could how can you add a user? contained a 3,000 Fs using user app?
So the question was similar the previous years one. but here I forced you to use them.
The one command version. So what this requires you to do is just look the man page of user.
Add and realize what you needed it to do which you needed it to do was to create a home directory, create a group that make the same name as the user
I don't think I I don't think dash copy was strictly necessary, though that certainly makes it.
And then the And then this dash are, you know, present Working Directory.
You could just do it, manually and put that in because it just runs the command, and that's what the back tick does, and that that gives you.
Oh, we want to run the command in this directory basically have it pretend like That's the disc, you know.
So, and then the username is contained. So So you had to play around with user, adding to get this to work, which is actually how I got it to work, because I had to play around try a couple of different options like is that the option.
That works. No, that would mess up my system and think so.
The actual answer is pretty compact getting. There is a bit of a journey.
If you did it slightly differently. it depends on what you're, slightly different answers.
So. as long as your answer was just this. and it, you know, meets the requirements that are saying here like I, The thing that is strictly not necessary.
Actually I think is dash you that's probably new I don't think it's certainly necessary.
At least over I asked it. Oh, no, no, no, I did say make sure.
The user also has a isn't a new group called contain so that means that cash capital in new business
Yeah, that's use it. Wait use dashp I couldn't get dash p to work dash P.
Kept changing my I I tried using dashp for the prefix, and I thought that could work, but it always broke for me, and it ended up changing:
Oh, yeah, yeah. you can copy your command here.
May is because it's into a fully qualified thing, but I mean the other people try using dash capital. P.
And did it work for you cause I tried that and I thought it didn't work, although based on the manpage.
I thought it should work. I mean dashr are definitely work, So that gives us but dash capital P.
I think, doesn't actually work so I thought about the prefix argument. alright.
So let me know. but I know dashboard works
And then how can you mount the main root file system inside of the confined environment?
What part of So so what's 2 things one is you look at user ad.
But then also, this is getting to understand what are all the pieces of making an account.
I
Jay: Yeah, Josh: R. Works: Yeah. Jason.
If I don't know if I I don't know you might lose Mark.
I I have to check to see what the ta you know did for that.
But
But if you feel like you should have gotten points, let me know and then
Yeah, that's 9 for 10 How do you mount So so what this is really getting you to understand?
Here is the rational between devices and file systems.
Yeah, yeah, dashboard needs the absolute path. Yes. But so this is so.
What am I talking about here when you nicely? So I type
Okay, so let me get onto the Vm. here. So if I go here I go.
Df Dot. So this is the the the device associated with it.
So, if I can. If I look at this device
So it's pointing to that so we look at
So that's the device Dm: 0. This is what actually is getting mounted for the root file system.
You notice that users in, You know the root user can read.
Write to this and users in the group disc convenient right to it.
But it's not generally available. if you have rewrite access to this device.
You can read and write any file on the file system and in fact, you can change it so that's so by exposing slash dev inside the confined environment.
You aren't really confined
Question I didn't say you need a set of passwords.
Why didn't bother you to use p okay fine
What this requires is that so? you can, just if you have access to the right depth, you make this directory, and then you mount the root file system, and then you have access to all.
The So while this is kind of contained in fact it's not that confined.
And in fact, this is one big problem with containers containers.
You can isolate things from a tendency perspective, but it's not isolated from a security perspective.
And in fact, if you want to isolate from the security perspective, you have to use other technologies things like app farm or Selinux system call filtering it's a bit of a mess actually that's an area of research
i've got i'm working on some better solutions for it.
But you know containers look like an independent system until you poke at them, and you realize they're not
If you do
If you do what So if you if you do your updates?
So the question is, why is the wise always seem to have more updates?
Well, you should first do app get update that way. you Get the latest list of updates before you do the disc upgrade.
That's what Because if you don't do the update, then follow the disk upgrade. you don't actually you're just updating based on the old list, and then you know as part of that update it will
refresh this part of that, and go like oh, wait there's actually more.
Now. Well, periodically, it updates the list, and so when you so when that happens, then you see the new ones, so you should force that
Yeah, So that's what's happy is part of the as soon as you do the update.
If you haven't if you're just doing app dis upgrade and not update after this upgrade you're gonna eventually see more.
Yeah. So that So this is just teaching you about confinement and understanding the file system that when you give access to slash, Deb, you have access to all the devices, and if you have access to all the devices you have access to
basically everything. there's a way to you if you actually mapped the root user to another user in the confined environment.
They potentially would have less access, and so that would actually make this less dangerous.
It's. But then you get rude inside of it and then you have Dev and yeah.
Oh, this is just talking about a little side thing which isn't really. yeah.
If you if you do this, you actually don't you won't see that it looks like the root file system.
But it's the arrangement is a little different that's not.
That's just a side thing going to worry about that's why it's in the parentheses.
And the reason why you can do this is because we mount slash depth in the setup script
Oh, what we try to talk is my research question is, what are we trying to achieve with containers?
Question 10 is a demonstration that containers aren't so confined, I think that you can actually make containers very highly confined, potentially equivalent or even stronger than a hardware virtual machine with the right software
in the kernel. and I think I think we could actually do it using Ebpf technology.
So There's a system if you're curious about this Google Bpf contain.
We have a tech report version of it out in room we're working on the technology hopefully.
Full papers will be published like we basically submitted it.
They said it. what we didn't quite make our case and we kind of agree.
And so the research continues. But the code is out there.
But yeah, this I it's amazing when you go out into the world, and you start using containers.
People often do not realize if you go using docker like this, of course this one's kind of crapping, but even if you use docker docker containers are not much more secure than these containers the only way they get
more secure is by using things like app armor and Selinux.
But the policies they use for those. These are security technologies for locking things.
Now, though the policies they have to use are actually white permissive.
So they they do limit a lot of attacks. But there are definitely ways around it, and there are via, and it's very easy to have things that allow you to escape a container.
Oh, so so with Ebpf technology, I i'm Really, i'm very interested in Egypt from a research perspective.
I think we can make next generation security technologies.
Anyway. So let's talk about so Then 11 How can you change the host name of the confined environment.
I can tell you without chain the point of this question was for you to realize, if you had to look at the man page for unshare, and realize that there isn't fact many namespaces and that confine you can
choose to fun. share different. Okay, Rosie, I will let you out.
And then here's Rosie, going you want to go out Okay.
I think someone's moving downstairs, and just hoping to get some food out of them.
So what what? i'm looking for is create a more complete solution So container confinement currently relies on tools that we use for locking down regular hosts. They aren't designed for confining containers and so making it per is
it's very it's very hard to make a precise policy, and it's hard to audit it and stuff it's just it's at the wrong level of abstraction.
So I really think we you to do when you have a new kind of security problem like a lot of problems in computer science. it helps to have a domain specific language to solve that problem.
And so i'm saying, Well, that simple man a new language but of course, if you just normally say like when I implement a new language. Oh, now you got to change how every system works.
It's been a big thing, but oh, we have this thing called Ebpf, where we can add code to the kernel in this very safe way.
It's not allow limitations. But now you can actually do security policies.
So if we use that, then it can work on basically all modern versions of Linux, you have a portable solution, and you have the abstraction that matches the problem
Okay, that that's all we'll sign you up there going back to this.
What this is going to look at containers and realizing that this unshare command is actually rather powerful how system resources can be shared and not share. There's a lot of different namespaces well, a lot of different yeah.
Yeah, and you can choose which ones to be unshared, and we only unshared.
Some of them with a pin namespace, we unshared but we didn't do the host name one you'd also like unsure the mount namespace and and and you would do these things to help with the the
confinement. But It's really more about hot it's more about virtualizing things, making it different in virtualization is not confinement.
I'm not gonna test you about these ideas because frankly they're more research ideas than they are mainstream practice.
But doesn't make it less true
No, the the point of of the research is I don't need a line.
This is agreement, because they've already made the infrastructure with Ebpf.
We just use the Ppf. and it will work everywhere.
No kernel changes require. Yeah. And also this is just so.
You know, learning about what host names are that's kind of more of a minor thing.
I was more interesting to sort of say, wow, there's all these different ways. Things are sharing stuff.
But you should understand. the host names questions.
So no, literally what i'm gonna do for the final exam is just I mean, i'm gonna dump in the midterm questions and dump in the double these questions into you know the the exam.
And then just mess with them the formats the same as the midterm.
No, there will not be multiple choice I don't do multiple choice
I might pull one or 2 that's possible but I don't know It's the point is I try to be consistent so you know what to expect.
Oh!
Otherwise
Trying to think of things I have yeah our interviews yeah there won't be that many out in the interviews.
But I I get interviews or an opportunity to get more.
The the interviews mostly. I end up giving people more points on their exams.
You know I never lower people's, grades the only time it would be an issue, is it for some reason I suspected, you know, that this doesn't represent your work, and then it's gonna be a whole thing.
But the point of doing the interviews is to make sure people don't do that.
And so the interviews are actually quite pleasant.
If there are any more questions about assignment. 3 or some 4, I can talk a bit more about scheduling and stuff just trying to fill in some pieces.
I kind of don't wanna like throw too much in your heads
Actually what I think I do want to talk about scheduling if I've got a few minutes if people won't ask anything else that's something I haven't gotten a chance to talk too much about and
it's
So well. it's not really going back since colonel module on this.
So so an assignment for okay, I I can talk about that.
So let's go to tutorial like so what do you have to have in a module which I have in a module?
Is this: You gotta have something that you know, you know, initializes the module.
You have to have something that exit the module that's all you strictly need right.
This is all you need I can't really replace these Ivy's print info and and these are macros.
And now built in, I should probably replace those in my module from rather having these defines.
I should do that for next time. I teach this class.
But anyway, the reason why we keep seeing these things with struct file operational things is because we're making device modules.
These are. These are modules that create a device and dev and so creating a device.
And Dev, we're making a special file the thing with the special file. Is you define how file operations work on it?
Here. we only define open works, how we works and releases.
What happens when you know what happens when you close everyone closes that no resources are freed.
That's all we do. We could also define right we could also define, seek.
We could do lots of things to make this more functional.
But this is all we've done for this particular one that's all we've done in the modules
No, I say device module, No, this is a kernel module that's all.
This is this is a kernel module. but this kernel module, a colonel.
Module is just code. you are inserting into the colonel.
Colonel Module can do basically anything a 0 kernel functionality.
Most kernel modules implement device drivers and if you're implementing a device driver.
You probably want to implement a special file in slash down.
So when I talk block devices and character devices anything that isn't a file or directory, or somebacco. if it's not a it's not a file or directory, it's generally considered a special file and
normally. when we talk about special files we're talking about block block block devices and character devices for more of a general term, It's just the files that don't stores stuff that do other things so if
you're seeing a character device. it's a special file it's just just switching special files from regular files.
So it's not a regular file, I would for a group directories in with regular files.
If I was actually it's a special file yeah they're like a file.
But they're special exactly exactly
So with windows, plug and plague, Does that mean the Os searches required kernel?
Module installed them automatically. yes, basically they aren't called their windows.
Just call them drivers. But they're essentially it's the same thing. and it's a little bit of isolation between them and the rest of the code and the windows operating system but not that much but yeah fundamentally it's just looking
for code. The kernel has its own inf functionality and abstractions and things.
But point of the kernel is to get to allow you to use an abstract.
Various piece of hardware. Each piece of hardware is its own special snowflake.
It has things. So you have to have drivers. which basically just needs code to help the operating system understand it, And then, normally, we'll load it into the kernel.
You can have drivers work as processes and user space.
But that has definite efficiency concerns because then you have to, you know, make a system call you go to the kernel.
It'll come back to user space and a kernel it's just extra going in and out of the kernel.
When you have a user space driver there are ways to mitigate that there are major drivers that are like this. But most drivers are kernel space, because it's efficient and frankly, most of the things that are so much access
anyway, if they're compromised they could already compromise your system.
Oh, no, this is this is not a so for hard drives.
Is this how you actually implement the Os. So for a hard drive you would implement it as a block device, not as a
A hard drive would be able as a block device, because block devices.
The data is cached. This would be implement like the the loop back device is a block device, and thus you put files on it.
This is a character device. So you wouldn't put a file system on this, but certainly like, if you other devices will be definitely in this way, you know.
So you you would have to. there Me? Well, look at
So if I look at this, what do I have here? May I have things representing my terminal?
I stuff representing my graphic stack and there's like USB.
Like all my USB devices let's see if I go into
So I've got like I this is probably referring to my I think this is probably my camera.
My video camera is probably this
And after all, I have 2 cameras on this. Do we have 2 cameras?
No, I have only one camera, because this one does not have a built in.
My laptop does not have a built in camera. I have one camera.
This is a line printer i've had up you actually have a printer plugged in here, and that's the Lp.
2 that's a laser print of us plugged in there.
I i'm gonna explain the mode stuff in a second here.
I'm getting to okay, so so that's what these are.
So then the question is, is, these are devices. They have permission bits that decide who can access them.
By default. All device files are owned by route, and you know root root is what the user group is.
When you go to the code here and You look at the what's this one doing It's asking about the device?
That device node. This is the I note information for but it's a struct device.
So it's a little more. complicated it's not it's like, an I node but for a special device file and so that one has up, you know, if they want if you want the mode you know if if if mode
is not null like if this was no it wouldn't fill it in.
But if this is actually a valid pointer it's just filling in that value, and saying what's the mode of the file, what does this mean?
It means that it's read, read, read it's real by the user real.
We go by the group, and we will buy this. Remember, if we have 6 for now.
6, one sorry, 4, 2, and one so bit 4 it, which is the third bit is is reed.
The second bit is right, which is one no that'd be 2 or 0, and then execute is one or 0.
So in something 7, 7, 7, that means it's read write execute if it's 6, 6, 6, it's read right, and if it's 4, 4, 4, it means we never 4 4 0 that means it'd be readable by the user and
group. Okay, this is just this is fun, permission, mode
So that this. So this is a when we run this module we call creating a file programmatically, but it's not actually stored anywhere.
It's really just functionality. So we have a function that's called We do open and read, and this provides the data.
Similar. We have to have a function that's called when when someone wants to know the metadata about the file, and the only metadata we're really giving you're saying it's readable because if we didn't say it was
readable, no one would be able to access it.
I can't
I can talk about whalen versus x Org. if no one has
If you do a so, so you can actual. If you do a make make, not on the device.
You can make that and those things, and the device nodes you make, you can define whatever permissions you want.
You can change it. this is really just saying the default ones In fact, I'm pretty sure i'm pretty sure you can change them.
So let's say, Oh, that was 2 total eggs
Hmm.
Oh!
Oh, where is it? Do you remember what the
I did that was that was her. Oh.
I'm typing something wrong
Dot dot there's no dot dot
Oh, yeah. But thank you. Thank you. Okay.
Okay, So here we got this, Nick.
That's a good idea no
Okay.
Yeah, I i've got to do that you'll actually what you do is the best way to do Dvd in file.
That's the safe way of doing it that's the same way to me, Anyway.
What was I doing. i'll look at
Okay, and then i'll try the same dvd command mission denied.
So that this this whole thing of requesting the of setting the permissions here is just the initial permission, but it's not. but it won't always be this way. and in fact, I can you know I can now do
So just remember I can do
So you can't actually right to it
Yes, check. Well, once you remove the module so so anything in slash, dev slash
Notice. Dev you dev is mounted here. This is this is a virtual file system.
Note how much space is used by Dev 0, no space. So if we just do a Df.
And you see all these things. How are you scared? Well, you can do Df.
And I drives like, but you see how yeah df actually doesn't it's like you do so we do.
Df: Dasha, you can see all the all the file systems are actually mounted.
And what how much space they're using you'll notice these all these file systems here have 0 used if it has 0 used it's probably not a real file.
System. it's probably a virtual file system so it's just created programmatically when you boot and then disappears.
Of course, when you shutdown well it's not so just re it.
It will reinitialize it with the default.
You dev stuff. But notice that it's because it's not stored anywhere on older unix system.
Deb was actually stored on the real file system, and it would take up space on disc with all those I know.
But on model Linux system. it's one that's programmatically created, just exists in memory in the kernel.
And thus, you know, you can make changes to it the next time you reboot all those changes Will we'll go away.
Yeah, So while working that way now is it's not you you can't it's not persistent you shouldn't treat it like a regular file system in terms of storing things because they won't stay that way you
don't want I mean you could have a script that changes permissions and things, but it would have to run every time he restarted the system.
So going back to the code here. so actually, just I will see the curvature
I was just getting this here. so
Updating this. So I have the code here. So when you like, This is a good module, one is good just to see, like everything else, is more complications.
But you should know what all these functions are doing like one's demo that's setting up the device know the initial permissions.
This is defined. What operations are actually defined you know these are the functions that have when you read, you know when you open what they're doing.
They're mostly just stubs and Then here this is doing the work of actually setting up the character device and adding it for class, and creating the device node and stuff.
You know. How did I figure this? out I didn't figure this out in the sense, except for looking at other versions of this, You know these are specific Apis.
They're not widely documented like you don't just go and read it.
But what you can do is find examples of this, and then you can, and look at other.
How other modules are implemented, and then you just copy that and make modifications.
I mean that's in general for doing things in the kernel. If you're looking to do a new thing you look in the kernel to see how similar things have done find the code.
I mean it's 50 million lines of code there's a lot of similar things for probably anything you want to do.
And then you specialize that code to, or your modify that kind of uses the basis for building what you want to do like. How do you build a new device driver?
You look at old device drivers and see how they work and pick a device.
Maybe that's similar to one you're trying to support lead to that. Are you trying to add a new file system?
Look at all existing file systems are built. If I do a new network feature, look at existing network.
Features are done. The code is your documentation you can't rely on any book
Man can help you some, but when you get to the internal stuff you really are just having to follow the code, I mean, there are some.
And look in the kernel source code. There is some some documentation.
The documentation isn't even always up to date the authority is the Yeah.
Is the code. and in fact, we can. Yeah, would be specific here.
I'm starting out
I'm starting out my class browser here and let me share it.
So if you go here browsing through the source code
So you wanna understand how file systems work you know you've got all these examples of file systems, you know.
Like. Oh, let's look at you know no fat file to ext 2.
That's an old older file system. This was a lot simpler, but like how is you know?
File operations implemented. Okay, now, now, here's an area no fault.
Now you have to go through and under like. Understand how these things work.
If you look at different files, that you actually see easier versions of this bye, that's what you're gonna be doing to really understand stuff.
Oh, by the way, I just saw this I mean you heard of Riser Fs.
Are fast from a technical perspective. is Yeah, that's the guy that murdered his wife.
Yeah. So it's a great yeah so and he named his file system out.
So Riser Fs is really only there is a legacy.
Yeah, Google, Hans Riser: look them up. Yeah, Yeah, this is made by people
Carson, you work for the same company he did. Oh, my goodness, I think I remember back in the day Riser Fs.
Was actually very cool. but yeah, anyway, and like you looking at
So you Wanna understand how system calls work. Arch X.
86, I think. kernels. Here we go. So you know, a lot of things are dash dot capital S.
Those are assembly files and where's the entry here
I try. I guess this is all the process that this in here is a system called Dispatcher, and i'm trying to remember exactly where it is.
Heads, I mean, I think this might be it actually
This is like, you know, start in 32 bit and switch to 64 bit stuff.
And services. you know this Is it getting initialized Oh, look here's 5 level page tables and stuff
Yep: I I Yeah, yeah. for Dev described, I actually told you how to exactly get that code.
There. I was a malewater bride to Oh, God.
There x 86,
Wow, for here we go entry entry Dot: S: Okay. Yeah.
So entry dot 64. This is how this is what happens when you know when you enter for a system call.
This is the code that's run every time you do a system call as pushing things onto the stack, and then it's like, call.
Do, Sis: call 64. Okay, So that's and then yeah, and then all the system call things are here
Some assistant call on each all kinds of redirection.
But if you wanted to like, learn exactly how system calls are handled, you go through this current.
So back in the day. I want, you know, when you really wanted to change how like I I did.
My dissertation was on hacking the Linux kernel to do real time system call based intrusion, detection, and response.
As part of that. I had to hack this version of this, but it was like 20 years ago, and it was simpler.
It was, It was definitely simpler. stuff but what's cool now is you'll actually have to modify the list Colonel to do some of the stuff I did. You'll actually do most of with Eddpf
Mr. Robots, on the different ha I I hopefully don't have quite that personality, anyway.
What's the difference
What's the difference with the earlier versions so the big reason why the Linux kernel has changed over the years is support for more hardware. Basic computers have gotten more powerful a lot more devices have been
implemented. you know processors, you know I have changed address.
Spaces have gotten bigger, more yeah th the there's always features, capabilities that are being added at the hardware level.
The Linux kernel keeps changing in order to support those, and as part of supporting those new things, they go like, Oh, the assumptions we made for this code to do it this way.
Now, don't make sense so much when we have to we have to deal with this like, for example, the original linux kernel only ran on a single processor, a single core, and it could not deal with multiple cores.
And so there was a huge amount of effort to make it support multiple cores, and the initial versions will only support like 2 cores.
But now, of course, the lace kernel will scale up to 64 cores, and more.
It'll scale up to thousands of wars because the hardware is there, and people have added the code necessary to support that efficiently, and to do so in a way that doesn't compromise the performance significantly of other systems
so. Oh, also, another big thing is different Platforms, you know all the you know.
Every new you know Cpu and stuff you know if you're good.
There's been a lot hardware changes the legs Colonel's complexity reflects that so, Mr.
Robot. Yeah, Mr. Row is definitely a interesting show. I mean, I I I will say that.
What did you say about the plot and other things? And you may like or may not. The technically insulting from Mr.
Robot is on point, hey?
Oh, one thing to understand about how the linux kernel works
It's not just linus linus actually doesn't he's approving things.
But there's lots of people now that help run the linux kernel and stuff it's it's not any one person really that does this.
I mean, if if one is provolved with a way it would be sad, and i'm sure that you know.
No, there might be some issues, cause he definitely does. It has an important role as a leader.
But the technical bench. and and actually the leadership bench is actually quite deep.
His standards. that's true his he's he's definitely managed to oppose a good aesthetic otherwise Colonel
Anyway. I'm going to stop here We definitely are covering anything critical right now.
But I will. I have office hours after this. I am happy to answer any questions in private.
You have. if you need help with the assignment, things confusing you.
Please feel free to drop by otherwise thursday we will go through assignment for, and maybe talk a bit about the midterm, and just sort of wrap up what's gonna be on the final exam take care