From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1795947252; b=U4kj9tPAEmU6sN1RqGGhG0zZdveFRdHE8f3wRoPmCXBdh93QfeTBJVVB9sqKk2f9Pftv ffNqpOxBrJkeIPtp7PlijnRpF9eus286eWnoCuwhXeO64pyY90oJIOz73Gw7080gAGnWK 6TWClzwKslp33BkNda2zdAwza8PWZonKoGw5bpv+GqSWJ+nfg/BCfabaKCK6AArZhe+PC ljY/k5m76OsJkYzP8V4Eq4Qe+vmMsQT9KdexDuH7AaLdU0oZ2He7LVmUZB9CAmJeP/6/U VzqrReYNEHEhwGt96sKK5gvJcXTY62S92OFUjyaZ/D7pjnswjxRunz69YmwsezvPCxQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1795947252; h=Received:DKIM-Signature:From:Date:Subject:MIME-Version:Content-Type: Content-Transfer-Encoding:Message-Id:References:In-Reply-To:To:Cc: X-Mailer:X-Developer-Signature:X-Developer-Key; bh=0YelYYqPKeHvW8t5bj2/T+0yXrn8o8+jlGRNtVzj5Rw=; b=YWheT46UKh7vF1aeqLGaFlsRGcYWjJt3zyY/YCzK+lJ7J91xLv124nONQMrtJ8to1zGz lw9GQ0vgtTQpKkgYhi7w9FwHtXCigKiBhRBon2w0wrx6UKYELcU0jSKz+xZX8FyBENKhl 8U020k/Bcf/Sx/3A4Xyau75T7LrzILn9U8Z4sbpFgzdl214opzfCpWwCzBdhCvEcN+0n8 g/tnWaW+cD86J1bIPHS0AUy9V4TNO2KaRK2dvaWMxdk/6m8TPWkG2AA0Wp9lSK3jxUoY9 0ZEiYM0JbQO0i2yn/JB24y9mbcE9w59lEh5SohvpytPyXvYtXcZfXVUbBV/sCiuRj7Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kZzKFnKU; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D2AF2606A31C; Sun, 29 Nov 2026 10:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=kZzKFnKU Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6B31A1F00896; Sun, 29 Nov 2026 10:13:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1795947252; bh=0YelYYqPKeHvW8t5bj2/T+0yXrn8o8+jlGRNtVzj5Rw=; h=From:Date:Subject:References:In-Reply-To:To:Cc; b=kZzKFnKUQUbqbM39/re+13IB4kOZ6mjApQ8Sp0HVCSmPs/Og6iZlu7M309cp63sXg k2EZs0w8USr0Gf7x0qgyW5OiqNfXAZ6s5AYzEDy1TxGerzXv/Hzzs5/Y4Om14Ya330 cc8vLoDEr4F6PX1co8pCMfAdQCWQs27VneqhLDntFFVpHsjwWNyUOoq0WcC3YypsRP utbhzQ5tcCn2hdq5Lx/iaS+ncrffTdIMdK27Iu0dNeC/muROvUMhoHEy0yeVTTRptQ 4qnliDflX4ECXaIem55a73SahLfBZLYfxhVK78QG5a+W2CArq0uio2fE6rS4SMV5e5 uImCrlUf3u7rQ== From: "David Hildenbrand (Arm)" Date: Sun, 29 Nov 2026 11:06:54 +0100 Subject: [PATCH 23/32] mm/mempolicy: check access under exec_update_lock X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20261129-fixes_core_3-v1-23-f66094116801@kernel.org> References: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> In-Reply-To: <20261129-fixes_core_3-v1-0-f66094116801@kernel.org> To: Hugh Dickins , Baolin Wang , Andrew Morton , Mike Rapoport , Peter Xu , Michal Hocko , Kiryl Shutsemau , Manfred Spraul , Davidlohr Bueso , Cyrill Gorcunov , Zi Yan , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Yang Shi , Zach O'Keefe , Song Liu , David Stevens , Kefeng Wang , Alex Williamson , Suren Baghdasaryan , Dave Jiang , Matthew Wilcox , Miaohe Lin , David Rientjes , Shakeel Butt , Jan Kara , Mel Gorman , Jason Gunthorpe , John Hubbard , Gerd Hoffmann , Vivek Kasireddy , Dave Airlie , Matthew Brost , Joshua Hahn , Byungchul Park , Gregory Price , Ying Huang , Alistair Popple , Hagen Paul Pfeifer , James Bottomley , Felix Kuehling , Alex Sierra , Balbir Singh , Kairui Song , Qi Zheng , Axel Rasmussen , Yuanchu Xie , Wei Xu , Baoquan He , Oscar Salvador , Muchun Song , Dan Williams , Rakie Kim , Hao Li , Christoph Lameter , Roman Gushchin , Sebastian Andrzej Siewior , Clark Williams , Steven Rostedt , Alexei Starovoitov , Xu Xin , Chengming Zhou , Shivank Garg Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-cxl@vger.kernel.org, linux-rt-devel@lists.linux.dev, SJ Park , "David Hildenbrand (Arm)" , Chris Mason , Oleg Nesterov X-Mailer: b4 0.16.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=3507; i=david@kernel.org; h=from:subject:message-id; bh=6L9fFdPqcD1tbHGDW/ml6/iC+3h4bew3Di8xHeH12Z0=; b=owGbwMvMwCF2/OVpCdfQ3ZWMp9WSGLK5f+oe3vAi55hOSN2WqbYxc9UF7lvp7wp52//4+HHFo 4p3uSIXdJSyMIhxMMiKKbIEBd83ePlyXW21Gx8zzBxWJpAhDFycAjCRn0sZ/ilGsotynGMsz/qi 1XQp6rA9v6T1ZccTx8WO3YpSFnpXU8DIcGjXe6Pk/m83Obeu7D4YbKB7hG9fQFRv2P6tJ/o4WMO T2AE= X-Developer-Key: i=david@kernel.org; a=openpgp; fpr=1BD9CAAD735C4C3A460DFCCA4DDE10F700FF835A From: Chris Mason The access check in migrate_pages() can race with concurrent execve(): if the target task execs a setuid binary, migrate_pages() can migrate the pages of the new mm, which the checks would otherwise deny. The impact is limited, but we should just handle it consistently. kernel_migrate_pages() calls ptrace_may_access() on the target and takes its mm with get_task_mm() later, so the credentials that the check sees have to belong to that mm. execve() replaces the mm in exec_mmap() and the credentials in commit_creds(), and holds signal->exec_update_lock for writing across both. Let's fix it by holding the target's exec_update_lock for reading until we have grabbed the mm, as move_pages() does ever since commit 13f77972b94c ("mm/migrate: find_mm_struct: fix race between security checks and suid exec"). Regarding dropping the RCU read lock earlier, as explained by Oleg: "kernel_migrate_pages() calls ptrace_may_access() under rcu_read_lock() for no reason. This is a leftover from before the commit 313674661925 ("Unify migrate_pages and move_pages access checks"), where rcu_read_lock() was needed to protect __task_cred(task). So we can drop the RCU lock right after get_task_struct()." Waiting for concurrent execve() is not really relevant, and move_pages() already does the same. This has low urgency, as the impact is limited. No need to CC stable. Fixes: 313674661925 ("Unify migrate_pages and move_pages access checks") Reported-by: Oleg Nesterov Closes: https://lore.kernel.org/r/ahMt6xyUNnacZU8-@redhat.com Suggested-by: Oleg Nesterov Signed-off-by: Chris Mason [ david: simplify description and comment ] Signed-off-by: David Hildenbrand (Arm) --- mm/mempolicy.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 1d999a037d1b8..1f68a463b3bc7 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1981,6 +1981,12 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, goto out; } get_task_struct(task); + rcu_read_unlock(); + + /* Exclude execve() until we have grabbed the MM from this task. */ + err = down_read_killable(&task->signal->exec_update_lock); + if (err) + goto out_put; err = -EINVAL; @@ -1989,28 +1995,28 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, * Use the regular "ptrace_may_access()" checks. */ if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) { - rcu_read_unlock(); err = -EPERM; - goto out_put; + goto out_unlock; } - rcu_read_unlock(); task_nodes = cpuset_mems_allowed(task); /* Is the user allowed to access the target nodes? */ if (!nodes_subset(*new, task_nodes) && !capable(CAP_SYS_NICE)) { err = -EPERM; - goto out_put; + goto out_unlock; } task_nodes = cpuset_mems_allowed(current); if (!nodes_and(*new, *new, task_nodes)) - goto out_put; + goto out_unlock; err = security_task_movememory(task); if (err) - goto out_put; + goto out_unlock; mm = get_task_mm(task); + up_read(&task->signal->exec_update_lock); + put_task_struct(task); if (!mm) { @@ -2027,6 +2033,8 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, return err; +out_unlock: + up_read(&task->signal->exec_update_lock); out_put: put_task_struct(task); goto out; -- 2.56.1