From nobody Mon Sep 28 07:17:44 2026 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (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 DB6F319CC14 for ; Tue, 25 Aug 2026 04:04:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787630661; cv=none; b=h98pJyeBFrqjmBPG5zU9r6Z9UFU4+baLg5U06ckl6nyHszkT2Tu4Ghaxs6ptqpRDuQx14iF2Ss6i2XPsb3vZZUdMrVI6cErejDhZi5clLMtxK7yxyBLU2WVr4a0+eprVITHchpAqjEsSmDS05gg8/x0k77BiTYMeH5x/J5KkKCc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1787630661; c=relaxed/simple; bh=SoTvn6u1nBsHaKXnWNHeQ87Z/kyy/lzwbSFW5uKNLKI=; h=From:To:Cc:Subject:Date:Message-Id:MIME-Version; b=Xlix3aNfUIVQ9tCDLwDHPNqpZQtD8qRIl/gVPpag9qFA9k9ejvKH5K+k4EmQYYk9lCHKmUp4y8/BAg/p8A51mX3plU0h4qQPDvtbONI2uh2cXslDKeS1E+mhqcRGpFfj6Rj8utuunV0NtbEr+xS/Ts1QyYaDBwpSr/NsIAdMjiM= 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=mvKj/ACu; arc=none smtp.client-ip=209.85.208.51 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="mvKj/ACu" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-6a36982a875so6388587a12.0 for ; Mon, 24 Aug 2026 21:04:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1787630658; x=1788235458; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=bIz1d+M2XopEmaZu4JMwJQJno6roCNCxkVfrOrxuSFI=; b=mvKj/ACugcyKt/F/1km4HzrIxX3rdOVBEaei48buJYQk3hRoHW0YMxFNDLYQYWcKFI VcQiFe/6iTmH+yLvIgP+dohIPoX80hAFJ8zN8zdzZtkASHxmJOhcv+gRu3dFZ8c1/gIs 0NDu8Z26joB5A/fuVvdTFkRxc0pXrxckk4yq08KwSsfyc/A0DQnasEOxNiqfgaxyPMoM PkZu+fKK4QbyZGVyPfv7vUUVmp85gPdHIAaCoyKGGFyABccjPAKQ5bKGjs9YYfMBIArR xmSCnGxV4FqWmlBY5md1KhGYAvDeb+GIdQloXN5PBplRa51BcU8xxZkvF6SzUJmkHhtz XdDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1787630658; x=1788235458; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=bIz1d+M2XopEmaZu4JMwJQJno6roCNCxkVfrOrxuSFI=; b=GJfY9apGS0MOXqebf9EcPcgIcrU17csBFauHhCvyAyjOEsK/tWXEnbzjibBY/UfZ+U /XLjQM7sY55Sj8aYhXsqeZWNLuBbZdlmMr8bLtXMcNOzBa+jFSOFamd9Msl7d7wL/ZF9 1u9oG8vIubK3l4IKwuGnVw3Eo1jAU1dchExyqULsqQ4oNcaq6/uK1ETJkZd+CkMz/R3d S4IcTwY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:b0:6a1:f95b:8cff with SMTP id 4fb4d7f45d1cf-6a42f14d945mr36628081a12.1.1787630657941; Mon, 24 Aug 2026 21:04:17 -0700 (PDT) Received: from localhost.localdomain (dynamic-2a02-3100-af54-b201-7419-a557-62e9-4d13.310.pool.telefonica.de. [2a02:3100:af54:b201:7419:a557:62e9:4d13]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-6a59e00108asm17474345a12.2.2026.08.24.21.04.16 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 24 Aug 2026 21:04:17 -0700 (PDT) From: Karl Mehltretter To: Andrew Morton Cc: Karl Mehltretter , Matthew Wilcox , Greg Kroah-Hartman , "Rafael J. Wysocki" , Danilo Krummrich , driver-core@lists.linux.dev, linux-kernel@vger.kernel.org, syzbot+9cb1ac7fce4944ba9165@syzkaller.appspotmail.com, stable@vger.kernel.org Subject: [PATCH] klist: avoid accesses after waking klist_remove() Date: Tue, 25 Aug 2026 06:04:08 +0200 Message-Id: <20260825040408.59225-1-kmehltretter@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" klist_release() publishes waiter->woken before its final accesses to the stack waiter and node. klist_remove() can then return, allowing the waiter to go out of scope and its caller to free or reuse the node. Clear n_klist and take a task reference before publishing woken. Use release/acquire accesses for that publication and wake the referenced task. The task reference keeps the waiter task alive if it returns and exits before wake_up_process(). wake_up_process() provides the full barrier required by the sleep/wakeup protocol, so remove the explicit mb(). Fixes: 8b0c250be489 ("[PATCH] add klist_node_attached() to determine if a n= ode is on a list or not.") Fixes: 210272a28465 ("driver core: Remove completion from struct klist_node= ") Reported-by: syzbot+9cb1ac7fce4944ba9165@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D9cb1ac7fce4944ba9165 Tested-by: syzbot+9cb1ac7fce4944ba9165@syzkaller.appspotmail.com Cc: stable@vger.kernel.org Assisted-by: LLM Signed-off-by: Karl Mehltretter --- lib/klist.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/klist.c b/lib/klist.c index 332a4fbf18ff..7242f4cc1c1b 100644 --- a/lib/klist.c +++ b/lib/klist.c @@ -36,6 +36,7 @@ #include #include #include +#include =20 /* * Use the lowest bit of n_klist to mark deleted nodes and exclude @@ -187,18 +188,23 @@ static void klist_release(struct kref *kref) =20 WARN_ON(!knode_dead(n)); list_del(&n->n_node); + knode_set_klist(n, NULL); spin_lock(&klist_remove_lock); list_for_each_entry_safe(waiter, tmp, &klist_remove_waiters, list) { + struct task_struct *p; + if (waiter->node !=3D n) continue; =20 + p =3D waiter->process; + get_task_struct(p); list_del(&waiter->list); - waiter->woken =3D 1; - mb(); - wake_up_process(waiter->process); + /* Publish only after the final waiter and n accesses */ + smp_store_release(&waiter->woken, 1); + wake_up_process(p); + put_task_struct(p); } spin_unlock(&klist_remove_lock); - knode_set_klist(n, NULL); } =20 static int klist_dec_and_del(struct klist_node *n) @@ -250,7 +256,8 @@ void klist_remove(struct klist_node *n) =20 for (;;) { set_current_state(TASK_UNINTERRUPTIBLE); - if (waiter.woken) + /* Pairs with the release store in klist_release() */ + if (smp_load_acquire(&waiter.woken)) break; schedule(); } --=20 2.39.5 (Apple Git-154)