Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp2410953ybh; Fri, 24 Jul 2020 12:03:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBzyjmPcsYBdcLOYrnHSbrb2ZoLcylFeZyksYztjE5FIBPBKyAVaLktIBpmF5iZnTdBj55 X-Received: by 2002:a17:906:6606:: with SMTP id b6mr10963328ejp.102.1595617430608; Fri, 24 Jul 2020 12:03:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595617430; cv=none; d=google.com; s=arc-20160816; b=rRlCDB/iuCui6ZxLXwKTAltBW/0SZtEERXufcsLsVDdTve+FY8nG8+h0/6dJT230ip PhJ9us7asDJsfVJyIEebXGWcOPoYHyYKSLfvZeMqDmbTgbTlDwMo1rIH83eRhYEfxPrj SEjIY9Y5ibl+f3y2rlEqFAlbS3yevSr6DH6wJsYmHVin70ZcyaA9Gh4GQATd3kfzoqeB d5wyoRHWMUNSIqJAIZDZjb9pTMC9ZOo11+VI65bMStvNTgyEGt9FxflN8FMuJpA7NEDn I1C2+VHSpeH4bs2jxH5Q00Wvtt+ESgq1B/Wgs+wloyHhLzwjf4onee44d+tIWnCDrTmh VdDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=LYsHHvmbnOnKOT161wgYJ0QUn66UfJfCSOHkGeru+cM=; b=CTi420zUUyhHsTtP1S4nPyqRHZT6Mdvl1EpNDDbQizo+8FBqkz2CDo2HEbW8/TZ8y7 92nMpr0oQnlagyDZsRUR05c7hSPm3QpO31wCLEAhbRoIuJfPS/ly6c70MviU9QR4GfFx duwKP4zHO3cnkRfbQVsyXOwNjdyneIBYrf1rxvYWp+jHvyxqEo79uj34jXZyp1oFitOU a4wupnE55Vvag6cQ1VmToA0I88j2vD3/Y5IfIbXxpnVp31WBrZVA74dovmukhjtL++hD +3i9D4CHv2IjY0rvrQtShktV4iHuh9TyMDeN2L8FJdEQx4OTe0ek16plOaZyzxLo3h3u R0Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=epxr0OVX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id p23si1195403ejz.151.2020.07.24.12.03.27; Fri, 24 Jul 2020 12:03:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=epxr0OVX; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726686AbgGXTDE (ORCPT + 99 others); Fri, 24 Jul 2020 15:03:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33634 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726658AbgGXTDE (ORCPT ); Fri, 24 Jul 2020 15:03:04 -0400 Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B44C9C0619E6 for ; Fri, 24 Jul 2020 12:03:03 -0700 (PDT) Received: by mail-pf1-x441.google.com with SMTP id z3so5705261pfn.12 for ; Fri, 24 Jul 2020 12:03:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to; bh=LYsHHvmbnOnKOT161wgYJ0QUn66UfJfCSOHkGeru+cM=; b=epxr0OVXttEVlXmK9gG8sngCnRWPyA1Tl8s5eFiDuptGA3XfZ7D42jzmy8C+dHex+z O4t0er5aVcVIeElSNW4xKoTusneqHOYH3qTX0imlgipraUmww8ZAz/FAdRhZ2XYidyPD DxcDODdQ821AGi0c+CClL91b4u9fYF+8edV0o= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=LYsHHvmbnOnKOT161wgYJ0QUn66UfJfCSOHkGeru+cM=; b=Ufz7QlVT/XgtLxWHPbhLkUkhg8IdXihrJE+9SPze9NLq5QLzkBkhKIW4JxusIOEnBT hGSmbvbdLhDKJl1L/oOioVa45s7kOx2TdpEFaeDJgrCPaSG3uYhWYL2UXyOnV4rHmOXa FvhxXyOn8OteeHR0vey446b/l2ZOmcgmDIqG0jOAc/xU8Iwx2QzhzdDsTM9hb1JMtlyx aWzoN0MrK2sJXRCYipc2CiSBS4lEGAY0DfTDqttMwyuFxW4IH5szgYs0lpZgQeq7pfg1 TeZzy4m1Qj0m4HIElhgPpmqVNgMnBUBFjMHNMepqh0h5vVJSrGRRrmjv0g0qOq3bcMqn mXPQ== X-Gm-Message-State: AOAM530dWW7YCZ9aOmOfjrI0tYx502U/HpE3aB4g4YMG5W2Y32HSUYrn Za8b2RvJW8dZITYM/MYuX6WKbg== X-Received: by 2002:a62:2bd0:: with SMTP id r199mr9978051pfr.160.1595617383058; Fri, 24 Jul 2020 12:03:03 -0700 (PDT) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id s89sm6440672pjj.28.2020.07.24.12.03.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 24 Jul 2020 12:03:02 -0700 (PDT) Date: Fri, 24 Jul 2020 12:03:01 -0700 From: Kees Cook To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: linux-kernel@vger.kernel.org, Aleksa Sarai , Alexei Starovoitov , Al Viro , Andrew Morton , Andy Lutomirski , Christian Brauner , Christian Heimes , Daniel Borkmann , Deven Bowers , Dmitry Vyukov , Eric Biggers , Eric Chiang , Florian Weimer , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , Mimi Zohar , Philippe =?iso-8859-1?Q?Tr=E9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , Tetsuo Handa , Thibaut Sautereau , Vincent Strubel , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-integrity@vger.kernel.org, linux-security-module@vger.kernel.org, linux-fsdevel@vger.kernel.org, Thibaut Sautereau Subject: Re: [PATCH v7 4/7] fs: Introduce O_MAYEXEC flag for openat2(2) Message-ID: <202007241202.8D07E1F276@keescook> References: <20200723171227.446711-1-mic@digikod.net> <20200723171227.446711-5-mic@digikod.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20200723171227.446711-5-mic@digikod.net> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jul 23, 2020 at 07:12:24PM +0200, Micka?l Sala?n wrote: > When the O_MAYEXEC flag is passed, openat2(2) may be subject to > additional restrictions depending on a security policy managed by the > kernel through a sysctl or implemented by an LSM thanks to the > inode_permission hook. This new flag is ignored by open(2) and > openat(2) because of their unspecified flags handling. When used with > openat2(2), the default behavior is only to forbid to open a directory. > > The underlying idea is to be able to restrict scripts interpretation > according to a policy defined by the system administrator. For this to > be possible, script interpreters must use the O_MAYEXEC flag > appropriately. To be fully effective, these interpreters also need to > handle the other ways to execute code: command line parameters (e.g., > option -e for Perl), module loading (e.g., option -m for Python), stdin, > file sourcing, environment variables, configuration files, etc. > According to the threat model, it may be acceptable to allow some script > interpreters (e.g. Bash) to interpret commands from stdin, may it be a > TTY or a pipe, because it may not be enough to (directly) perform > syscalls. Further documentation can be found in a following patch. > > Even without enforced security policy, userland interpreters can set it > to enforce the system policy at their level, knowing that it will not > break anything on running systems which do not care about this feature. > However, on systems which want this feature enforced, there will be > knowledgeable people (i.e. sysadmins who enforced O_MAYEXEC > deliberately) to manage it. A simple security policy implementation, > configured through a dedicated sysctl, is available in a following > patch. > > O_MAYEXEC should not be confused with the O_EXEC flag which is intended > for execute-only, which obviously doesn't work for scripts. However, a > similar behavior could be implemented in userland with O_PATH: > https://lore.kernel.org/lkml/1e2f6913-42f2-3578-28ed-567f6a4bdda1@digikod.net/ > > The implementation of O_MAYEXEC almost duplicates what execve(2) and > uselib(2) are already doing: setting MAY_OPENEXEC in acc_mode (which can > then be checked as MAY_EXEC, if enforced). > > This is an updated subset of the patch initially written by Vincent > Strubel for CLIP OS 4: > https://github.com/clipos-archive/src_platform_clip-patches/blob/f5cb330d6b684752e403b4e41b39f7004d88e561/1901_open_mayexec.patch > This patch has been used for more than 12 years with customized script > interpreters. Some examples (with the original O_MAYEXEC) can be found > here: > https://github.com/clipos-archive/clipos4_portage-overlay/search?q=O_MAYEXEC > > Co-developed-by: Vincent Strubel > Signed-off-by: Vincent Strubel Acked-by: Kees Cook -- Kees Cook