LinuxQuestions.org
Visit Jeremy's Blog.
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 12-04-2011, 11:34 AM   #1
mopinion
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Rep: Reputation: Disabled
Linux System Calls


Hey all. So i'm creating a program for linux using C programming and was wondering if its possible to alter a current system call to receive an argument from a user level program. If so, is there any specific way of doing so?
Thanks all!
 
Old 12-04-2011, 12:30 PM   #2
firstfire
Member
 
Registered: Mar 2006
Location: Ekaterinburg, Russia
Distribution: Debian, Ubuntu
Posts: 709

Rep: Reputation: 428Reputation: 428Reputation: 428Reputation: 428Reputation: 428
Hi.
Could you please provide some example of what you'd like to do.
As I understand, system calls (e.g. open, read, write) is a user-level interface to kernel, so they always recieve an argument from a user-level program. You want to pass some additional arguments? Anyway, to alter a system call you probably should alter kernel code.
 
Old 12-04-2011, 02:23 PM   #3
mopinion
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
I would like to block the open system call until a certain program (that i have created) is run. This open system call is only to be blocked when the user chooses a certain state.
 
Old 12-04-2011, 08:06 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,659
Blog Entries: 4

Rep: Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941Reputation: 3941
Almost all system calls are issued by (shared) libraries that have been loaded by the applications in question. Usually there are "debug" versions of those libraries, or you can simply roll one of your own.
 
Old 12-04-2011, 08:28 PM   #5
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
I would highly, highly advise against even attempting to think about modifying the open system call.

While adding a new system call that did what you want is a technical possibility, I would also highly recommend against that.

Why don't you just wait until the external condition is met in your program, and THEN call open?

If that's not an option, then perhaps you can implement a pseudo device (in the kernel) that implements its own open method, which does what you want.
 
Old 12-04-2011, 11:19 PM   #6
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Root-kit, innit?
 
Old 12-04-2011, 11:53 PM   #7
mopinion
LQ Newbie
 
Registered: Nov 2011
Posts: 4

Original Poster
Rep: Reputation: Disabled
So.. maybe i should clearly state what my intent is. I am trying to block the open system call whenever it is invoked in order to stop files within a directory from being altered (written to, deleted, moved etc.) before a backup is made.
Therefore for example:

If a user chooses option 1 in the user level program.
Then if someone writes to a file, the open system call has to be invoked.
The open system call is first blocked.
A user level program then creates a backup of that file/directory.
The open system call resumes.

If a user chooses option 2 in the user level program, then the open system call should not be blocked, no backup should be created and the user continues as usual.
 
Old 12-05-2011, 12:18 AM   #8
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> Then if someone writes to a file, the open system call has to be invoked.

Not necessarily, it may have been opened beforehand... If it really is a backup-problem, then perhaps you should remount the whole affected partition read-only before you start the backup.
 
Old 12-05-2011, 12:33 AM   #9
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
I'm just curious - is there any way to do what he's suggesting (tamper with kernel code) using a kernel module?
 
Old 12-05-2011, 12:57 AM   #10
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
Yes -- that's a way how a 'trojan horse' corrupts a system.
 
Old 12-05-2011, 01:42 AM   #11
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
Don't want to hijack the thread, but - how exactly does it work? What exactly does inserting a kernel module DO?
 
Old 12-05-2011, 02:03 AM   #12
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
When a kernel module is loaded, it becomes part of the kernel, so it can do virtually anything: for example can redirect system-calls to itself, and that way it can hide files/processes from any user-land programs, for example.
 
Old 12-05-2011, 02:20 AM   #13
resetreset
Senior Member
 
Registered: Mar 2008
Location: Cyberspace
Distribution: Dynebolic, Ubuntu 10.10
Posts: 1,340

Rep: Reputation: 62
No no, I am more interested in the specifics - how exactly does a module "insert", i.e. how exactly are the capabilities of int 80h extended?
 
Old 12-05-2011, 02:32 AM   #14
jhwilliams
Senior Member
 
Registered: Apr 2007
Location: Portland, OR
Distribution: Debian, Android, LFS
Posts: 1,168

Rep: Reputation: 211Reputation: 211Reputation: 211
Quote:
Originally Posted by resetreset View Post
No no, I am more interested in the specifics - how exactly does a module "insert", i.e. how exactly are the capabilities of int 80h extended?
Hi Reset, you can read the manpage for the insmod(8) command to get a basic idea.
 
Old 12-05-2011, 02:41 AM   #15
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,862
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
or google for "rootkit", "linux" and "kernel module"... it is rather off-topic here
 
  


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
how does java calls the system calls which are written in c babu198649 Linux - General 3 12-05-2011 03:40 AM
linux system calls rblampain Programming 3 02-24-2010 11:06 PM
Linux System Calls or Interupts Moaxam Linux - Software 1 05-03-2007 10:56 AM
LINUX System calls Jitin Programming 1 08-02-2006 08:47 PM
linux system calls blanny Programming 4 03-04-2006 12:15 AM

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

All times are GMT -5. The time now is 10:06 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