Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp1026429rdb; Fri, 2 Feb 2024 11:03:20 -0800 (PST) X-Google-Smtp-Source: AGHT+IFijMY/a4Z4UB4A+A7S9scYCJIo99SJY9GfbSX4/BGmXy8o7BZk3Ru9ufqzvTiB1K+czqfT X-Received: by 2002:a17:902:848b:b0:1d8:fcac:eff0 with SMTP id c11-20020a170902848b00b001d8fcaceff0mr7869158plo.9.1706900600563; Fri, 02 Feb 2024 11:03:20 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706900600; cv=pass; d=google.com; s=arc-20160816; b=JQsMjggHS4sN8A6OlZxlNw9KjK/87qUSox3sn74gBEHetumuGS+dt9irQdUe7/9JMB uqAbJcwG7x6D/oBer9trJO2OU38xXWQEz5kYIrzx9hW9fGlOpSK76eZuJlkqsNha48QA 9av1za/+odJqhQCGivQBXpsDiN993GOHM9puAR7q+/r4ZV3DW1oIa0ugGeefFstMe0Aq jq3lIkqWcA8WIymYgNBPXJ+YswEQBIb5ugkMwque/1LeFiR1J2RQkbMVpJOqBp622A15 RTLQF7i0UxyA2v/xjGO+t/HJ/KjubHsgrFrES+6G4VS94CtW3lLRC7/tXu/I7Fff8uZZ b3rg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=U7zqPNLeOzITdl5LYbjOEm8d/dfeRoFB98j1bYReVR8=; fh=y3fRC1Ssi+SLTbubL9q1KnZb8Wai6vGwWQW4r1pfLEU=; b=tqiPU8vdorF8XeuuNAb7tck/Czu0nXjdfbiI/2oJ1Sj7U8oLJiciNRMTLsAVGwj1a3 MfnNzrbv6Vhxhwb4ro7RmKFzRR84nCtt7hnze28Hy4iUJsdkkyei1EPeYBmtdH5tdOhD SCgnJijh+E3pWX+lLisIrOIEOeKf7iXhlD70+4Bowz++TKozWO9YTMqxb8/bEcAGlg9H yW1BwdH1EpZFjE5DYV0/j2leWuVfzUNnDMqAXvoLsYvezsN+avnIDNl7SZLt8pCvmGxT o1dyPsud1wc6amtpt/JlSOjZiVd9UNk9Ylzlixen1aygdASrRg0IvAghf2U8H/qfYqlY YDSg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ku6zuzzN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50424-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50424-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org X-Forwarded-Encrypted: i=1; AJvYcCUunQMGNHcq3IaJ3IscxxuUTkR7pvaahAiSC+vt+DUUsxSecL8LaGpkp7GyXfROz8POpfMSspURK3D4/9BqjshVM/89rDYFz/4+fn9ISg== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id g2-20020a170902c38200b001d4974385bdsi2079797plg.411.2024.02.02.11.03.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Feb 2024 11:03:20 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-50424-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ku6zuzzN; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-50424-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-50424-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 37B3F284DCC for ; Fri, 2 Feb 2024 19:00:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 39F9915AAD4; Fri, 2 Feb 2024 18:42:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="ku6zuzzN" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 5D41F1565E2; Fri, 2 Feb 2024 18:42:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706899331; cv=none; b=ZpxDiZAVy2kYGtZYSXDhTGqCFFHSAIc31TGAtatrqYJ2+CO50X3Kuekd//R9x3CyLk+G/rHvwG8jzu7JNjAZR1JXHGOlrgvh06INfsgqTm2l/JEnLnbBe1o/SWIOY3ZJEtJKo9GFhR5mIKZANJpowGpQ9xz4fyQ+B2iVA6NDDiQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706899331; c=relaxed/simple; bh=uezgj+oNmphdSlN+YJCe2E3qwAs5jx2TqUTdE4zM3s0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=AQ0frfX3h0Z+N2KvBaEZTDwA10zBIqpMilxeTu/hEdmjG7VxRRdPSE4ZMaaCpltCVVO67sttutkcaevtd6nionkEHY4HiCygi4osO4kaJ0SKTOJMh+Bs+Gvu45gBiJkiRgUHN9VarVPHGd8RmSFiYZSFI6Y14ASi9t/oDkF8UaE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=ku6zuzzN; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id AB3D4C433C7; Fri, 2 Feb 2024 18:42:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1706899331; bh=uezgj+oNmphdSlN+YJCe2E3qwAs5jx2TqUTdE4zM3s0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ku6zuzzNIbi9A/s02NLgUU8okONmdLEpNsH16M6BIfmh9bu1BXW1c9fhjfXM1MYlY zLtwzefzC3fZimjrQSFuHwboIBrOoXBlI4ERudQqOMJI4TUuqLytJc+SaCrVLfIbAQ z44kWVoDTl6HUrT+KJbCz8KodCpjO7KqPEQOPZ2njanUtNokkx/grgMAtATYh+2SVc OpeGyYU+8QmkuRuTMtUfJmJPMqOmAzw/okghweZEM6nECVtwIyUZr46pwV6rxVj74m uPSnMgOvbnRCkB1i1e+HRlkUOcM6vJwKzRYm0KZ2bB/nvuoOU4a0+PIuLknCW9+2A4 WslHLdHkIEJHg== 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, michael.christie@oracle.com, mst@redhat.com, mjguzik@gmail.com, npiggin@gmail.com, zhangpeng.00@bytedance.com, hca@linux.ibm.com Subject: [PATCH AUTOSEL 5.10 7/8] exec: Distinguish in_execve from in_exec Date: Fri, 2 Feb 2024 13:41:51 -0500 Message-ID: <20240202184156.541981-7-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240202184156.541981-1-sashal@kernel.org> References: <20240202184156.541981-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 5.10.209 Content-Transfer-Encoding: 8bit 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 983295c0b8ac..b809f4a39296 100644 --- a/fs/exec.c +++ b/fs/exec.c @@ -1565,6 +1565,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 aa015416c569..65cfe85de8d5 100644 --- a/include/linux/sched.h +++ b/include/linux/sched.h @@ -806,7 +806,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 633b0af1d1a7..906dbaf25058 100644 --- a/kernel/fork.c +++ b/kernel/fork.c @@ -1452,6 +1452,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