Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1363580rdb; Wed, 24 Jan 2024 12:48:26 -0800 (PST) X-Google-Smtp-Source: AGHT+IHK/1DKe7TDgeQhHCjb2dI9WDrYlVvLDlKw3GybOSTyiNg3WZV8ekY5ZpPlgw7VhxYO+tf3 X-Received: by 2002:a05:6a00:1783:b0:6db:cae0:a720 with SMTP id s3-20020a056a00178300b006dbcae0a720mr116281pfg.16.1706129305859; Wed, 24 Jan 2024 12:48:25 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706129305; cv=pass; d=google.com; s=arc-20160816; b=YEaCZptkvHJVn0Nj8CK4YYPKJyE4WNlIhGjKVBT2wFQiraCjguQ/t3Bx9Q8WzP3m6P 9JD/OOlpJNYyroP/7PS9yHdteeeWrEkBfI+am30T8zhRjnM3cA/lKKKfz8xRSchojJrG SHXDl4yE/v0mi0eSeFcg0qOcSpj4YEMQ1IMALLeRgOpHJfK54KWNKcUepSljuV9mPKIu JrI3ZB8HZGR2TINZ2kXdsh4gWx/h007cZDNc3nQquIJ8k9NnqYw7VHeEA4j+IDU6u7TS c2WjKF+K6pBWDMl+lIAbNf+fI60uouWoAN1unhSgk+Hj87SrY8ISFJkuv+qGH8MIJiPE SEfg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=Rk3ry+wMmO/dN2zz3UHRD0lGEi4syprX1/TUT7irM/o=; fh=R099Q2pXi8529UUY6b5YhL9YaICD5QWv//jbklIYPcs=; b=uZn56Aj+s/dBgYsGxuQVPaalf5IYCzODTP3SoaTQlHXk2r2PdkNW1yRFt/+ugkDWWb nJAm6VOIjPxrU6V1aa/AT3l5CauVQ4yfrYbVySv4U5bDVliV3Qe8eKwIPZKeWa2DtRI1 32zO/GKJOGhGwKIMOcGNhepe+loJUYUgChDXqJAqG/1Qk5t7VjihBh8NlcfhvIkQIuAy mMcY/DiAeM8chyNmfcg/Rl5ZQ3D9/GXpfIvXyr469kknxkkmpNJeN/Pbqa1wo18F461K O48yqywWqMhFpwaKgdPXw+Eik9nHCcXBE8rI7Wyr+zyWtvraQwlh4nQmGLxhRtTvCmgF FrxQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JCf5YSNv; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-37660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37660-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id fd39-20020a056a002ea700b006db8f4389fesi14670208pfb.98.2024.01.24.12.48.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 12:48:25 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=JCf5YSNv; arc=pass (i=1 spf=pass spfdomain=linuxfoundation.org dkim=pass dkdomain=linux-foundation.org); spf=pass (google.com: domain of linux-kernel+bounces-37660-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37660-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 sy.mirrors.kernel.org (Postfix) with ESMTPS id 61602B21760 for ; Wed, 24 Jan 2024 20:48:23 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id B19D21350CC; Wed, 24 Jan 2024 20:48:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="JCf5YSNv" Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB9EA134750 for ; Wed, 24 Jan 2024 20:48:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706129296; cv=none; b=kU73TOES2SA2C/TfEJvGdmXmSCMPwV7E6ENc7hAiHQuRiaclXan45NtzoZWFEKI0W1AGs0wqJeDOxoQzNHvmeFXu/mNXDaWXq5FglPYrq9RSv5CDdH6lALOd/T0Z79Truq8Zrv8jLjqZBZ6TT0fw6YIgYr4NlLhdAl1Udg50PuE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706129296; c=relaxed/simple; bh=7cPnVJTTwAqS5m/D9fwBaWJXEtqGZq8IcE/AOficsKI=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=sIIbGEVaA7Vs4XJAuLt4MH5i5lt/2ahnP0CQxwAFXRXZDKDAp1OdwlHvSj5MHWfUaq4tbxaAy7jqzYzmxADEwMyhvf1tZbBjUsXQ9rei33Ek0I6LlL6O/lGzO27Xq16Vl6CbgtCfe6lHxQISWpme2pSO2Z2+KsvoWaI4spFTXaQ= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org; spf=pass smtp.mailfrom=linuxfoundation.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=JCf5YSNv; arc=none smtp.client-ip=209.85.218.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=linux-foundation.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linuxfoundation.org Received: by mail-ej1-f47.google.com with SMTP id a640c23a62f3a-a28a6cef709so619026066b.1 for ; Wed, 24 Jan 2024 12:48:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; t=1706129293; x=1706734093; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=Rk3ry+wMmO/dN2zz3UHRD0lGEi4syprX1/TUT7irM/o=; b=JCf5YSNv1AEp68/Ka12er32EYzrHNguUv/zyrA8tULnBiIA+/7Bm5imRwSGEPHJe9u 8R3gxPxQcloqGfIo/jgZIqjH/621XGstAc4mDpsJDcfx0ku3sybiMhkRnd0/pRI9p0N3 4hlX6qEFwjW5w63BCmZuPl6b9ZZBig/bUozOg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706129293; x=1706734093; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Rk3ry+wMmO/dN2zz3UHRD0lGEi4syprX1/TUT7irM/o=; b=tVZ+SUCn2LUq7qqduHg+7gDsWcRXJBJvMjOeqEMYOHYTTMPFK+LVLaIBwP+2ZkDLPX FiHAgsS3nGSyP2LFzrXG/yS6WsW5jGamSFg+pd4lJcADOqfBnM7paOnYbMIWE37QSXYt MrHk6WO39/DMLSJDnRaphxKh29xeyiBKEg9Z0YAtesLdj6u2EHkUc/a80LEBWmN4IjcC JsH7+rt/OZPR+ZhBAY7L15v/IZmYWaD4G/NXx8COe2PPaIoshKGcWoEzpeGM6p8UFLqw BAc4bTgikmZ66w+KLUeTxqJzvoPXJhD79ox7f6PXn80B5dkLbvLCjeh3clflKycN/aL8 qHkQ== X-Gm-Message-State: AOJu0YxfGwvbKfWhLs16nYbzRaZBPV1Kp9eNG6BzSIQ23QbN3ANUmUgZ iQd5xc4eP8siDyWHENLFyn9EQyhC9OzqX6APcaK6BT9aZPOoNgvwqQNuq3Z0g7nheq9rz40rpC+ srh98pA== X-Received: by 2002:a17:906:5aca:b0:a2a:19c8:e4ef with SMTP id x10-20020a1709065aca00b00a2a19c8e4efmr1183058ejs.141.1706129293071; Wed, 24 Jan 2024 12:48:13 -0800 (PST) Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com. [209.85.128.49]) by smtp.gmail.com with ESMTPSA id k14-20020a1709065fce00b00a28aa4871c7sm241360ejv.205.2024.01.24.12.48.12 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 24 Jan 2024 12:48:12 -0800 (PST) Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-40e76626170so65476055e9.2 for ; Wed, 24 Jan 2024 12:48:12 -0800 (PST) X-Received: by 2002:a05:600c:4ec9:b0:40e:a3aa:a463 with SMTP id g9-20020a05600c4ec900b0040ea3aaa463mr1545745wmq.20.1706129271244; Wed, 24 Jan 2024 12:47:51 -0800 (PST) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240124192228.work.788-kees@kernel.org> <202401241206.031E2C75B@keescook> In-Reply-To: <202401241206.031E2C75B@keescook> From: Linus Torvalds Date: Wed, 24 Jan 2024 12:47:34 -0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] exec: Check __FMODE_EXEC instead of in_execve for LSMs To: Kees Cook Cc: 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 Content-Type: text/plain; charset="UTF-8" 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. Well, we could just remove the __FMODE_EXEC from uselib. It's kind of wrong anyway. Unlike a real execve(), where the target executable actually takes control and you can't actually control it (except with ptrace, of course), 'uselib()' really is just a wrapper around a special mmap. And you can see it in the "acc_mode" flags: uselib already requires MAY_READ for that reason. So you cannot uselib() a non-readable file, unlike execve(). So I think just removing __FMODE_EXEC would just do the RightThing(tm), and changes nothing for any sane situation. In fact, I don't think __FMODE_EXEC really ever did anything for the uselib() case, so removing it *really* shouldn't matter, and only fix the new AppArmor / Tomoyo use. 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. And at least the nfs stuff was about "don't require read permissions for exec", which was already wrong for the uselib() case as per above. So I think the simple oneliner is literally just --- a/fs/exec.c +++ b/fs/exec.c @@ -128,7 +128,7 @@ SYSCALL_DEFINE1(uselib, const char __user *, library) struct filename *tmp = getname(library); int error = PTR_ERR(tmp); static const struct open_flags uselib_flags = { - .open_flag = O_LARGEFILE | O_RDONLY | __FMODE_EXEC, + .open_flag = O_LARGEFILE | O_RDONLY, .acc_mode = MAY_READ | MAY_EXEC, .intent = LOOKUP_OPEN, .lookup_flags = LOOKUP_FOLLOW, but I obviously have nothing that uses uselib(). I don't see how it really *could* break anything, though, exactly because of that .acc_mode = MAY_READ | MAY_EXEC, that means that the *regular* permission checks already require the file to be readable. Never mind any LSM checks that might be confused. Linus