Follow @Openwall on Twitter for new release announcements and other news
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date: Fri, 06 Sep 2019 14:50:02 -0400
From: Steve Grubb <>
To: Mickaël Salaün <>
Cc:, Aleksa Sarai <>, Alexei Starovoitov <>, Al Viro <>, Andy Lutomirski <>, Christian Heimes <>, Daniel Borkmann <>, Eric Chiang <>, Florian Weimer <>, James Morris <>, Jan Kara <>, Jann Horn <>, Jonathan Corbet <>, Kees Cook <>, Matthew Garrett <>, Matthew Wilcox <>, Michael Kerrisk <>, Mickaël Salaün <>, Mimi Zohar <>, Philippe Trébuchet <>, Scott Shell <>, Sean Christopherson <>, Shuah Khan <>, Song Liu <>, Steve Dower <>, Thibaut Sautereau <thibaut.>, Vincent Strubel <>, Yves-Alexis Perez <>,,,,
Subject: Re: [PATCH v2 0/5] Add support for O_MAYEXEC

On Friday, September 6, 2019 11:24:50 AM EDT Mickaël Salaün wrote:
> The goal of this patch series is to control script interpretation.  A
> new O_MAYEXEC flag used by sys_open() is added to enable userspace
> script interpreter to delegate to the kernel (and thus the system
> security policy) the permission to interpret/execute scripts or other
> files containing what can be seen as commands.

The problem is that this is only a gentleman's handshake. If I don't tell the
kernel that what I'm opening is tantamount to executing it, then the security
feature is never invoked. It is simple to strip the flags off of any system
call without needing privileges. For example:

#define _GNU_SOURCE
#include <link.h>
#include <fcntl.h>
#include <string.h>

unsigned int
la_version(unsigned int version)
    return version;

unsigned int
la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie)

typedef int (*openat_t) (int dirfd, const char *pathname, int flags, mode_t mode);
static openat_t real_openat = 0L;
int my_openat(int dirfd, const char *pathname, int flags, mode_t mode)
        flags &= ~O_CLOEXEC;
        return real_openat(dirfd, pathname, flags, mode);

la_symbind64(Elf64_Sym *sym, unsigned int ndx, uintptr_t *refcook,
        uintptr_t *defcook, unsigned int *flags, const char *symname)
    if (real_openat == 0L && strcmp(symname, "openat") == 0) {
        real_openat = (openat_t) sym->st_value;
        return (uintptr_t) my_openat;
    return sym->st_value;

gcc -c -g -Wno-unused-parameter -W -Wall -Wundef -O2 -Wp,-D_GLIBCXX_ASSERTIONS -fexceptions -fPIC  test.c
gcc -o -shared -Wl,-soname, -ldl test.o

Now, let's make a test program:

#include <stdio.h>
#include <dirent.h>
#include <fcntl.h>
#include <unistd.h>

int main(void)
        int dir_fd, fd;
        DIR *d = opendir("/etc");
        dir_fd = dirfd(d);
        fd = openat(dir_fd, "passwd", O_RDONLY|O_CLOEXEC);
        close (fd);
        return 0;

gcc -g -W -Wall -Wundef test.c -o test

OK, let's see what happens.
$ strace ./test 2>&1 | grep passwd
openat(3, "passwd", O_RDONLY|O_CLOEXEC) = 4

Now with LD_AUDIT
$ LD_AUDIT=/home/sgrubb/test/openflags/ strace ./test 2>&1 | grep passwd
openat(3, "passwd", O_RDONLY)           = 4

No O_CLOEXEC flag.


Powered by blists - more mailing lists

Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.