Date: Fri, 19 Jun 2020 10:33:46 +0000 (UTC) From: Konstantin Belousov <kib@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-12@freebsd.org Subject: svn commit: r362370 - stable/12/libexec/rtld-elf Message-ID: <202006191033.05JAXkjo066651@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: kib Date: Fri Jun 19 10:33:45 2020 New Revision: 362370 URL: https://svnweb.freebsd.org/changeset/base/362370 Log: MFC r362128: rtld: set osrel when in the direct exec mode. Modified: stable/12/libexec/rtld-elf/rtld.c Directory Properties: stable/12/ (props changed) Modified: stable/12/libexec/rtld-elf/rtld.c ============================================================================== --- stable/12/libexec/rtld-elf/rtld.c Fri Jun 19 09:27:58 2020 (r362369) +++ stable/12/libexec/rtld-elf/rtld.c Fri Jun 19 10:33:45 2020 (r362370) @@ -384,8 +384,9 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr const char *argv0, *binpath; caddr_t imgentry; char buf[MAXPATHLEN]; - int argc, fd, i, phnum, rtld_argc; - bool dir_enable, explicit_fd, search_in_path; + int argc, fd, i, mib[4], old_osrel, osrel, phnum, rtld_argc; + size_t sz; + bool dir_enable, direct_exec, explicit_fd, search_in_path; /* * On entry, the dynamic linker itself has not been relocated yet. @@ -423,6 +424,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr main_argv = argv; trust = !issetugid(); + direct_exec = false; md_abi_variant_hook(aux_info); @@ -438,6 +440,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, &argv0); @@ -767,6 +784,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);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202006191033.05JAXkjo066651>