What Happens If We Stack Overflow in Linux Kernel

Sdílet
Vložit

Komentáře • 65

  • @nirlichtman
    @nirlichtman  Před 10 dny +8

    - For more information about how the guard pages are used in the kernel to detect stacko check out this article from the kernel docs docs.kernel.org/mm/vmalloced-kernel-stacks.html
    - In this video I demonstrate with x64, but on other architectures (like ARM for example) this may work differently

  • @havok6051
    @havok6051 Před 10 dny +21

    It's funny how the man addresses a very specific programming "prank" that only people familiar with IT can understand, yet he still explains that you should press Enter to opt out of an option in the GUI. :)

  • @vantavoids
    @vantavoids Před 11 dny +91

    im so glad to not be the only one that has the kind of intrusive thoughts that makes you wanna stack overflow a kernel

  • @DimDima09
    @DimDima09 Před 11 dny +91

    Hi! what will happen if you remove die() or other interruption in kernel code? what would happen on StackOverflow?

    • @BenjaminWheeler0510
      @BenjaminWheeler0510 Před 11 dny +27

      I imagine it would just go “off into the weeds” since it has no way to handle an unrecoverable error

    • @Ed.E
      @Ed.E Před 11 dny +28

      @@BenjaminWheeler0510technically it could keep going but it’s likely memory corruption would cause either an infinite loop or a number of CPU exceptions

    • @gwentarinokripperinolkjdsf683
      @gwentarinokripperinolkjdsf683 Před 11 dny +27

      If you remove the handler for CPU exceptions, they generate a double fault, if you remove that, or the code for it is unreachable (for instance, you get a segmentation fault when trying to reach that code) then it will generate a triple fault and reboot your machine

    • @jackkendall6420
      @jackkendall6420 Před 9 dny +18

      It'll get removed as a duplicate by a moderator.

  • @ayyyylmao-rg3ik
    @ayyyylmao-rg3ik Před 11 dny +27

    Thank you for showing so many interesting stuff on your channel, a peak into the inner workings of things is always great.

  • @AntonioDoesMetal
    @AntonioDoesMetal Před 11 dny +7

    Such a fun video, I’ve never really thought too much about kernel issues like this. It’s very easy to forget it even exists and has to follow the same rules when developing user mode software

  • @Hans_Magnusson
    @Hans_Magnusson Před 9 dny +4

    Yep, redirection to the serial port is a good one. Used it when I fixed a NIC driver for SCO UNIX way back in the good old days.
    Just capture the output to a file and you have an excellent source of information without cluttering your console.
    I redirected the debug messages only…

  • @Maric18
    @Maric18 Před 11 dny +6

    lol i was kind of expecting an angry linus mail about people doing like mid tier coding advice in merge requests to the kernel like stack overflow

  • @user-br6ku7jj6n
    @user-br6ku7jj6n Před 11 dny +11

    I love your videos, straight to the point

  • @Nunya58294
    @Nunya58294 Před 11 dny +5

    It makes me happy to see new comers try this stuff out; It's how you learn and become better at programming, etc

  • @salsaman
    @salsaman Před 10 dny +3

    but what does die() do ? - Potentially the most interesting part here.Maybe we need another video - "What happens when the Linux kernel dies ?"

  • @ABCABC-sw8mh
    @ABCABC-sw8mh Před 11 dny +2

    Nice vid, looked similar vid a few weeks ago.
    Simple, good understandable, short, nice vid
    Thanks Nir

  • @vikenemesh
    @vikenemesh Před 10 dny

    Didn't expect to be taken on such a journey in 5 minutes!
    Thanks for showing how easy qemu is, this might stir some inspiration for potential kernel hackers, I guess!

  • @kpjVideo
    @kpjVideo Před 11 dny

    Another excellent video! Keep up the content man this is great stuff

  • @BenjaminWheeler0510
    @BenjaminWheeler0510 Před 11 dny +7

    I’d be interested about what the convention is for kernel dev. I presume kernel maintainers generally avoid recursion?

    • @pachinger
      @pachinger Před 11 dny

      Same thought here… also, does that mean kernel code is always free of any warnings?

    • @Ed.E
      @Ed.E Před 11 dny +3

      @@pachingeryes, though the rules are set up so any irrelevant warnings may be changed to notes or discarded

    • @paulstelian97
      @paulstelian97 Před 10 dny

      Generally no recursion, though in some situations you do get some (btrfs for example uses up a lot of stack space)

  • @justinnamilee
    @justinnamilee Před 9 dny

    Oh, fun! Some useful QEMU tips, too.

  • @starc0w
    @starc0w Před 10 dny

    Very interessting, thanks! ❤

  • @roz1
    @roz1 Před 11 dny +3

    Hi @Nir Licthman this is a wonderful video... Can u make a sereis on the linux kernel internals the code walk through and steps that the kernel takes from start to finish

    • @nirlichtman
      @nirlichtman  Před 10 dny +4

      Yes I plan on also making videos about the boot process focusing on a specific subsystem each time

    • @roz1
      @roz1 Před 10 dny +1

      @@nirlichtman Thank you so much ❤️
      That would mean a lot to all of the people here .... Again Thank you

  • @Jifaxin
    @Jifaxin Před 7 dny +1

    you have already made a video about creating windows for X11 and Windows. Will there be a Wayland?

  • @bhaveshverma8629
    @bhaveshverma8629 Před 9 dny

    How do you know in depth knowledge about these things. I wonder i can learn that too. But these things are very much complicated and goes over my head. I am just a normal web back developer.Really your videos are very good.

  • @diminuendos_
    @diminuendos_ Před 5 dny

    Thanks!
    Can you pls share how to setup qemu on windows and development environment for linux kernel to try out these examples?

    • @nirlichtman
      @nirlichtman  Před 4 dny

      Added setup information to my welcome link on my channel :)

  • @Onyx-it8gk
    @Onyx-it8gk Před 11 dny +2

    Can you make a small Linux distro with the Rust coreutils?!!!

    • @nihil75
      @nihil75 Před 10 dny +1

      Exactly what I wanted to ask / watch!!!! 🥰

  • @UltimatePerfection
    @UltimatePerfection Před 9 dny

    I would love to know what Linus would say about this change 😂

  • @leonardotry
    @leonardotry Před 3 dny

    Now what if you remove the stack guard handler and allow it to "really" overflow? how would that system crash look? :D

  • @weathercontrol0
    @weathercontrol0 Před 10 dny +1

    Kernel_innit

  • @angelffg
    @angelffg Před 11 dny

    Good video!!!!
    Nir, I have a question please:
    I run this program on Windows and Linux, on Linux it takes less than 1 second and on Windows it takes almost 2 minutes.
    Why does that happen?
    #include
    #define MAX 1000000
    int main(int argc, char *argv)
    {
    int i;
    for(i=1;i

  • @aviinl1
    @aviinl1 Před 11 dny +1

    curious what happens if you comment out that call to `die` and `panic`

    • @Ed.E
      @Ed.E Před 11 dny

      Memory corruption, CPU memory exceptions

  • @zeteya
    @zeteya Před 10 dny

    How did you compile the kernel so fast? Normally it takes 30mins or so right?

    • @SkySumisu
      @SkySumisu Před 9 dny

      He divided it into eight distinct processes.

    • @nirlichtman
      @nirlichtman  Před 8 dny +1

      I already ran make before, so when I started make again it only built according to the changes in the source I made

  • @A5A5A5A5h
    @A5A5A5A5h Před 11 dny

    Try make a video where you disable the ISR(Interrupt service routine) in charge to manage division by zero, then try to run such division in user space and see what happens.

    • @paulstelian97
      @paulstelian97 Před 11 dny

      Well obviously the CPU can't handle it so the ISR is triggered. So it depends on _how_ you remove it.
      Remove the code in it? Handler does nothing, you have a CPU bound infinite loop that the scheduler can still deal with. Remove it from the ISR table? Kernel panic (double fault -- invalid ISR entry). You can also try to not change the kernel and register a signal handler for SIGFPU in the userspace, and if you do nothing in that you're gonna again have the infinite loop.

    • @iDontProgramInCpp
      @iDontProgramInCpp Před 8 dny

      The CPU will fail to call the division error interrupt causing a general protection fault or double fault (don't remember which)

    • @paulstelian97
      @paulstelian97 Před 8 dny

      @@iDontProgramInCpp If an IRQ handler is invalid then the double fault shall be called. If the double fault handler is also invalid a triple fault, which leads to an immediate CPU core/thread reset, occurs.

    • @A5A5A5A5h
      @A5A5A5A5h Před 5 dny

      @@paulstelian97That’s sounds like a reasonable way to reboot your machine when you don’t have an ACPI driver 😁

    • @paulstelian97
      @paulstelian97 Před 4 dny

      @@A5A5A5A5h Except it doesn’t really reboot the whole machine. Only a single CPU core is affected. In HT, only one thread is affected.

  • @fderty4
    @fderty4 Před 5 dny

    when I encounter a stack overflow, I ask for advice on stackoverflow 😏

  • @pingu0b
    @pingu0b Před 11 dny +1

    Are you using WSL in the video ?

    • @rishaydutt812
      @rishaydutt812 Před 11 dny +1

      He is

    • @pingu0b
      @pingu0b Před 10 dny

      @@rishaydutt812 thanks. i just had a doubt cuz it looked a bit different then usual wsl

  • @BenjaminWheeler0510
    @BenjaminWheeler0510 Před 11 dny +1

    Kernel panic attack :(((

  • @ChandrashekarCN
    @ChandrashekarCN Před dnem

    💖💖💖💖

  • @zawadhyaa
    @zawadhyaa Před 11 dny +1

    Next video create a kernel module from scratch but something interesting, like a kernel mod to put a camera filiter or a voice filter or a custom keyboard mapping something like that would be really fun

    • @Nunya58294
      @Nunya58294 Před 11 dny +1

      It's actually possible I had found an article on it. You can make a module without needing the kernel sources

    • @zawadhyaa
      @zawadhyaa Před 11 dny

      @@Nunya58294 no that I know, my focus was on the second part

  • @bramfran4326
    @bramfran4326 Před 11 dny

    cool !

  • @nihil75
    @nihil75 Před 10 dny

    Thanks! fun to look at something so familiar in a new way. But I have to say...
    "Works on Linux kernel, builds on Windows..." 🤣

  • @vlc-cosplayer
    @vlc-cosplayer Před 4 dny

    The rudest StackOverflow user would still be no match for Linus at his most polit-- wait, it's not that kind of stack overflow?

  • @ProSureStrings
    @ProSureStrings Před 11 dny +1

    hi!

  • @Paolog_
    @Paolog_ Před 11 dny +1

    the only problem that we can't solve when beeing root

    • @Nunya58294
      @Nunya58294 Před 11 dny

      Sometimes you need to be root for this stuff...