svn commit: r337067 - head/libexec/rtld-elf
Edward Tomasz Napierala
trasz at FreeBSD.org
Thu Aug 2 07:43:29 UTC 2018
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 <sys/types.h>
#include <sys/sysctl.h>
+#include <errno.h>
#include <stdarg.h>
#include <stddef.h>
#include <stdio.h>
@@ -55,7 +56,9 @@ static char *rcsid = "$FreeBSD$";
#include <unistd.h>
#include <sys/param.h>
#include <sys/mman.h>
+#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();
}
More information about the svn-src-all
mailing list