kernelnewbies.kernelnewbies.org archive mirror
 help / color / mirror / Atom feed
From: greg@kroah.com (Greg KH)
To: kernelnewbies@lists.kernelnewbies.org
Subject: Kernel panic after insmod
Date: Sun, 26 Jun 2016 07:54:26 -0700	[thread overview]
Message-ID: <20160626145426.GA8882@kroah.com> (raw)
In-Reply-To: <CAJKgH8A-zh=yG2WcoBygnu_+SmeOZqBarGHBHspRz_aGinVdkQ@mail.gmail.com>

On Sun, Jun 26, 2016 at 09:35:55AM +0000, Manavendra Nath Manav wrote:
> Can someone explain the following kernel module code. I'm not familiar with x86
> assembly so have problem understanding this part. Also it seems this code is
> able to modify the kernel stack.
> 
> /******************start****************/
> 
> #include <linux/module.h>
> 
> MODULE_LICENSE("GPL");
> 
> int __init init(void) __attribute__((noreturn))
> {
> unsigned long long cr0 = read_cr0();
> write_cr0(cr0 & ~(1 << 4)); /* Clear Extension Type (ET) bit */
> *(unsigned char *)sys_kill = 0xc3; /* opcode for "ret" */
> write_cr0(cr0);
> 
> /* Optional code ahead to hide traces of this module. */
> __this_module.refcnt = 1;
> __this_module.state = MODULE_STATE_LIVE;
> 
> asm
> (
> "mov %0, %%rsp\n\t"
> "mov %1, %%rdi\n\t" /* name = __this_module.name */
> "xor %%rsi, %%rsi\n\t" /* flags = 0 */
> "jmp sys_delete_module\n\t" /* call delete_module(name, flags) */
> :: "r"(current->stack + THREAD_SIZE - sizeof(struct pt_regs) - 8), "r"(__
> this_module.name) :
> );
> }
> 
> void __exit exit(void)
> {
> return;
> }
> 
> /*******************end*****************/

What exactly was the crash?  And where did you find this kernel module
source from?

greg k-h

  reply	other threads:[~2016-06-26 14:54 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-26  9:35 Kernel panic after insmod Manavendra Nath Manav
2016-06-26 14:54 ` Greg KH [this message]
2016-06-26 16:38   ` Aruna Hewapathirane
2016-06-26 17:56     ` Greg KH
2016-06-27  7:51     ` Silvan Jegen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160626145426.GA8882@kroah.com \
    --to=greg@kroah.com \
    --cc=kernelnewbies@lists.kernelnewbies.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).