Skip to contentSkip to conversation

Get UID from netlink/conntrack

DISCUSSION Justin McCann 2 participants 2 messages Feb 7, 2008 netfilter

lore
Share & tools
lore
#0 lore raw

----- Original Message ----

Quoted 7 lines

From: Jan Engelhardt <[email protected]>

Quoted 2 lines

I'd like to use libnetfilter_conntrack to track connections per UID and/or by PID, ...

You are facing the same issues as xt_socket (currently, and unfortunately, still named xt_owner) - in that sockets do not necessarily have an owner, much less exactly one associated PID.

That doesn't surprise me too much, given how e.g. sshd handles connections (sockets are uid 0). Is this mainly a setuid issue, or is there something else interesting going on behind the scenes?

I'm attempting to make an auto-updating tcpdump filter, so unprivileged users could tcpdump their own connections without compromising privacy. For those purposes having the largest possible subset of connections 'owned/initiated' by a given user will do-- better something than nothing. In the cases where there isn't a known PID/UID, 0 would suffice (maybe -1 for PID since it appears to be a signed int). There are probably other applications this wouldn't work too well for, e.g. using the firewall to prevent any new connections by a user. But there are probably better ways to do that.

It doesn't look like nfnetlink_log does any special handling in case the real uid isn't known. Is distinguishing between 'unknown/not set' and 0 important enough to handle specially (e.g. with a separate flag)?

BTW, I see that in 2.6.23, net/netfilter/nfnetlink_log.c:505 just grabs the uid directly out of the skb->.... Should that use sock_i_uid(skb) instead? That chain of macros/functions uses vfs_inode instead of sk_socket->file->f_uid, FWIW.

Justin

      ____________________________________________________________________________________

Be a better friend, newshound, and
know-it-all with Yahoo! Mobile. Try it now. http://mobile.yahoo.com/;_ylt=Ahu06i62sR8HDtDypao8Wcj9tAcJ

#1 lore raw
Quoted 10 lines · Justin McCann
Quoted 7 lines
Quoted 3 lines

I'd like to use libnetfilter_conntrack to track connections per UID and/or by PID, ...

You are facing the same issues as xt_socket (currently, and unfortunately, still named xt_owner) - in that sockets do not necessarily have an owner, much less exactly one associated PID.

That doesn't surprise me too much, given how e.g. sshd handles connections (sockets are uid 0).

- sshd created the socket as root (dunno why it did that as root :-)
- so skb->sk->sk_socket->file->f_uid is root, no matter if it called setuid(2) or not.
- binds to port 22 (requires root)
- accept(2), privilege separation and all that

(I notice an interesting upcoming problem for input-path owner processing as projected with tproxy's help.)

Quoted 6 lines

Is this mainly a setuid issue, or
is there something else interesting going on behind the scenes?

I'm attempting to make an auto-updating tcpdump filter, so unprivileged users could tcpdump their own connections without compromising privacy.

In that case, using ->f_uid should work for all (locally-generated) outgoing traffic. It is the best you can get right now.

About input, a test would be needed (examining things) because I suspect that ssh sessions can be wrongly attributed to root when there's a normal user sitting behind it.

PID matching is not possible. Or rather, if it was, you'd spend a ridiculous amount of time scanning all processes' fd tables on every packet.

And that's just the kernel side. How you wire that up in netlink is another story.