LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-14-2009, 01:21 AM   #1
alek314
LQ Newbie
 
Registered: Aug 2009
Posts: 3

Rep: Reputation: 0
Question how to create overflow-proof data segment?


hi
Is it possible to create a segment of memory(in c++), such that any attempt to overflow the data would trigger a SIGSEGV?

000000ddddddddd0000

e.g: the critical data lies in "ddddd", any attemp to write "000" would trigger SIGSEGV or crash the progam.

thanks!
 
Old 08-14-2009, 03:19 AM   #2
alek314
LQ Newbie
 
Registered: Aug 2009
Posts: 3

Original Poster
Rep: Reputation: 0
i look up <Advanced Linux Programming> and come to something like this:

size_t page_size = getpagesize ();
int fd = open ("/dev/zero", O_RDONLY);
char* memory = (char*)mmap (NULL, page_size * 3, PROT_READ | PROT_WRITE,MAP_PRIVATE, fd, 0);
close (fd);
mprotect (memory, page_size, PROT_READ);
mprotect (memory + page_size*2, page_size, PROT_READ);
memory[0] = 1; // SIGSEGV
memory[page_size] = 1; // OK
memory[page_size*2-1] = 1; // OK
memory[page_size*2] = 1; // SIGSEGV
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] how to create overflow-proof data segment? alek314 Linux - Software 1 08-14-2009 12:22 AM
Where is LKM's text and data segment once it is loaded into kernel? tommy24 Linux - Kernel 4 07-25-2008 09:13 PM
getting the virtual address of the .data segment ravi Linux - Newbie 0 01-31-2006 01:35 AM
Creating Ora10g database on FC2 gives unable to create shared memory segment.... deanbrown3d Linux - Software 1 10-23-2004 11:40 AM
Create a hash with any data Nerox Programming 3 07-31-2004 08:15 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 03:08 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration