public inbox for libc-alpha@sourceware.org
 help / color / mirror / Atom feed
* [hurd,commited 0/5] hurd patches
@ 2018-03-18 19:45 Samuel Thibault
  2018-03-18 19:45 ` [hurd,commited 5/5] Hurd: fix port leak in TLS Samuel Thibault
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Samuel Thibault @ 2018-03-18 19:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

Richard Braun (1):
  Hurd: fix port leak in TLS

Samuel Thibault (4):
  hurd: Fix O_NOFOLLOW
  hurd: Fix O_DIRECTORY | O_NOFOLLOW
  hurd: Fix boot with statically-linked exec server
  hurd: Add mlockall support

 ChangeLog                           | 15 +++++++++++++
 hurd/hurdlookup.c                   |  2 +-
 hurd/lookup-retry.c                 | 38 +++++++++++++++++++--------------
 sysdeps/mach/hurd/i386/init-first.c |  2 +-
 sysdeps/mach/hurd/i386/tls.h        | 21 ++++++++++++-------
 sysdeps/mach/hurd/mlockall.c        | 42 +++++++++++++++++++++++++++++++++++++
 sysdeps/mach/hurd/munlockall.c      | 40 +++++++++++++++++++++++++++++++++++
 7 files changed, 134 insertions(+), 26 deletions(-)
 create mode 100644 sysdeps/mach/hurd/mlockall.c
 create mode 100644 sysdeps/mach/hurd/munlockall.c

-- 
2.16.2

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

* [hurd,commited 1/5] hurd: Fix O_NOFOLLOW
  2018-03-18 19:45 [hurd,commited 0/5] hurd patches Samuel Thibault
  2018-03-18 19:45 ` [hurd,commited 5/5] Hurd: fix port leak in TLS Samuel Thibault
@ 2018-03-18 19:45 ` Samuel Thibault
  2018-03-18 19:45 ` [hurd,commited 2/5] hurd: Fix O_DIRECTORY | O_NOFOLLOW Samuel Thibault
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2018-03-18 19:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

The error code documented by POSIX for opening a symlink with O_NOFOLLOW
is ELOOP.

Also, if the translator does not expose symlink as a symlink translator but
as a S_IFLNK file, O_NOFOLLOW needs to return ELOOP too.

	* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ELOOP
	when opening a symlink with O_NOFOLLOW.
---
 ChangeLog           |  2 ++
 hurd/lookup-retry.c | 36 ++++++++++++++++++++----------------
 2 files changed, 22 insertions(+), 16 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index af84374b68..82ddda54ba 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -62,6 +62,8 @@
 2018-03-18  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
 	* sysdeps/mach/hurd/cthreads.c: Include <cthreads.h>.
+	* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ELOOP
+	when opening a symlink with O_NOFOLLOW.
 
 2018-03-17  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index 319e9c0a4c..12b5c30962 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -127,7 +127,7 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
 		{
 		  /* In Linux, O_NOFOLLOW means to reject symlinks.  If we
 		     did an O_NOLINK lookup above and io_stat here to check
-		     for S_IFLNK, a translator like firmlink could easily
+		     for S_IFLNK only, a translator like firmlink could easily
 		     spoof this check by not showing S_IFLNK, but in fact
 		     redirecting the lookup to some other name
 		     (i.e. opening the very same holes a symlink would).
@@ -145,23 +145,27 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
 		     one exception to our general translator-based rule.  */
 		  struct stat64 st;
 		  err = __io_stat (*result, &st);
-		  if (!err
-		      && (st.st_mode & (S_IPTRANS|S_IATRANS)))
+		  if (!err)
 		    {
-		      if (st.st_uid != 0)
-			err = ENOENT;
-		      else if (st.st_mode & S_IPTRANS)
+		      if (S_ISLNK (st.st_mode))
+			err = ELOOP;
+		      else if (st.st_mode & (S_IPTRANS|S_IATRANS))
 			{
-			  char buf[1024];
-			  char *trans = buf;
-			  size_t translen = sizeof buf;
-			  err = __file_get_translator (*result,
-						       &trans, &translen);
-			  if (!err
-			      && translen > sizeof _HURD_SYMLINK
-			      && !memcmp (trans,
-					  _HURD_SYMLINK, sizeof _HURD_SYMLINK))
-			    err = ENOENT;
+			  if (st.st_uid != 0)
+			    err = ELOOP;
+			  else if (st.st_mode & S_IPTRANS)
+			    {
+			      char buf[1024];
+			      char *trans = buf;
+			      size_t translen = sizeof buf;
+			      err = __file_get_translator (*result,
+							   &trans, &translen);
+			      if (!err
+				  && translen > sizeof _HURD_SYMLINK
+				  && !memcmp (trans,
+					      _HURD_SYMLINK, sizeof _HURD_SYMLINK))
+				err = ELOOP;
+			    }
 			}
 		    }
 		}
-- 
2.16.2

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

* [hurd,commited 2/5] hurd: Fix O_DIRECTORY | O_NOFOLLOW
  2018-03-18 19:45 [hurd,commited 0/5] hurd patches Samuel Thibault
  2018-03-18 19:45 ` [hurd,commited 5/5] Hurd: fix port leak in TLS Samuel Thibault
  2018-03-18 19:45 ` [hurd,commited 1/5] hurd: Fix O_NOFOLLOW Samuel Thibault
@ 2018-03-18 19:45 ` Samuel Thibault
  2018-03-18 19:45 ` [hurd,commited 3/5] hurd: Fix boot with statically-linked exec server Samuel Thibault
  2018-03-18 19:53 ` [hurd,commited 4/5] hurd: Add mlockall support Samuel Thibault
  4 siblings, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2018-03-18 19:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

Appending / to the path to be looked up would make us always follow a final
symlink, even with O_NOTRANS (since the final resolution is after the
'/').  In the O_DIRECTORY | O_NOFOLLOW case, we thus have to really open
the node and stat it, which we already do anyway, and check for
directory type.

	* hurd/hurdlookup.c (__hurd_file_name_lookup): Do not append '/' to
	path when flags contains O_NOFOLLOW.
	* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ENOTDIR
	if flags contains O_DIRECTORY and the result is a directory.
---
 ChangeLog           | 4 ++++
 hurd/hurdlookup.c   | 2 +-
 hurd/lookup-retry.c | 2 ++
 3 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index 82ddda54ba..a02f9017de 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -64,6 +64,10 @@
 	* sysdeps/mach/hurd/cthreads.c: Include <cthreads.h>.
 	* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ELOOP
 	when opening a symlink with O_NOFOLLOW.
+	* hurd/hurdlookup.c (__hurd_file_name_lookup): Do not append '/' to
+	path when flags contains O_NOFOLLOW.
+	* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ENOTDIR
+	if flags contains O_DIRECTORY and the result is a directory.
 
 2018-03-17  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
diff --git a/hurd/hurdlookup.c b/hurd/hurdlookup.c
index 1861d5879d..a642c49002 100644
--- a/hurd/hurdlookup.c
+++ b/hurd/hurdlookup.c
@@ -72,7 +72,7 @@ __hurd_file_name_lookup (error_t (*use_init_port)
   if (flags & O_NOFOLLOW)	/* See lookup-retry.c about O_NOFOLLOW.  */
     flags |= O_NOTRANS;
 
-  if (flags & O_DIRECTORY)
+  if (flags & O_DIRECTORY && (flags & O_NOFOLLOW) == 0)
     {
       /* The caller wants to require that the file we look up is a directory.
 	 We can do this without an extra RPC by appending a trailing slash
diff --git a/hurd/lookup-retry.c b/hurd/lookup-retry.c
index 12b5c30962..b596848624 100644
--- a/hurd/lookup-retry.c
+++ b/hurd/lookup-retry.c
@@ -147,6 +147,8 @@ __hurd_file_name_lookup_retry (error_t (*use_init_port)
 		  err = __io_stat (*result, &st);
 		  if (!err)
 		    {
+		      if (flags & O_DIRECTORY && !S_ISDIR (st.st_mode))
+			err = ENOTDIR;
 		      if (S_ISLNK (st.st_mode))
 			err = ELOOP;
 		      else if (st.st_mode & (S_IPTRANS|S_IATRANS))
-- 
2.16.2

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

* [hurd,commited 5/5] Hurd: fix port leak in TLS
  2018-03-18 19:45 [hurd,commited 0/5] hurd patches Samuel Thibault
@ 2018-03-18 19:45 ` Samuel Thibault
  2018-03-18 19:45 ` [hurd,commited 1/5] hurd: Fix O_NOFOLLOW Samuel Thibault
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2018-03-18 19:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

From: Richard Braun <rbraun@sceen.net>

	* sysdeps/mach/hurd/i386/tls.h (_hurd_tls_init): Use a temporary
	thread reference.
---
 ChangeLog                    |  5 +++++
 sysdeps/mach/hurd/i386/tls.h | 21 +++++++++++++--------
 2 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 1a34efca45..ddf8c9c9d1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2018-03-18  Richard Braun  <rbraun@sceen.net>
+
+	* sysdeps/mach/hurd/i386/tls.h (_hurd_tls_init): Use a temporary
+	thread reference.
+
 2018-03-18  Agustina Arzille  <avarzille@riseup.net>
 
 	* sysdeps/mach/libc-lock.h (__libc_cleanup_frame): Define structure.
diff --git a/sysdeps/mach/hurd/i386/tls.h b/sysdeps/mach/hurd/i386/tls.h
index c443552df4..771c94ff95 100644
--- a/sysdeps/mach/hurd/i386/tls.h
+++ b/sysdeps/mach/hurd/i386/tls.h
@@ -111,36 +111,41 @@ static inline const char * __attribute__ ((unused))
 _hurd_tls_init (tcbhead_t *tcb)
 {
   HURD_TLS_DESC_DECL (desc, tcb);
+  thread_t self = __mach_thread_self ();
+  const char *msg = NULL;
 
   /* This field is used by TLS accesses to get our "thread pointer"
      from the TLS point of view.  */
   tcb->tcb = tcb;
 
-  /* Cache our thread port.  */
-  tcb->self = __mach_thread_self ();
-
   /* Get the first available selector.  */
   int sel = -1;
-  error_t err = __i386_set_gdt (tcb->self, &sel, desc);
+  error_t err = __i386_set_gdt (self, &sel, desc);
   if (err == MIG_BAD_ID)
     {
       /* Old kernel, use a per-thread LDT.  */
       sel = 0x27;
-      err = __i386_set_ldt (tcb->self, sel, &desc, 1);
+      err = __i386_set_ldt (self, sel, &desc, 1);
       assert_perror (err);
       if (err)
-	return "i386_set_ldt failed";
+      {
+	msg = "i386_set_ldt failed";
+	goto out;
+      }
     }
   else if (err)
     {
       assert_perror (err); /* Separate from above with different line #. */
-      return "i386_set_gdt failed";
+      msg = "i386_set_gdt failed";
+      goto out;
     }
 
   /* Now install the new selector.  */
   asm volatile ("mov %w0, %%gs" :: "q" (sel));
 
-  return 0;
+out:
+  __mach_port_deallocate (__mach_task_self (), self);
+  return msg;
 }
 
 /* Code to initially initialize the thread pointer.  This might need
-- 
2.16.2

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

* [hurd,commited 3/5] hurd: Fix boot with statically-linked exec server
  2018-03-18 19:45 [hurd,commited 0/5] hurd patches Samuel Thibault
                   ` (2 preceding siblings ...)
  2018-03-18 19:45 ` [hurd,commited 2/5] hurd: Fix O_DIRECTORY | O_NOFOLLOW Samuel Thibault
@ 2018-03-18 19:45 ` Samuel Thibault
  2018-03-18 19:53 ` [hurd,commited 4/5] hurd: Add mlockall support Samuel Thibault
  4 siblings, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2018-03-18 19:45 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

	* sysdeps/mach/hurd/i386/init-first.c (init): Also find ELF headers by
	oneself when the pointer given in D is nul (as set by ext2fs).
---
 ChangeLog                           | 2 ++
 sysdeps/mach/hurd/i386/init-first.c | 2 +-
 2 files changed, 3 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index a02f9017de..e090c75b74 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -68,6 +68,8 @@
 	path when flags contains O_NOFOLLOW.
 	* hurd/lookup-retry.c (__hurd_file_name_lookup_retry): Return ENOTDIR
 	if flags contains O_DIRECTORY and the result is a directory.
+	* sysdeps/mach/hurd/i386/init-first.c (init): Also find ELF headers by
+	oneself when the pointer given in D is nul (as set by ext2fs).
 
 2018-03-17  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
diff --git a/sysdeps/mach/hurd/i386/init-first.c b/sysdeps/mach/hurd/i386/init-first.c
index f4a4df33de..226de02a99 100644
--- a/sysdeps/mach/hurd/i386/init-first.c
+++ b/sysdeps/mach/hurd/i386/init-first.c
@@ -107,7 +107,7 @@ init1 (int argc, char *arg0, ...)
   /* If we are the bootstrap task started by the kernel,
      then after the environment pointers there is no Hurd
      data block; the argument strings start there.  */
-  if ((void *) d == argv[0])
+  if ((void *) d == argv[0] || d->phdr == NULL)
     {
 #ifndef SHARED
       /* With a new enough linker (binutils-2.23 or better),
-- 
2.16.2

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

* [hurd,commited 4/5] hurd: Add mlockall support
  2018-03-18 19:45 [hurd,commited 0/5] hurd patches Samuel Thibault
                   ` (3 preceding siblings ...)
  2018-03-18 19:45 ` [hurd,commited 3/5] hurd: Fix boot with statically-linked exec server Samuel Thibault
@ 2018-03-18 19:53 ` Samuel Thibault
  4 siblings, 0 replies; 6+ messages in thread
From: Samuel Thibault @ 2018-03-18 19:53 UTC (permalink / raw)
  To: libc-alpha; +Cc: Samuel Thibault

	* sysdeps/mach/hurd/mlockall.c: New file.
	* sysdeps/mach/hurd/munlockall.c: New file.
---
 ChangeLog                      |  2 ++
 sysdeps/mach/hurd/mlockall.c   | 42 ++++++++++++++++++++++++++++++++++++++++++
 sysdeps/mach/hurd/munlockall.c | 40 ++++++++++++++++++++++++++++++++++++++++
 3 files changed, 84 insertions(+)
 create mode 100644 sysdeps/mach/hurd/mlockall.c
 create mode 100644 sysdeps/mach/hurd/munlockall.c

diff --git a/ChangeLog b/ChangeLog
index e090c75b74..1a34efca45 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -70,6 +70,8 @@
 	if flags contains O_DIRECTORY and the result is a directory.
 	* sysdeps/mach/hurd/i386/init-first.c (init): Also find ELF headers by
 	oneself when the pointer given in D is nul (as set by ext2fs).
+	* sysdeps/mach/hurd/mlockall.c: New file.
+	* sysdeps/mach/hurd/munlockall.c: New file.
 
 2018-03-17  Samuel Thibault  <samuel.thibault@ens-lyon.org>
 
diff --git a/sysdeps/mach/hurd/mlockall.c b/sysdeps/mach/hurd/mlockall.c
new file mode 100644
index 0000000000..6fa944b21f
--- /dev/null
+++ b/sysdeps/mach/hurd/mlockall.c
@@ -0,0 +1,42 @@
+/* mlockall -- lock in core all the pages in this process.  Hurd version.
+   Copyright (C) 2001-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <hurd.h>
+#include <mach/mach_host.h>
+
+/* Cause all currently mapped pages of the process to be memory resident
+   until unlocked by a call to the `munlockall', until the process exits,
+   or until the process calls `execve'.  */
+
+int
+mlockall (int flags)
+{
+  mach_port_t host;
+  error_t err;
+
+  err = __get_privileged_ports (&host, NULL);
+  if (err)
+    return __hurd_fail (err);
+
+  err = __vm_wire_all (host, __mach_task_self (), flags);
+  __mach_port_deallocate (__mach_task_self (), host);
+  return err ? __hurd_fail (err) : 0;
+}
diff --git a/sysdeps/mach/hurd/munlockall.c b/sysdeps/mach/hurd/munlockall.c
new file mode 100644
index 0000000000..615b77f034
--- /dev/null
+++ b/sysdeps/mach/hurd/munlockall.c
@@ -0,0 +1,40 @@
+/* munlockall -- undo the effects of all prior mlock calls.  Hurd version.
+   Copyright (C) 2001-2018 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <errno.h>
+#include <hurd.h>
+#include <mach/mach_host.h>
+
+/* Undo the effects of all prior mlock calls in this process.  */
+
+int
+munlockall (void)
+{
+  mach_port_t host;
+  error_t err;
+
+  err = __get_privileged_ports (&host, NULL);
+  if (err)
+    return __hurd_fail (err);
+
+  err = __vm_wire_all (host, __mach_task_self (), VM_WIRE_NONE);
+  __mach_port_deallocate (__mach_task_self (), host);
+  return err ? __hurd_fail (err) : 0;
+}
-- 
2.16.2

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

end of thread, other threads:[~2018-03-18 19:53 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-18 19:45 [hurd,commited 0/5] hurd patches Samuel Thibault
2018-03-18 19:45 ` [hurd,commited 5/5] Hurd: fix port leak in TLS Samuel Thibault
2018-03-18 19:45 ` [hurd,commited 1/5] hurd: Fix O_NOFOLLOW Samuel Thibault
2018-03-18 19:45 ` [hurd,commited 2/5] hurd: Fix O_DIRECTORY | O_NOFOLLOW Samuel Thibault
2018-03-18 19:45 ` [hurd,commited 3/5] hurd: Fix boot with statically-linked exec server Samuel Thibault
2018-03-18 19:53 ` [hurd,commited 4/5] hurd: Add mlockall support Samuel Thibault

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 read-only IMAP folder(s) and NNTP newsgroup(s).