LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices

Reply
 
LinkBack Search this Thread
Old 12-28-2011, 07:53 AM   #1
yogesh.kumar
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Rep: Reputation: Disabled
Where in the linux code is linux's instruction memory made non writable?


Hi,

I am a computer science student and doing a project on trying to find bugs in the linux kernel.
For that I needed to patch the linux instruction memory while the kernel is running. I have changed the code of the linux kernel to do this.
My code runs fine just as the kernel boots but then after 1-2 seconds when I try to write in the instruction memory the kernel panics. So most probably after the kernel is booted its instruction memory is made non writable by the kernel itself (as for 1-2 seconds I am able to change the instruction memory and for that time my code runs perfectly).

So it would be a great help to me if anyone could tell me where in the linux kernel code is the kernel's instruction memory is made non-writable.

Thanks in advance
Yogesh Kumar
 
Old 12-28-2011, 09:04 AM   #2
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 3,681

Rep: Reputation: 329Reputation: 329Reputation: 329Reputation: 329
I don't know why you would be doing this, when "/dev/mem" exists to enable rootly programs to do this sort of thing.

Kernel code is protected through the use of page and segment tables. Each process's view of "memory" is governed by these tables and the same is actually true of the kernel.
 
1 members found this post helpful.
Old 12-28-2011, 10:43 AM   #3
yogesh.kumar
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
changing the linux code has to do with my project.
but as you said can we change the linux instruction memory using /dev/mem
if yes that will be great.
thanks for your help
 
Old 01-11-2012, 12:56 PM   #4
yogesh.kumar
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Unhappy

Hi,
I tried /dev/mem to read and write in physical memory. But when I try to write to the location where kernel code is loaded it gives me a error. So I am still stuck on how do I make the linux kernel code writable while the kernel is running..
 
Old 01-23-2012, 08:18 AM   #5
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,177

Rep: Reputation: 48
I don't know if I have the expertise to help you, but first of all - what's "instruction memory"? Could you explain?
 
Old 01-23-2012, 08:24 AM   #6
yogesh.kumar
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by resetreset View Post
I don't know if I have the expertise to help you, but first of all - what's "instruction memory"? Could you explain?
by linux's instruction memory i mean the memory where the kernel image is loaded, from where the cpu reads and execute instructions.
 
Old 01-23-2012, 10:45 AM   #7
sundialsvcs
Senior Member
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 3,681

Rep: Reputation: 329Reputation: 329Reputation: 329Reputation: 329
The kernel is successfully protecting itself [u]from[u] "Computer science students!"

Remember that Unix has been used for many years in universities that are filled with very bright, usually bored, "computer science students."
 
Old 01-24-2012, 12:14 AM   #8
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,177

Rep: Reputation: 48
Quote:
Originally Posted by yogesh.kumar View Post
by linux's instruction memory i mean the memory where the kernel image is loaded, from where the cpu reads and execute instructions.
OK, I don't KNOW this, but the area of memory where the Linux kernel resides would be protected - how have you modified the kernel so that you can write to this memory?

Do you have an understanding of protected mode?
 
Old 01-24-2012, 12:19 AM   #9
yogesh.kumar
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by resetreset View Post
OK, I don't KNOW this, but the area of memory where the Linux kernel resides would be protected - how have you modified the kernel so that you can write to this memory?

Do you have an understanding of protected mode?
I have changed the code of linux kernel to do that. but whenever my code try to write into instruction memory kernel panics.
Thought initially for about 1-2 sec I can write but after that I can't so it must be made non-writable by the kernel itself.

I don't know what protected mode you are talking about.
 
Old 01-24-2012, 01:12 PM   #10
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,177

Rep: Reputation: 48
You program the Linux kernel, but you don't know what protected mode is???!! I would ask you to post a little of whatever code it is (I don't program in C), but as it is I don't think I can help you. Maybe someone else on this forum...?
 
Old 01-24-2012, 01:29 PM   #11
yogesh.kumar
LQ Newbie
 
Registered: Dec 2011
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by resetreset View Post
You program the Linux kernel, but you don't know what protected mode is???!! I would ask you to post a little of whatever code it is (I don't program in C), but as it is I don't think I can help you. Maybe someone else on this forum...?
uint64_t *patch_address = &msleep;
unsigned int dif = &msleep1 - ((void (*)())patch_address + 5);
uint64_t content = 0x0000000000000000 | dif;
content = 0x00000000000000e8 | (content << 8);
orignal = *patch_address;
*patch_address = content; //at this line kernel panics.
 
Old 01-25-2012, 02:56 PM   #12
resetreset
Senior Member
 
Registered: Mar 2008
Location: India
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,177

Rep: Reputation: 48
I said I DON'T program in C.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
What is the first instruction of Arm Linux? Richard.Yang Linux - Kernel 1 11-08-2010 03:27 AM
How to retrieve CPU, Disk and Memory utilization in linux userspace code NilesBor Linux - Kernel 2 06-17-2009 08:27 AM
machine code of BL instruction topworld Programming 1 04-11-2006 04:41 PM
Which linux instruction is equivalent to windows' instruction "tracert"? backpacker Linux - Software 1 04-04-2006 10:55 PM
USB memory stick not writable Hermann.G Linux - Hardware 3 01-14-2004 05:16 PM


All times are GMT -5. The time now is 12:50 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration