From owner-svn-src-all@freebsd.org Thu Aug 2 07:43:29 2018 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 9F6CB105C0EF; Thu, 2 Aug 2018 07:43:29 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 45E5A78317; Thu, 2 Aug 2018 07:43:29 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 217376C05; Thu, 2 Aug 2018 07:43:29 +0000 (UTC) (envelope-from trasz@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w727hTK8023395; Thu, 2 Aug 2018 07:43:29 GMT (envelope-from trasz@FreeBSD.org) Received: (from trasz@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w727hS6S023393; Thu, 2 Aug 2018 07:43:28 GMT (envelope-from trasz@FreeBSD.org) Message-Id: <201808020743.w727hS6S023393@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: trasz set sender to trasz@FreeBSD.org using -f From: Edward Tomasz Napierala Date: Thu, 2 Aug 2018 07:43:28 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r337067 - head/libexec/rtld-elf X-SVN-Group: head X-SVN-Commit-Author: trasz X-SVN-Commit-Paths: head/libexec/rtld-elf X-SVN-Commit-Revision: 337067 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.27 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 02 Aug 2018 07:43:29 -0000 Author: trasz Date: Thu Aug 2 07:43:28 2018 New Revision: 337067 URL: https://svnweb.freebsd.org/changeset/base/337067 Log: Make sure the rtld(1) error messages go to stderr, not stdout. While here fix capitalization of a few nearby strings, add the rtld's file name prefix so it's obvious where the message come from, and return zero when "-h" is used. Reviewed by: kib MFC after: 2 weeks Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D16530 Modified: head/libexec/rtld-elf/malloc.c head/libexec/rtld-elf/paths.h head/libexec/rtld-elf/rtld.c Modified: head/libexec/rtld-elf/malloc.c ============================================================================== --- head/libexec/rtld-elf/malloc.c Thu Aug 2 06:26:51 2018 (r337066) +++ head/libexec/rtld-elf/malloc.c Thu Aug 2 07:43:28 2018 (r337067) @@ -47,6 +47,7 @@ static char *rcsid = "$FreeBSD$"; #include #include +#include #include #include #include @@ -55,7 +56,9 @@ static char *rcsid = "$FreeBSD$"; #include #include #include +#include "rtld.h" #include "rtld_printf.h" +#include "paths.h" static void morecore(); static int findbucket(); @@ -472,9 +475,11 @@ int n; if (pagepool_end - pagepool_start > pagesz) { caddr_t addr = (caddr_t) (((long)pagepool_start + pagesz - 1) & ~(pagesz - 1)); - if (munmap(addr, pagepool_end - addr) != 0) - rtld_fdprintf(STDERR_FILENO, "morepages: munmap %p", - addr); + if (munmap(addr, pagepool_end - addr) != 0) { + rtld_fdprintf(STDERR_FILENO, _BASENAME_RTLD ": " + "morepages: cannot munmap %p: %s\n", + addr, rtld_strerror(errno)); + } } offset = (long)pagepool_start - ((long)pagepool_start & ~(pagesz - 1)); @@ -482,7 +487,9 @@ int n; if ((pagepool_start = mmap(0, n * pagesz, PROT_READ|PROT_WRITE, MAP_ANON|MAP_PRIVATE, fd, 0)) == (caddr_t)-1) { - rtld_printf("Cannot map anonymous memory\n"); + rtld_fdprintf(STDERR_FILENO, _BASENAME_RTLD ": morepages: " + "cannot mmap anonymous memory: %s\n", + rtld_strerror(errno)); return 0; } pagepool_end = pagepool_start + n * pagesz; Modified: head/libexec/rtld-elf/paths.h ============================================================================== --- head/libexec/rtld-elf/paths.h Thu Aug 2 06:26:51 2018 (r337066) +++ head/libexec/rtld-elf/paths.h Thu Aug 2 07:43:28 2018 (r337067) @@ -34,7 +34,7 @@ #ifdef COMPAT_32BIT #define _PATH_ELF_HINTS "/var/run/ld-elf32.so.hints" #define _PATH_LIBMAP_CONF "/etc/libmap32.conf" -#define _PATH_RTLD "/libexec/ld-elf32.so.1" +#define _BASENAME_RTLD "ld-elf32.so.1" #define STANDARD_LIBRARY_PATH "/lib32:/usr/lib32" #define LD_ "LD_32_" #endif @@ -47,8 +47,12 @@ #define _PATH_LIBMAP_CONF "/etc/libmap.conf" #endif +#ifndef _BASENAME_RTLD +#define _BASENAME_RTLD "ld-elf.so.1" +#endif + #ifndef _PATH_RTLD -#define _PATH_RTLD "/libexec/ld-elf.so.1" +#define _PATH_RTLD "/libexec/" _BASENAME_RTLD #endif #ifndef STANDARD_LIBRARY_PATH Modified: head/libexec/rtld-elf/rtld.c ============================================================================== --- head/libexec/rtld-elf/rtld.c Thu Aug 2 06:26:51 2018 (r337066) +++ head/libexec/rtld-elf/rtld.c Thu Aug 2 07:43:28 2018 (r337067) @@ -408,8 +408,8 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr phdr = (const Elf_Phdr *)aux_info[AT_PHDR]->a_un.a_ptr; if (phdr == obj_rtld.phdr) { if (!trust) { - rtld_printf("Tainted process refusing to run binary %s\n", - argv0); + _rtld_error("Tainted process refusing to run binary %s", + argv0); rtld_die(); } dbg("opening main program in direct exec mode"); @@ -420,7 +420,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr if (!explicit_fd) fd = open_binary_fd(argv0, search_in_path); if (fstat(fd, &st) == -1) { - _rtld_error("failed to fstat FD %d (%s): %s", fd, + _rtld_error("Failed to fstat FD %d (%s): %s", fd, explicit_fd ? "user-provided descriptor" : argv0, rtld_strerror(errno)); rtld_die(); @@ -447,8 +447,8 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr dir_enable = true; } if (!dir_enable) { - rtld_printf("No execute permission for binary %s\n", - argv0); + _rtld_error("No execute permission for binary %s", + argv0); rtld_die(); } @@ -477,7 +477,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entr break; } } else { - rtld_printf("no binary\n"); + _rtld_error("No binary"); rtld_die(); } } @@ -962,6 +962,7 @@ rtld_die(void) if (msg == NULL) msg = "Fatal error"; + rtld_fdputstr(STDERR_FILENO, _BASENAME_RTLD ": "); rtld_fdputstr(STDERR_FILENO, msg); rtld_fdputchar(STDERR_FILENO, '\n'); _exit(1); @@ -2441,7 +2442,7 @@ do_load_object(int fd, const char *name, char *path, s return NULL; } if (fs.f_flags & MNT_NOEXEC) { - _rtld_error("Cannot execute objects on %s\n", fs.f_mntonname); + _rtld_error("Cannot execute objects on %s", fs.f_mntonname); return NULL; } } @@ -5317,12 +5318,12 @@ open_binary_fd(const char *argv0, bool search_in_path) if (search_in_path && strchr(argv0, '/') == NULL) { pathenv = getenv("PATH"); if (pathenv == NULL) { - rtld_printf("-p and no PATH environment variable\n"); + _rtld_error("-p and no PATH environment variable"); rtld_die(); } pathenv = strdup(pathenv); if (pathenv == NULL) { - rtld_printf("Cannot allocate memory\n"); + _rtld_error("Cannot allocate memory"); rtld_die(); } fd = -1; @@ -5348,8 +5349,7 @@ open_binary_fd(const char *argv0, bool search_in_path) } if (fd == -1) { - rtld_printf("Opening %s: %s\n", argv0, - rtld_strerror(errno)); + _rtld_error("Cannot open %s: %s", argv0, rtld_strerror(errno)); rtld_die(); } return (fd); @@ -5393,7 +5393,7 @@ parse_args(char* argv[], int argc, bool *use_pathp, in opt = arg[j]; if (opt == 'h') { print_usage(argv[0]); - rtld_die(); + _exit(0); } else if (opt == 'f') { /* * -f XX can be used to specify a descriptor for the @@ -5403,13 +5403,13 @@ parse_args(char* argv[], int argc, bool *use_pathp, in */ if (j != arglen - 1) { /* -f must be the last option in, e.g., -abcf */ - _rtld_error("invalid options: %s", arg); + _rtld_error("Invalid options: %s", arg); rtld_die(); } i++; fd = parse_integer(argv[i]); if (fd == -1) { - _rtld_error("invalid file descriptor: '%s'", + _rtld_error("Invalid file descriptor: '%s'", argv[i]); rtld_die(); } @@ -5418,7 +5418,7 @@ parse_args(char* argv[], int argc, bool *use_pathp, in } else if (opt == 'p') { *use_pathp = true; } else { - rtld_printf("invalid argument: '%s'\n", arg); + _rtld_error("Invalid argument: '%s'", arg); print_usage(argv[0]); rtld_die(); }