From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (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 080783AC0C5 for ; Sun, 24 May 2026 16:58:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779641917; cv=none; b=JZeAl9FNdJWXuHIyH2tn6RTczJiEDWCkj9qBOCY9ojNtK20KZBYbS5Yam+RQ6qNxXm2Cmk2guCtZh3aKiPBlW7kjspvU6hYDFEOIuh19Ew8XrGFZ6HTlw8oGamIRpuVL7GiASxo0ZZgyXRZekintj3rnNOOyw+Zp10Atco1yLSw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779641917; c=relaxed/simple; bh=oraoDfKvAg6Qzi7tm1y6JPOAo7evISin/YWdv0pGGe4=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition:In-Reply-To; b=Ma1Y7/hryiFzy+Htgttt35gBWl5aWtvYp0LloDeMhlytdEBu+008onbU04aDjpUDsVCEWHL/Qedyud/+cxSrtm5o9WZPc56uj7WriN4qOszImqzHChu+Gm8TcRl4DLHBUuGguHLhBbG0EArltuWBS/sa4p45Zpv99ZG/kljrtJ0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=HhSMCbH8; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="HhSMCbH8" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779641915; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to; bh=fx9P0XwhXW7SmBYCB2M08iDg2xYh5gHDBQzMHIVQsRI=; b=HhSMCbH8nDMdUqUuwOa+Hp4QRzq0tybHvbUgjxQZQKqYMO10jayNpySZkPj82lCAA4Nc4+ W+YLxniyd1N3lu2ZPTRf7fdG8dKAXj8KqMNSnci107HMU8FA5SQCKY6z9Mmmyc81mwDda+ Dud5OKhhZKQLPXrei2w0KuwiqICjIb4= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-80-SAQWZFcuOPSreD9kou7wRA-1; Sun, 24 May 2026 12:58:29 -0400 X-MC-Unique: SAQWZFcuOPSreD9kou7wRA-1 X-Mimecast-MFC-AGG-ID: SAQWZFcuOPSreD9kou7wRA_1779641907 Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C661419560A1; Sun, 24 May 2026 16:58:26 +0000 (UTC) Received: from fedora (unknown [10.44.48.14]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id BE6D119560A3; Sun, 24 May 2026 16:58:21 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Sun, 24 May 2026 18:58:26 +0200 (CEST) Date: Sun, 24 May 2026 18:58:20 +0200 From: Oleg Nesterov To: Alistair Popple , Andrew Morton , Byungchul Park , David Hildenbrand , Gregory Price , Joshua Hahn , Matthew Brost , Rakie Kim , Ying Huang , Zi Yan Cc: Jann Horn , Kees Cook , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH 4/4] mm/mempolicy: kernel_migrate_pages: fix race between security checks and suid exec Message-ID: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 The target task can execute a setuid binary between ptrace_may_access() and get_task_mm(). Protect this critical section with exec_update_lock. Sadly, we don't have DEFINE_LOCK_GUARD_1_COND(rwsem_read, _kill) yet. Signed-off-by: Oleg Nesterov --- mm/mempolicy.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index c09ff9f9aa96..cbb45a876a93 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1902,24 +1902,31 @@ static int kernel_migrate_pages(pid_t pid, unsigned long maxnode, goto out_put; } + err = down_read_killable(&task->signal->exec_update_lock); + if (err) + goto out_put; /* * Check if this process has the right to modify the specified process. * Use the regular "ptrace_may_access()" checks. */ if (!ptrace_may_access(task, PTRACE_MODE_READ_REALCREDS)) { err = -EPERM; - goto out_put; + goto unlock; } err = security_task_movememory(task); if (err) - goto out_put; + goto unlock; mm = get_task_mm(task); if (!mm) { err = -EINVAL; - goto out_put; + goto unlock; } +unlock: + up_read(&task->signal->exec_update_lock); + if (err) + goto out_put; err = do_migrate_pages(mm, old, new, capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE); -- 2.52.0