Page MenuHomeFreeBSD

D56152.id174509.diff
No OneTemporary

D56152.id174509.diff

diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -178,6 +178,7 @@
static int symlook_obj1_gnu(SymLook *, const Obj_Entry *);
static void *tls_get_addr_slow(struct tcb *, int, size_t, bool) __noinline;
static void trace_loaded_objects(Obj_Entry *, bool);
+static int try_fds_open(const char *name, const char *path);
static void unlink_object(Obj_Entry *);
static void unload_object(Obj_Entry *, RtldLockState *lockstate);
static void unref_dag(Obj_Entry *);
@@ -2875,9 +2876,13 @@
* using stat().
*/
if ((fd = open(path, O_RDONLY | O_CLOEXEC | O_VERIFY)) == -1) {
- _rtld_error("Cannot open \"%s\"", path);
- free(path);
- return (NULL);
+ if (trust && path[0] == '#' && ld_library_dirs != NULL)
+ fd = try_fds_open(path, ld_library_dirs);
+ if (fd == -1) {
+ _rtld_error("Cannot open \"%s\"", path);
+ free(path);
+ return (NULL);
+ }
}
} else {
fd = fcntl(fd_u, F_DUPFD_CLOEXEC, 0);
@@ -3586,6 +3591,51 @@
{
}
+/*
+ * Parse string of the format '#number/name", where number must be a
+ * decimal number of the opened file descriptor listed in
+ * LD_LIBRARY_PATH_FDS. If successful, tries to open dso name under
+ * dirfd number and returns resulting fd.
+ * On any error, returns -1.
+ */
+static int
+try_fds_open(const char *name, const char *path)
+{
+ const char *n;
+ char *envcopy, *fdstr, *last_token, *ncopy;
+ size_t len;
+ int fd, dirfd, dirfd_path;
+
+ for (n = name + 1; *n != '\0' && *n != '/'; n++)
+ ;
+ if (*n != '/')
+ return (-1);
+ len = n - name - 1;
+ ncopy = xmalloc(len + 1);
+ memcpy(ncopy, name + 1, len);
+ ncopy[len] = '\0';
+ dirfd = parse_integer(ncopy);
+ free(ncopy);
+ if (dirfd == -1)
+ return (-1);
+
+ envcopy = xstrdup(path);
+ dirfd_path = -1;
+ for (fdstr = strtok_r(envcopy, ":", &last_token); fdstr != NULL;
+ fdstr = strtok_r(NULL, ":", &last_token)) {
+ dirfd_path = parse_integer(fdstr);
+ if (dirfd_path == dirfd)
+ break;
+ }
+ free(envcopy);
+ if (dirfd_path != dirfd)
+ return (-1);
+
+ fd = __sys_openat(dirfd, n + 1, O_RDONLY | O_CLOEXEC | O_EMPTY_PATH |
+ O_VERIFY);
+ return (fd);
+}
+
/*
* Iterate over a search path, translate each element, and invoke the
* callback on the result.

File Metadata

Mime Type
text/plain
Expires
Tue, Sep 29, 11:39 AM (4 h, 52 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
39874069
Default Alt Text
D56152.id174509.diff (2 KB)

Event Timeline