From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.8 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DE5EDC43331 for ; Fri, 6 Sep 2019 18:50:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C02BB2173B for ; Fri, 6 Sep 2019 18:50:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389779AbfIFSuH convert rfc822-to-8bit (ORCPT ); Fri, 6 Sep 2019 14:50:07 -0400 Received: from mx1.redhat.com ([209.132.183.28]:37016 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388320AbfIFSuH (ORCPT ); Fri, 6 Sep 2019 14:50:07 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 4364610C0930; Fri, 6 Sep 2019 18:50:06 +0000 (UTC) Received: from x2.localnet (ovpn-117-48.phx2.redhat.com [10.3.117.48]) by smtp.corp.redhat.com (Postfix) with ESMTP id F2E5D60BF1; Fri, 6 Sep 2019 18:50:02 +0000 (UTC) From: Steve Grubb To: =?ISO-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: linux-kernel@vger.kernel.org, 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 , =?ISO-8859-1?Q?Micka=EBl_Sala=FCn?= , Mimi Zohar , Philippe =?ISO-8859-1?Q?Tr=E9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Song Liu , Steve Dower , Thibaut Sautereau , Vincent Strubel , Yves-Alexis Perez , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org Subject: Re: [PATCH v2 0/5] Add support for O_MAYEXEC Date: Fri, 06 Sep 2019 14:50:02 -0400 Message-ID: <2989749.1YmIBkDdQn@x2> Organization: Red Hat In-Reply-To: <20190906152455.22757-1-mic@digikod.net> References: <20190906152455.22757-1-mic@digikod.net> MIME-Version: 1.0 Content-Transfer-Encoding: 8BIT Content-Type: text/plain; charset="iso-8859-1" X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (mx1.redhat.com [10.5.110.66]); Fri, 06 Sep 2019 18:50:06 +0000 (UTC) Sender: owner-linux-security-module@vger.kernel.org Precedence: bulk List-ID: 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 #include #include unsigned int la_version(unsigned int version) { return version; } unsigned int la_objopen(struct link_map *map, Lmid_t lmid, uintptr_t *cookie) { return LA_FLG_BINDTO | LA_FLG_BINDFROM; } 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); } uintptr_t 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 strip-flags.so.0 -shared -Wl,-soname,strip-flags.so.0 -ldl test.o Now, let's make a test program: #include #include #include #include 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); closedir(d); 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/strip-flags.so.0 strace ./test 2>&1 | grep passwd openat(3, "passwd", O_RDONLY) = 4 No O_CLOEXEC flag. -Steve