Revert "elf: Refuse to dlopen PIE objects [BZ #24323]" 37/295237/1
authorDongkyun Son <dongkyun.s@samsung.com>
Wed, 22 Jan 2020 10:10:22 +0000 (19:10 +0900)
committerDongkyun Son <dongkyun.s@samsung.com>
Tue, 4 Jul 2023 05:41:16 +0000 (14:41 +0900)
This reverts commit 2c75b545de6fe3c44138799c68217a94bc669a88.

Tizen C/C++ application uses launchpad-loader to improve application execution
speed. When the application execution request is received, the launchpad-loader
opens the executables of the application built with -fPIE via dlopen() to call
the main() function. With this patch, the launchpad-loader cannot open the
executables via dlopen().

Change-Id: I9c994a27890c8954e64d9bea566a63f03682a570

ChangeLog.old/ChangeLog.19
elf/Makefile
elf/dl-load.c
elf/tst-dlopen-pie.c [deleted file]
include/elf.h

index 84d56ed..2778414 100644 (file)
        * dlfcn/dlfcn.h (Dl_serinfo): Do not use array of length 1 for
        dls_serpath field.
 
-2019-06-18  Florian Weimer  <fweimer@redhat.com>
-
-       [BZ #24323]
-       * include/elf.h (DT_1_SUPPORTED_MASK): Include DF_1_PIE.
-       * elf/dl-load.c (_dl_map_object_from_fd): Check for DF_1_PIE and
-       fail when called from dlopen.
-       * elf/Makefile [have-fpie && build-shared] (tests): Add
-       tst-dlopen-pie.
-       (tst-dlopen-pie): Link with -ldl.
-       (tst-dlopen-pie.out): Add run-time dependency on tst-pie1.
-       * elf/tst-dlopen-pie.c (do_test): New file.
-
 2019-06-17  Rafał Lużyński  <digitalfreak@lingonborough.com>
 
        [BZ #24614]
index b509b3e..d558e33 100644 (file)
@@ -1008,7 +1008,7 @@ test-xfail-tst-protected1b = yes
 endif
 ifeq (yesyes,$(have-fpie)$(build-shared))
 modules-names += tst-piemod1
-tests += tst-pie1 tst-pie2 tst-dlopen-pie tst-dlopen-tlsmodid-pie \
+tests += tst-pie1 tst-pie2 tst-dlopen-tlsmodid-pie \
   tst-dlopen-self-pie
 tests-pie += tst-pie1 tst-pie2 tst-dlopen-tlsmodid-pie tst-dlopen-self-pie
 ifeq (yes,$(have-protected-data))
@@ -1859,7 +1859,6 @@ CFLAGS-tst-pie2.c += $(pie-ccflag)
 
 $(objpfx)tst-piemod1.so: $(libsupport)
 $(objpfx)tst-pie1: $(objpfx)tst-piemod1.so
-$(objpfx)tst-dlopen-pie.out: $(objpfx)tst-pie1
 
 ifeq (yes,$(build-shared))
 # NB: Please keep cet-built-dso in sysdeps/x86/Makefile in sync with
index e2e6e79..aacc01e 100644 (file)
@@ -1238,10 +1238,6 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
     for (size_t i = 0; i < nloadcmds; i++)
       loadcmds[i].mapalign = p_align_max;
 
-    /* dlopen of an executable is not valid because it is not possible
-       to perform proper relocations, handle static TLS, or run the
-       ELF constructors.  For PIE, the check needs the dynamic
-       section, so there is another check below.  */
     if (__glibc_unlikely (type != ET_DYN)
        && __glibc_unlikely ((mode & __RTLD_OPENEXEC) == 0))
       {
@@ -1281,17 +1277,11 @@ _dl_map_object_from_fd (const char *name, const char *origname, int fd,
   elf_get_dynamic_info (l, false, false);
 
   /* Make sure we are not dlopen'ing an object that has the
-     DF_1_NOOPEN flag set, or a PIE object.  */
-  if ((__glibc_unlikely (l->l_flags_1 & DF_1_NOOPEN)
-       && (mode & __RTLD_DLOPEN))
-      || (__glibc_unlikely (l->l_flags_1 & DF_1_PIE)
-         && __glibc_unlikely ((mode & __RTLD_OPENEXEC) == 0)))
+     DF_1_NOOPEN flag set.  */
+  if (__glibc_unlikely (l->l_flags_1 & DF_1_NOOPEN)
+      && (mode & __RTLD_DLOPEN))
     {
-      if (l->l_flags_1 & DF_1_PIE)
-       errstring
-         = N_("cannot dynamically load position-independent executable");
-      else
-       errstring = N_("shared object cannot be dlopen()ed");
+      errstring = N_("shared object cannot be dlopen()ed");
       goto lose;
     }
 
diff --git a/elf/tst-dlopen-pie.c b/elf/tst-dlopen-pie.c
deleted file mode 100644 (file)
index 3a009a0..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-/* dlopen test for PIE objects.
-   Copyright (C) 2019-2023 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
-   <https://www.gnu.org/licenses/>.  */
-
-/* This test attempts to open the (otherwise unrelated) PIE test
-   program elf/tst-pie1 and expects the attempt to fail.  */
-
-#include <dlfcn.h>
-#include <stddef.h>
-#include <string.h>
-#include <support/check.h>
-#include <support/support.h>
-
-static void
-test_mode (int mode)
-{
-  char *pie_path = xasprintf ("%s/elf/tst-pie1", support_objdir_root);
-  if (dlopen (pie_path, mode) != NULL)
-    FAIL_EXIT1 ("dlopen succeeded unexpectedly (%d)", mode);
-  const char *message = dlerror ();
-  const char *expected
-    = "cannot dynamically load position-independent executable";
-  if (strstr (message, expected) == NULL)
-    FAIL_EXIT1 ("unexpected error message (mode %d): %s", mode, message);
-}
-
-static int
-do_test (void)
-{
-  test_mode (RTLD_LAZY);
-  test_mode (RTLD_NOW);
-  return 0;
-}
-
-#include <support/test-driver.c>
index 14ed67f..ab76aaf 100644 (file)
@@ -23,7 +23,7 @@
 # endif
 # define DT_1_SUPPORTED_MASK \
    (DF_1_NOW | DF_1_NODELETE | DF_1_INITFIRST | DF_1_NOOPEN \
-    | DF_1_ORIGIN | DF_1_NODEFLIB | DF_1_PIE)
+    | DF_1_ORIGIN | DF_1_NODEFLIB)
 
 #endif /* !_ISOMAC */
 #endif /* elf.h */