aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2021-11-06 03:06:34 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2021-11-10 19:36:20 +0000
commit1d6fd007ebd4d7d3cf857fa7c4fcf8770102614b (patch)
tree45f91a849d2be74f575a3bffcc005676dbccc818
parent4ac2d43111f005ea8a326dc30fcf4df522bcf661 (diff)
downloadsrc-1d6fd007ebd4d7d3cf857fa7c4fcf8770102614b.tar.gz
src-1d6fd007ebd4d7d3cf857fa7c4fcf8770102614b.zip
rtld: ignore fstatfs(2) errors when checking MNT_NOEXEC flag
(cherry picked from commit c5637b8be8a5b6aaf663a58b0027f7f924d78b04)
-rw-r--r--libexec/rtld-elf/rtld.c16
1 files changed, 7 insertions, 9 deletions
diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c
index 5a8e4f6bbc96..db89a878c5f9 100644
--- a/libexec/rtld-elf/rtld.c
+++ b/libexec/rtld-elf/rtld.c
@@ -2773,19 +2773,17 @@ do_load_object(int fd, const char *name, char *path, struct stat *sbp,
struct statfs fs;
/*
- * but first, make sure that environment variables haven't been
+ * First, make sure that environment variables haven't been
* used to circumvent the noexec flag on a filesystem.
+ * We ignore fstatfs(2) failures, since fd might reference
+ * not a file, e.g. shmfd.
*/
- if (dangerous_ld_env) {
- if (fstatfs(fd, &fs) != 0) {
- _rtld_error("Cannot fstatfs \"%s\"", printable_path(path));
- return NULL;
- }
- if (fs.f_flags & MNT_NOEXEC) {
+ if (dangerous_ld_env && fstatfs(fd, &fs) == 0 &&
+ (fs.f_flags & MNT_NOEXEC) != 0) {
_rtld_error("Cannot execute objects on %s", fs.f_mntonname);
- return NULL;
- }
+ return (NULL);
}
+
dbg("loading \"%s\"", printable_path(path));
obj = map_object(fd, printable_path(path), sbp);
if (obj == NULL)