How to build a Linux loadable kernel module that Rickrolls people

Поделиться
HTML-код
  • Опубликовано: 19 янв 2019
  • A totally legit use for Linux loadable kernel modules because....Linux.
    Hope you enjoyed the video!
    Check out this code here:
    github.com/engineer-man/youtu...
    Join my Discord server to chat with me:
    / discord
    Check out some code on my GitHub:
    github.com/ebrian/engineerman
    Tweet me something funny on Twitter:
    / _engineerman
    Say hi over at Facebook:
    / engineermanyt
    Sincerely,
    Engineer Man
  • НаукаНаука

Комментарии • 182

  • @garryvee
    @garryvee 2 года назад +20

    As a retired software engineer, starting with IBM 370 systems, I find your videos to be remarkably interesting and educational. Very much appreciated.

  • @stephenjames5745
    @stephenjames5745 5 лет назад +148

    Awesome introduction to kernel module development! Show me more! 😁

    • @pavel9652
      @pavel9652 3 года назад +6

      You probably don't need it, but for future generations ;) There is a free book on Linux drivers development on LWN, which involves writing kernel modules. It is fairly old, as had been written for kernel 2.6, but these things didn't change much. Linux Device Drivers, Third Edition: lwn.net/Kernel/LDD3/

    • @Nunya58294
      @Nunya58294 2 года назад

      Linux drivers are pretty easy to compile and write as long as you have a basic understanding of what your doing

  • @speediestmoon1404
    @speediestmoon1404 5 лет назад +126

    1:43 "Kernel Space Program" my favorite video game... Oh wait, it's Kerbal Space Program? Crap

    • @ChristopherGray00
      @ChristopherGray00 3 года назад +6

      That would be interesting, the system crashing along with your ship.

  • @spicy_wizard
    @spicy_wizard 5 лет назад +73

    Hope you can do more on Operating System Programming as compared to web dev/machine learning, the resources on OS is scarce ! And you did great job on teaching it!!

    • @tissuepaper9962
      @tissuepaper9962 3 года назад +2

      There's a book (somewhat outdated now) called just "Linux Kernel Development" by O'Reilly. Also "Linux Device Drivers" by someone else, can't remember.
      Really creative names, I know.

  • @Askaholic907
    @Askaholic907 3 года назад +10

    Correctly me if I’m wrong, but I’m pretty sure you will have a buffer overflow if the user only supplies a small buffer.
    Always check the length of your destination buffers people!

  • @ancbi
    @ancbi 3 года назад +21

    Me yesterday: researching kernel module & device file.
    Me today: Listening to rickroll in medieval style.
    RUclips algorithm today:

  • @batlin
    @batlin 2 года назад +8

    Recent versions of the kernel won't build the module if it's missing the MODULE_LICENSE tag. You can do that by adding it after calling the module_init/exit registration functions:
    MODULE_LICENSE("GPL");

  • @milostean8615
    @milostean8615 5 лет назад +18

    Just the right amount of detail in your videos brother : ]

  • @CyborgElf
    @CyborgElf 5 лет назад +10

    Nice video :) kernel is always difficult to explain, you did it perfectly

  • @inqmusician2
    @inqmusician2 4 года назад +16

    You can make a virus, that opens Never Gonna Give You Up, as soon as browser is closed.

  • @kallikantzaros
    @kallikantzaros 3 года назад +1

    Reading LPIC-1 book and got to the part with modules and this video taught me a lot of things on how this works. Thanks

  • @williamdurocher207
    @williamdurocher207 5 лет назад +1

    Great video, I struggled with creating a kernel module before. Wish the video had been there then !

  • @katout75
    @katout75 5 лет назад +1

    Thanks, what a great video to quickly explain how to start writing kernel modules.

  • @theburntcrumpet8371
    @theburntcrumpet8371 5 лет назад +28

    This was extremely informative. Thank you

  • @vtrandal
    @vtrandal Год назад

    I'm glad I found my way back here over a year later. Very cool stuff.

  • @umairgillani699
    @umairgillani699 5 лет назад +33

    just by seeing word "Linux" in title, liked the video and now watching.. more Linux videos please!

  • @Skyler9604
    @Skyler9604 3 года назад +5

    Came for the meme, stayed for the knowledge

  • @yourneighbour5738
    @yourneighbour5738 5 лет назад +101

    Big Chungus OS

  • @realrunujhkj
    @realrunujhkj 3 года назад

    Yo this video is amazing dude. Finally understand how these modules work! And with a choice example too 👍👍

  • @N0AGI
    @N0AGI 3 года назад

    Thank you for sharing this knowledge; Very helpful. I am hoping to learning kernel module programming - never had the prior opportunity to; Your video will motivate me in that direction. Thanks again. God Bless.

  • @Mrdejjay
    @Mrdejjay 2 года назад +7

    For anyone running into the module license error, insert this under the header for your .c file:
    MODULE_LICENSE("Dual BSD/GPL");

    • @Chris-no9tn
      @Chris-no9tn Год назад

      Thanks! Solved the problem for me.

  • @marcbeatove7149
    @marcbeatove7149 5 лет назад

    message_len should be size_t as it contains a length. Of course this shouldn't cause any problem as strlen() never returns a value lower than 0 and any further operation is done with the variable, but still, it's nice to get the beginners used to use the correct data types. Great video btw :D

  • @Karrq
    @Karrq 5 лет назад +5

    More Linux dev stuff pls! It was awesome

  • @felipekenzoshiraishi3746
    @felipekenzoshiraishi3746 4 года назад +1

    Awsome introduction! Thanks a lot!

  • @crmafra
    @crmafra 5 лет назад

    Awesome! You made it look really simple, thank you!

  • @thomasburke7995
    @thomasburke7995 2 года назад

    I have been unable to comprehend what you did.. but I know what that rickroll can be used for.. brilliant..

  • @pcfreak1992
    @pcfreak1992 5 лет назад +2

    I didn't know that making kernel modules was this simple. Nonetheless, I learned something new today and enjoyed it 👍

  • @carlesg0n
    @carlesg0n 5 лет назад

    Nice video man, really interesting! Keep doing these

  • @richardbenes9
    @richardbenes9 3 года назад +1

    Great explanation, thanks! Btw. would it be a good idea to register the device at the time of loading of the module?

  • @adaminsanoff
    @adaminsanoff 3 года назад

    Great introduction into kernel modules.

  • @nischalbhandari9964
    @nischalbhandari9964 3 года назад

    I could not understand this thing by reading a book for four days but your video made it very clear. Thanks dude.

  • @pwlegolas3
    @pwlegolas3 3 года назад

    This is simply amazing.. Thanks Eng. Man !!!

  • @coldhardwick
    @coldhardwick 5 лет назад +1

    Could you also use psuedo devices to create a com port to replace tty to ease serial communication from a device to program running on WINE? Very informative video, even though I'd never build that lol

  • @user-he4dh1ig4i
    @user-he4dh1ig4i 5 лет назад +1

    Thanks for the quality content !!!
    Can you make a video on removing rootkits using rootkit hunter and how to remove the false positive warnings

  • @treyquattro
    @treyquattro 3 года назад +3

    good video. I anticipated you'd access the module via cat /dev/rickroll, but I expected that just registering the module would have automatically created the entry in /dev

    • @d1rtyharry378
      @d1rtyharry378 3 года назад +2

      I thought the same thing. Registering shows the new device in /proc/devices. But when I do ls -l /dev it doesn't show up. My guess is the device is created but the directory entry that points to this device is not created. Mknod helps to create that directory/file which is managed by the device we created and registered

  • @chHJChang
    @chHJChang 7 месяцев назад

    This video helps me a lot, thx!

  • @anupraj762
    @anupraj762 5 лет назад

    Thanks for sharing knowledge

  • @8v2000
    @8v2000 5 лет назад +14

    Brb installing linux

  • @r.savage1283
    @r.savage1283 5 лет назад +1

    Love your content. Just subscribed. I just found atom . Any chance of an overview of it?

  • @OscarCortesV
    @OscarCortesV 3 года назад

    Thank you very much, this is exactly what I was looking for, clear information, I will subscribe and like... but I have a doubt, how can you know which kernel module goes to which device in /dev?

  • @ramesherrabolu1590
    @ramesherrabolu1590 3 года назад

    Thanks for a short and clear presentation. Do you have one on DKMS

  • @ZeeLegend
    @ZeeLegend 5 лет назад +3

    Awesome video!

  • @alecthenice8115
    @alecthenice8115 5 лет назад

    Thx for helping me with custom boot.img creation

  • @AmeenAltajer
    @AmeenAltajer 2 года назад

    Love your work, keep these videos coming! Haha!

  • @ivmaxxim100
    @ivmaxxim100 2 года назад

    Really high quality video. Thanks!

  • @ianlang6058
    @ianlang6058 2 года назад

    Nicely presented video

  • @inputignhere
    @inputignhere 5 лет назад

    very useful, ill be sure to use it in the future

  • @0xssff
    @0xssff 3 года назад

    Amazing content, thanks a lot!

  • @HasanAmmori
    @HasanAmmori 3 года назад

    This video deserves way more views

  • @unh0lys0da16
    @unh0lys0da16 2 года назад +1

    This is so valuable, there is way too little material on LKM's

  • @clementyves6154
    @clementyves6154 5 лет назад

    Thanks dude ! this is again a very good lesson !

  • @mattt2684
    @mattt2684 5 лет назад +2

    That was epic!

  • @kevinalexander4959
    @kevinalexander4959 3 года назад

    Would love to see you do the same project on an un-rooted Android device running newer OS. I was having error: "insmod: failed to load test.ko: Exec format error", loaded just fine on Ubuntu -- I'm guessing this example is not for Android.

  • @guyfromconcordia
    @guyfromconcordia 3 года назад +1

    maybe you should compose a , say, main.c program, to show how to call the character-device through syscall, like read, write, and then to demonstrate the relationship between kernel module and user space process.

  • @JosephDAndrea0121
    @JosephDAndrea0121 4 года назад

    Studying for linux+ I keep a running notebook in evernote. I linked to this video as an example of creating and managing modules. I'm going to provide my notebook stack internally for the other guys who want to study for the linux+ exam. Though you might like to know that future generations of linux admins learned kernel modules by rickrolling their buddies

  • @BroscutaGaming
    @BroscutaGaming 5 лет назад

    Hey man! What font are you using on the terminal?

  • @MinhPhamGators
    @MinhPhamGators 3 года назад +1

    "...🎶 never gonna let you down...🎶 ... never gonna panick ...🎶 unless you create a buffer overflow...🎶"

  • @spyingpro4563
    @spyingpro4563 3 года назад

    I have no idea what I’m watching but I like it

  • @cantanzim6215
    @cantanzim6215 3 года назад

    grate video really.... grate informations... amazing thanks

  • @zinsy23
    @zinsy23 5 лет назад

    Did you paste multiple things sequentially one at a time? It didn't look like the video was cut at 3:08 and 3:14 when I noticed this. If so, how do you do this in Linux? I've done this before with Autohotkey in Windows by writing to a text file and pasting one line at a time. I'm curious to see how you did this in Linux if you did.

  • @ramsaiachanta5553
    @ramsaiachanta5553 Год назад

    bro how to rectify the error if the compiler differs from the one used in the kernal,since my program is not working as like you
    plz someone explain how to get out of this
    my compiler showing gcc 11.3 and kernal showing gcc 11.2

  • @yoyonel1808
    @yoyonel1808 5 лет назад +2

    Thx for the video.
    Your link to github repo not pointed to the correct subdirectory (subproject).

    • @EngineerMan
      @EngineerMan  5 лет назад +2

      Thanks for pointing that out. I just corrected it.

    • @yoyonel1808
      @yoyonel1808 5 лет назад

      @@EngineerMan You're welcome :)

  • @paulwirkus4182
    @paulwirkus4182 3 года назад

    That video is kinda wholesome.

  • @faozi1000
    @faozi1000 2 года назад

    Hi Engineers! I have a doubt if anyone could help me... I am trying to get to know how LKM's Work. I Successfully completed an installation with the insmod command, but when I reboot i do not find my module loaded. ( tried to add the name of the module installed into /etc/modules and got an error while loading the raspberry where it is installed . Any hint ?
    Best regards to everybody!

  • @RonnyMandal75
    @RonnyMandal75 3 года назад

    Great! Instead of "Sorry, rickroll is real only" it should say "You know the rules and so do I!"

  • @utsavtayde3378
    @utsavtayde3378 3 года назад

    Can this code be treated as a code for s device driver in linux?
    and
    is this code works in ubuntu? coz I am facing issues here in my ubuntu system

  • @GlennHamblin
    @GlennHamblin 5 лет назад

    Very cool. Thanks.

  • @AtomkeySinclair
    @AtomkeySinclair 5 лет назад +2

    Mad scientist laugh...

  • @Ncky
    @Ncky 5 лет назад +7

    How to make it to write only once and then close it self? Call dev_release inside dev_read?

    • @paulstelian97
      @paulstelian97 4 года назад

      You can't normally close the file, but you can use the *offset field to ensure it looks like a normal file. Closing should be handled by the kernel based on the system call itself. Take a look into the source code of the close() system call to see what exactly it does if you do want to close the file yourself.

  • @adameverett3414
    @adameverett3414 5 лет назад

    Hey, great vid. Could you please make a tutorial of running an ssh server on Linux?

    • @MrArondc
      @MrArondc 5 лет назад

      what distro are you running?

  • @chrissmith6028
    @chrissmith6028 День назад

    I had just learned that the '&&' only executes cmd2 IF cmd1 succeeds. So I have been doing "make clean && make". Is there a problem with that ? My thought would be that it is going to make sure dir is cleaned before running "make". p.s. Trying to follow the video leaves out the '"%d", major ' so I was having a lot of problems until I viewed the repo.

  • @skunchtv
    @skunchtv 5 лет назад

    awesome stuff

  • @rohitnarwal8284
    @rohitnarwal8284 5 лет назад +1

    you are awesome❤

  • @perpirisgg
    @perpirisgg 5 лет назад

    We need engineer man cap merch

    • @EngineerMan
      @EngineerMan  5 лет назад

      Here you go :)www.amazon.com/Falari-Classic-Baseball-Cotton-Adjustable/dp/B010RDCIM2/ref=sr_1_2

  • @MebiusProject
    @MebiusProject 3 года назад

    Hey Engineer Man, do you have any info on how to install the module from kernel 5.4 ? 'insmod' return 'Operation not permitted', apparently due to the new lockdown feature...

    • @SheIITear
      @SheIITear 3 года назад +2

      Use sudo. Works fine on 5.6.

  • @echoptic775
    @echoptic775 2 года назад

    Im having a problem im missing linux/init.h file but have all others

  • @BrianClem
    @BrianClem 5 лет назад

    Awesome!
    because.... Linux

  • @jonathanengwall2777
    @jonathanengwall2777 4 года назад

    Good one

  • @CurrentlyObsessively
    @CurrentlyObsessively 3 года назад

    Well. Linus always says don't break userspace. Your rickroll can be exited with Ctrl - C, so you're good.

  • @0vivekeviv0
    @0vivekeviv0 3 года назад

    7:44 Copy in it is shamocha

  • @patrickmullen2914
    @patrickmullen2914 Год назад

    Great video

  • @pauloseifer7324
    @pauloseifer7324 5 лет назад

    Nice video! Tks!

  • @lyghters
    @lyghters 4 года назад

    Dude, i can't get over of how you look exactly like one of Half-Life 2 civilian/resistance NPCs.
    And.. take that as a compliment, i guess

    • @joegatton4138
      @joegatton4138 4 года назад

      Lol, now I'm going to be reminded of this for every video.

  • @MrEklipze
    @MrEklipze 2 года назад

    I think some code is missing, the code in the tutorial does not print the major number shown at min 9:59

  • @ivanramadhan5487
    @ivanramadhan5487 2 года назад

    Anyone got this error when compiling the makefile:
    ERROR: modpost: missing MODULE_LICENSE()

  • @JeffSmith-vc9ii
    @JeffSmith-vc9ii 5 лет назад +3

    Does this work on Windows 10 Linux subsystem with Wine?
    I use Arch btw.

    • @vladimirtatarsky9928
      @vladimirtatarsky9928 5 лет назад +9

      What you are referring to as Linux, is in fact, GNU/‘Windows Subsystem for Linux’, or as I've recently taken to calling it, GNU plus Windows. Linux is not an operating system unto itself, but rather another free component of a fully functioning GNU system.

    • @TobiasSN
      @TobiasSN 5 лет назад +4

      No. The Windows Subsystem for Linux doesn't use the Linux kernel, but rather it converts kernel calls to Win32 calls.

    • @TobiasSN
      @TobiasSN 5 лет назад +2

      Lorem Ipsum If you read my comment properly, I said “the Linux kernel”, indicating that I’m talking about Linux itself, not GNU/Linux.

    • @TobiasSN
      @TobiasSN 5 лет назад +1

      Lorem Ipsum Did you even read my reply?

    • @RandyFortier
      @RandyFortier 5 лет назад +1

      @@MantasXVIII I read your reply, and @Tobias SN is correct. He was talking about two things:
      Windows Subsystem for Linux - the official name Microsoft/Ubuntu use for this component of Windows, and
      Linux - the kernel, specifically (not the operating system frequently called "Linux" incorrectly, as you have pointed out)
      Neither correction you made was appropriate, in this case. People do make that mistake, but that isn't what happened here. Then, you just copied and pasted the same reply again, making it clear you didn't real his reply (or, at least not carefully enough). In fact, I'm not even certain you aren't a bot. I guess we'll find out if you reply.

  • @rajinkhan7611
    @rajinkhan7611 5 лет назад

    Everyone commenting this video is a boss...almost Everything he says are going over my head..cant understand anything as a noob

  • @danielderwertvolle6354
    @danielderwertvolle6354 5 лет назад

    Great video!
    Maybe somebody can help me with this: For some reason I'm missing init.h...
    I did "apt-get install build-essential linux-source linux-headers-`uname -r`" but init.h is not where it's supposed to be. "locate" doesn't find it at all actually. maybe I'm missing something obvious but those are the packages everybody tells me i need...

    • @AryaFairywren
      @AryaFairywren 5 лет назад +1

      you can use apt-file to find a package containing a file you're after. Install apt-file, then try apt-file search init.h

  • @PauxloE
    @PauxloE 3 года назад +5

    9:08 Shouldn't you only copy min(len, message_len) characters? Otherwise you might write over the bounds of the buffer.
    10:35 I guess it's more effective if the device is not named "rickroll". And can you do the equivalent of this mknod call also from your init function, so it stays over restarts of the system?

  • @GlennHamblin
    @GlennHamblin 4 года назад

    Fun!

  • @___etc8291
    @___etc8291 4 года назад +1

    KERN_LOG undeclared

  • @santoshjackman
    @santoshjackman 5 лет назад +14

    Do you age..?

  • @franchufranchu119
    @franchufranchu119 3 года назад

    You could make it stream the video, so that you can play it with mplayer or other similar app

  • @rizwin9212
    @rizwin9212 2 года назад

    awesome

  • @rolandsz8831
    @rolandsz8831 3 года назад +3

    I suspect that this code can overflow the userspace buffer, in case len < message_len. Do I miss something here?

    • @tissuepaper9962
      @tissuepaper9962 3 года назад

      I don't actually know, but I suspect that the function used to copy into the userspace buffer checks for this and would reflect such an error in its return value

  • @ZacKoch
    @ZacKoch 5 лет назад

    Haha, I dig it!

  • @josephbelhadj193
    @josephbelhadj193 4 года назад

    Awesome

  • @xiaochris7467
    @xiaochris7467 3 года назад

    register_chrdev is an outdated function in Linux kernel module programming.

  • @Erandros
    @Erandros 3 года назад

    very good intro haha

  • @David-pz4gy
    @David-pz4gy 5 лет назад +9

    discord squad!