LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
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 11-28-2012, 10:16 AM   #1
itrilok
LQ Newbie
 
Registered: Jan 2009
Distribution: Fedora
Posts: 29

Rep: Reputation: 0
Kernel Panic when netlink message is sent from User space to kernel space


Hi all,

The below code is w.r.t netlinks. I just ported the below code from 2.6.27 kernel to 2.6.34 kernel. And this code works fine in 2.6.27 kernel and when I run it in 2.6.34 it is giving kernel panic. When I debugged it "nlh" value is null i.e skb->data is pointing to some garbage value. What could be the reason. Please help me.

Kernel Code:
------------
int nl_rcv_func (struct sk_buff *skb)
{
struct nlmsghdr *nlh;

if (!skb && !(struct nlmsghdr *)skb->data)
return FAILURE;

/* Get the Netlink message header from the buffer */
nlh = (struct nlmsghdr *)skb->data;

/* Kernel panic is happening here since nlh is NULL */
printk (KERN_INFO "%d:"nlh->nlmsg_len);

}

struct sock *nl_sock ()
{
struct sock *ns = NULL;
ns = netlink_kernel_create (&init_net, NETLINK_USERSOCK, 0,
nl_rcv_func, &rtnl_mutex,THIS_MODULE);
return ns;
}

UserSpace Code:
----------------

int init_module ( )
{
struct ctrl c;
struct sockaddr_nl nladdr;
struct
{
struct nlmsghdr nlmh;
struct ctrl c;
}
rq;
int ns;

/* Initialize the socket */
ns = netlink_open ();
if (ns <= 0)
{
perror ("socket failed");
return -1;
}

pal_mem_set(&rq, 0, sizeof(rq));
pal_mem_set(&nladdr, 0, sizeof(nladdr));
void *data = NLMSG_DATA(&rq);
req.nlmh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ctrl));

pal_mem_cpy(data, 40, sizeof(struct ctrl));
nladdr.nl_family = AF_NETLINK;

return sendto(ns, (u_char *)&rq, 20, 0, (struct sockaddr *)&nladdr,
sizeof(nladdr));
}
 
Old 11-28-2012, 10:56 AM   #2
sundialsvcs
Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 5,397

Rep: Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114Reputation: 1114
My immediate assumption is that the network support is being implemented by a loadable kernel-module that is somehow out-of-sync with the remainder of the system. If you have upgraded your kernel (package...), reinstall any additional packages that might be involved e.g. with device support.

I would be profoundly surprised if the API in question was changed for a minor-release ... naah, it simply wouldn't still be "2.6.xx." So, this fairly screams to me to be a "bullsh*t problem," probably quite external to the code that you're currently debugging. I would, in other words, very thoroughly eliminate all other possible "way out in left field" possibilities first.

Last edited by sundialsvcs; 11-28-2012 at 10:58 AM.
 
  


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
Free user space pages of different user processes from inside kernel space trueskyte Linux - Kernel 1 10-22-2010 04:37 PM
Netlink Kernel User-space communication code for 2.6.33, 2.6.34+ Kernels kiran_cyberpro Programming 0 06-09-2010 03:19 AM
Division of Logical Memory Space in to User Space and Kernel Space shreshtha Linux - Newbie 2 01-14-2010 09:59 AM
Netlink sockets usage to communicate b/w user and kernel space. vinodkr83 Linux - Newbie 1 07-03-2009 03:22 AM
Kernel Module to send Message to User Space Application hnshashi Linux - Newbie 2 08-22-2008 12:48 AM


All times are GMT -5. The time now is 05:51 AM.

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 Google+: linuxquestions
Open Source Consulting | Domain Registration