Received: by 2002:a25:868d:0:0:0:0:0 with SMTP id z13csp39597ybk; Tue, 12 May 2020 14:44:53 -0700 (PDT) X-Google-Smtp-Source: APiQypLfPHCb8bS5KzKsCuNUlQxLNGBDKlJNr3nGbWUCtIJB/LokTY3QaIwql7BnXsT9TeaUAnoB X-Received: by 2002:a50:dac4:: with SMTP id s4mr18875373edj.277.1589319893162; Tue, 12 May 2020 14:44:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1589319893; cv=none; d=google.com; s=arc-20160816; b=zqQCb7lPqMSCpsSkhLmumu0dWujkYM4PIVeLjoGeymGKr8lPX0bLa2QEFDfo+w2eua R6FBslLyqkb61+E0UGRZn5SCJsaJqb+Ygqi6rBxHWiKZJVOrM5Ga5QxCxdKDzvs2Hm5P N56awUXnw2J7SKTl3VXtTRvi7SAcm52LkoTvupSNXyhVpfp2M66B3ZuOwWiRdymulWno tSvoikOAdSCDIOAgNREHjyRPW3MtpZsxm1I7WRAKyqyn0rowtm08SX25BULJg+Oh0BSF 11yYXrQLde6tx60zAXtqoogFvJI3zxWLXWUQ+fBMkAxiboSRXRUZDpmKL5zHcOScs7LI 5SZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:date:message-id:autocrypt :from:references:cc:to:subject:dkim-signature; bh=iV+cMVwJVDfLlMEkIyQr+vY04RUJ1CCDelHyGxGMTug=; b=Q8g3L3N0NSyyJaLV6Jm322x8zR9C70N1sOqSl4od/SxpQiKCZjy/TxyHS20ViAkrVu 63P7ycn3gNcEXSt0bLW/VVq+9OBr+lYGTar4PY+Jx3mNVpPNqQC0fU73mBIW1OPXwmDT VBwNpWtLccMGH4RMDOCN0DbzApsHxGN3SntxBqTlwNnqEmDK18yf8EMhX++Qrfgc8smh yvpgwtzdnb2qg2NEKMyhFKrdMST5SSi8VpWR8apuQ3JLwY1lUALnq6mXe6De/NT88Itj xZB9YozFVk5FpgiMT69uWhOnUIbwQmcx90P0K9r9ZOD0yjByZHlKD4zF/55B+0VP1TvI wu0w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@python.org header.s=200901 header.b=fo27wUx9; 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=python.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id c12si9463109edx.92.2020.05.12.14.44.30; Tue, 12 May 2020 14:44:53 -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=@python.org header.s=200901 header.b=fo27wUx9; 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=python.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731464AbgELVkj (ORCPT + 99 others); Tue, 12 May 2020 17:40:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48864 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726268AbgELVki (ORCPT ); Tue, 12 May 2020 17:40:38 -0400 Received: from mail.python.org (mail.python.org [IPv6:2a03:b0c0:2:d0::71:1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AFF11C061A0C; Tue, 12 May 2020 14:40:37 -0700 (PDT) Received: from seneca.home.cheimes.de (unknown [IPv6:2a04:4540:6510:1f00:49ee:d60d:b990:1a75]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mail.python.org (Postfix) with ESMTPSA id 49MB7745LTzpFD9; Tue, 12 May 2020 17:40:35 -0400 (EDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=python.org; s=200901; t=1589319635; bh=5X03pNntp4aida3A8i1HP9pAxlVP60DfoAigezXtE3Y=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=fo27wUx9UR7x6VmF7xXiio9GscL/aHHHHa1Qo7TAqwNzvNk0q1RFmRgo3JMCoGNOd Ibr+/HXNAWmOJ6LIOwposSA9rHd4l6OgWHNwlVx7UuVupa/rDfpEjaRmZmQsFTfug0 Gkvzi7fxirEgw42Z14GJqeeEWuz7qCuUAwY/JwyE= Subject: Re: [PATCH v5 1/6] fs: Add support for an O_MAYEXEC flag on openat2(2) To: Kees Cook , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= Cc: linux-kernel@vger.kernel.org, Aleksa Sarai , Alexei Starovoitov , Al Viro , Andy Lutomirski , Daniel Borkmann , Deven Bowers , Eric Chiang , Florian Weimer , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Lakshmi Ramasubramanian , Matthew Garrett , Matthew Wilcox , Michael Kerrisk , =?UTF-8?Q?Micka=c3=abl_Sala=c3=bcn?= , Mimi Zohar , =?UTF-8?Q?Philippe_Tr=c3=a9buchet?= , Scott Shell , Sean Christopherson , Shuah Khan , Steve Dower , Steve Grubb , 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 References: <20200505153156.925111-1-mic@digikod.net> <20200505153156.925111-2-mic@digikod.net> <202005121258.4213DC8A2@keescook> From: Christian Heimes Autocrypt: addr=christian@python.org; prefer-encrypt=mutual; keydata= mQINBE7+DrcBEADUwaeHYCbhr4YUqLH6n2ufkbUfEBrqh6xMiw7E/CKKq/9bZ6rIyntwcU2k q3Jkuq6UXEy5y97ixXOnFZtZcF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M1LJokJiTIW5SWMeI/2zezZTQNnaLYgDfFI3ppia0qkr6zzQhYUdyS6GwHq7 XuuUrohXBq65yG3d0rtGLqlQKbi0RY9e9cQreFm7gVd+CQARAQABiQI8BBgBCAAmAhsMFiEE u5evi8TnpcDZYiPTx4jEwdRVDUUFAl0bZfQFCQnoXewACgkQx4jEwdRVDUU9ZQ/+LLMW+TCU 3+sdNN5yZIN8CqIuVl3/vw6on3K7S2DsZu8LQIH73muT3/9Yiwu1IEgFvgwVI6u3DY/y+pT6 aCwzorXQx923wpHA2bR/+pfvQT9m9oXk7DOU3oWZldqXc6s+vvRmfCox9Ge8o8qRBMqdSnTT CIXnWCjZvTt+cHBz79lWd/s2fxEr60G2q5Eax3ZywZOU0vZk7RUQdY1e9FzfEjpX/4ZKUNLd JGulUpSHFRnz+Fog/D123nOiegdP76XeLbVa5HpJO7ncsIn4oRyoit8TAORxq/myHCaCXRBa y5ilMLWvbGll8BVn5JKs5rlHu+xS7orP+HtEfdJN79+/utQXv3o/deOtF5R59stzcSZtBwXF kwX14TsD1t2DGQUDZdsvXbv4td/FZD86xqLoh3qiT5KXOi6bhytLpNKseXbC9RruPRs+2O4S LoZMPB9HTsw9lRn1sXxXLhWTWtNcVMRXaQGJGm5ifa7+Ub/RFEZVeLPY6hqEogP2D+p3duj0 7fb4dD9eD79TND0L9DL2kCmPbZ1hArh015Otj/IEe+P4S1BTjopJ+lKhgRo1RmAaiU+LmRZW YQW5GUWP/LBkR7VmFpTI9Nj91ql+YaGZMWTuO5QLvtbL4x0kSgczJmIK7fECI7nqsL4rtHmv 53+DNOMi/34rdBwm0I62QkVYJYU= Message-ID: <0c70debd-e79e-d514-06c6-4cd1e021fa8b@python.org> Date: Tue, 12 May 2020 23:40:35 +0200 MIME-Version: 1.0 In-Reply-To: <202005121258.4213DC8A2@keescook> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/05/2020 23.05, Kees Cook wrote: > On Tue, May 05, 2020 at 05:31:51PM +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). >> >> 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. > > You touch on this lightly in the cover letter, but it seems there are > plans for Python to restrict stdin parsing? Are there patches pending > anywhere for other interpreters? (e.g. does CLIP OS have such patches?) > > There's always a push-back against adding features that have external > dependencies, and then those external dependencies can't happen without > the kernel first adding a feature. :) I like getting these catch-22s > broken, and I think the kernel is the right place to start, especially > since the threat model (and implementation) is already proven out in > CLIP OS, and now with IMA. So, while the interpreter side of this is > still under development, this gives them the tool they need to get it > done on the kernel side. So showing those pieces (as you've done) is > great, and I think finding a little bit more detail here would be even > better. Hi, Python core dev here. Yes, there are plans to use feature for Python in combination with additional restrictions. For backwards compatibility reasons we cannot change the behavior of the default Python interpreter. I have plans to provide a restricted Python binary that prohibits piping from stdin, disables -c "some_code()", restricts import locations, and a couple of other things. O_MAYEXEC flag makes it easier to block imports from noexec filesystems. My PoC [1] for a talk [2] last year is inspired by IMA appraisal and a previous talk by Mickaël on O_MAYEXEC. Christian [1] https://github.com/zooba/spython/blob/master/linux_xattr/spython.c [2] https://speakerdeck.com/tiran/europython-2019-auditing-hooks-and-security-transparency-for-cpython