From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp-42ab.mail.infomaniak.ch (smtp-42ab.mail.infomaniak.ch [84.16.66.171]) (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 97CF019B3C3; Tue, 16 Jul 2024 15:15:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721142946; cv=none; b=XsGPgwprBB2m+EUTtwcgy0hqjcJsxh972ZrUjODZIIAJb2C1Ml2r1gmVfz6ZzZ/8V0l8xTS4AFB7h04jiCD4wTPh8O+58LGyzWdgMxEKE57t+pkgRe4IGjSFMWmdhfJykN09ohaRX/1RENYc7BypHR7oOaarA91R1JA7G42cs6M= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1721142946; c=relaxed/simple; bh=+ykSzV3fkNPy2WdmM0RJLsMfj+Tpi+DbuVtC9MODNqE=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=ltAKe7m+yISlPFNF4Z8EqDrDMd40rWcezPepwyBVDrvUhJ3GOBx44LF0HlZH7RzpjRzAD+Z0HIIxKAXoxcDgf+Vxrr4OaD90Ry3PugoYGeMGBqNFyU3MVKWFtzaBGm+NgE60Y323Ec2X1L1TBh8sqF+hi4YsEtqbOAg6CIkZuio= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net; spf=pass smtp.mailfrom=digikod.net; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b=xNKcZO2j; arc=none smtp.client-ip=84.16.66.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=digikod.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=digikod.net Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="xNKcZO2j" Received: from smtp-4-0000.mail.infomaniak.ch (smtp-4-0000.mail.infomaniak.ch [10.7.10.107]) by smtp-4-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4WNjLc08mnz18Zq; Tue, 16 Jul 2024 17:15:36 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=digikod.net; s=20191114; t=1721142935; bh=n0Yyov6793OgT9UdlDqw0KaNB/lL9GCWiAZax8WYA8Q=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=xNKcZO2jTScaIsHJJ9zP+OUxUwTBkPrcBA1yOc1q+QKNt+FHN/k4cg67/GrzLLdJi imfD9u0LbeCeE3RQsj4zkCXY8TWGoinZMOzqifRdvWlYs/h6Vg/BDKB+K2iD/f4mWS fmkY/ksgCatUJ/DslEjxtcF/8/FKyo6Kcl12Spmc= Received: from unknown by smtp-4-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4WNjLT50v4zKmx; Tue, 16 Jul 2024 17:15:29 +0200 (CEST) Date: Tue, 16 Jul 2024 17:15:28 +0200 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: Jeff Xu Cc: Kees Cook , 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: <20240716.Zah8Phaiphae@digikod.net> References: <20240708.quoe8aeSaeRi@digikod.net> <20240709.aech3geeMoh0@digikod.net> <20240710.eiKohpa4Phai@digikod.net> <202407100921.687BE1A6@keescook> <20240711.sequuGhee0th@digikod.net> Precedence: bulk X-Mailing-List: linux-security-module@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-Infomaniak-Routing: alpha On Tue, Jul 16, 2024 at 08:02:37AM -0700, Jeff Xu wrote: > On Thu, Jul 11, 2024 at 1:57 AM Mickaël Salaün wrote: > > > > On Wed, Jul 10, 2024 at 09:26:14AM -0700, Kees Cook wrote: > > > 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 > > > > Yes, that's the idea. > > > > > > > > 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. > > > > Indeed. We don't want AT_CHECK's behavior to change according to > > securebits. > > > One bit is good. > > > > > > > > - 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! > > > > Good! Jeff, Steve, Florian, Matt, others, what do you think? > > For below two cases: will they be restricted by one (or some) mode above ? > > 1> cat /tmp/a.sh | sh > > 2> sh -c "$(cat /tmp/a.sh)" Yes, DENY_INTERACTIVE=1 is to deny both of these cases (i.e. arbitrary user command). These other examples should be allowed with AT_CHECK and RESTRICT_FILE=1 if a.sh is executable though: * sh /tmp/a.sh * sh < /tmp/a.sh