From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452620; b=J1Cr3GH8hAVP0HPNRABwidEnpl9tLlodtyMs6qlL/kvMrOoJmQEdbFl+PQ/v4SKv7Wju E2+BgDTSZaWdEiLjcyT9x1cyPn47QiniZGPJ0PR5Ce7xbCOZFB2sXvohZaEDblgAbaWYG gtIlBKS+h1pgR8m5UeYfqAYGQEOnR0QsUVsk6ho/dtu2UkhHCzF6QXL3YwH1khLC5qV0J fKXRG3qqWp9tQXn0quOLezrQZZer3mcnM1StkdItGjifIsjzTwz9dFAUnNdVrXAYyiQWM lObZauBVSv1PEmXpJ2dKfNWs9mFPcffHcLza4gDsxaPM7h+1jBA1DreNpdiG4k5mL7Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796452620; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: From:To:Cc:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; bh=aQfihSGHMdkM6GKjkHfhkcrz05TsdUP1tFiMF63M+U0=; b=U0pZWOxNck6SN8ZnJfVAhJGy6ga2ZvR7ERtLDGBTE0Fcao4rTKoR1NtGwKDFnSdOd+Nj McEsuYeqedmbnRjesil4GJL55Bs+ZzeLnA+Er90gDsVm5o008GiWJYA6pCIOaYJhbukSq E0bJblmayyYyeCHxRizS52055vg89jgOcBhDSxx5TcFKxyBECVDzoIw7Em8YAc7dnBh2Q ovTa6kBZ4SZSWu83mnEzZF5RrT0+OwjISj/MouSq2sKKkm8+uRqYAwFoSDj6Juwwcmfg7 AoZZlxXG65SYNEBYCud/7rx0UAr20hK1/Q0qHNYKz1E3PIWAVVE/G11YQLRlnPce58A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=RMCsnVL7; arc=none smtp.remote-ip=74.125.82.180 Received: from mail-dy1-f180.google.com (mail-dy1-f180.google.com [74.125.82.180]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E17E4606A322 for ; Sat, 5 Dec 2026 06:36:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org E17E4606A322 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.a=rsa-sha256 header.s=20260707 header.b=RMCsnVL7 Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-38747f42472so2770351eec.0 for ; Fri, 04 Dec 2026 22:36:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796452619; x=1797057419; 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=aQfihSGHMdkM6GKjkHfhkcrz05TsdUP1tFiMF63M+U0=; b=RMCsnVL7+QOWx2JLzFCMvEKnPDo+CPU0vhAauAseab1sZTbVHOy8zwolxP20ux2cBp JCAA7w6wFbUPCmT+IiCS6cA6F+EsWj02s7BDVutmSJNSxRB39l+EFvz9RaIAaeM0v3n/ 1sdD7ZugfkQPWzKVBLzpQlfq2ZT5NwoG2TCaGo/DEbeedICk/6pTVMJ03D59e/+Kw/XF xOkm+PYV+bub0sgqaMXGzmLDznUUtk2JD9oftaD7If8APTYGPGZxUo2MG7NRjDsP2eSo rwbZLtSTXyZ4/BI+Ef1a2UYlaRz9Kq6B51tXIoKBcTG4GW0AiQai9siqHXGYadoe2Ydb NUBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796452619; x=1797057419; 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=aQfihSGHMdkM6GKjkHfhkcrz05TsdUP1tFiMF63M+U0=; b=VKpRXFdpimYOy2d2fO461JeQ07eojfxGqownykUs31Ih94gaAUfYwDOsnd91zwAmz4 uaz5yDUkiUzMEXa+Jv/vN6ijy48KiWq2B7Vjt3XK9iyJqSgzkyfIuWowGf9IPW6teid3 Zo2I6cNwHJ+gBo8ptYRuofcsH0egn3k3oSPqQbFuW/+7P4qEFoyon55Jfp1fW16E9OGt 9W5fIaxPjkMY2qb1WqjOFLX5vR9n9vcQEgV5vmTmrLRQM/yWO8F4g1DQ7ypp1o6LVi+Q ni8/+7MLGLdpJOoTKz5DxpMu0N1G9O4tFrHfQiKvNMej5MUvff6e3RwkxPYmSzEfc2ov 5eHw== X-Forwarded-Encrypted: i=1; AL+hErHr2DmusHM75U2INMeb1totRTcJzkh2W6+1daptCpKUrQAwd6uVCpUjUWixkWeawzfQxglAjSk=@vger.kernel.org X-Gm-Message-State: AB4q+uG+Zp9Idck4PBQOgkIvJrMhAlsCDeiFwBW7pVXkXVSj+wFi0Js3 T8FgMDII6EKyHN88aQh4d92I1ypTuEbj/zgMitqdbZpISyr/KGeeU/oV X-Gm-Gg: AZFdTZdpml955qmNSbKXnO8GIarqkth5z+cU6KqNuDkXCI+o0eceAFOr3Lee6IhmLpv QYafTmu2XRXnv/Qs6EBjmZLFwfHE+b+PvWnvEry3WFG1pL6p+CSjDrbzzzEGikcllfCYNze0IA/ hmTBFhEraxC8vA4X8Tfj2R4hZhKgsjK+S+AAAKJ0eIBcCJ6162iMMhNCct4wvBbfFEDQVEqTRMU LJJ+pBELlsu4Eq2NuNWOgvjyTUrDMVnWouWpzovGGVZsY1EmAlcl0hAbhPhM74xetgT38AGt+nh jmQjuNpcMT20nkuewJv8lu4ILX2Crl9Ay60AkNujD1MZQKvY/N/OAnIIyR27sJHmv3Y2YOLufUB 3jNKtCqwE/GqOhJ4pQ/F3itAwiGQ4+kvbXK2CE+roTZAqf/QGNxT/WqCfEEdfaRlPzfTW6CtJpz Hb4yScQbWTFf+Q0wCutIJQbDr78YGs9irHg+YbTV9BvoInETqNvvFMWEiwNssItQK/CrSyiRByj B4Fc7mCb55YtHHrqQgDbKbN3mN8PeaBp7SLDPapQM+Nx5ECR5vdHi9ymQtkYHAazltkgS97kAcu nd/cKG1K0Oqd/ilpT45Qwjl6YejMoJ9FQZSKpL7upYda8oAZEICUbLe9mcXysgOx/Rk= X-Received: by 2002:a05:7301:6f0b:b0:387:474a:c46c with SMTP id 5a478bee46e88-38752139e7dmr4300628eec.12.1796452619101; Fri, 04 Dec 2026 22:36:59 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-387521e5c89sm23831785eec.18.2026.12.04.22.36.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 22:36:58 -0800 (PST) From: Praneeth Balasubramanian To: Konstantin Sinyuk , Koby Elbaz , Oded Gabbay Cc: Praneeth Balasubramanian , stable@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org Subject: [PATCH] accel/habanalabs: Fix timestamp record release on reset Date: Fri, 4 Dec 2026 22:36:51 -0800 Message-Id: <20261205063651.2523441-1-praneethb2002@gmail.com> X-Mailer: git-send-email 2.25.1 X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit On reset, wake_pending_user_interrupt_threads() releases the pending timestamp registrations. For each record, under ts_list_lock, it unlinks the record, puts its timestamp buffer and then puts its CQ buffer. This has three problems: - The record is part of the kernel buffer of the timestamp buffer. If that put drops the last reference, the buffer is freed, and reading pend->ts_reg_info.cq_cb for the next put is a use-after-free. - The last put frees the buffer with vfree(), which may sleep, while the spinlock is held with interrupts off. The interrupt handler path defers these puts to a workqueue for this reason. - ts_reg_info.in_use stays set. A compute reset can leave the process running. If it then registers the same timestamp offset again, unregister_timestamp_node() sees in_use, unlinks the record a second time and puts both buffers again. Do what unregister_timestamp_node() does: under the lock, take the pointers, unlink the record and clear in_use. Then drop the lock and put the references. This was found by an LLM-based audit that checks code against the rules stated in kernel comments. Fixes: 9158bf69e74f ("habanalabs: Timestamps buffers registration") Fixes: 1157b5d6b3b0 ("accel/habanalabs: optimize timestamp registration handler") Cc: stable@vger.kernel.org Signed-off-by: Praneeth Balasubramanian --- Notes: This was found by an LLM-based audit, part of research at UCSB SecLab. An LLM turned a kernel comment into a rule, and three LLM votes checked the code against it. The fix and changelog were drafted with GLM-5.3, then checked against the source and partly rewritten with Claude Opus 5.5. I reviewed the patch and take responsibility for it. Testing: builds without new warnings with W=1 (x86_64 allmodconfig), clang 23. checkpatch.pl is clean. Not runtime-tested, and there is no reproducer. I do not have this hardware. The kernel-doc of hl_mmap_mem_buf_put() says it "Shall be called from an interrupt context", but its release may sleep, as the comment above handle_registration_node() in irq.c says. It may be meant to say "not". This patch does not change that comment. .../habanalabs/common/command_submission.c | 22 ++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c index 8a3febc2089e..8bff77bf42f8 100644 --- a/drivers/accel/habanalabs/common/command_submission.c +++ b/drivers/accel/habanalabs/common/command_submission.c @@ -1098,6 +1098,8 @@ static void wake_pending_user_interrupt_threads(struct hl_user_interrupt *interrupt) { struct hl_user_pending_interrupt *pend, *temp; + struct hl_mmap_mem_buf *buf; + struct hl_cb *cq_cb; unsigned long flags; spin_lock_irqsave(&interrupt->wait_list_lock, flags); @@ -1108,10 +1110,24 @@ wake_pending_user_interrupt_threads(struct hl_user_interrupt *interrupt) spin_unlock_irqrestore(&interrupt->wait_list_lock, flags); spin_lock_irqsave(&interrupt->ts_list_lock, flags); - list_for_each_entry_safe(pend, temp, &interrupt->ts_list_head, list_node) { + while (!list_empty(&interrupt->ts_list_head)) { + pend = list_first_entry(&interrupt->ts_list_head, + struct hl_user_pending_interrupt, list_node); + buf = pend->ts_reg_info.buf; + cq_cb = pend->ts_reg_info.cq_cb; list_del(&pend->list_node); - hl_mmap_mem_buf_put(pend->ts_reg_info.buf); - hl_cb_put(pend->ts_reg_info.cq_cb); + pend->ts_reg_info.in_use = false; + spin_unlock_irqrestore(&interrupt->ts_list_lock, flags); + + /* + * As in unregister_timestamp_node(), put the references without + * the lock: the release may sleep, and it may free the buffer + * that holds pend. + */ + hl_mmap_mem_buf_put(buf); + hl_cb_put(cq_cb); + + spin_lock_irqsave(&interrupt->ts_list_lock, flags); } spin_unlock_irqrestore(&interrupt->ts_list_lock, flags); } base-commit: 29beb21c21ada7207692b2d69fc58dcd15dab6e9 -- 2.25.1