2005-12-26 16:22:20

by Mikado

[permalink] [raw]
Subject: How to obtain process ID that created a packet

Hi,

Is there any way to catch REAL pid that generated a packet from 'struct sk_buff', 'struct sock',
'struct socket',
'struct file' or etc... ? direct/indirect ways are accepted.

Thank you!




__________________________________
Yahoo! for Good - Make a difference this year.
http://brand.yahoo.com/cybergivingweek2005/


2005-12-26 22:36:47

by Jan Engelhardt

[permalink] [raw]
Subject: Re: How to obtain process ID that created a packet

>Hi,
>
>Is there any way to catch REAL pid that generated a packet from 'struct sk_buff', 'struct sock',
>'struct socket',
>'struct file' or etc... ? direct/indirect ways are accepted.

The question is: when do you test for the PID? You would have to do it
within send(), because anywhere else, you do not know. A socket may be
shared among multiple processes (most simple way: fork()).



Jan Engelhardt
--

2005-12-27 01:47:12

by Mikado

[permalink] [raw]
Subject: Re: How to obtain process ID that created a packet

> >Hi,
> >
> >Is there any way to catch REAL pid that generated a packet from 'struct sk_buff', 'struct
sock', 'struct socket', 'struct file' or etc... ? direct/indirect ways are accepted.
>
> The question is: when do you test for the PID? You would have to do it
> within send(), because anywhere else, you do not know. A socket may be
> shared among multiple processes (most simple way: fork()).

I'm hooking in NF_IP_LOCAL_OUT of netfilter code using nf_register_hook() function.

__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com

2005-12-27 08:26:45

by Jan Engelhardt

[permalink] [raw]
Subject: Re: How to obtain process ID that created a packet


>> The question is: when do you test for the PID? You would have to do it
>> within send(), because anywhere else, you do not know. A socket may be
>> shared among multiple processes (most simple way: fork()).
>
>I'm hooking in NF_IP_LOCAL_OUT of netfilter code using nf_register_hook() function.

In sys_send(), I would have said you could use "current", but in netfilter
I can't tell exactly whether it is going to work on SMP.

Check net/ipv4/netfilter/ipt_owner.c, it provides a way to match packets vs
pids, but it's not easy to find out.



Jan Engelhardt
--

2005-12-27 10:55:29

by Michael Tokarev

[permalink] [raw]
Subject: Re: How to obtain process ID that created a packet

Jan Engelhardt wrote:
>>>The question is: when do you test for the PID? You would have to do it
>>>within send(), because anywhere else, you do not know. A socket may be
>>>shared among multiple processes (most simple way: fork()).
>>
>>I'm hooking in NF_IP_LOCAL_OUT of netfilter code using nf_register_hook() function.
>
>
> In sys_send(), I would have said you could use "current", but in netfilter
> I can't tell exactly whether it is going to work on SMP.
>
> Check net/ipv4/netfilter/ipt_owner.c, it provides a way to match packets vs
> pids, but it's not easy to find out.

In current 2.6 kernel, net/ipv4/netfilter/ipt_owner.c:checkentry() :

if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) {
printk("ipt_owner: pid, sid and command matching "
"not supported anymore\n");
return 0;
}

So... even netfilter, breaking backward compatibility, does not support
pid match anymore...

/mjt

2005-12-27 18:03:59

by Jan Engelhardt

[permalink] [raw]
Subject: Re: How to obtain process ID that created a packet


>In current 2.6 kernel, net/ipv4/netfilter/ipt_owner.c:checkentry() :
>
> if (info->match & (IPT_OWNER_PID|IPT_OWNER_SID|IPT_OWNER_COMM)) {
> printk("ipt_owner: pid, sid and command matching "
> "not supported anymore\n");
> return 0;
> }
>
>So... even netfilter, breaking backward compatibility, does not support
>pid match anymore...

Because they do not work on SMP. That's the reason they are disabled.



Jan Engelhardt
--
| Alphagate Systems, http://alphagate.hopto.org/
| jengelh's site, http://jengelh.hopto.org/