From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 742F5C4828F for ; Fri, 2 Feb 2024 18:40:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0C4F86B007D; Fri, 2 Feb 2024 13:40:51 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0743C6B007E; Fri, 2 Feb 2024 13:40:51 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id E57086B0080; Fri, 2 Feb 2024 13:40:50 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id D33856B007D for ; Fri, 2 Feb 2024 13:40:50 -0500 (EST) Received: from smtpin07.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id AE164A030C for ; Fri, 2 Feb 2024 18:40:50 +0000 (UTC) X-FDA: 81747730260.07.061E8BF Received: from sin.source.kernel.org (sin.source.kernel.org [145.40.73.55]) by imf24.hostedemail.com (Postfix) with ESMTP id 63D0C18001D for ; Fri, 2 Feb 2024 18:40:47 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AKgOLoAH; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of sashal@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sashal@kernel.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1706899249; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=DKl1hHX7yPXfkoDTDLpNIR+CCSDOrLv9RRe6GXvmkOg=; b=t3T0krc9woBWxWdysELrCwSXj1Kiidz6HerLLfQ6y5CV69kb6eoVJ9Z2wZWBHCfr/wq1kd vS+hUotqR8fkIEqfoufw056ERiIWo/DwXaSj2vAYO0nS02tZeVs/UQgok7wBXtUlz5gngE 2AVaWhPRhhRISb3zr1c7QgRVebJMVIw= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=kernel.org header.s=k20201202 header.b=AKgOLoAH; dmarc=pass (policy=none) header.from=kernel.org; spf=pass (imf24.hostedemail.com: domain of sashal@kernel.org designates 145.40.73.55 as permitted sender) smtp.mailfrom=sashal@kernel.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1706899249; a=rsa-sha256; cv=none; b=Gf5F07VWrr+yMZuUA5i1hV+9l3r4l0MS/F0Q1uSpHV+whX1RPID57GpDerxyy4JXkU93q7 iNFPdMByCsJo2N0D11g/I3V2EoChNdbiPWrd7BQoG4bHE/SWJV1nM/TxSuEnfDmrTfDxjM kmCt7LwcV2ur8XNtxLBMQ3w19hKzIs4= Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 26FB0CE2D1D; Fri, 2 Feb 2024 18:40:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CCFDBC433C7; Fri, 2 Feb 2024 18:40:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706899244; bh=iNFafJR22TQxMVXHVTQvbaJRTbsIbHqq8o288GxB84Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=AKgOLoAHbUswOO+oBlvPqWUDOTPBZIWXrsfC64mNykMsXma+4CU/a5cZO44/3Er+d spWRmbBUyHzuULNcmczBZ2SGziF6C/3DbEMvHh5fLfn0znJ3W77iixhaXhPI6aSQeA VY6tUwBgo+68KxywmjdtV443bOHdf4b6uPxfQLXbWrbpDBaoGybpcB00L5SDDEPwIK 02QkSzRmfrSHJiU9TYOhpPSnoypTqQKAu1+aE2sy8/NGEiO+xntME1kFHaMwEqR4Ed +MkaUhx/agLiuVSzhCxsFUZmVH4oZszDIMxlbABiYcZOS1kL/vw2LdvxBu3GMMH9dK UVf+r2Y52ZxnQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Kees Cook , 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, Sasha Levin , mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, surenb@google.com, mst@redhat.com, michael.christie@oracle.com, mjguzik@gmail.com, npiggin@gmail.com, zhangpeng.00@bytedance.com, hca@linux.ibm.com Subject: [PATCH AUTOSEL 6.6 17/21] exec: Distinguish in_execve from in_exec Date: Fri, 2 Feb 2024 13:40:04 -0500 Message-ID: <20240202184015.540966-17-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202184015.540966-1-sashal@kernel.org> References: <20240202184015.540966-1-sashal@kernel.org> MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.6.15 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 63D0C18001D X-Rspam-User: X-Rspamd-Server: rspam04 X-Stat-Signature: kwejm8yp1zwm5dpn6s7z33wbk6pr36d9 X-HE-Tag: 1706899247-981354 X-HE-Meta: U2FsdGVkX19/BFHFwtxgX84oPJxcNGsEUVAdJHxWmy2ESB1eMncokp1jt9mjzcnHqevLEmSJ8K54tmx95cabpoMznhz3Z0yf5D040KBv2hXsqMK6mQxzlcVNa92jxOJlkbr4wWH26/4yHZRc7Dj8Zn6vsDL5/fOZSgGlti9BO3HcycPS7iiPOcWxXSiLag+EWMFSHFFVLR9ObI3JD/NQ1SXgu8Eq5A4u1LJWDh6MzJAUTAytHcIJq1y9ijZNI+3cJ40EbzyM7GMIeZkudAXYkkZV6XEvPvIXFYSDpFI+M9mZYWC7rTD52UBe3P/8JqxMcGfxHk1EFPDbbHsdvx7lVOkDR81MiXnvPRYnNg898znmSnEOzu4rBtMeTqWB46RNcrhqS0pJyPdeJrUSz02zjiFtDohTy2VK7InzWHIBPADA18GF6yntHyriwsfoZw7JM5iP+mAZqHXRYutJV+84XPq7+PlTdEbyViy4Vd9oWmTAm/pncJS6bLuuiGSEyY9aCXxx0aywfK/v9cvW/bAtqAtL89Db4bSM5QOHx8d2YCidTn3LLbLDS2lgTxG0CZPRsyH3K/+UzMRGHZdlwnhKRA+8ufCbxujjFFOBAu3Fi+Hr5MvD3WzE0y0w1HZ965ShRdVh5GvcyilVHQszlk+d99auhS2nGodNQPjn0AYGZ9K9zS38+Lk+URqiuafl0zbpwrmKNtuK5kk3uExbh+0rP1g4JjDjUgOFXxQs+gC02ZTV3ORdG9JGDaIWq2pqYOkJ+wC8n9apWFYZkYYM+bsaVwa1z1eWzkZWQJp3kWWxv4zUWiTmIM+jJM60gDQf5x575WtGuh6gCd9G5aSJHKrefIeGkKkTy4FKAN0S7kzEmuhcvLMj2S6NyloshlDLHqbFBB0VU2ra6966k2vjNfkjM5acXn2yA3AruIIOrMn2G7JtQXVezULewjuUrC1iz6Z/ZYkmt5TGggTl73fFFAC 1VWe2lQN T4JFo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: From: Kees Cook [ Upstream commit 90383cc07895183c75a0db2460301c2ffd912359 ] Just to help distinguish the fs->in_exec flag from the current->in_execve flag, add comments in check_unsafe_exec() and copy_fs() for more context. Also note that in_execve is only used by TOMOYO now. Cc: Kentaro Takeda Cc: Tetsuo Handa Cc: Alexander Viro Cc: Christian Brauner Cc: Jan Kara Cc: Eric Biederman Cc: Andrew Morton Cc: Sebastian Andrzej Siewior Cc: linux-fsdevel@vger.kernel.org Cc: linux-mm@kvack.org Signed-off-by: Kees Cook Signed-off-by: Sasha Levin --- fs/exec.c | 1 + include/linux/sched.h | 2 +- kernel/fork.c | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/exec.c b/fs/exec.c index 6518e33ea813..3bd1784b92c5 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1590,6 +1590,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm) } rcu_read_unlock(); + /* "users" and "in_exec" locked for copy_fs() */ if (p->fs->users > n_fs) bprm->unsafe |= LSM_UNSAFE_SHARE; else diff --git a/include/linux/sched.h b/include/linux/sched.h index 77f01ac385f7..9fb7851384f9 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -912,7 +912,7 @@ struct task_struct { */ unsigned sched_remote_wakeup:1; - /* Bit to tell LSMs we're in execve(): */ + /* Bit to tell TOMOYO we're in execve(): */ unsigned in_execve:1; unsigned in_iowait:1; #ifndef TIF_RESTORE_SIGMASK diff --git a/kernel/fork.c b/kernel/fork.c index 177ce7438db6..97dd79386c62 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1749,6 +1749,7 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk) if (clone_flags & CLONE_FS) { /* tsk->fs is already what we want */ spin_lock(&fs->lock); + /* "users" and "in_exec" locked for check_unsafe_exec() */ if (fs->in_exec) { spin_unlock(&fs->lock); return -EAGAIN; -- 2.43.0