From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f181.google.com (mail-qk1-f181.google.com [209.85.222.181]) (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 3F7ED2EEE95 for ; Sun, 26 Jul 2026 22:54:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=pass smtp.client-ip=209.85.222.181 ARC-Seal:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785106466; cv=pass; b=Rg+fWCNwxTkzUQAr2x+agT9IydHkv2KUlrar+t3oViAhazS9g+WEI7syUOCrvFjJmx50+zVCBlz3qrwsGEetJe1TnzEVwHEZVmV1gr2FlPQCsN4taKgy3r7u2/khp/Yo9/hT1PGdaqLCMBnjMOsorH70aOy8Aa1qsoodmU6cL6c= ARC-Message-Signature:i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785106466; c=relaxed/simple; bh=INH7cEdaGCjwUK+4yAesdj50e1t5cbdHTGpMEhFfT9k=; h=MIME-Version:In-Reply-To:References:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=SrT1eVxJMBRT6ox3Aji+Vv14O3zZLDaWWnNx4Sk8zLa8UU994tTiBzlp0hALX00f0TJygHlwr67DjYYTmkqp9CjxEb0Nq21tANogAZplK6UuWewPpPNvLPDVyM/vx7aZNllsDQ2rsCy90nnqd0LcOMceE3BmfEVFmcFmO+o+Qag= ARC-Authentication-Results:i=2; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=juliahub.com; spf=pass smtp.mailfrom=juliahub.com; dkim=pass (2048-bit key) header.d=juliahub.com header.i=@juliahub.com header.b=cgfh9UBu; arc=pass smtp.client-ip=209.85.222.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=juliahub.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=juliahub.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=juliahub.com header.i=@juliahub.com header.b="cgfh9UBu" Received: by mail-qk1-f181.google.com with SMTP id af79cd13be357-92e85499ffbso170219085a.0 for ; Sun, 26 Jul 2026 15:54:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1785106464; cv=none; d=google.com; s=arc-20260327; b=SvwMTQ0POvmjb5fADvXp2bvBJgoi8MFw2l3psgGakBft/lM03lJUWc2uJT4UE1mIhb hGcEnVjPaQFPzgNLce1OeGeekCHhj+1updpFMbsjJSWkirx3Tu/gB4Xvl9scX5Bv1drI e0+b0FHWfPSW495v2F9it/QpiGkN0lnGL2QL+BDZBvdBtbnzrcessr1zPGUrVVEs4gHq i9qTO72I4NsTJSikJw4MAmefitoEcbMi82GAOD76MTdvTHPCQah0H6iPG4xDs+KRn6Ww R2DQfpG6IaKWXFFa41WaBr9eIjz6bBCsU3TtmX3WXwrPQIBdLGIa4taNi/qdJIWEQhqj pyew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20260327; h=cc:to:subject:message-id:date:from:references:in-reply-to :mime-version:dkim-signature; bh=yGmhXoSde90feAqgXfhxNDvC05OmFmrJPIv3G3OJRH8=; fh=craHgqezA2CQ4tWONSAMU5Pdy89asj0BnxVAw0KGNVU=; b=bDD+v4hyPcvtIILzNPxtdvowFMmm+7t4xoU6e7IIQcAsmZupUGMym9v/wLDfTFLr1N 8TDwKRy9adVqvxz1tZp7eO4kRrmk8enEjB3YX5O2Gnin8YV4HPFGx30foZw8909/jVbF Bi6LbwRMVF0StmGNwl/kXPe1ym6c8WelqtFjOyInnWjDeB/Z6NFjMK1VgWmoimVnFUz1 3I2svlLjaBHmaKTgqhrso0+QR4/Iy6HgBEtnYt5FgatCyT2bGaWxA90DeywqvzZA7qgb sTwjyhdx8Fb2MemhyppYirvybtbli5U1Ksbgc1ofGVx61zmo5aUhbha9bcoPMx5he6jv emeg==; darn=vger.kernel.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=juliahub.com; s=google; t=1785106464; x=1785711264; darn=vger.kernel.org; h=content-type:cc:to:subject:message-id:date:from:references :in-reply-to:mime-version:from:to:cc:subject:date:message-id :reply-to:content-type; bh=yGmhXoSde90feAqgXfhxNDvC05OmFmrJPIv3G3OJRH8=; b=cgfh9UBumAhGpPmjmysjSZFym8NGhtIazbNJstC1tm4O6yXoYFuX9zKziFLw3bN5TZ P8lY8VBAV5pmrPEEeuzJ0pepuyeAg14AwbA3mmlWQzwnRhnNzQSdkHi8qMonW4di3sly WmNWk/wOBWOvYwccqAdN3yhxOB1KrFRCxhB5s9KHuIiXFi2B4Si19MYVkQhMwdd1h9uP XFWyrMZAFt6NsX7QOEkP3Ddfoh8BoehaJFugkyotB+mroEJ8sTKwUVtnD3YmvwzeHAaQ dE39QAfgpGFMWQi30JSjyWT01LgYZtFy+uiY/IIfBj7VYmO2TWzBtrJt1q+wcwqn/zY8 tEyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785106464; x=1785711264; h=content-type:cc:to:subject:message-id:date:from:references :in-reply-to:mime-version:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=yGmhXoSde90feAqgXfhxNDvC05OmFmrJPIv3G3OJRH8=; b=E8rAaohpYI3GSjmimDYuQRN27zp/SF2didkNr4yuLhfITC1RL+oM8ZdSQomj3JpswP 4u7IptVaK0zbchbnFB3qwonc9l7UYzNzlynM5zZOMpo8gAOAK6KjSK1NzGyO5KF1lboR r3p9U9Tt6ESp2Se+2mVx7MQtxXPIoDm5TtXSo2t2uL4svru5FEZwevGvk1jTDQ1VtXtz qh/4JF81C4kcLzfnam40jIOjjgNDnYKxB+Ts+d1G7OU0F5Vbw8MoSA8FdbyusM6EwQeq k6z/hcv03b1S2mPoMm4bw791DiileDjFgQ7h1N+Fwkeq0o6ZnaC+djUNflVdxThjHl1E FwzA== X-Forwarded-Encrypted: i=1; AHgh+RpRg/GLOxDlC/v2EzKrRszr36e2qhGHB2mWZM9zplAYYionRmm2jr4hU1VSLx5McND9fEPFfBfDIyOVSQs=@vger.kernel.org X-Gm-Message-State: AOJu0Yxr9BkjQQFbwD4aI/BIP7imsrF2mzFOtyAOvFeexSEob1W3Py/s lyMQOxjHD6poRpM6PAvibygNK45YDnt6t6oe+MgGTFCW/R0MQmuwgj2ef46H+Ym0cQ03YfvIEEM ATfsA9ot0FCImmwysiRX1yM8srthXlisWWNTCwGvzLvsvHgqR4NE+ X-Gm-Gg: AR+sD12tJALCny/Ln9Rlha1uAtjAZt+fLg+pT3qj7ClS5yOZxb0i4UXnmrkvF8343af wTio1VM5Fzdu02AcbHqTYC3xEaxuPwILg7yU0Un2haQzIuChIhr4uO608qwK7w8ykPazFlGu/sn fSADwBnrheJBbvMw5JFZAJMu/FO3inAHkRG2+HS06FQmZbVPWmWcTx5lMlUNvsaY311RfruQMa9 LdOlZB7RDdx+Fm8HnIeMOog6/FXbGlaqGqp2JdQ02bpJBenIoV00gd8VihLh/rnU4pLGv/ECYVt zioVIYuiemBBehuDgQ== Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:620a:471e:b0:92b:855f:e91b with SMTP id af79cd13be357-932df6aca72mr675260785a.26.1785106463777; Sun, 26 Jul 2026 15:54:23 -0700 (PDT) Received: from 960782262270 named unknown by gmailapi.google.com with HTTPREST; Sun, 26 Jul 2026 15:54:22 -0700 Received: from 960782262270 named unknown by gmailapi.google.com with HTTPREST; Sun, 26 Jul 2026 15:54:22 -0700 In-Reply-To: <87zezdiiyg.ffs@fw13> References: <87bjc0led9.ffs@fw13> <87v7a7jeav.ffs@fw13> <87zezdiiyg.ffs@fw13> From: Keno Fischer Date: Sun, 26 Jul 2026 15:54:22 -0700 X-Gm-Features: AUfX_mx_IaCTsMQHYhejNBmZReJLtMTG7W9zcKgou_HEaACiBvcFIj4q9d_306o Message-ID: Subject: Re: [PATCH] futex: Prevent robust futex exit race more To: Thomas Gleixner Cc: Keno Fischer , Ingo Molnar , Peter Zijlstra , Darren Hart , Davidlohr Bueso , =?UTF-8?Q?Andr=C3=A9_Almeida?= , Yang Tao , Yi Wang , Linux Kernel Mailing List , stable@vger.kernel.org, Florian Weimer , Oleg Nesterov , Christian Brauner Content-Type: text/plain; charset="UTF-8" On Sun, 26 Jul 2026 22:39:35 +0200, Thomas Gleixner wrote: > Something like the compiled but completely untested below. Two issues noted below. With those fixed, passed my local test cases. However, I re-ran the full TLA+ analysis over this protocol and it doesn't fully resolve the lost-wakeup issue (both your and my revised patch). In particular, if we drop the hb lock for a pagefault, the waiter(s) we collected could have died and run exit processing before we perform the store (so exit handling wouldn't have performed the extra wakeup). In that case, waiters behind are stranded. I think the simplest fix would be to separate the count and waiter collection and only ->wake the waiters *AFTER* the release store has run successfully. > +static int collect_waiters(struct futex_hash_bucket *hb, struct futex_wake_q_head *fwake_q, > + union futex_key *key, unsigned int nr_wake, u32 bitset) > +{ > + struct futex_q *this, *next; > + unsigned int matches = 0; `matches` cannot be local here - either needs to go into futex_wake_q_head or needs to set `waiters_left` in `continue` path an the robust nr_wake path. > +/* > + * Wake up waiters matching bitset queued on this futex (uaddr). > + */ > +int futex_wake(u32 __user *uaddr, unsigned int flags, void __user *pop, int nr_wake, u32 bitset) > +{ > + bool robust_unlock = !!(flags & FUTEX_ROBUST_UNLOCK); FLAGS_ROBUST_UNLOCK > + if (!bitset || nr_wake < 0) > + return -EINVAL; Noting that this changes userspace ABI for `nr_wake < 0` (e.g. for userspace accidentally passing UINT_MAX rather than INT_MAX), although the current behavior is of course surprising and in a quick audit, I didn't see any public userspace code that gets this wrong, so worth trying probably. It's certainly better behavior.