LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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
  Search this Thread
Old 11-04-2013, 04:25 AM   #1
jyteh
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Rep: Reputation: Disabled
How to set breakpoint to obtain address of a function in fork.c , in the kernel sourc


Good day to all. I have this query which I hope someone is able to help me with. I forward my gratitude and thanks in advance. I had done hours of search but unable to find a solution.

My problem overview:

1. I need to obtain the address of the " security_task_create(clone_flags)" function in the following code snippet (located in line 926 ,fork.c as per "/usr/src/linux-2.6.27/kernel/fork.c") :-


2. I need to acquire the address of the " security_task_create(clone_flags)" function when it is called while the function is in runtime operation, in the memory. The " security_task_create(clone_flags)" function is a LSM hook to the SELinux Security Hook selinux_task-create.



************************************************************

static struct task_struct *copy_process(unsigned long clone_flags,
unsigned long stack_start,
struct pt_regs *regs,
unsigned long stack_size,
int __user *child_tidptr,
struct pid *pid,
int trace)

{

int retval;
struct task_struct *p;
int cgroup_callbacks_done = 0;

if ((clone_flags & (CLONE_NEWNS|CLONE_FS)) == (CLONE_NEWNS|CLONE_FS))
return ERR_PTR(-EINVAL);

/*
* Thread groups must share signals as well, and detached threads
* can only be started up within the thread group.
*/
if ((clone_flags & CLONE_THREAD) && !(clone_flags & CLONE_SIGHAND))
return ERR_PTR(-EINVAL);

/*
* Shared signal handlers imply shared VM. By way of the above,
* thread groups also imply shared VM. Blocking this case allows
* for various simplifications in other code.
*/
if ((clone_flags & CLONE_SIGHAND) && !(clone_flags & CLONE_VM))
return ERR_PTR(-EINVAL);

****retval = security_task_create(clone_flags);****
if (retval)
goto fork_out;

retval = -ENOMEM;
p = dup_task_struct(current);
if (!p)
goto fork_out;

rt_mutex_init_task(p);
************************************************************

My attempts at arriving at a solution - so far:

1. I've enabled KDB access over keyboard in my Fedora Core 16 machine with kernel 3.1.7. Used "kdb[0]> bp security_task_create" to set breakpoints for obtaining the runtime address of " security_task_create(clone_flags)" function. But kdb says "unable to set breakpoint" after I typed go.


The " security_task_create(clone_flags)" function operates at kernel space.

My questions:

1. How do I obtain the address of the security_task_create() function when security_task_create() had been loaded to memory during runtime? (especially if its in the kernel space memory)


2. What functions or libraries do I use?


3. Would greatly appreciate if some example codes are available.

Thank you in advance.
 
Old 11-05-2013, 02:06 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Have you tried printk()? Given that it's in fork() you'd need to detect the calling case unique to the one you wish to see debug for, but you ought to be able to print out more information in addition to that address. Like you might have to add some printk() statements before it calls copy_process() so as to identify the process name being cloned. There's an example calling printk() in my copy of the do_fork() function.
 
1 members found this post helpful.
Old 11-05-2013, 07:17 PM   #3
jyteh
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Request for code - calling printk() in do_fork

Dear rtmistler ,

Thank you for your reply. Would it be possible if you could supplement me with the sample code of calling printk() in your copy of the do_fork() function?
 
Old 11-06-2013, 07:09 AM   #4
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,877
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Just grep for printk in your source directory and I'm sure you'll find tons of examples.

Code:
			printk(KERN_INFO "fork(): process `%s' used deprecated "
					"clone flags 0x%lx\n",
				get_task_comm(comm, current),
				clone_flags & CLONE_STOPPED);
 
1 members found this post helpful.
Old 11-08-2013, 03:47 AM   #5
jyteh
LQ Newbie
 
Registered: Nov 2013
Posts: 3

Original Poster
Rep: Reputation: Disabled
Thank you for sharing the information.
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
GDB: Setting breakpoint on a class's member function in a file Aquarius_Girl Programming 5 09-07-2011 10:46 PM
Problem setting breakpoint on function with GDB Ganahim Programming 4 02-24-2011 08:03 AM
breakpoint address different with symbol address?? valpa Programming 8 08-23-2008 12:46 AM
Mandrake update kernel-sourc 2.4.22.21 klatu Mandriva 4 11-19-2003 05:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

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