From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f48.google.com (mail-pj1-f48.google.com [209.85.216.48]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5C8C3AA1A1 for ; Fri, 15 May 2026 02:18:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778811525; cv=none; b=cob+s2uuM+V6m901jnOxzgwRel44qT+P+AEwqqsL2r39XBKUP9FSW7F7tfyShRZJkCriR4JB/jy2NyldNfke2kmhw3x0TuGX+CivwzG+qOUtH6ccoit8JSJY8EQR45zNyhcBhfuaXN2PDJ3f7fBUG/AgdBdDNzE4XoQI8MToZkQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1778811525; c=relaxed/simple; bh=YtA/+oUq61arUH9G+U4+jm9MfSezuu3/x+MSTK4rIfU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=roO9ZehwhYxLOKfoBeQyGdqbzB1cZcz2AJlLKdKzNQNf/T9XDxjIO6y6k/7ro1La9hC2XudaCU0YkhZxcHEnKklhD7Wmn6jLUb55eYeojX01vYhGvAcMbx9zLdiz5qmPcYnThtSja0aPQEgBjnKwrtc+tJ7cw6EzYl5iN5qUzC0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=T0Ke3r8p; arc=none smtp.client-ip=209.85.216.48 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="T0Ke3r8p" Received: by mail-pj1-f48.google.com with SMTP id 98e67ed59e1d1-3665a90bcd3so6914479a91.1 for ; Thu, 14 May 2026 19:18:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1778811523; x=1779416323; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=cYGbBeyYL66MJHHWtqRDGmkXp8kM8c8cIQHDr9q5rmk=; b=T0Ke3r8pSNLty6oTaDlPUtP1boHIVq5+/9nnnVtyY3afDZESCOVgW4LNtt/CMNAUFV mR0Dr8Wg0khG+LwU2Gv5tlIp+5JtDnTnu3OVfiaz8JKYC0Q2ZRdfBZXzB9vSuwjTfHjs 06ygmJABl9BGUP6nCLtOQ2KqliUnoi1rPhuWVAxgeeZ1GlbkZNP2K/g58uCKheQGSUua CL0/1D0s5P8USnQ1FzaFnMk8IQtysLLLntxPVcH80ZA1YrsOQHuWGUOV9VWr43459x0i 9kIIiNdNxQRTnPsH9AB3AAJhrUJFdafeyJbbwohiOG/HmrNF0mP1yTTWRHn3T05UprW6 jKfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1778811523; x=1779416323; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=cYGbBeyYL66MJHHWtqRDGmkXp8kM8c8cIQHDr9q5rmk=; b=ct/BxsuttWeW6iduE88XZUXs20vuwTnrapDfIh537ouUZ0uu3uQLBi8EUx+s+9tVsU 8PVrcAavNGOT9FqU3phX68qFiHDQNZC3/yFQtm7E0tMth/TqpxnRcFB3LwRD0sETRQ5R 45OwiBaaVBoOgywG8qvmgn2gsguaoF7R2mhC6MIoRMbuibdYyjP1qXyuS1ZjlB9EwXlW 2K9tSEvKLZfWtYjSv7PjMGBfzmiEMXq43cOtjZn82AxrgmhG+pKqfPbpwaGWeSP/zpEN BzN4wTnOadxmY8Vh3z72QCMsJ2RxN/1fpaOl+Ux3jMMTHQJnR5mz2KC8xHLBHQ/b9xcD mRXg== X-Gm-Message-State: AOJu0Yy97lkKANIriZDPghFrbpbeksthYQYMP/A62dk5vFI6MBPffk02 aJEa3MzT/tX+kwX2VlYKDaqH972gf96sJhz/YGqqIijn22OilpkfXIHh X-Gm-Gg: Acq92OHQt+3999GIZD8GDaP/i84UAv6gzr06eqrGmhivqQLGOoQQLPdSakVNQFXlssq DtuUoPOM0l6oRZR2xiqL46aQNl89kPuhTDJZSuWh14/jPyfvE1jPp0c2X/NpUC0AyFp+FEcV8Kp 22ESaAy8QBh0GZeP7yOGJP/JcluhadQLeHUXcOMQDnQyuiyqE8b8dq9R4U7n829FAgotxU3TkYY 2gbTuXul5OL1fyW0VFoxXVKRhPO9Si+UagcO3w+MbvnAVsP8+qyYk+awJcxpkiQVGzEz9G+yaVM uc9CN5jAoQJuis6D9bArINWprHsF1xIej2JsOkIfaWm7QrhnDyVM5u9O3MNhAJcY8M+BzBPQ+It 4Q0crVPKOiL5rE0uQ+DwfNNdLwgjcen58x6H0kA+USV0r2Oidwcg174ia8C685DGYThR6NaqpgH fPQg3aJYl7eJQzdHuDtWrrm79KthqOwsyhBZ5k2oZhz/Q= X-Received: by 2002:a17:903:32ce:b0:2b0:6a22:5165 with SMTP id d9443c01a7336-2bd7e77a968mr21383875ad.7.1778811522892; Thu, 14 May 2026 19:18:42 -0700 (PDT) Received: from v4bel ([58.123.110.97]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2bd5cfe7270sm39626325ad.50.2026.05.14.19.18.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 14 May 2026 19:18:42 -0700 (PDT) Date: Fri, 15 May 2026 11:18:39 +0900 From: Hyunwoo Kim To: oleg@redhat.com, mingo@redhat.com, peterz@infradead.org, juri.lelli@redhat.com, vincent.guittot@linaro.org, torvalds@linux-foundation.org, qsa@qualys.com, kees@kernel.org Cc: linux-kernel@vger.kernel.org, imv4bel@gmail.com Subject: Re: [PATCH] ptrace: prefer live sibling mm over user_dumpable when task->mm is NULL Message-ID: References: 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: On Fri, May 15, 2026 at 09:04:53AM +0900, Hyunwoo Kim wrote: > task_still_dumpable() reads task->user_dumpable when task->mm is NULL. > That cache is written exactly once in exit_mm(): a single > get_dumpable(mm) load taken just before task->mm is cleared. > > The load is not ordered against set_dumpable() writes performed by > CLONE_VM siblings, either via commit_creds() (any uid/gid/fsuid/fsgid > or capability transition) or via prctl(PR_SET_DUMPABLE). If a sibling > stores SUID_DUMP_DISABLE after the exiting thread observed > SUID_DUMP_USER, the live shared mm and the cached value diverge with > no later refresh, so task_still_dumpable() keeps returning the stale > SUID_DUMP_USER answer for the exiting task. > > In the task->mm == NULL branch, walk the thread group under > rcu_read_lock and spin_trylock(&t->alloc_lock); use the first sibling > that still holds the shared mm and read its current get_dumpable(). > Pin the mm's user_ns with get_user_ns() so it can outlive the > locked region (the actual ptrace_has_cap() may sleep). Keep > task->user_dumpable only as the fallback when no live sibling mm is > observable: a single-threaded exit, a PF_KTHREAD, or all siblings > simultaneously contended on alloc_lock. > > Fixes: 31e62c2ebbfd ("ptrace: slightly saner 'get_dumpable()' logic") > Signed-off-by: Hyunwoo Kim > --- > kernel/ptrace.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 44 insertions(+) > > diff --git a/kernel/ptrace.c b/kernel/ptrace.c > index 130043bfc209..2b2d8402b9ee 100644 > --- a/kernel/ptrace.c > +++ b/kernel/ptrace.c > @@ -272,15 +272,59 @@ static bool ptrace_has_cap(struct user_namespace *ns, unsigned int mode) > return ns_capable(ns, CAP_SYS_PTRACE); > } > > +static bool task_sibling_mm_dumpable(struct task_struct *task, > + unsigned int mode, bool *result) > +{ > + struct task_struct *t; > + bool found = false; > + > + rcu_read_lock(); > + for_each_thread(task, t) { > + struct mm_struct *sib_mm; > + struct user_namespace *sib_uns; > + int sib_dumpable; > + > + if (t == task) > + continue; > + if (!spin_trylock(&t->alloc_lock)) > + continue; > + sib_mm = t->mm; > + if (!sib_mm) { > + spin_unlock(&t->alloc_lock); > + continue; > + } > + sib_dumpable = get_dumpable(sib_mm); > + sib_uns = get_user_ns(sib_mm->user_ns); > + spin_unlock(&t->alloc_lock); > + > + if (sib_dumpable == SUID_DUMP_USER) > + *result = true; > + else > + *result = ptrace_has_cap(sib_uns, mode); > + put_user_ns(sib_uns); > + found = true; > + break; > + } > + rcu_read_unlock(); > + return found; > +} > + > static bool task_still_dumpable(struct task_struct *task, unsigned int mode) > { > struct mm_struct *mm = task->mm; > + bool sib_result; > + > if (mm) { > if (get_dumpable(mm) == SUID_DUMP_USER) > return true; > return ptrace_has_cap(mm->user_ns, mode); > } > > + /* user_dumpable can be stale; prefer a live sibling mm if any. */ > + if (!(task->flags & PF_KTHREAD) && > + task_sibling_mm_dumpable(task, mode, &sib_result)) > + return sib_result; > + > if (task->user_dumpable) > return true; > return ptrace_has_cap(&init_user_ns, mode); > -- > 2.43.0 > To avoid confusion: a v2 patch has been submitted. https://lore.kernel.org/all/agZ_Ug3EzCYn-Jkg@v4bel/ Best regards, Hyunwoo Kim