From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (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 42B024D8D95 for ; Tue, 3 Mar 2026 16:20:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772554815; cv=none; b=oSJSS0+g5bYwjSuWU+gnr8KN7gxqzu0QkAGPSo4Vh2EP2p1ZgNGZS2LF/6Y3Po0grBAHYrhEZ//ihzgmSmPI6SUVEj+eMcAcv4BkRhDW8C4geMCRgQzTMTMMTtq4er3N1Y54a82XKoGqf4AV80r4dnkHX8946l4AmS+0dAtNgLk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1772554815; c=relaxed/simple; bh=pRWVtA0NPBuRlebAWpqWGdY4rkxOs6wGjx/Hbb76f4Y=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=V+0z0yivoT3km9GTcWPLTopWlogH5XnngZXzOkMm+KDV1C0xNPSAbw3lqpiJ01pWtTpl3uU4jNXDosLSV0w3r5CXTNDot74qNTDbfSPFOKVBnV/WX6luMp8zroPc904ZNDjq9X6l6L4F1zp2iNG8/YnndNykd1xB26qdy6M6tV4= 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=WSJe0M9f; arc=none smtp.client-ip=209.85.128.182 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="WSJe0M9f" Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-79854193a54so57352337b3.3 for ; Tue, 03 Mar 2026 08:20:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1772554813; x=1773159613; 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=o834rxCETENfWBz/+3Of3O+oNKGzA/VUJ8iJDGGROqo=; b=WSJe0M9f6srdsuyYUPjFWYa7uouZDVRVXCEjpbYlU0Xx9tlGWn1cX4+2Xqr5HgObXW K1rjwG16PHIU2SPUAhR3iciAmESCjFqnPrHjgWF/5/IU0TXlSG42nkDe8x8CwPrGWo3I vtxINb2qnmnVccpiv2T4cDWW6InEhcdE53Lk+1K/1GxpJmLWKpHr6pogN9zo/DUjj1Gb ziO0BH66TyPlesZuJyh+Qv/JIH/p3h/9QsPqogZATlYF5sMCf0Kiz2t7lMO9RhGjUn5O qgdLab8G+lh2pnI4ukswaaa9tanDWbspJ6JHEfZmsUcltNBNj4mKE99MMLkNo70IMu+h KCFg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1772554813; x=1773159613; 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=o834rxCETENfWBz/+3Of3O+oNKGzA/VUJ8iJDGGROqo=; b=HoNjf7WUOtHalhjj5WFk0dSGR9LshkLfR9XjLfiJM6GOinTQqUfUl6C2CiQv65dKKZ WfgNNnE2unTe3r/XpjHdVDvuXINwbySqlCskF8lEE60XjT+INQzKoPLiyJpmMXIv7mMo Vjt6qQ4CThZ1LsK93IeOM3Dei8fZEbc3fnSYHLlnaDbZHdhP0/hrmtGVIKBfezF3N72Z klQL82E54NOa5mENuSHW69dVq5P6J3KGGlyWO85/AHRNFXKbI6vtGrtL+LqThDcvmoQw yIDAVEinCglSNBspF6QYGvE0ww4zA91denvmQP/9KYku5PPdn62ROlNmSanenktcgiZv PuTw== X-Forwarded-Encrypted: i=1; AJvYcCUguEP0zNjvSOLhjo2BBZHACR85v8etOwYwD9PjYAp4YTGRpZeKu4iAVpyfwy3QFQDfin3k10txPkmACzk=@vger.kernel.org X-Gm-Message-State: AOJu0YyBwQN/xTh5VhxMcd8ZDLVQtf/4cj3iVHJdwQ67Nc5flot6pKjM j/4tyiyqhC2pXosufOxEUlGadHSJhWoqH1QB7vqm46eDLX+cnXIRE38L X-Gm-Gg: ATEYQzzn4eMJRjnTC7sWDIG6JTPcTBeCmc6eWt4yOhDucbHGzbXwFXG3o0dLxS/waMg sXCBpkdBGXytzqhnjXI0d/HFjG6Lzz4aFK8rEFodzMhN/QfWONjiDbn4y+doXexpa4pgn2Oe3k0 uAG7YIjYwajtAoseEOJqRIozLLCyl5Yrmp4K0vIMU6WzCaIDBAGVFbkCY+zSkc6H4TLJlISGjRM jyykNM0y4mheN91LEmaSOpZCCMAnWU2mMTDRVeatxrOM39o2v7MwAy1g0yWr1ftGyGZk0dNNJqG V3I0JXhsSwiLex832wpDh+kJCfuHGpk+a0XEM9+I4KFGD6XAaDNABqHxKZh+BZ2bdWO5FQXnmsk aBIFQJqFchyfZmpEkrELG8RcwprrNvyYAWf4wrqdk5i97wqmMgA8n6DLbSaCZSkcnhqv9YlT0se Cpstcg2Lk2kFGoC30lXtRmMVwjwflHQg== X-Received: by 2002:a05:690c:650a:b0:795:1d73:4d7d with SMTP id 00721157ae682-7988544b709mr153197667b3.12.1772554813155; Tue, 03 Mar 2026 08:20:13 -0800 (PST) Received: from suesslenovo ([129.222.254.128]) by smtp.gmail.com with ESMTPSA id 00721157ae682-79876c7fa3fsm65285537b3.45.2026.03.03.08.20.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Mar 2026 08:20:12 -0800 (PST) Date: Tue, 3 Mar 2026 11:20:10 -0500 From: Justin Suess To: Yihan Ding Cc: =?iso-8859-1?Q?Micka=EBl_Sala=FCn?= , =?iso-8859-1?Q?G=FCnther?= Noack , 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: 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; These two lines above introduced a test failure in tsync_test completing_enablement. The commit that introduced the bug is 3d6327c306b3e1356ab868bf27a0854669295a4f (this patch) and is currently in the mic/next branch. I noticed the test failure while testing an unrelated patch. The bug is because this code never actually yields or restarts the syscall. This is the test output I observed: [+] Running tsync_test: TAP version 13 1..4 # Starting 4 tests from 1 test cases. # RUN global.single_threaded_success ... # OK global.single_threaded_success ok 1 global.single_threaded_success # RUN global.multi_threaded_success ... # OK global.multi_threaded_success ok 2 global.multi_threaded_success # RUN global.multi_threaded_success_despite_diverging_domains ... # OK global.multi_threaded_success_despite_diverging_domains ok 3 global.multi_threaded_success_despite_diverging_domains # RUN global.competing_enablement ... # tsync_test.c:156:competing_enablement:Expected 0 (0) == d[1].result (-1) # competing_enablement: Test failed # FAIL global.competing_enablement not ok 4 global.competing_enablement # FAILED: 3 / 4 tests passed. Brief investigation and the additions of these pr_warn lines: diff --git a/security/landlock/syscalls.c b/security/landlock/syscalls.c index 0d66a68677b7..84909232b220 100644 --- a/security/landlock/syscalls.c +++ b/security/landlock/syscalls.c @@ -574,6 +574,9 @@ SYSCALL_DEFINE2(landlock_restrict_self, const int, ruleset_fd, const __u32, const int err = landlock_restrict_sibling_threads( current_cred(), new_cred); if (err) { + pr_warn("landlock: restrict_self tsync err pid=%d tgid=%d err=%d flags=0x%x ruleset_fd=%d\n", + task_pid_nr(current), task_tgid_nr(current), err, + flags, ruleset_fd); abort_creds(new_cred); return err; } diff --git a/security/landlock/tsync.c b/security/landlock/tsync.c index 5afc5d639b8f..deb0f0b1f081 100644 --- a/security/landlock/tsync.c +++ b/security/landlock/tsync.c @@ -489,8 +489,11 @@ int landlock_restrict_sibling_threads(const struct cred *old_cred, * Serialize concurrent TSYNC operations to prevent deadlocks when multiple * threads call landlock_restrict_self() simultaneously. */ - if (!down_write_trylock(¤t->signal->exec_update_lock)) + if (!down_write_trylock(¤t->signal->exec_update_lock)) { + pr_warn("landlock: tsync trylock busy pid=%d tgid=%d\n", + task_pid_nr(current), task_tgid_nr(current)); return -ERESTARTNOINTR; + } /* * We schedule a pseudo-signal task_work for each of the calling task's @@ -602,6 +605,10 @@ int landlock_restrict_sibling_threads(const struct cred *old_cred, tsync_works_release(&works); up_write(¤t->signal->exec_update_lock); + if (atomic_read(&shared_ctx.preparation_error)) + pr_warn("landlock: tsync preparation_error pid=%d tgid=%d err=%d\n", + task_pid_nr(current), task_tgid_nr(current), + atomic_read(&shared_ctx.preparation_error)); return atomic_read(&shared_ctx.preparation_error); } Resulted in the following output: landlock: tsync trylock busy pid=1263 tgid=1261 landlock: landlock: restrict_self tsync err pid=1263 tgid=1261 err=-513 flags=0x8 ruleset_fd=6 # tsync_test.c:156:competing_enablement:Expected 0 (0) == d[1].result (-1) # competing_enablement: Test failed # FAIL global.competing_enablement not ok 4 global.competing_enablement I have a fix that I will send as a patch. Kind Regards, Justin Suess