Reading Kernel Source Code - Analysis of an Exploit

Sdílet
Vložit
  • čas přidán 30. 07. 2024
  • Last video we looked at a kernel exploit against SerenityOS Kernel. This video we dig deep into the sources to find out why the vulnerability exists. After that we even attempt to find our own exploit.
    Part 1 - The Kernel Exploit: • Kernel Root Exploit vi...
    00:00 - Intro
    00:27 - Part 1 - Linux vs. Serenity
    01:17 - Finding ptrace() in Linux
    01:31 - Finding ptrace() in Serenity
    02:12 - Comparing Linux and Serenity ptrace() Code
    04:07 - Architecture Specific Code in Linux
    04:45 - Continue Comparing Linux vs. Serenity ptrace() Code
    05:08 - Conclusion of Part 1
    05:57 - Part 2 - hxp wisdom2 Exploit Analysis
    06:44 - Reading ptrace() again
    07:26 - Reading execve() code
    08:46 - The Critical execve() code
    09:30 - Do You Notice The Vulnerability?
    10:17 - Race Condition Exploit Strategy
    11:48 - Part 3 - Doing Own Research
    13:15 - Doing an Experiment
    15:44 - Kernel Changes for Experiment
    16:00 - Failed Experiment
    16:26 - Asking Andreas Kling About Scheduler Code
    17:45 - Conclusion - Read More Code
    18:38 - Outro
    =[ ❤️ Support ]=
    → per Video: / liveoverflow
    → per Month: / @liveoverflow
    =[ 🐕 Social ]=
    → Twitter: / liveoverflow
    → Instagram: / liveoverflow
    → Website: liveoverflow.com/
    → Subreddit: / liveoverflow
    → Facebook: / liveoverflow

Komentáře • 170

  • @_DeProgrammer
    @_DeProgrammer Před 3 lety +247

    Much respect to Andreas Kling. We take these projects for granted sometimes. We should give these guys the credit and respect they deserve. They don't ask for one cent. Wishing him happiness and wealth!

  • @Dr.Underscore
    @Dr.Underscore Před 3 lety +153

    11:05 This is not true! That Vector type is from the AK namespace (with the namespace omitted due to frequency of use) -- it is NOT a standard vector, nor an implementation of it. Although you're probably still right about the linear complexity, just wanted to clear that up.
    -Also for fun points, the AK library stands for Andreas Kling :^)-
    I have lied, it stands for Agnostic Kit, not Andreas Kling.

    • @networkException
      @networkException Před 3 lety +7

      oooh I always wondered what AK meant, thank you for sharing

    • @erwinjitsu_3706
      @erwinjitsu_3706 Před 3 lety +17

      It means Автомат Калашникова or also known as Automat Kalašnikov or Automat Kalashnikov.
      You know, the cheap rifle.

    • @andresvieira7943
      @andresvieira7943 Před 3 lety +2

      I might be wrong as I can't find the source, but I think that on one of the Car Talk videos someone asked about that. As a response I think Andreas stated that it was just a coincidence, but that the name AK comes from.. apple? (might be wrong, nokia?), being derived from Application Toolkit, just a container namespace for tools with a handy, compact name.

    • @aymensekhri
      @aymensekhri Před 3 lety

      I was wondering about the meaning of AK since a long time lol

    • @kiro_f
      @kiro_f Před 3 lety +3

      I believed Andreas talked about how it referred to Agnostic Kit

  • @krumpy8259
    @krumpy8259 Před 3 lety +13

    I just loved this video for several reasons namely:
    1. You showed exactly how to search for details for the problem in question.
    2. You showed how to ignore the steps not relevant for the problem and what to care about
    3. You showed how to get around technical details and getting an experiment done without being too technical about low level stuff and still getting a useful outcome.
    I'd love to see more videos like that, because they are well structured and give a nice learning path.

  • @unsafecast3636
    @unsafecast3636 Před 3 lety +53

    11:05 Actually, the Vector class used in SerenityOS is custom, especially in the kernel. You can't use the standard library in freestanding environments such as the kernel. But they are very similar, so you can definitely look up the std docs to learn something about it.

    • @Mankindux
      @Mankindux Před 2 lety

      searched this comment to say that.

    • @thewhitefalcon8539
      @thewhitefalcon8539 Před rokem

      You can totally use it with some patches. C++ allows you to override global "operator new"

    • @gianni50725
      @gianni50725 Před rokem

      @@thewhitefalcon8539 you definitely can, but in the kernel it's not too useful. you want to have total knowledge of what allocates and in what circumstance beyond the info the standard provides
      besides, the most useful headers (e.g. atomic) have freestanding implementations (or they're supposed to... it's a bit of a pain to set up still.)

    • @thewhitefalcon8539
      @thewhitefalcon8539 Před rokem

      @@gianni50725 Actually you do not need the kernel to have full knowledge of everything. It's useful in mature kernels to have that kind of introspection ability (see what is using up your memory) but it's not required for a toy or prototype

  • @GBlunted
    @GBlunted Před 3 lety +5

    The way you edit your videos is fuckin dope! Feels like it makes the such heavy technical topics you go after so watchable and almost fun to [try and] follow along with!👌

  • @rawbytes7356
    @rawbytes7356 Před 3 lety

    Thank you for constantly providing such high quality educational videos. Thanks a lot

  • @Paginski
    @Paginski Před 3 lety +49

    Serenity is such an interesting project

  • @naturallyinterested7569
    @naturallyinterested7569 Před 3 lety +163

    Wow, I actually didn't know that $ was a legal character in c++ identifiers.

    • @OmarChida
      @OmarChida Před 3 lety +4

      Same here!

    • @overlisted
      @overlisted Před 3 lety +7

      in js too

    • @RedStone576
      @RedStone576 Před 3 lety +1

      Damn

    • @PhoenixClank
      @PhoenixClank Před 3 lety +18

      @@overlisted That much is obvious, since jQuery defines a function called $

    • @OMGclueless
      @OMGclueless Před 3 lety +30

      Technically $ is not a legal character in C++ identifiers according to the standard. But it allows for implementation-defined identifier characters, and MSVC and GCC both allow $, so there you go.

  • @aayub
    @aayub Před 3 lety

    Very informative channel... Highly unrated... Keep up the good work...

  • @spicybaguette7706
    @spicybaguette7706 Před 3 lety +176

    Fun fact: Linux also started as a "toy project"

    • @Extys
      @Extys Před 3 lety +47

      "Nothing serious" - Linus, 1991

    • @xmine64
      @xmine64 Před 3 lety

      Linux doesn't worth more but people are taking it serious. Just take a look at a real Unix/real OS.

    • @defofoff987
      @defofoff987 Před 2 lety +14

      @@xmine64 What about 90% of the public cloud workload that is being run by Linux?

    • @kumarisuman4565
      @kumarisuman4565 Před 2 lety +13

      @@xmine64 Seems you live in a fourth world!

    • @andreicapi3535
      @andreicapi3535 Před 2 lety

      @@kumarisuman4565 😂

  • @SuryaTejaKarra
    @SuryaTejaKarra Před 3 lety

    Great content as always 😍

  • @lambdaboy-29
    @lambdaboy-29 Před 3 lety +1

    Man your intro is just nostalgic 😍

  • @santhoshvr
    @santhoshvr Před 3 lety +1

    Worth video 🔥🔥 Keep rock bro..

  • @henke37
    @henke37 Před 3 lety +7

    My first thought was to use an excessive number of threads to introduce a larger timing window. My second thought was to start new threads in the middle of the old threads being destroyed.

  • @zanidd
    @zanidd Před 3 lety +57

    Do TempleOS next 😂

    • @treyquattro
      @treyquattro Před 3 lety +3

      did you get all my error messages?

    • @zanidd
      @zanidd Před 3 lety +1

      @@treyquattro no only this one

    • @dannwe123
      @dannwe123 Před 3 lety +31

      He will not be able to find a bug, keep in mind it was created using divine intellect.

    • @heavy0119
      @heavy0119 Před 8 dny

      @@dannwe123 it's so bug ridden that Terry didn't even write a network stack lmao

  • @mushenji
    @mushenji Před 3 lety +1

    This is extremely awesome

  • @iyxan2340
    @iyxan2340 Před 3 lety

    Very great explanation!

  • @devnull7970
    @devnull7970 Před 3 lety +2

    Your exploit explanations are amazing! I hope u don't mind a bit of unsolicited advice, but I personally find browsing the source code documentation generated by ctags inline when ur already using vscode is much more preferable than having to google things or look at the header file.

  • @mccoysebrell630
    @mccoysebrell630 Před 3 lety

    Excellent points being raised

  • @rujotheone
    @rujotheone Před 3 lety

    Now that you explain it this bug is very cool. I should look at race conditions more.

  • @w3w3w3
    @w3w3w3 Před 3 lety

    Great video. My fav channel :)

  • @tomydurazno6243
    @tomydurazno6243 Před 2 lety

    This is great content!

  • @solcloud
    @solcloud Před rokem

    Thank you for this video!

  • @CodingWorm
    @CodingWorm Před 3 lety +2

    He's back.

  • @Zedoy
    @Zedoy Před 3 lety +10

    Wow the hax program makes an ad appear you are a cool hacker :D

  • @AkashSingh-uk5ub
    @AkashSingh-uk5ub Před 3 lety +80

    I wish,i had him as teacher,during my bachelors.

    • @priyanshugupta3207
      @priyanshugupta3207 Před 3 lety +9

      Well, Having him on CZcams is best for u and everyone, Right?? :)

    • @AkashSingh-uk5ub
      @AkashSingh-uk5ub Před 3 lety +5

      @@priyanshugupta3207 Absolutely,why should only i have all the fun 😀

    • @Asdayasman
      @Asdayasman Před 3 lety +6

      What’s with your use of commas dude?

    • @AkashSingh-uk5ub
      @AkashSingh-uk5ub Před 3 lety +2

      @@Asdayasman uhhm ummh uhhhm ...

    • @tacokoneko
      @tacokoneko Před 3 lety

      i paid for university for 4 years and got 95 credits and failed, waste of money. videos like this for free are a much better deal

  • @tonicuenca4043
    @tonicuenca4043 Před 3 lety

    Amazing! Thank you

  • @epicujjwal
    @epicujjwal Před 3 lety +22

    serenity is cool af

  • @n0trusts3c
    @n0trusts3c Před 3 lety

    Thanks! V3ry interesting topic

  • @totemkid7976
    @totemkid7976 Před 3 lety

    As always great video :)

  • @OthmanAlikhan
    @OthmanAlikhan Před 3 lety

    Thanks for the video =)

  • @sembutininverse
    @sembutininverse Před 3 lety +1

    thank you 🙏🏻🙏🏻🙏🏻

  • @dislikebutton9925
    @dislikebutton9925 Před 3 lety +1

    True man, Serenity is great, we have a lot of space to implement basic stuff in Serenity OS

  • @PhatPazzo
    @PhatPazzo Před 3 lety

    If the scheduler could run on multiple cores, there could still be a race condition by running yields, if the check in the scheduler could run before the action of the scheduler. Try slowing down the scheduler too, and make sure the VM has at least two physical cores.

  • @JannisAdmek
    @JannisAdmek Před 3 lety

    you are incredible :)

  • @seraphina985
    @seraphina985 Před 3 lety

    There I was speculating about all of those unveil calls and from the generation of a long list of conspicuously irrelevant data I figured that must be a roundabout way of implementing a delay loop without the ability to inject code where you need it. While unconventional to build a large data structure just to serve as an iteration counter it still gets the job done when the input data to the loop is the only access you have to the desired delay injection point. After all it is an effective way of implementing the basic form of any delay loop which is simply for largeSet; do burnCyclesToWasteTime; done how that set is generated or the opcodes used to burn CPU cycles as a crude inefficient timer are arbitrary implementation details the result is the same.

  • @eternaldoorman5228
    @eternaldoorman5228 Před 3 lety

    Looking forward to a video "Linux vs Mental Health" 😀

  • @diegodejesus9668
    @diegodejesus9668 Před 3 lety +2

    Is it convenient to practice buffer overflow or string formatting, even when these types of exploits are no longer so common (because systems are more protected)? What kinds of things should you investigate to find vulnerabilities in more current systems?

  • @luckyverri3374
    @luckyverri3374 Před 3 lety +1

    gREAT JOB.

  • @DerThomyLP
    @DerThomyLP Před 3 lety +1

    After completing the Operating System Course at my Univiersity I wish i knew about serenity OS earlier. As we also had to implement features like exec in a C++ Kernel following the POSIX standard, this would have been much more usefull than trying to understand the Linux implementation. Still thank you for this awsome video! :)

  • @cyber1377
    @cyber1377 Před 3 lety +1

    Thanks

  • @binaryagenda
    @binaryagenda Před 3 lety +10

    A different way to exploit kill_threads_except_self and make the execution take longer (so that the ptrace poke from another process has time to work), might be to create a large number of threads with resources in those threads which this kill_threads_* code needs to clean up. Maybe an alternative to using unveil.

    • @Keldor314
      @Keldor314 Před 3 lety

      I was looking at that too. Also, what happens if some of those threads have things like open file handles? Bad things can happen if the rug is pulled at certain critical points, so presumably the OS would have safeguards to prevent this. Though I expect these would be resolved in the set_thread() call, which is too early to take advantage of.

  • @Grub4K
    @Grub4K Před 3 lety +1

    Just as a thought experiment, cant you also increase the time it takes to reach the euid set by slowing down kill_threads_except_self by spawning many Threads beforehand?

  • @julianelischer6961
    @julianelischer6961 Před 2 lety

    When I wrote the threading code for FreeBSD I put changes in both exec and fork to make sure that other threads did not proceed in the child or new process. It's pretty obvious if you think about it that only the running thread should continue.. Other threads will just "vanish"

  • @Jay-je8tu
    @Jay-je8tu Před 3 lety +1

    I'm looking for the theme that the SerenityOS Dev uses. Looks really easy on eyes

  • @BlackHermit
    @BlackHermit Před 3 lety +1

    Much respect to Andreas Kling.

  • @NetworkITguy
    @NetworkITguy Před 3 lety +7

    That's why I say learn Minix, it's so small and easy to understand. If you learn Minix you will essentially learn SerenityOS

    • @tacokoneko
      @tacokoneko Před 3 lety

      i think i understand now, by the time you understand linux perfectly enough to be a linux kernel developer, you have already had to learn every other unix like os that exists, like stepping stones

    • @NetworkITguy
      @NetworkITguy Před 3 lety

      @@tacokoneko More or less, this video showed you kind of just need to learn three'ish OSs. Which OSs you learn from dictate how much time you'll spend, minix versus SerenityOS versus full on Linux (like slackware). Then wherever you start you can move to ReactOS to start understanding Windows. By the way being a kernel developer is a totally different concept then just trying to understand operating system theory and practice.

    • @tacokoneko
      @tacokoneko Před 3 lety +1

      @@NetworkITguy yes as he has said, to be a kernel developer you have to read and understand a kernel source code and then change it it be better. i dont want to understand windows i only like GNU/Linux and other unix like operating systems

  • @think-IT42
    @think-IT42 Před 3 lety +1

    Cool Beard :)

  • @Anonymouspock
    @Anonymouspock Před 3 lety +1

    It's interesting that this bug proposed can't happen because of lack of SMP support: there's nothing to stop the other threads there, and it relies on being in kernel implying nothing else is running

  • @FatalRescue
    @FatalRescue Před 3 lety

    Talk about the massive solar winds hack please!

  • @AK.Adventures
    @AK.Adventures Před 3 lety

    I am not getting most of the thing right now, will come back after primer

  • @tg7943
    @tg7943 Před 3 lety

    Push!

  • @andybryanboutchouangsimbaf8395

    Lmao the “Linux vs Serenity” got to me 😭

  • @williamobando4159
    @williamobando4159 Před 3 lety

    Lol interesting?? Super interesting !!

  • @mundusesttuum2536
    @mundusesttuum2536 Před 2 lety

    Hi... I know this is old post but I want to comment something... What happens if you filter all inputs? Like by integers or chars only and sanitize all before...? It's more hard to found vulns?😁

  • @Benjji
    @Benjji Před 3 lety +6

    this type of stuff interests me but i have ZERO clue what is actually going on hahaha

  • @Dominik-K
    @Dominik-K Před 2 měsíci

    Love serenity

  • @chyza2012
    @chyza2012 Před 3 lety +12

    11:05, Serenity Vector is not std::vector, serenity doesn't use std:: at all

    • @OmarChida
      @OmarChida Před 3 lety +1

      I was surprised and skeptical in the same time

    • @tacokoneko
      @tacokoneko Před 3 lety +6

      if, as he's been saying, the _implementation_ is _very similar_ though, does that matter? if number of instruction cycles increases by the same factors, his point is the same

    • @chyza2012
      @chyza2012 Před 3 lety +1

      @@tacokoneko If he knew it wasn't std::vector he wouldn't've gone to the documentation for std::vector, because its completely unrelated, you might as well be reading java documentation.
      Its clearly as mistake.
      He was correct about the time complexity by chance but that doesn't really change anything.

  • @KitsuneAlex
    @KitsuneAlex Před rokem

    You making Andreas heart bleed saying his baby is unusable xDDD

  • @julianelischer6961
    @julianelischer6961 Před 2 lety

    have you compared it with FreeBSD as well?

  • @Simon-xi8tb
    @Simon-xi8tb Před 3 lety

    Redox OS next!

  • @sefzxm6486
    @sefzxm6486 Před 3 lety +1

    saying "nello" in thirtynine languages.. spelt different, completely different, sometimes sound similar or even nowhere close. but exactly the same thing. ish.... i am probably wrong with my analogy.

  • @SSS-sz8mg
    @SSS-sz8mg Před 3 lety +1

    Yes, This means Linux is much sophisticated and harder to break or not ?

  • @benricok
    @benricok Před 3 lety +7

    @LiveOverflow Any plans to start posting your content on LBRY/Odysee?

  • @hk5716
    @hk5716 Před 3 lety

    the beard is very scary

  • @Sqwan2
    @Sqwan2 Před 3 lety

    You could also read a good book. But why would that be fun :D

  • @kuldeepsingh2983
    @kuldeepsingh2983 Před 3 lety

    5 min into the video and i am already lost.

  • @maratmkhitaryan9723
    @maratmkhitaryan9723 Před 3 lety

    1:07 they are very useful for aimbots and other cheats yeah?

  • @supernov4678
    @supernov4678 Před 3 lety +3

    Kernelman has been destroyed by LiveOverflow

  • @miklov
    @miklov Před 3 lety +1

    Wow, didn't know C++11 had anonymous functions, I had to try =D

    • @Cons-Cat
      @Cons-Cat Před 2 lety +1

      They got better in every update since then, and there's an accepted proposal in C++23 to continue improving them for the next update.

  • @yari_dawg
    @yari_dawg Před 3 lety +5

    42nd view i am therefore life

  • @samin5900
    @samin5900 Před 3 lety

    hi

  • @jordanoconnell48
    @jordanoconnell48 Před 3 lety

    You look like the guy out superbad lol

  • @TheeMelloMan
    @TheeMelloMan Před 3 lety

    what ??

  • @jonshouse1
    @jonshouse1 Před 3 lety +2

    As someone who only writes C I find it simpler to read the Linux source. The idea that C++ is "better" or "simpler" only exists in the generation that learnt object oriented programming. When I learnt to code (self taught mostly) we had assembler, C, Fortran or Pascal... that was pretty much it.

  • @quentinquadrat9389
    @quentinquadrat9389 Před 3 lety

    Probably people will yield at me but on both sides, code source could have more comments :-/ This is what I hate from programmers (and I am one): no comments, no PDF explaining algorithm/main purpose of the file, no examples, why calling functions in this particular order. I just get a laugh when hearing "and that sounds like one of the important functions"

    • @davidfrischknecht8261
      @davidfrischknecht8261 Před 3 lety

      I prefer writing self-documenting code. If your identifiers have decent names, you shouldn't need a whole lot of comments.

    • @quentinquadrat9389
      @quentinquadrat9389 Před 3 lety

      @@davidfrischknecht8261 Half troll: I hope this does not mean to type 100+ char for each variable or function :/

    • @gabiold
      @gabiold Před 3 lety +3

      Maybe I am wrong, but the code should be just as much commented as necessary for a competent programmer to understand the details, not more.
      The codes shown in the video is well readable in my opinion, and understandable if you dive deep enough into them.
      I think, teaching how a paricular system or subsystem works (in general, to a "stranger" who not familiar with the topic) is out of scope of the comments.
      Books or application notes or similar could be written separately, but it should not be in the comments.
      On a side note, programmers hate to write documents, which is understandable, especially for community-driven projects, as writing documentation terribly lowers the efficiency of programming. Which only lowers the accomplished tasks in a given time frame at best, but might lead to losing motivation at worst. Not everyone is a good teacher, one could possibly write excellent code, but have difficulty explaining it to non-competent people, thus it won't find it interesting.

  • @shallwebeginvg5750
    @shallwebeginvg5750 Před 3 lety +1

    Brother, I recommend eating potatoes and pork fat (
    сало), I suspect you will be feeling much better after you try it, seriously.
    As for the video, like always, I understand only the basic concepts - but a very interesting video indeed. Thank you!

  • @Indic4Zone
    @Indic4Zone Před 3 lety

    sixth comment!

  • @hey9433
    @hey9433 Před 3 lety +1

    1st

  • @lior_haddad
    @lior_haddad Před 3 lety

    Hi

  • @bocah_ingusan5285
    @bocah_ingusan5285 Před 3 lety

    Aku enggak paham bang artinya😭

  • @mayaliii
    @mayaliii Před 3 lety

    Oooooo

  • @1e1001
    @1e1001 Před 3 lety

    Get fake

  • @chigozie123
    @chigozie123 Před 3 lety +1

    SerenityOs kinda reminds me of TempleOs; both in naming and implementation

    • @Cons-Cat
      @Cons-Cat Před 2 lety

      How are their implementations similar? To me they seem night and day. TempleOS is 64 bit, Serenity is 32 bit. TempleOS was written in asm and jit-compiled HolyC, SerenityOS was written in asm and aot-compiled C++20. TempleOS was antithetical to POSIX / Unix, SerenityOS is extremely Unix-like. TempleOS deliberately has no internet capabilities or advanced graphics, Serenity is working towards having a Javascript and CSS compliant custom web browser and OpenGL conformant graphics implementation.

  • @kentmiggalen9756
    @kentmiggalen9756 Před 3 lety

    tell me what is your natural language? because all of your videos i thought your just an indian guy

    • @lummarh9385
      @lummarh9385 Před 3 lety +5

      He is german, his accent is strong but quite different from the Indian one

    • @sk8sbest
      @sk8sbest Před 3 lety +9

      😂 indian wtf. He doesn't sound like it at all

    • @Asdayasman
      @Asdayasman Před 3 lety

      Lmao are you the non-weeb version of me? Subbed to PoE stuff, chess stuff, and code stuff.

    • @kentmiggalen9756
      @kentmiggalen9756 Před 3 lety +1

      @@lummarh9385 maybe it's just me i watched many Indian tutorial vids lately

    • @kentmiggalen9756
      @kentmiggalen9756 Před 3 lety +1

      @@Asdayasman yes.. FINALLY!! YOU FOUND ME!!!!

  • @zungaloca
    @zungaloca Před 3 lety

    Bsd like licenses suck

  • @takedownccp
    @takedownccp Před 3 měsíci

    like a mutex lock