Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp75711rdb; Thu, 25 Jan 2024 08:39:25 -0800 (PST) X-Google-Smtp-Source: AGHT+IEA10vp2Ia6MqiSq1hC7LXbXg04gljRrlrawEezBM6sCOReZKkWjepJTNMbcgeWdHE1dnDA X-Received: by 2002:a05:622a:54a:b0:42a:7204:3865 with SMTP id m10-20020a05622a054a00b0042a72043865mr382831qtx.130.1706200765670; Thu, 25 Jan 2024 08:39:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706200765; cv=pass; d=google.com; s=arc-20160816; b=NwCS29vdeOFpf0TI31P+QL9YBP/SXVNU8DR2T6Q6aVahl0xpZq8TehZrSofe+bN4Ux JgJG67dMAPSn0Q8f0EqvxqUGI38N2S4P/YliywKJ7Dps9jTsaDRQ8LRasiev771B9atE NPEjsq+Iljf7nYpuyCMI4zq/w/xKvf2i+W6rIWR2NVYUt9UBZCw18imSqr6nRg4HVlRs VXHcvrixflkWRtCeVfoa5++k5goVcfB5uFQy181kfKY8QlYf+9ne+HkKGKbPP3mLGE5Z whRdgmVRK+7H4ZcGJUHcQmgHS7VoIYuzUP+TiVCmyCsdOW2QpNrbZICCp1SLoeMC73ya R4WA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=UC/r9AqbXnpFUmxwrrZGjwIncG3ZxY7IDhmnn12gWZg=; fh=Y3Xyp8wULpYctoA7qeuj23DldSd14ZR6FhXGPzdD6jo=; b=T3gZkZQwAsXWFkJPe2jzK/6kTPR1xWOnh2y/xKWb12v0aAehzay9K1/9ARakdcxHCa Wh9H38PI5qhHaTE5U7iTTFKDtLOnQHT/rr+Qpm0xyt4CRiDjq1DFmA4sSV+fZTWJmu2K d7hXB/KqwewVw6tuVWDTaJY4YqPRTASOYtVbPxASe6fLkEupUYz0Zk05FjtyNbLIfoHU 6FC+oKe7e/vng8E8CB6N7fEV838F4/IAarLlVjjt0LPytCuObbCEabIS6Omhaq2sq/2L 7sZhe8vqEyDIQTu6HHFOHK+lCbHiCX1hpxYau64jJOMIa/9XGopChjv+w0d8F+Hl9Zml ps+w== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="DO8PBK/6"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-38908-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38908-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id o13-20020a05622a138d00b0042a4f641b33si6433053qtk.277.2024.01.25.08.39.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Jan 2024 08:39:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-38908-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@digikod.net header.s=20191114 header.b="DO8PBK/6"; arc=pass (i=1 spf=pass spfdomain=digikod.net dkim=pass dkdomain=digikod.net); spf=pass (google.com: domain of linux-kernel+bounces-38908-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-38908-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 6D1721C252ED for ; Thu, 25 Jan 2024 16:39:25 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 3D559129A63; Thu, 25 Jan 2024 16:39:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=digikod.net header.i=@digikod.net header.b="DO8PBK/6" Received: from smtp-42aa.mail.infomaniak.ch (smtp-42aa.mail.infomaniak.ch [84.16.66.170]) (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 D0D667CF13 for ; Thu, 25 Jan 2024 16:39:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=84.16.66.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706200755; cv=none; b=ayjxPYQXP9C00uLQikwlNd1I2Rr88ZYy3CEqooGOhTtiigv00dtYtqGDC1iiV3L8sSk9oCvDT2dd3IYJqM0A6EFQt2v744mbH7Ma15+qBuwI744XegcMUYCFNBOXVNeBB3qfQaU3I1jm2xZmhTZ1tNRvOsu6M3fwynJPwXQ1V/Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706200755; c=relaxed/simple; bh=du31PmGw/fTX+38J7um3nXoKGi9MdQjFP4Xk4imtbeU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=dzt+7eiE2OBEiG9McdR+mH0MwsRP2+LfiZIImXAFmzxYseMPUKdQ0cTs6rNl4NqdUyJU/DbXA0Auguj+8fSVb6/sPaEE4x7oCXPMZrM1XUvlte6/fl1Eeh2pyuBRR3vRxIZMmPzsEvVaj7ZhknRbAoNivMWEXGshbo7EqTRJUhQ= 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=DO8PBK/6; arc=none smtp.client-ip=84.16.66.170 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 Received: from smtp-3-0000.mail.infomaniak.ch (unknown [10.4.36.107]) by smtp-3-3000.mail.infomaniak.ch (Postfix) with ESMTPS id 4TLRNh6dy5zMqbBv; Thu, 25 Jan 2024 17:39:00 +0100 (CET) Received: from unknown by smtp-3-0000.mail.infomaniak.ch (Postfix) with ESMTPA id 4TLRNd3PKVz3f; Thu, 25 Jan 2024 17:38:57 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=digikod.net; s=20191114; t=1706200740; bh=du31PmGw/fTX+38J7um3nXoKGi9MdQjFP4Xk4imtbeU=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=DO8PBK/6IihpHWk1hJ0RnfwFUiEI5PVdOR0kOr5uSXu696eAYNVKL8OoG3hr3ZBqO 7NLJ7YfkSQETMHL9do9sD+BxXeEVD0vF42DMEasjGMEl5UxF22smEjqqzNtUjAU2ww o3XlB60Dumm/C8JlxtzDsXde456a7Bm2+fmY5HgU= Date: Thu, 25 Jan 2024 17:38:53 +0100 From: =?utf-8?Q?Micka=C3=ABl_Sala=C3=BCn?= To: Kees Cook Cc: Linus Torvalds , Jann Horn , Josh Triplett , Kevin Locke , John Johansen , Paul Moore , James Morris , "Serge E. Hallyn" , Kentaro Takeda , Tetsuo Handa , Alexander Viro , Christian Brauner , Jan Kara , Eric Biederman , Andrew Morton , Sebastian Andrzej Siewior , linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, apparmor@lists.ubuntu.com, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, linux-hardening@vger.kernel.org Subject: Re: Re: [PATCH] exec: Check __FMODE_EXEC instead of in_execve for LSMs Message-ID: <20240125.bais0ieKahz7@digikod.net> References: <20240124192228.work.788-kees@kernel.org> <202401241206.031E2C75B@keescook> <202401241310.0A158998@keescook> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <202401241310.0A158998@keescook> X-Infomaniak-Routing: alpha On Wed, Jan 24, 2024 at 01:32:02PM -0800, Kees Cook wrote: > On Wed, Jan 24, 2024 at 12:47:34PM -0800, Linus Torvalds wrote: > > On Wed, 24 Jan 2024 at 12:15, Kees Cook wrote: > > > > > > Hmpf, and frustratingly Ubuntu (and Debian) still builds with > > > CONFIG_USELIB, even though it was reported[2] to them almost 4 years ago. > > For completeness, Fedora hasn't had CONFIG_USELIB for a while now. > > > Well, we could just remove the __FMODE_EXEC from uselib. > > > > It's kind of wrong anyway. > > Yeah. > > > So I think just removing __FMODE_EXEC would just do the > > RightThing(tm), and changes nothing for any sane situation. > > Agreed about these: > > - fs/fcntl.c is just doing a bitfield sanity check. > > - nfs_open_permission_mask(), as you say, is only checking for > unreadable case. > > - fsnotify would also see uselib() as a read, but afaict, > that's what it would see for an mmap(), so this should > be functionally safe. > > This one, though, I need some more time to examine: > > - AppArmor, TOMOYO, and LandLock will see uselib() as an > open-for-read, so that might still be a problem? As you > say, it's more of a mmap() call, but that would mean > adding something a call like security_mmap_file() into > uselib()... If user space can emulate uselib() without opening a file with __FMODE_EXEC, then there is no security reason to keep __FMODE_EXEC for uselib(). Removing __FMODE_EXEC from uselib() looks OK for Landlock. We use __FMODE_EXEC to infer if a file is being open for execution i.e., by execve(2). If __FMODE_EXEC is removed from uselib(), I think it should also be backported to all stable kernels for consistency though. > > The issue isn't an insane "support uselib() under AppArmor" case, but > rather "Can uselib() be used to bypass exec/mmap checks?" > > This totally untested patch might give appropriate coverage: > > diff --git a/fs/exec.c b/fs/exec.c > index d179abb78a1c..0c9265312c8d 100644 > --- a/fs/exec.c > +++ b/fs/exec.c > @@ -143,6 +143,10 @@ SYSCALL_DEFINE1(uselib, const char __user *, library) > if (IS_ERR(file)) > goto out; > > + error = security_mmap_file(file, PROT_READ | PROT_EXEC, MAP_FIXED | MAP_SHARED); > + if (error) > + goto exit; > + > /* > * may_open() has already checked for this, so it should be > * impossible to trip now. But we need to be extra cautious > > > Of course, as you say, not having CONFIG_USELIB enabled at all is the > > _truly_ sane thing, but the only thing that used the FMODE_EXEC bit > > were landlock and some special-case nfs stuff. > > Do we want to attempt deprecation again? This was suggested last time: > https://lore.kernel.org/lkml/20200518130251.zih2s32q2rxhxg6f@wittgenstein/ > > -Kees > > -- > Kees Cook >