LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Kernel Panic when netlink message is sent from User space to kernel space (http://www.linuxquestions.org/questions/programming-9/kernel-panic-when-netlink-message-is-sent-from-user-space-to-kernel-space-4175439157/)

itrilok 11-28-2012 10:16 AM

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));
}

sundialsvcs 11-28-2012 10:56 AM

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.


All times are GMT -5. The time now is 04:32 PM.