Skip to contentSkip to conversation

How to obtain process ID that created a packet

DISCUSSION Mikado 3 participants 6 messages Dec 26, 2005 – Dec 27, 2005

lore
Share & tools
lore

Mikado

author
#0 lore raw

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/

#1 lore raw
Quoted 5 lines

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

author
#2 lore raw
Quoted 3 lines
Quoted 3 lines

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.

Quoted 4 lines

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

#3 lore raw
Quoted 6 lines
Quoted 4 lines

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

#4 lore raw
Quoted 4 lines · Jan Engelhardt
Quoted 4 lines
Quoted 3 lines

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()).

Quoted 8 lines
Quoted 1 line

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

#5 lore raw
Quoted 11 lines

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

Signature · 2 lines
| Alphagate Systems, http://alphagate.hopto.org/
| jengelh's site, http://jengelh.hopto.org/