pflocal getsockname not working with payload

2015-08-13 Thread Samuel Thibault
Hello,

X11 authentication is currently broken, because pflocal's implementation
of getsockname is broken.  It seems to happen since the enabling of
payload optimization.

I have attached a simple testcase: in glibc getsockname()
calls socket_name() which returns a port, and then calls
socket_whatis_address() on that port.  In pflocal, that turns into
calling sock_get_addr() which eventually calls addr_create which creates
a port in the addr_port_class.  Then socket_whatis_address is called, but
addr is NULL, i.e. the lookup failed...

I've added a call to mach_port_clear_protected_payload to disable the
payload optimization for those addr ports, and it then works nicely.

Also, I had to disable the msgh_bits and msgh_protected_payload
mangling, otherwise pflocal was completely not working, I'm not sure
what these bits were useful for actually.

Thoughts?
Samuel
#include 
#include 

int main(void) { 
int s = socket(PF_UNIX, SOCK_STREAM, 0);
if (s < 0)
perror("socket");

struct sockaddr sock;
size_t size = sizeof(sock);

if (getsockname(s, &sock, &size) < 0)
perror("getsockname");

printf("%d\n", sock.sa_family);

return 0;
}
Index: hurd-debian/libports/manage-multithread.c
===
--- hurd-debian.orig/libports/manage-multithread.c
+++ hurd-debian/libports/manage-multithread.c
@@ -173,6 +173,7 @@ ports_manage_port_operations_multithread
   else
{
  pi = ports_lookup_port (bucket, inp->msgh_local_port, 0);
+#if 0
  if (pi)
{
  inp->msgh_bits = MACH_MSGH_BITS (
@@ -180,6 +181,7 @@ ports_manage_port_operations_multithread
MACH_MSG_TYPE_PROTECTED_PAYLOAD);
  inp->msgh_protected_payload = (unsigned long) pi;
}
+#endif
}
 
   if (pi)
Index: hurd-debian/libports/manage-one-thread.c
===
--- hurd-debian.orig/libports/manage-one-thread.c
+++ hurd-debian/libports/manage-one-thread.c
@@ -64,6 +64,7 @@ ports_manage_port_operations_one_thread
   else
{
  pi = ports_lookup_port (bucket, inp->msgh_local_port, 0);
+#if 0
  if (pi)
{
  inp->msgh_bits = MACH_MSGH_BITS (
@@ -71,6 +72,7 @@ ports_manage_port_operations_one_thread
MACH_MSG_TYPE_PROTECTED_PAYLOAD);
  inp->msgh_protected_payload = (unsigned long) pi;
}
+#endif
}
 
   if (pi)
Index: hurd-debian/pflocal/sock.c
===
--- hurd-debian.orig/pflocal/sock.c
+++ hurd-debian/pflocal/sock.c
@@ -262,6 +262,7 @@ addr_create (struct addr **addr)
 
   if (! err)
 {
+  mach_port_clear_protected_payload (mach_task_self (), 
(*addr)->pi.port_right);
   ensure_sock_server ();
   (*addr)->sock = NULL;
   pthread_mutex_init (&(*addr)->lock, NULL);


Re: pflocal getsockname not working with payload

2015-08-13 Thread Samuel Thibault
Samuel Thibault, le Fri 14 Aug 2015 00:03:33 +0200, a écrit :
> I have attached a simple testcase

I've forgotten to provide details: the getsockname() call is supposed to
work, and the sa_family is supposed to be 1 (PF_LOCAL).

Samuel



[committed hurd] pflocal: fix receiver lookup

2015-08-13 Thread Justus Winter
* pflocal/mig-decls.h (begin_using_addr_payload): Use
`ports_lookup_payload'.
---
 pflocal/mig-decls.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pflocal/mig-decls.h b/pflocal/mig-decls.h
index b1da797..6c044ce 100644
--- a/pflocal/mig-decls.h
+++ b/pflocal/mig-decls.h
@@ -58,7 +58,7 @@ begin_using_addr_port(mach_port_t port)
 static inline addr_t __attribute__ ((unused))
 begin_using_addr_payload (unsigned long payload)
 {
-  return ports_lookup_port (NULL, payload, addr_port_class);
+  return ports_lookup_payload (NULL, payload, addr_port_class);
 }
 
 static inline void __attribute__ ((unused))
-- 
2.1.4




Re: pflocal getsockname not working with payload

2015-08-13 Thread Samuel Thibault
Thanks for the commited fix, it does work indeed.

Samuel