From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5B6AB19AD93; Wed, 10 Jul 2024 16:26:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720628775; cv=none; b=lHhJxuTtPpjLe2I8cZaaL2Wl+vxxb6SVjBfo7Y497DE3ZSczGFeRIq7R2SVvl7aQY7bS4h85EJMEIwLpETHzuoUVDQUctxms46Qmz5/ejlE3HeQ8PwnJaGdtZtGz0iAxxmJKJSRQ8RaJAX1mJSVczj3TCH690kBTCDoD9Yb2Us4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1720628775; c=relaxed/simple; bh=6SS1VzsAN02ABjDahpP3q5Q9MfB8o/CX8E1l3SuhboU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=X0rJ2UsM9GsZAIBp/3eYFux3omGov92dhC4OwOVvDlx7RhoGh5q2Lu4b0kY0/7SJKpveKvCjglSD6XJwjf0LhvBKwaBOQtP3T8h2KaUml74JFcpe5tjB4smzA7eGpD+0Uudpe68gDfTGAJiUNlCH4Iq5shmD8rEGJthv2awGfeQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EOoq4U1y; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EOoq4U1y" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA285C32781; Wed, 10 Jul 2024 16:26:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1720628774; bh=6SS1VzsAN02ABjDahpP3q5Q9MfB8o/CX8E1l3SuhboU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EOoq4U1ybtMOS83+O4Pt4y4wluYXnG29O5G4LSWXFYV7rH7syR0lBDZXcbc5UcYX/ kF7a+kOhG55Bs6NXCmkFwZOISzkENspnSwr20lmmJ4e4t1G9JWChqIj2cFUYHjr7qJ vTRo+9wwBKa5v8080kSQHhQlUNv85enpW4fd+p71m4AdtrwBNuwW/SUgbxG354jNsB 56Hc7+4q62olrBxTzcuFPicf4rL7SCaydxmqd4S4V6N0yoXaZigjjMyB4RdORKLxLt t6+nJ4XirQdY0UcjIyyOrqjGM3BXXDzn7z3d6qc6gxRqDu6003ehkGL+VNHUDUROZR CcOJjjW1YTdjQ== Date: Wed, 10 Jul 2024 09:26:14 -0700 From: Kees Cook To: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= Cc: Jeff Xu , Steve Dower , Al Viro , Christian Brauner , Linus Torvalds , Paul Moore , Theodore Ts'o , Alejandro Colomar , Aleksa Sarai , Andrew Morton , Andy Lutomirski , Arnd Bergmann , Casey Schaufler , Christian Heimes , Dmitry Vyukov , Eric Biggers , Eric Chiang , Fan Wu , Florian Weimer , Geert Uytterhoeven , James Morris , Jan Kara , Jann Horn , Jonathan Corbet , Jordan R Abrahams , Lakshmi Ramasubramanian , Luca Boccassi , Luis Chamberlain , "Madhavan T . Venkataraman" , Matt Bobrowski , Matthew Garrett , Matthew Wilcox , Miklos Szeredi , Mimi Zohar , Nicolas Bouchinet , Scott Shell , Shuah Khan , Stephen Rothwell , Steve Grubb , Thibaut Sautereau , Vincent Strubel , Xiaoming Ni , Yin Fengwei , kernel-hardening@lists.openwall.com, linux-api@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-integrity@vger.kernel.org, linux-kernel@vger.kernel.org, linux-security-module@vger.kernel.org Subject: Re: [RFC PATCH v19 2/5] security: Add new SHOULD_EXEC_CHECK and SHOULD_EXEC_RESTRICT securebits Message-ID: <202407100921.687BE1A6@keescook> References: <20240704190137.696169-3-mic@digikod.net> <20240708.quoe8aeSaeRi@digikod.net> <20240709.aech3geeMoh0@digikod.net> <20240710.eiKohpa4Phai@digikod.net> Precedence: bulk X-Mailing-List: linux-api@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20240710.eiKohpa4Phai@digikod.net> On Wed, Jul 10, 2024 at 11:58:25AM +0200, Mickaël Salaün wrote: > Here is another proposal: > > We can change a bit the semantic by making it the norm to always check > file executability with AT_CHECK, and using the securebits to restrict > file interpretation and/or command injection (e.g. user supplied shell > commands). Non-executable checked files can be reported/logged at the > kernel level, with audit, configured by sysadmins. > > New securebits (feel free to propose better names): > > - SECBIT_EXEC_RESTRICT_FILE: requires AT_CHECK to pass. Would you want the enforcement of this bit done by userspace or the kernel? IIUC, userspace would always perform AT_CHECK regardless of SECBIT_EXEC_RESTRICT_FILE, and then which would happen? 1) userspace would ignore errors from AT_CHECK when SECBIT_EXEC_RESTRICT_FILE is unset or 2) kernel would allow all AT_CHECK when SECBIT_EXEC_RESTRICT_FILE is unset I suspect 1 is best and what you intend, given that SECBIT_EXEC_DENY_INTERACTIVE can only be enforced by userspace. > - SECBIT_EXEC_DENY_INTERACTIVE: deny any command injection via > command line arguments, environment variables, or configuration files. > This should be ignored by dynamic linkers. We could also have an > allow-list of shells for which this bit is not set, managed by an > LSM's policy, if the native securebits scoping approach is not enough. > > Different modes for script interpreters: > > 1. RESTRICT_FILE=0 DENY_INTERACTIVE=0 (default) > Always interpret scripts, and allow arbitrary user commands. > => No threat, everyone and everything is trusted, but we can get > ahead of potential issues with logs to prepare for a migration to a > restrictive mode. > > 2. RESTRICT_FILE=1 DENY_INTERACTIVE=0 > Deny script interpretation if they are not executable, and allow > arbitrary user commands. > => Threat: (potential) malicious scripts run by trusted (and not > fooled) users. That could protect against unintended script > executions (e.g. sh /tmp/*.sh). > ==> Makes sense for (semi-restricted) user sessions. > > 3. RESTRICT_FILE=1 DENY_INTERACTIVE=1 > Deny script interpretation if they are not executable, and also deny > any arbitrary user commands. > => Threat: malicious scripts run by untrusted users. > ==> Makes sense for system services executing scripts. > > 4. RESTRICT_FILE=0 DENY_INTERACTIVE=1 > Always interpret scripts, but deny arbitrary user commands. > => Goal: monitor/measure/assess script content (e.g. with IMA/EVM) in > a system where the access rights are not (yet) ready. Arbitrary > user commands would be much more difficult to monitor. > ==> First step of restricting system services that should not > directly pass arbitrary commands to shells. I like these bits! -- Kees Cook