svn commit: r362378 - stable/11/libexec/rtld-elf

Konstantin Belousov kib at FreeBSD.org
Fri Jun 19 12:38:28 UTC 2020


Author: kib
Date: Fri Jun 19 12:38:27 2020
New Revision: 362378
URL: https://svnweb.freebsd.org/changeset/base/362378

Log:
  MFC r362128:
  rtld: set osrel when in the direct exec mode.

Modified:
  stable/11/libexec/rtld-elf/rtld.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/libexec/rtld-elf/rtld.c
==============================================================================
--- stable/11/libexec/rtld-elf/rtld.c	Fri Jun 19 12:35:29 2020	(r362377)
+++ stable/11/libexec/rtld-elf/rtld.c	Fri Jun 19 12:38:27 2020	(r362378)
@@ -366,9 +366,9 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr
     const char *binpath;
     caddr_t imgentry;
     char buf[MAXPATHLEN];
-    int argc, fd, i, mib[2], phnum, rtld_argc;
-    size_t len;
-    bool dir_enable, explicit_fd, search_in_path;
+    int argc, fd, i, mib[4], old_osrel, osrel, phnum, rtld_argc;
+    size_t len, sz;
+    bool dir_enable, direct_exec, explicit_fd, search_in_path;
 
     /*
      * On entry, the dynamic linker itself has not been relocated yet.
@@ -427,6 +427,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr
     }
 
     trust = !issetugid();
+    direct_exec = false;
 
     md_abi_variant_hook(aux_info);
 
@@ -442,6 +443,21 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr
 		  argv0);
 		rtld_die();
 	    }
+	    direct_exec = true;
+
+	    /*
+	     * Set osrel for us, it is later reset to the binary'
+	     * value before first instruction of code from the binary
+	     * is executed.
+	     */
+	    mib[0] = CTL_KERN;
+	    mib[1] = KERN_PROC;
+	    mib[2] = KERN_PROC_OSREL;
+	    mib[3] = getpid();
+	    osrel = __FreeBSD_version;
+	    sz = sizeof(old_osrel);
+	    (void)sysctl(mib, 4, &old_osrel, &sz, &osrel, sizeof(osrel));
+
 	    dbg("opening main program in direct exec mode");
 	    if (argc >= 2) {
 		rtld_argc = parse_args(argv, argc, &search_in_path, &fd);
@@ -772,6 +788,18 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr
      * init functions.
      */
     pre_init();
+
+    if (direct_exec) {
+	/* Set osrel for direct-execed binary */
+	mib[0] = CTL_KERN;
+	mib[1] = KERN_PROC;
+	mib[2] = KERN_PROC_OSREL;
+	mib[3] = getpid();
+	osrel = obj_main->osrel;
+	sz = sizeof(old_osrel);
+	dbg("setting osrel to %d", osrel);
+	(void)sysctl(mib, 4, &old_osrel, &sz, &osrel, sizeof(osrel));
+    }
 
     wlock_acquire(rtld_bind_lock, &lockstate);
 


More information about the svn-src-stable mailing list