netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* netlink nlmsg_pid supposed to be pid or tid?
@ 2005-11-21 19:32 Christopher Friesen
  2005-11-21 19:46 ` Christopher Friesen
  2005-11-21 20:51 ` Herbert Xu
  0 siblings, 2 replies; 14+ messages in thread
From: Christopher Friesen @ 2005-11-21 19:32 UTC (permalink / raw)
  To: netdev, Linux Kernel Mailing List


When using netlink, should "nlmsg_pid" be set to pid (current->tgid) or 
tid (current->pid)?

Chris

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 19:32 netlink nlmsg_pid supposed to be pid or tid? Christopher Friesen
@ 2005-11-21 19:46 ` Christopher Friesen
  2005-11-21 20:51 ` Herbert Xu
  1 sibling, 0 replies; 14+ messages in thread
From: Christopher Friesen @ 2005-11-21 19:46 UTC (permalink / raw)
  To: netdev, Linux Kernel Mailing List

Friesen, Christopher [CAR:VC21:EXCH] wrote:
> 
> When using netlink, should "nlmsg_pid" be set to pid (current->tgid) or 
> tid (current->pid)?

The reason I ask is that with 2.6.10 we had to set it to tid, which 
really doesn't make much sense given than sockets are shared across all 
threads in a process (and gettid() isn't even a libc function).

Chris

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 19:32 netlink nlmsg_pid supposed to be pid or tid? Christopher Friesen
  2005-11-21 19:46 ` Christopher Friesen
@ 2005-11-21 20:51 ` Herbert Xu
  2005-11-21 21:35   ` Alexey Kuznetsov
  1 sibling, 1 reply; 14+ messages in thread
From: Herbert Xu @ 2005-11-21 20:51 UTC (permalink / raw)
  To: Christopher Friesen; +Cc: netdev, linux-kernel, davem, kuznet

Christopher Friesen <cfriesen@nortel.com> wrote:
> 
> When using netlink, should "nlmsg_pid" be set to pid (current->tgid) or 
> tid (current->pid)?

I tend to agree with you here that tgid makes more sense.  Dave, what
do you think?

However, you should never assume whatever value the kernel uses since
it may always choose an arbitrary value should the preferred pid/tgid
be taken by someone else.

So always use getsockname(2) to find out the correct address.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 20:51 ` Herbert Xu
@ 2005-11-21 21:35   ` Alexey Kuznetsov
  2005-11-21 21:47     ` Christopher Friesen
  2005-11-21 22:16     ` [NETLINK]: Use tgid instead of pid for nlmsg_pid Herbert Xu
  0 siblings, 2 replies; 14+ messages in thread
From: Alexey Kuznetsov @ 2005-11-21 21:35 UTC (permalink / raw)
  To: Herbert Xu; +Cc: Christopher Friesen, netdev, linux-kernel, davem

Hello!

> I tend to agree with you here that tgid makes more sense.

I agree, apparently netlink_autobind was missed when sed'ing pid->tgid.
Of course, it does not matter, but tgid is nicer choice from user's viewpoint.

Alexey

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 21:35   ` Alexey Kuznetsov
@ 2005-11-21 21:47     ` Christopher Friesen
  2005-11-21 22:15       ` Herbert Xu
  2005-11-21 22:49       ` Alexey Kuznetsov
  2005-11-21 22:16     ` [NETLINK]: Use tgid instead of pid for nlmsg_pid Herbert Xu
  1 sibling, 2 replies; 14+ messages in thread
From: Christopher Friesen @ 2005-11-21 21:47 UTC (permalink / raw)
  To: Alexey Kuznetsov; +Cc: Herbert Xu, netdev, linux-kernel, davem

Alexey Kuznetsov wrote:
> Hello!
> 
> 
>>I tend to agree with you here that tgid makes more sense.
> 
> 
> I agree, apparently netlink_autobind was missed when sed'ing pid->tgid.
> Of course, it does not matter, but tgid is nicer choice from user's viewpoint.

I'm glad you agree, but I'm not sure what you mean by "it does not matter".

TIPC wants the user to fill in the pid to use in the nlmsghdr portion of 
a particular message.

When an NPTL child thread uses getpid() to specify the pid, it never 
receives a response to this request.  Running the same code on the 
parent works, and running the same code under Linuxthreads works.

Using gettid() works, but it also means that only the thread that issued 
the request can read the reply.

Chris

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 21:47     ` Christopher Friesen
@ 2005-11-21 22:15       ` Herbert Xu
  2005-11-21 22:51         ` Christopher Friesen
  2005-11-21 22:49       ` Alexey Kuznetsov
  1 sibling, 1 reply; 14+ messages in thread
From: Herbert Xu @ 2005-11-21 22:15 UTC (permalink / raw)
  To: Christopher Friesen; +Cc: kuznet, herbert, netdev, linux-kernel, davem

Christopher Friesen <cfriesen@nortel.com> wrote:
> 
> When an NPTL child thread uses getpid() to specify the pid, it never 
> receives a response to this request.  Running the same code on the 
> parent works, and running the same code under Linuxthreads works.

As I said before, you should not rely on getpid() to work.  Any other
process in the system can bind to your pid which makes it unavailable
to your process.  In which case the kernel will pick an arbitrary
negative pid as your address.

You should always use getsockaddr(2) to get your local address.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* [NETLINK]: Use tgid instead of pid for nlmsg_pid
  2005-11-21 21:35   ` Alexey Kuznetsov
  2005-11-21 21:47     ` Christopher Friesen
@ 2005-11-21 22:16     ` Herbert Xu
  2005-11-22 22:43       ` David S. Miller
  1 sibling, 1 reply; 14+ messages in thread
From: Herbert Xu @ 2005-11-21 22:16 UTC (permalink / raw)
  To: Alexey Kuznetsov; +Cc: herbert, cfriesen, netdev, linux-kernel, davem

Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> wrote:
> 
> I agree, apparently netlink_autobind was missed when sed'ing pid->tgid.
> Of course, it does not matter, but tgid is nicer choice from user's viewpoint.

Great, here is the patch to do just that.

Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Thanks,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -476,7 +476,7 @@ static int netlink_autobind(struct socke
 	struct hlist_head *head;
 	struct sock *osk;
 	struct hlist_node *node;
-	s32 pid = current->pid;
+	s32 pid = current->tgid;
 	int err;
 	static s32 rover = -4097;
 

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 21:47     ` Christopher Friesen
  2005-11-21 22:15       ` Herbert Xu
@ 2005-11-21 22:49       ` Alexey Kuznetsov
  2005-11-21 23:34         ` Herbert Xu
  1 sibling, 1 reply; 14+ messages in thread
From: Alexey Kuznetsov @ 2005-11-21 22:49 UTC (permalink / raw)
  To: Christopher Friesen; +Cc: Herbert Xu, netdev, linux-kernel, davem

Hello!

> TIPC wants the user to fill in the pid to use in the nlmsghdr portion of 
> a particular message.

It is wrong. netlink_pid used not to be associated with process pids.
Kernel used pid just as a seed to calculate a random value to bind,
when user did not bind explicitly. It is equal to current->pid occasionally.
F.e. libnetlink from iproute autobinds and gets netlink_pid with
getsockname().

When user binds the socket himself, he was free to bind to any value,
including pid and tgid.

Actually, I remember one discussion. Herbert, wait a minute...
That's it: February 2005, Subject: [PATCH] Add audit uid to netlink credentials
We decided (or not?) that binding to anything but tgid and pid
must be prohibited by security reasons. Apaprently, the finding was lost.

Alexey

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 22:15       ` Herbert Xu
@ 2005-11-21 22:51         ` Christopher Friesen
  2005-11-22  0:09           ` Herbert Xu
  0 siblings, 1 reply; 14+ messages in thread
From: Christopher Friesen @ 2005-11-21 22:51 UTC (permalink / raw)
  To: Herbert Xu; +Cc: kuznet, netdev, linux-kernel, davem

Herbert Xu wrote:

> As I said before, you should not rely on getpid() to work.

> You should always use getsockaddr(2) to get your local address.

Should that be getsockname(2)?  Anyways, I now understand the issues.

As it turns out, we were actually already calling getsockname() a bit 
earlier in the code path, so we can just use the "pid" value from there.

Chris

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 22:49       ` Alexey Kuznetsov
@ 2005-11-21 23:34         ` Herbert Xu
  0 siblings, 0 replies; 14+ messages in thread
From: Herbert Xu @ 2005-11-21 23:34 UTC (permalink / raw)
  To: Alexey Kuznetsov; +Cc: Christopher Friesen, netdev, linux-kernel, davem

On Tue, Nov 22, 2005 at 01:49:13AM +0300, Alexey Kuznetsov wrote:
> 
> Actually, I remember one discussion. Herbert, wait a minute...
> That's it: February 2005, Subject: [PATCH] Add audit uid to netlink credentials
> We decided (or not?) that binding to anything but tgid and pid
> must be prohibited by security reasons. Apaprently, the finding was lost.

Thanks for reminding me.  We may still need to track that down (we
have now serialised most of the netlink processing so this my not be
as bad as it was).

However, I think explicit binding should still be allowed for root,
so nobody should take the PID for granted.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: netlink nlmsg_pid supposed to be pid or tid?
  2005-11-21 22:51         ` Christopher Friesen
@ 2005-11-22  0:09           ` Herbert Xu
  0 siblings, 0 replies; 14+ messages in thread
From: Herbert Xu @ 2005-11-22  0:09 UTC (permalink / raw)
  To: Christopher Friesen; +Cc: kuznet, netdev, linux-kernel, davem

On Mon, Nov 21, 2005 at 04:51:03PM -0600, Christopher Friesen wrote:
> 
> Should that be getsockname(2)?  Anyways, I now understand the issues.

Yes that's what I meant.

> As it turns out, we were actually already calling getsockname() a bit 
> earlier in the code path, so we can just use the "pid" value from there.

Excellent.

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [NETLINK]: Use tgid instead of pid for nlmsg_pid
  2005-11-21 22:16     ` [NETLINK]: Use tgid instead of pid for nlmsg_pid Herbert Xu
@ 2005-11-22 22:43       ` David S. Miller
  2005-11-23  0:03         ` Herbert Xu
  0 siblings, 1 reply; 14+ messages in thread
From: David S. Miller @ 2005-11-22 22:43 UTC (permalink / raw)
  To: herbert; +Cc: kuznet, cfriesen, netdev, linux-kernel

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Tue, 22 Nov 2005 09:16:27 +1100

> Alexey Kuznetsov <kuznet@ms2.inr.ac.ru> wrote:
> > 
> > I agree, apparently netlink_autobind was missed when sed'ing pid->tgid.
> > Of course, it does not matter, but tgid is nicer choice from user's viewpoint.
> 
> Great, here is the patch to do just that.
> 
> Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>

Applied, of course.

I can't for the life of me figure out how we missed this when
we fixed up all the current->pid references under net/.
Ulrich Drepper let us know that the problem existed, and
I was sure we eliminated all such cases.

It is possible we accidently reintroduced current->pid when
we redid all of the netlink hashing. :-)

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

* Re: [NETLINK]: Use tgid instead of pid for nlmsg_pid
  2005-11-22 22:43       ` David S. Miller
@ 2005-11-23  0:03         ` Herbert Xu
  2005-11-23  6:18           ` David S. Miller
  0 siblings, 1 reply; 14+ messages in thread
From: Herbert Xu @ 2005-11-23  0:03 UTC (permalink / raw)
  To: David S. Miller; +Cc: kuznet, cfriesen, netdev, linux-kernel

On Tue, Nov 22, 2005 at 02:43:34PM -0800, David S. Miller wrote:
> 
> Applied, of course.

Thanks Dave.
 
> It is possible we accidently reintroduced current->pid when
> we redid all of the netlink hashing. :-)

I just checked using git-whatchanged and that line goes back to
2002 :)

Cheers,
-- 
Visit Openswan at http://www.openswan.org/
Email: Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt

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

* Re: [NETLINK]: Use tgid instead of pid for nlmsg_pid
  2005-11-23  0:03         ` Herbert Xu
@ 2005-11-23  6:18           ` David S. Miller
  0 siblings, 0 replies; 14+ messages in thread
From: David S. Miller @ 2005-11-23  6:18 UTC (permalink / raw)
  To: herbert; +Cc: kuznet, cfriesen, netdev, linux-kernel

From: Herbert Xu <herbert@gondor.apana.org.au>
Date: Wed, 23 Nov 2005 11:03:37 +1100

> On Tue, Nov 22, 2005 at 02:43:34PM -0800, David S. Miller wrote:
> > It is possible we accidently reintroduced current->pid when
> > we redid all of the netlink hashing. :-)
> 
> I just checked using git-whatchanged and that line goes back to
> 2002 :)

Ho hum, I guess we just missed it on the current->pid
scan then :-)

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

end of thread, other threads:[~2005-11-23  6:18 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-11-21 19:32 netlink nlmsg_pid supposed to be pid or tid? Christopher Friesen
2005-11-21 19:46 ` Christopher Friesen
2005-11-21 20:51 ` Herbert Xu
2005-11-21 21:35   ` Alexey Kuznetsov
2005-11-21 21:47     ` Christopher Friesen
2005-11-21 22:15       ` Herbert Xu
2005-11-21 22:51         ` Christopher Friesen
2005-11-22  0:09           ` Herbert Xu
2005-11-21 22:49       ` Alexey Kuznetsov
2005-11-21 23:34         ` Herbert Xu
2005-11-21 22:16     ` [NETLINK]: Use tgid instead of pid for nlmsg_pid Herbert Xu
2005-11-22 22:43       ` David S. Miller
2005-11-23  0:03         ` Herbert Xu
2005-11-23  6:18           ` David S. Miller

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).