From nobody Mon Jun 8 20:41:15 2026 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.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 04FD34028D6 for ; Tue, 26 May 2026 14:42:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779806552; cv=none; b=ELx2XK+dq2G3k/Xbvmmo/2EkR3C5HV3IZBZ6LJuY3C1cuVWN+gzgt/NuTyBxXpSzZN3LHVoR/sxHIu73VIdUmEqicBTPA3q4qWvLtaTdfTV/ooWxrgrHRMAjTZbdzl7mDYm3PS+c74FNlmZsa7utgI4RioNf2bSrQ1GgNuhezNM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1779806552; c=relaxed/simple; bh=BzvnstnPZdmSxKDnjFO7JOYhpr/8Agv8q96XfbDl+b8=; h=Date:From:To:Cc:Subject:Message-ID:MIME-Version:Content-Type: Content-Disposition; b=sNjl+aLh+a0UI6hbS1X0eJQ5dc487u3PeapW/hpXBb7btja9Rrm11dFQuQv2HOqdP0dZLs1SS/3zhYBvAylCSgkbvtOVXtDQ6/QRNUAaQDR9mFulDxMhDEofoVmVhu+VGbv5QNYzyTvmsFer4pr7FYL7wv/pcn0sI9wDgYwMTD4= 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=cK7/m5wH; arc=none smtp.client-ip=170.10.129.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="cK7/m5wH" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1779806548; 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; bh=Z6DGhUFUUW1v4/QYZY1KnUPM8YZLgV/Jg4ZMzLHbAgA=; b=cK7/m5wHi8n0dxinpMsKt0cr7eKuX/uTGTfrzmv/Y0JzcHrsTRfoLRlf/FrAGqWCkSazDk RYXcgHKFBLkimo+lZPeEc3bgLt+C3ak5z8Tpo3t1k0L7qo7pmkr0HpvcCgK8x8L8vITVd4 L0oNUM/5pBaot2d5D5FBrAhE83bSe2E= Received: from mx-prod-mc-06.mail-002.prod.us-west-2.aws.redhat.com (ec2-35-165-154-97.us-west-2.compute.amazonaws.com [35.165.154.97]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-479-1J2E5ENRMkSY9Ontjkx6nQ-1; Tue, 26 May 2026 10:42:20 -0400 X-MC-Unique: 1J2E5ENRMkSY9Ontjkx6nQ-1 X-Mimecast-MFC-AGG-ID: 1J2E5ENRMkSY9Ontjkx6nQ_1779806538 Received: from mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.111]) (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-06.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id DA5341800619; Tue, 26 May 2026 14:42:17 +0000 (UTC) Received: from fedora (unknown [10.44.48.14]) by mx-prod-int-08.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id A5B60180034E; Tue, 26 May 2026 14:42:12 +0000 (UTC) Received: by fedora (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Tue, 26 May 2026 16:42:17 +0200 (CEST) Date: Tue, 26 May 2026 16:42:11 +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] mm/migrate: find_mm_struct: 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-Disposition: inline X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.111 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" The target task can execute a setuid binary between ptrace_may_access() and get_task_mm(). Protect this critical section with exec_update_lock. I don't think cpuset_mems_allowed(task) should be called under exec_update_lock, but this patch just tries to add the minimal fix. Perhaps we can later add a common helper which can be used by find_mm_struct() and kernel_migrate_pages(). Signed-off-by: Oleg Nesterov Reviewed-by: Gregory Price --- mm/migrate.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/mm/migrate.c b/mm/migrate.c index 8a64291ab5b4..e4cf664fb161 100644 --- a/mm/migrate.c +++ b/mm/migrate.c @@ -2557,24 +2557,29 @@ static struct mm_struct *find_mm_struct(pid_t pid, = nodemask_t *mem_nodes) } =20 task =3D find_get_task_by_vpid(pid); - if (!task) { + if (!task) return ERR_PTR(-ESRCH); - } =20 + if (down_read_killable(&task->signal->exec_update_lock)) { + mm =3D ERR_PTR(-EINTR); + goto out; + } /* * 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)) { mm =3D ERR_PTR(-EPERM); - goto out; + goto unlock; } =20 mm =3D ERR_PTR(security_task_movememory(task)); if (IS_ERR(mm)) - goto out; + goto unlock; *mem_nodes =3D cpuset_mems_allowed(task); mm =3D get_task_mm(task); +unlock: + up_read(&task->signal->exec_update_lock); out: put_task_struct(task); if (!mm) --=20 2.52.0