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
This commit is contained in:
@@ -1370,6 +1370,8 @@ digest_dynamic1(Obj_Entry *obj, int early, const Elf_Dyn **dyn_rpath,
|
||||
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, struct stat *sbp,
|
||||
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)) ==
|
||||
|
||||
@@ -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 */
|
||||
|
||||
Reference in New Issue
Block a user