Author: kib
Date: Tue Jun  2 16:20:58 2020
New Revision: 361725
URL: https://svnweb.freebsd.org/changeset/base/361725

Log:
  Do not allow to load ET_DYN object with DF_1_PIE flag set.
  
  Linkers are supposed to mark PIE binaries with DF_1_PIE, such binary
  cannot be correctly and usefully loaded neither by dlopen(3) nor as a
  dependency of other object.  For instance, we cannot do anything
  useful with COPY relocations, among other things.
  
  Glibc already added similar restriction.
  
  Requested and reviewed by:    emaste
  Sponsored by: The FreeBSD Foundation
  MFC after:    1 week
  Differential revision:        https://reviews.freebsd.org/D25086

Modified:
  head/libexec/rtld-elf/rtld.c
  head/libexec/rtld-elf/rtld.h

Modified: head/libexec/rtld-elf/rtld.c
==============================================================================
--- head/libexec/rtld-elf/rtld.c        Tue Jun  2 12:23:04 2020        
(r361724)
+++ head/libexec/rtld-elf/rtld.c        Tue Jun  2 16:20:58 2020        
(r361725)
@@ -1370,6 +1370,8 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_D
                    obj->z_interpose = true;
                if (dynp->d_un.d_val & DF_1_NODEFLIB)
                    obj->z_nodeflib = true;
+               if (dynp->d_un.d_val & DF_1_PIE)
+                   obj->z_pie = true;
            break;
 
        default:
@@ -2580,6 +2582,10 @@ do_load_object(int fd, const char *name, char *path, s
     obj->path = path;
     if (!digest_dynamic(obj, 0))
        goto errp;
+    if (obj->z_pie) {
+       _rtld_error("Cannot load PIE binary %s as dso", obj->path);
+       goto errp;
+    }
     dbg("%s valid_hash_sysv %d valid_hash_gnu %d dynsymcount %d", obj->path,
        obj->valid_hash_sysv, obj->valid_hash_gnu, obj->dynsymcount);
     if (obj->z_noopen && (flags & (RTLD_LO_DLOPEN | RTLD_LO_TRACE)) ==

Modified: head/libexec/rtld-elf/rtld.h
==============================================================================
--- head/libexec/rtld-elf/rtld.h        Tue Jun  2 12:23:04 2020        
(r361724)
+++ head/libexec/rtld-elf/rtld.h        Tue Jun  2 16:20:58 2020        
(r361725)
@@ -257,6 +257,7 @@ typedef struct Struct_Obj_Entry {
     bool z_interpose : 1;      /* Interpose all objects but main */
     bool z_nodeflib : 1;       /* Don't search default library path */
     bool z_global : 1;         /* Make the object global */
+    bool z_pie : 1;            /* Object proclaimed itself PIE executable */
     bool static_tls : 1;       /* Needs static TLS allocation */
     bool static_tls_copied : 1;        /* Needs static TLS copying */
     bool ref_nodel : 1;                /* Refcount increased to prevent 
dlclose */
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to