From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) (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 A9C0538552B for ; Thu, 26 Feb 2026 07:23:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.47 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772090620; cv=none; b=oeQbxe57nSxaEB+llLo2qZS8i5B/2S2dURm9a/yDhbMOQhzkYGZErIF03/Oooi/GDPggbFY/xv2Ta6IXBGAgsOdTWgHFZdM8kg8URsyLfpfH5f79de+uvTXNoCTovXrst5o3xMUlQW5hYb9ab+iMVkUQZOxXG0MQvZ1Gh7CvYuQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772090620; c=relaxed/simple; bh=TlBZnFpvIh38dF8RUFeIpP5uiHDD561lacDSVT+06AM=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=bqmGidUthyWgg5B+U67Wz7nHvGvpBd5GmBqyQATE2aJrMd5/2ZP96oyvoHqKouIcFgsaMmMAQd/Tnz1CmWLhV+aJduoE6tLqC2FTutpVf1Hr8VClCgUP4s2YFQUGn5XKCNgYHMZFR1Yytaeo3r3dM7364SsyqDagFovWv+j2V+Q= 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=cJOeKd+I; arc=none smtp.client-ip=209.85.128.47 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="cJOeKd+I" Received: by mail-wm1-f47.google.com with SMTP id 5b1f17b1804b1-4837907f535so4622355e9.3 for ; Wed, 25 Feb 2026 23:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772090617; x=1772695417; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=7bAWuIclbGkjTG1lyT9k6PZ5UeO0kHHEk0ofPaogQPo=; b=cJOeKd+IbPMbtIMs5IVHTQ/8zf6EK89KQVZel+knRULxLiN51FTx4isr3NRqTSd4hN Gn8j04pazfQCXaoK0smaDfF7v53Z6vphH+yhDcmKi+GvVB/S6zb6C+gFqrdY5EUQab2B P98oXdnSS+JmzY/zKdjlUWtCckMX/d9utvDy6GvpjUPKlabbhB1m3ZsrWRqHnHa86zk6 Oo+xxyeFeOiUOxtjPe0wXnhpus0EuZO09Phj1mshwtvmrW4zVl3j5NDCsgUH7b534sJU kB5kfKeC9T1DjS/jO99b3kkW3mhx6uFcuJgZJBCo9jyw7XL/3+4zh3ZU9me8WNCt2GDz XFRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772090617; x=1772695417; h=in-reply-to:content-transfer-encoding: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=7bAWuIclbGkjTG1lyT9k6PZ5UeO0kHHEk0ofPaogQPo=; b=QGUMJ67egKnUd4CKfx6+SKHC3DXQaCnPMQ/d6mwu20+m5N2Sb+/hSuUWVcV/sFPSUo Zfdjb/6UtbBk7jHh3krNpyXLT2cBKhd9rIRM7rYr6gKgklOvyxxxQPQhKBblXB63+2bc XkMM9yDgeQoPzLXz1CD5cDEQrSMZdshJDrh+/8lrayu+H+ngImVb/21JwcX1estZdJqv Qn7f9zaermo4E0/r67YhgFWXclaaQBUhzDKHH5BMPAQFBJYBJY0LuSsr8P9282ysMVnh grc7nMM79F8v8sklmZJckq7VPRof4pJkvPxbkxjF5FKlPx1g8XXzCs/0nLTri/8lYzUh l9Rw== X-Forwarded-Encrypted: i=1; AJvYcCUWoK6tQeWMF0c/TtISdp7h7RC2qqCO6Yi166vBOYlvIYATJ7ZG9nzlZFMTBv71Syjxkwtx+TtEf41w55U=@vger.kernel.org X-Gm-Message-State: AOJu0YykPwwKIy3cd9yQ1RMoZy2sXOxl2fr16Oq9Np6et43rY+dnjuit a944WFP/eLLZG92zGBn05LHO20VxGx8gyZBT18/jnxgTMevvScERsGND X-Gm-Gg: ATEYQzwYluby0LGLYOnzWwu+Q5EV3CyC+NaKLHKcYzbvLEXm8SOXahJy3QvM/KjIgx4 e9R/q62yPwzEMRDz7OSJytzlT5ATZPadd0ah6LNea/Bk6hIyd/tsSVXGQHJMa9B6ObIYFFtPe52 /0PMTRUFBViHJG8oDZNYE08QDLq/AFhsSjPKk697vNuqj8uiKf/42ND340rBPlv58UexZt/ay2I xeJy8Nfs8vR3TJJnTpr9N+1lSGqlHZLO/8jIqytKUlWNR5jf9gzhAQAZHgp44okZVdMJOtcXq8P nBfTmUz8NaHW6bzkPgfy+JbpS5rQ93AyIbavOW5ccAoJC8EkIeKe65tfLTHUP/5QqiN1p3QUmEp 8HjwKlc6ha7bF//6OBXpspXVYkTgTuCeO1pf2ZPfbbE3ooZTZ+mW49HbvVzpLefLuIaCdVaGXMl BmMr/sNeOcNb16khtDKLCwY2jXjBaYeU0fR1FO+dmI4nppZ2vV X-Received: by 2002:a05:600c:198b:b0:483:9cdc:8ac1 with SMTP id 5b1f17b1804b1-483c216fa22mr46355745e9.11.1772090616640; Wed, 25 Feb 2026 23:23:36 -0800 (PST) Received: from localhost (ip87-106-108-193.pbiaas.com. [87.106.108.193]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-483c35910f1sm26165275e9.2.2026.02.25.23.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 25 Feb 2026 23:23:36 -0800 (PST) Date: Thu, 26 Feb 2026 08:23:24 +0100 From: =?iso-8859-1?Q?G=FCnther?= Noack To: Yihan Ding Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , Paul Moore , Jann Horn , linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org, syzbot+7ea2f5e9dfd468201817@syzkaller.appspotmail.com Subject: Re: [PATCH v3 1/2] landlock: Serialize TSYNC thread restriction Message-ID: <20260226.e93d63ac9547@gnoack.org> References: <20260226015903.3158620-1-dingyihan@uniontech.com> <20260226015903.3158620-2-dingyihan@uniontech.com> 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=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260226015903.3158620-2-dingyihan@uniontech.com> On Thu, Feb 26, 2026 at 09:59:02AM +0800, Yihan Ding wrote: > syzbot found a deadlock in landlock_restrict_sibling_threads(). > When multiple threads concurrently call landlock_restrict_self() with > sibling thread restriction enabled, they can deadlock by mutually > queueing task_works on each other and then blocking in kernel space > (waiting for the other to finish). > > Fix this by serializing the TSYNC operations within the same process > using the exec_update_lock. This prevents concurrent invocations > from deadlocking. > > We use down_write_trylock() and return -ERESTARTNOINTR if the lock > cannot be acquired immediately. This ensures that if a thread fails > to get the lock, it will return to userspace, allowing it to process > any pending TSYNC task_works from the lock holder, and then > transparently restart the syscall. > > Fixes: 42fc7e6543f6 ("landlock: Multithreading support for landlock_restrict_self()") > Reported-by: syzbot+7ea2f5e9dfd468201817@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=7ea2f5e9dfd468201817 > Suggested-by: Günther Noack > Signed-off-by: Yihan Ding > --- > Changes in v3: > - Replaced down_write_killable() with down_write_trylock() and > returned -ERESTARTNOINTR to avoid a secondary deadlock caused by > blocking the execution of task_works. (Caught by Günther Noack). > > Changes in v2: > - Use down_write_killable() instead of down_write(). > - Split the interrupt path cleanup into a separate patch. > --- > security/landlock/tsync.c | 8 ++++++++ > 1 file changed, 8 insertions(+) > > diff --git a/security/landlock/tsync.c b/security/landlock/tsync.c > index de01aa899751..xxxxxxxxxxxx 100644 > --- a/security/landlock/tsync.c > +++ b/security/landlock/tsync.c > @@ -447,6 +447,13 @@ int landlock_restrict_sibling_threads(const struct cred *old_cred, > shared_ctx.new_cred = new_cred; > shared_ctx.set_no_new_privs = task_no_new_privs(current); > > + /* > + * Serialize concurrent TSYNC operations to prevent deadlocks > + * when multiple threads call landlock_restrict_self() simultaneously. > + */ > + if (!down_write_trylock(¤t->signal->exec_update_lock)) > + return -ERESTARTNOINTR; > + > /* > * We schedule a pseudo-signal task_work for each of the calling task's > * sibling threads. In the task work, each thread: > @@ -556,6 +563,7 @@ int landlock_restrict_sibling_threads(const struct cred *old_cred, > wait_for_completion(&shared_ctx.all_finished); > > tsync_works_release(&works); > + up_write(¤t->signal->exec_update_lock); > > return atomic_read(&shared_ctx.preparation_error); > } > -- > 2.51.0 > Reviewed-by: Günther Noack