All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* problems with netlink_broadcast
@ 2004-01-13 11:56 John Williams Floroiu
  2004-01-13 17:03 ` Patrick McHardy
  0 siblings, 1 reply; 5+ messages in thread
From: John Williams Floroiu @ 2004-01-13 11:56 UTC (permalink / raw
  To: netfilter-devel


hi,

I am trying to send data to userspace from a kernel module each time a kernel timer expires. so I basically call
skb_alloc followed by netlink_broadcast.

the funny part is that if I call netlink_broadcast from the timer handler (which, according to my understanding, is a
softirq), I get a crash. on the other hand, if I dispatch a tasklet from the timer handler and call skb_alloc from the
tasklet, then I get a crash too.

the only combination that appears to work is calling skb_alloc in the timer handler (pass 'skb' to the tasklet) and
netlink_broadcast from the tasklet. this looks quite strange to me because ipt_ULOG and other kernel modules doing
similar things don't appear to hint at the existence of such restrictions. could anybody figure out what could be wrong?

thanks in advance.

cheers,
John.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problems with netlink_broadcast
  2004-01-13 11:56 problems with netlink_broadcast John Williams Floroiu
@ 2004-01-13 17:03 ` Patrick McHardy
  2004-01-13 18:16   ` John Williams Floroiu
  0 siblings, 1 reply; 5+ messages in thread
From: Patrick McHardy @ 2004-01-13 17:03 UTC (permalink / raw
  To: John Williams Floroiu; +Cc: netfilter-devel

Are you using GFP_ATOMIC for netlink_broadcast and alloc_skb ?

Regards,
Patrick

John Williams Floroiu wrote:
> 
> hi,
> 
> I am trying to send data to userspace from a kernel module each time a 
> kernel timer expires. so I basically call
> skb_alloc followed by netlink_broadcast.
> 
> the funny part is that if I call netlink_broadcast from the timer 
> handler (which, according to my understanding, is a
> softirq), I get a crash. on the other hand, if I dispatch a tasklet from 
> the timer handler and call skb_alloc from the
> tasklet, then I get a crash too.
> 
> the only combination that appears to work is calling skb_alloc in the 
> timer handler (pass 'skb' to the tasklet) and
> netlink_broadcast from the tasklet. this looks quite strange to me 
> because ipt_ULOG and other kernel modules doing
> similar things don't appear to hint at the existence of such 
> restrictions. could anybody figure out what could be wrong?
> 
> thanks in advance.
> 
> cheers,
> John.
> 

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problems with netlink_broadcast
  2004-01-13 17:03 ` Patrick McHardy
@ 2004-01-13 18:16   ` John Williams Floroiu
  2004-01-14 11:25     ` pablo neira
  0 siblings, 1 reply; 5+ messages in thread
From: John Williams Floroiu @ 2004-01-13 18:16 UTC (permalink / raw
  To: Patrick McHardy; +Cc: netfilter-devel


Hi Patrick,

> Are you using GFP_ATOMIC for netlink_broadcast and alloc_skb ?

Yes, here is the code of the tasklet and timer handler in the version of my "user-kernel" module that apparently works.

I also attached at the end the dump I got with the versions that calls alloc_skb from the tasklet.

Regards,
John.

----

void uk_task(void *arg) {

         local_bh_disable();
         printk(KERN_INFO "--- calling netlink_broadcast ---\n");
         netlink_broadcast(uknl, (struct sk_buff *)arg, 0, UKGRP_TEST, GFP_ATOMIC);
         local_bh_enable();
         printk(KERN_INFO "### uk_task terminates ###\n");
}

void uk_timer_handler(unsigned long arg){

         struct nlmsghdr *nl;
         struct sk_buff *skb;

         uktimer.expires = jiffies + HZ/2;
         add_timer(&uktimer);

         skb = alloc_skb(NLMSG_SPACE(256), GFP_ATOMIC);
         if (!skb) {
                 printk(KERN_INFO "### uk_task skb allocation failure ###\n");
                 return;
         }
         NLMSG_PUT(skb, 0, 0, UK_NOTIF_TEST, 0);
         NETLINK_CB(skb).dst_groups = UKGRP_TEST;
         printk(KERN_INFO "### skb->len = %d ###\n", skb->len);

         uk_work.data = skb;
         schedule_work(&uk_work);
         printk(KERN_INFO "### uk_timer_handler terminates ###\n");

         return;

nlmsg_failure:
         skb_trim(skb, skb->tail - skb->data);
         printk(KERN_INFO "### uk_task NLMSG_PUT failure ###\n");
}

----------------------------------------------------------------

Unable to handle kernel paging request at virtual address f6a34fb0
   printing eip:
  f88233ca
  *pde = 00488067
  *pte = 36a34000
  Oops: 0000 [#1]
  CPU:    1
  EIP:    0060:[__crc_utf8_wctomb+5448385/6417782]    Not tainted
  EFLAGS: 00010246
  EIP is at uk_task+0xda/0x160 [uk]
  eax: 00000000   ebx: f6a34f4c   ecx: 00000000   edx: fffffffd
  esi: f2f1fbf8   edi: f8824460   ebp: c1a95f64   esp: c1a95f48
  ds: 007b   es: 007b   ss: 0068
  Process events/1 (pid: 7, threadinfo=c1a94000 task=c1a619b0)
  Stack: f2fa7e94 f6a34f4c 00000000 00000159 00000020 c1a94000 f8824464 c1a95fec
         c01370f6 00000000 c1a95fa0 00000000 c1a64f90 c1a64fa0 00000000 f88232f0
         00000212 c1a64f88 c1a64f78 5a5a5a5a 5a5a5a5a 5a5a5a5a 00000001 00000000
  Call Trace:
   [worker_thread+534/960] worker_thread+0x216/0x3c0
   [__crc_utf8_wctomb+5448167/6417782] uk_task+0x0/0x160 [uk]
   [default_wake_function+0/32] default_wake_function+0x0/0x20
   [ret_from_fork+6/20] ret_from_fork+0x6/0x14
   [default_wake_function+0/32] default_wake_function+0x0/0x20
   [worker_thread+0/960] worker_thread+0x0/0x3c0
   [kernel_thread_helper+5/24] kernel_thread_helper+0x5/0x18

  Code: 8b 43 64 c7 04 24 a0 36 82 f8 89 44 24 04 e8 73 10 90 c7 83

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problems with netlink_broadcast
  2004-01-13 18:16   ` John Williams Floroiu
@ 2004-01-14 11:25     ` pablo neira
  2004-01-14 12:34       ` John Williams Floroiu
  0 siblings, 1 reply; 5+ messages in thread
From: pablo neira @ 2004-01-14 11:25 UTC (permalink / raw
  To: John Williams Floroiu, netfilter-devel

Hi John,

John Williams Floroiu wrote:

> void uk_task(void *arg) {
>
>         local_bh_disable();
>         printk(KERN_INFO "--- calling netlink_broadcast ---\n");
>         netlink_broadcast(uknl, (struct sk_buff *)arg, 0, UKGRP_TEST, 
> GFP_ATOMIC);
>         local_bh_enable();
>         printk(KERN_INFO "### uk_task terminates ###\n");
> }
>
> void uk_timer_handler(unsigned long arg){
>
>         struct nlmsghdr *nl;
>         struct sk_buff *skb;
>
>         uktimer.expires = jiffies + HZ/2;
>         add_timer(&uktimer);
>
>         skb = alloc_skb(NLMSG_SPACE(256), GFP_ATOMIC);
>         if (!skb) {
>                 printk(KERN_INFO "### uk_task skb allocation failure 
> ###\n");
>                 return;
>         }
>         NLMSG_PUT(skb, 0, 0, UK_NOTIF_TEST, 0); 


I think that you are trying to create a skbuff with no netlink header 
because you set last parameter of NLMSG_PUT to 0.

Set it to:
NLMSG_SPACE(256) - sizeof(struct nlmsghdr)

Have a look at the function __nlmsg_put which is called by the macro 
NLMSG_PUT:
http://lxr.linux.no/source/include/linux/netlink.h#L141

Anyway, if it doesn't work have a look at ip_queue.c and ipt_ULOG.c. It 
could help you out.

cheers,
Pablo

>
>         NETLINK_CB(skb).dst_groups = UKGRP_TEST;
>         printk(KERN_INFO "### skb->len = %d ###\n", skb->len);
>
>         uk_work.data = skb;
>         schedule_work(&uk_work);
>         printk(KERN_INFO "### uk_timer_handler terminates ###\n");
>
>         return;
>
> nlmsg_failure:
>         skb_trim(skb, skb->tail - skb->data);
>         printk(KERN_INFO "### uk_task NLMSG_PUT failure ###\n");
> }
>
> ----------------------------------------------------------------
>
> Unable to handle kernel paging request at virtual address f6a34fb0
>   printing eip:
>  f88233ca
>  *pde = 00488067
>  *pte = 36a34000
>  Oops: 0000 [#1]
>  CPU:    1
>  EIP:    0060:[__crc_utf8_wctomb+5448385/6417782]    Not tainted
>  EFLAGS: 00010246
>  EIP is at uk_task+0xda/0x160 [uk]
>  eax: 00000000   ebx: f6a34f4c   ecx: 00000000   edx: fffffffd
>  esi: f2f1fbf8   edi: f8824460   ebp: c1a95f64   esp: c1a95f48
>  ds: 007b   es: 007b   ss: 0068
>  Process events/1 (pid: 7, threadinfo=c1a94000 task=c1a619b0)
>  Stack: f2fa7e94 f6a34f4c 00000000 00000159 00000020 c1a94000 f8824464 
> c1a95fec
>         c01370f6 00000000 c1a95fa0 00000000 c1a64f90 c1a64fa0 00000000 
> f88232f0
>         00000212 c1a64f88 c1a64f78 5a5a5a5a 5a5a5a5a 5a5a5a5a 00000001 
> 00000000
>  Call Trace:
>   [worker_thread+534/960] worker_thread+0x216/0x3c0
>   [__crc_utf8_wctomb+5448167/6417782] uk_task+0x0/0x160 [uk]
>   [default_wake_function+0/32] default_wake_function+0x0/0x20
>   [ret_from_fork+6/20] ret_from_fork+0x6/0x14
>   [default_wake_function+0/32] default_wake_function+0x0/0x20
>   [worker_thread+0/960] worker_thread+0x0/0x3c0
>   [kernel_thread_helper+5/24] kernel_thread_helper+0x5/0x18
>
>  Code: 8b 43 64 c7 04 24 a0 36 82 f8 89 44 24 04 e8 73 10 90 c7 83
>
>
>
>
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: problems with netlink_broadcast
  2004-01-14 11:25     ` pablo neira
@ 2004-01-14 12:34       ` John Williams Floroiu
  0 siblings, 0 replies; 5+ messages in thread
From: John Williams Floroiu @ 2004-01-14 12:34 UTC (permalink / raw
  To: pablo neira; +Cc: netfilter-devel


Hi Pablo,

> I think that you are trying to create a skbuff with no netlink header 
> because you set last parameter of NLMSG_PUT to 0.

NLMSG_PUT allocates a buffer of NLMSG_LENGTH(len), which according to its definition:

     #define NLMSG_LENGTH(len) ((len)+NLMSG_ALIGN(sizeof(struct nlmsghdr)))

should create room for exactly one nlmsghdr in my case.

anyway, in one of the cases when I managed to make it work (as mentioned in my first email) the data could be received 
in user space.

> Anyway, if it doesn't work have a look at ip_queue.c and ipt_ULOG.c. It 
> could help you out.

I will check them in more detail.

cheers,
John.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2004-01-14 12:34 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2004-01-13 11:56 problems with netlink_broadcast John Williams Floroiu
2004-01-13 17:03 ` Patrick McHardy
2004-01-13 18:16   ` John Williams Floroiu
2004-01-14 11:25     ` pablo neira
2004-01-14 12:34       ` John Williams Floroiu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.