Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1349098rdb; Wed, 24 Jan 2024 12:13:23 -0800 (PST) X-Google-Smtp-Source: AGHT+IFRN85Jxj6he/AVtjiLA/6auqejDY8sgtsuGqUxonQ6nF1CB5wpXUXyDcScU54AwmUw4I0P X-Received: by 2002:a05:6a20:dda9:b0:199:76d8:402d with SMTP id kw41-20020a056a20dda900b0019976d8402dmr1303512pzb.111.1706127203569; Wed, 24 Jan 2024 12:13:23 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706127203; cv=pass; d=google.com; s=arc-20160816; b=S+rA+sC8TigRmfDb6R4XzuNE9mqKKam2CVkJLUHrZWVHV7AQCIzT4zMTudTV1eo5x/ ov4xgGp5mtcfkQp8rkft84l2a4TUZBBR0XZYvL95bsISQvgK+S7ylDG/zS4Ywj9zIKHT c+sIf9CKxNEdBa1McT2dLTnSElLWr0Gk8YAZZfgqlDgRN5VCa+xaUi1ynpgdginzH0nM AVM008w6qrUaaGK0tfOMfnUQjXLRgKvTUxY4BQBJSFQjTIIIclGhrsxW82M/6zjds1R2 RXf6Ca6sB98zVBBMzwjOLSn38L5e1tuY1Rux35UTdkKO4nzoh9SmDy7SUUgSIWpBrMw8 x+0g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=IbNRc2tTI3uRJ4hOoUG/LLCmL8sxwzKLKOM6UpHlIBE=; fh=k/PendSy9KC1fCz/DkWCEBVvYbqc5LGkai0DnPzeJ90=; b=CGM+8zP8mzjIXkxOV/wUG2TvsGY3neWwLxgNyAMh6p0pbj3oOnvpZZzKbpqLqkbdpu eA/JWuon4HoEGaZH4PJsCgCz6kQtoznBF0t/cdE4oQ4OE1RKQoH0CXQHkqItgza3OcEE KXHNlhC89IflLRBiT3npCX7uvZTT8fhxeDfrBARqb+PcaBqgYEIOo3ABEP5svDU5rxE2 /Bqb3OeGOLPjswK9LqHSIYvycBeKEwLOvRci944kse4LOPwssC3lNfV/NsnBJqOZJXyf dtORh9ZIEjDutG7VIHbXbbuuHoQ7K7OonEvXgylD7wHZrs6am7VYds/P2NxEK9gYjuPP rVVQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KkjH7Wly; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-37619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37619-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [2604:1380:40f1:3f00::1]) by mx.google.com with ESMTPS id y16-20020a634b10000000b005d24d531a21si3646491pga.483.2024.01.24.12.13.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 12:13:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) client-ip=2604:1380:40f1:3f00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=KkjH7Wly; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-37619-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:40f1:3f00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37619-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 4006CB225FD for ; Wed, 24 Jan 2024 19:59:47 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 32303133435; Wed, 24 Jan 2024 19:59:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="KkjH7Wly" Received: from mail-ed1-f50.google.com (mail-ed1-f50.google.com [209.85.208.50]) (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 BFCBD131E4E for ; Wed, 24 Jan 2024 19:59:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706126375; cv=none; b=LMTwjejczMC0ASg1xakgDlUjEJ+A2p+tvCD7DIjT8yJ+xOdIF/s/Yi8xrmLKlyr4B1zswzPKcrnXa8zn5ZNLYwu3nDAxGhLRfCvbXrgvtjVyJ6ffJMkqFZqLUAtK0hmauD8k5iDylGgGXyR5qAPJM6zXAcCpUB/eqVYwvmc3BSs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706126375; c=relaxed/simple; bh=IbNRc2tTI3uRJ4hOoUG/LLCmL8sxwzKLKOM6UpHlIBE=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=OW5mdQ5KNESjaJtQX2gNw5iQ3v+hNizSq89wToS8F5Al9yom5bhvEHQ1rJqOR+r2CWxbQKOL6H0JVRovLyQW6+pcUnhdJtrSIiR9BMLTNwcg/s+6zRPzOmmhZZl21SWwjlAQfDtjTQ3hCnfnVrk2hiFg4MaAcYsx4KQFSMn88lk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=KkjH7Wly; arc=none smtp.client-ip=209.85.208.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-ed1-f50.google.com with SMTP id 4fb4d7f45d1cf-55c89dbef80so1762a12.1 for ; Wed, 24 Jan 2024 11:59:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1706126372; x=1706731172; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=IbNRc2tTI3uRJ4hOoUG/LLCmL8sxwzKLKOM6UpHlIBE=; b=KkjH7Wly2be5bPpQh5/K+TpoIusUptoVc5hnVxbHKO89GQfrfwb+3t7RFDGtuAWXIj BYAH7Obe4FPxuW4m4u1eIvAJSCROmAD0CF3zIwjKHWKHQ0UE+y6qCi4n9Z1PqQlrYMyv vcKrU2tryisDF6PetjKM3JZVOSq7G39AHeA/B9F3BiHg5gMLB/nX0BiaP90ivp3l08XZ Ky642hhJpdnbm6jDuePdMl8nuUaSYx840Q/TbTjDcChYoW1L7YKE+RVeCL+qPfvEq4KT 7366EW/bODPQiBOWVdlz3TtM9Ag29CU69UWePfmI6pXlgWG2g8LyeD9p+YgG4UEcnw22 rxCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706126372; x=1706731172; h=content-transfer-encoding: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=IbNRc2tTI3uRJ4hOoUG/LLCmL8sxwzKLKOM6UpHlIBE=; b=d98VzjHDsW/yMvFlmoNYB+cjOvpGYGks62GJbfcLNXehJbj2n0P9gi0ZUI4EQHISh0 3YU595G+mYQSHWcv0dhoG1jPX6/YkSpMdt8nc3XlCoSZAoY3RmLrvB2+dFzKxTEYygoS BW+yPkIfhGXdvGa9i29OENeSnwSr0Yln6IkIqZ0O/QQ0c9u+XTQFfWzcq6yenbM4TYgI Evih1aM/R36E8ewaV2nwn8b/DvewP92pWNTscN3UF/4OR+Ztlxyf7ycelGlcyl8jAh5g Fg/S3EvVrPjGxwOa6jgFloj+s+sjFmhd6wBtA1zrmTWFMp7fbF/QYV2q+MF0+LMoLvXg xoOg== X-Gm-Message-State: AOJu0YzdzM1eLEbUpSl90tzWaKspmazrDiJr2BFIlGEyOBqE1GdD5+r3 PJVc/Yhzsnt6b1QKGPr6kwpbgtuBOk6eS28EISeIW4L0npWBHEiysM9PGe8tpParOdhYn8Tgbgi MwVzrlUSrfLRWYGWKnNq98nLAiax04GIpAbCs X-Received: by 2002:a05:6402:1bc9:b0:55c:8eda:6e19 with SMTP id ch9-20020a0564021bc900b0055c8eda6e19mr34873edb.2.1706126371819; Wed, 24 Jan 2024 11:59:31 -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> In-Reply-To: <20240124192228.work.788-kees@kernel.org> From: Jann Horn Date: Wed, 24 Jan 2024 20:58:55 +0100 Message-ID: Subject: Re: [PATCH] exec: Check __FMODE_EXEC instead of in_execve for LSMs To: Kees Cook Cc: Josh Triplett , Kevin Locke , Linus Torvalds , 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" Content-Transfer-Encoding: quoted-printable On Wed, Jan 24, 2024 at 8:22=E2=80=AFPM Kees Cook w= rote: > After commit 978ffcbf00d8 ("execve: open the executable file before > doing anything else"), current->in_execve was no longer in sync with the > open(). This broke AppArmor and TOMOYO which depend on this flag to > distinguish "open" operations from being "exec" operations. > > Instead of moving around in_execve, switch to using __FMODE_EXEC, which > is where the "is this an exec?" intent is stored. Note that TOMOYO still > uses in_execve around cred handling. I think this is wrong. When CONFIG_USELIB is enabled, the uselib() syscall will open a file with __FMODE_EXEC but without going through execve(). From what I can tell, there are no bprm hooks on this path. I don't know if it _matters_ much, given that it'll only let you read/execute stuff from files with valid ELF headers, but still.