From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796452620; b=Gc/EwdcZgTn2/GvOBaAsfPVK8wXeWCsclnqYFcEQ0JzL4dig/lESi/0bZsTUEy2umBaK 7zf/D5JqMS2bxMLrU0Yva3dqKdPX6S/QCKOK5w3B+1ZTTx6eKiUMOJNLMUUe+iIjLI59u lN6AqphSgpGkpyx09EHhIBzWcPZ23MAFfjswomIw3b1fkUUNffdS8Upqm2kFmky1SObRo dMRJ0BAU7klzhJPaEw+DNqcs75jo0JOjhZ/GptbLnbqv32ludWa/vys1C3uZ1Z3A3YYG8 gUcps2nPpKQsmOnmpUhynpC6hXjt4/H1IDga3nDvNcRh6gjHMGFS8Y9MiQetc8f9o2g== 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=qNDQ15PJW8wKc2CtsUhRb0sLumXe7f6yvu1wXgEWtbJeDNWdYoWyNgQzOJt7VUPdudXH T8CSFJZFjWHMGxfaw0jdUS0FYmOBxaNgdheVqHQzUg8ijzdyrDwuo2N5yVx/grvuPl/Cz RxstTya1p+xHe7rZI/y6hIxcZtQMjhEAtC0lpeog761Xiec5/dEYGM/0FDTiN7LzSHU8R /zt5YiUdBy9dTYr1YDzGdkxthR+hfAOMVQMPHHLhNvCH1G63gg9H1+VLFlvUePngrw/kY 0lQYs5x6AHI4Tasex8yK0InpMyRKVBaO7tlpkPEYezZywFu5Qrs2KOFSQ0tTKJ+yEBw== 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.182 Received: from mail-dy1-f182.google.com (mail-dy1-f182.google.com [74.125.82.182]) (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 ED483606A32F for ; Sat, 5 Dec 2026 06:36:59 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org ED483606A32F 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-f182.google.com with SMTP id 5a478bee46e88-385d8a00598so2347214eec.1 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=yxWWWvHA503gWoH1GY86wKjQ80phJUxK59Dkgq5jdkP1Z4k2skm0jBMHeAgpB4aAsh TdJF3LTAAcj09jVK0L00NT+epGE7QaxhzXpbbnSUQQSCsfzxRSuxmGakTSZoma6DP66J M3ZwwFPAUotlRwncPzcySHlyY6wu2sDFl9KNKUREirGJyglnWyKhtRr8mqCi6aDLxoD5 NZc+4IjHxvPlQKWlO9OFXslANUAWdltGj0rat+6X+ZgWiSfSIMx23WiILr5tnSu11nyn HTZVX+Z9LBHZ67pSpZhO+Ju/ljN2lZhMLqg/6eYxVPtWoVijrhYgH8CjS+Yik9rG91Rq tDvQ== X-Forwarded-Encrypted: i=1; AL+hErET7iXYyejccAnLf0KmvE1uwDk6nfFXWxijL+jz5ClGtqgIHFlYkBvow5fQw2vZrU6XPGzSrmaneJVIhBI=@vger.kernel.org X-Gm-Message-State: AB4q+uFVgzr0/MdopK9Ga789SxwEOedMGa7x/2+q8zPVVpXxP1r6CgAk FqW/EAIfwGKut9Wn4PESPwJxWwIckDmLb9ON4DugdDG8nQqIznSnEktx X-Gm-Gg: AZFdTZeUm0YLNWxs+KdUcxUjK2YekR8VowUkOi1xRdcyvy7HH4OnghozIrDBkWF0bne FRIvq6dDX2ClrUTX7APcXXRBMHulopJkgqMK4f0kSRPRQOD57EzB1PQGLwxW372CzSlu/tjXm4c /jb8sD2is7ND/xzHUdfu1832mbaWg9gmhP7alRdC5aDF+Vb3AVlNh/A5WuImXZR4HjtOSyL42H6 0nJRW8xsl/kk1O++vqSfp8MNC7wKwK9k3v+mhoDI+UYk/U+2I6ElX4x3w7yM/Ie8QFTSC1kJcG6 9VpAiLvRdvPPE03zXU7W5UW/Pk/U0TIA1Yeqbqz7SNWyHL0Fi3AgeJfd8gGCeIvZSBoL978C/ee ETy/u7MO5Bfyy7hSF4EsFZx04HC4UuY0k6W/v5UppVVx1SZ7i2rNXgb0YlEZv8wMt0n4q5xo6AB 6OtvEb530HiZGUCmoaJ3nXaVv/kMd91TEmN9GK1quAPIj8Xuvq5cqyvESlmRFvwKLG1DpzYMLUa siK8M3PeIUac1Do3hlmep4/E6zpsM79ecX5pgwUCGIhkUm9OYE0F6mbbY+tQD5mBDUCE0e2R9pC 7QoaxIqCpixFat61X1fW50UssJlC2LIshMLosOVGW/MrYi27gS9qW69UGsiUeAipBGA= 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: linux-kernel@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