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=1796459464; b=RfBPhUYCwHTVaYQxMhu/8o9fjfJBccJuFsxfMoW9/BKJ6XLtFFCVCBZvd3nHnu3LddgO D6l4M6SKZlnHRgdUEUsyJ3b2OuU1czslAOo34uffcbq3dB0+ssDR797Rf1RVFIEBB9kfw VrcnILPCakyCXqxEFpq6JBcTcoioqFtri/PqpIqLutqoEJgOV/ZmqfnoPlvSZ63BAWSBx 6mZw6Dl8ka/JowLNMxOByLbMo/CPR9gSvqC4BiPFWIZaXRqKJT3TafKOIgMv1fCyDiVpI mWfpweCYt2jDnvCaNgpa9CC/jJfWlD+Iij9QiUrgeWPTcYP3Bm+zouDc7BQlvBCC0oQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796459464; 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=b7NS5VjWHBGqszmq1yLLDbVRIEpdd9nMEt4Sq6/h+nE=; b=rQ1xLogBs1QlAO8t+csXDIoVpDDluA8Cic+FyZ5LQvEmCgYzrDmk/6lv7BMV2qgsiETo V28HJ8Oq8aIz3mcskn/4JaZXuEOhWr8BMnSvhg7WSJOO6TNEBjfVhgwyDDe59/l0YD6Zf KTGoiNFpyC83bx7mTc541G07Vl21v/F1aJ13404Wms7rnAbhNQrTH0lWXdY3ZkvoLpAiA Ri9CrlKuWhZ+JfTQJ1TOpw2nV5juleuqtFw9qzb7L4Tjdj+GjDgKh1+xj8PeYGdeZ3Apl llav1NAEYzkv9stp8EZwPTLU398Bfi39RHkJvepSOg1H8l4HaWyzmlrHv8N9xjaml0w== 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=Ynz4TGL8; 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 EFD51606A322 for ; Sat, 5 Dec 2026 08:31:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EFD51606A322 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=Ynz4TGL8 Received: by mail-dy1-f180.google.com with SMTP id 5a478bee46e88-386c71feeeaso2198651eec.0 for ; Sat, 05 Dec 2026 00:31:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796459463; x=1797064263; 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=b7NS5VjWHBGqszmq1yLLDbVRIEpdd9nMEt4Sq6/h+nE=; b=Ynz4TGL8e1mHfEwE3H1nlGUUrgRzHnuX6+6ThNqlzwJb7vMFzbMpYwHW0aiWoHV2hv zqR4vz2mKkCVOl2m1CoeFH+COfz71gAeXZqcEwrUl5XGd0n7d71b0bpYNclq0P6bl3Bi mMLSE7rL4f6EEfQ3I4YBzxA1ihzG1AS5mruotK1vq1kLKIG/4ibC5A2DCeOy6/eAJ11L XMTC2+7aB7AvqEUlnhb44tX7orKdanGAWeSitQJgTsTIoWkAyDZj6GLWeNtcoN2u/PMc bookajce1hvDxlSDiwbiPHlZVh1rfJY2Mq6x2WU7FfNLqCNHnAbc69zQ6sIvqMZfu80Y 8DpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796459463; x=1797064263; 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=b7NS5VjWHBGqszmq1yLLDbVRIEpdd9nMEt4Sq6/h+nE=; b=paEmriNnAv66zs0mLKVQqTjiZz9vkDmfljwBVyDJnXgqdpNCVqr88JaAfPv/TbtO+4 5pXotGmVeWRXcM7VO3fQrJNoKcSVV+PQeABnSqOy5PixB///Ba0z6TNbo+3aBxeuYT3O pWQTWAnqLOj1XBLhN3Su5gua6TQK7X+MFv1BRapiG5rupzcZZ3fLoRwDZ7810Tu06FVO /421/WRonNrS/outk0faYrEHYUCdWErMDTLU3yRLObfgwtTxC5V6fDcmLDwozK8CDgUN egl/I0YX8Sw/mbBFtLbu2y+nDE3dcFfpb3rHWBeG+ANYUiAmlQ96g+k3mgv/FFlwzviJ 8BSg== X-Forwarded-Encrypted: i=1; AL+hErEGRy5ZgVGc+vx6ecZJWnVbuRoplHAISr5EWKEK1wJOyRrVZ9iAe1/vn8yOa/BFLF+LKqQOOMI=@vger.kernel.org X-Gm-Message-State: APuU4Z+/LHxTwcKH0H6PvCyWDVIwnDuc0sWZsaALfClNjPYKlYC8+kTw txFNfJB6hyjo7xJezKsChR77UOCjxLIRZWjxipTe7eXo7VwCPy3I//tG X-Gm-Gg: AZFdTZdzzBZaARbmmgpjSNAdcN73VRIyblvKwKjg4mnOIzwoahbFLtyNehNvb6yyh+4 BJXuqB+Cm1MfUkhPb/n1slLTm9MpTvk/Bdhp/oOXZqn47IofSII9uq5jiVJEIgYeq3pdty3UUvA CxXX2mKe9bc44X9d+sXYBbyyRrBBT+TSCNXe2hqMbb5OvNGMiWyn6+lKg7Cc1p7kuBBIQSmiJgX Pziy5kEETh/zyJfGX4Ny1lpnK5JzFk/gJM/dA1QpLPRIBQsREPbUr8VzWdSLx/vLQ2Cl768V6mX 1YnJRNZes10+2rJALZqv8s9OBcY4Z1Rg6oFgaX82BWQkTlV7CFIn95SnYzN+iH9ToZ2CtMYlmhm A0z6BoRSULIRxRc2RBVIxUtNcty6KFd3bSc7dumXcws7m6Z38GBQtdC4h7zxyBmyRTOF0E0gtAp KfBOgJwUgX1yi6CXTewH/ecwrQEVqG30odZXzfxwww41GglNCgljxfV2N6AlMfHpQQ98KlbetWD /NuB2bozmD/dpqFzjQQ/ZTAOW9S0C+KAQYfwbi9Bo2q1k0e9864Rt2vFQNNRwOfElsHhzaiOhje 8xWDU1nthXjAdccuy/I9QfFDYuPSKPuASXFP5ymJpsO7L5d6nBaNwPGLEu/w1NvnqOE= X-Received: by 2002:a05:693c:884f:b0:386:de41:be4e with SMTP id 5a478bee46e88-387521de421mr4299802eec.27.1796459462653; Sat, 05 Dec 2026 00:31:02 -0800 (PST) Received: from localhost.localdomain (wood.seclab.cs.ucsb.edu. [128.111.49.37]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3875220c35asm16840767eec.22.2026.12.05.00.31.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Dec 2026 00:31:02 -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 v2] accel/habanalabs: Fix timestamp record release on reset Date: Sat, 5 Dec 2026 00:30:56 -0800 Message-Id: <20261205083056.2602922-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. Under the lock, save the two buffer pointers, unlink the record and clear in_use. Then drop the lock and put the references. The pointers are saved first because the first put may free the record. unregister_timestamp_node() also clears in_use and unlinks the record under the lock before putting 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: Changes in v2: - Rewrote the comment and the changelog. v1 said the code does what unregister_timestamp_node() does, which is only partly true (Sashiko). No code change apart from the comment. v1: https://lore.kernel.org/all/20261205063651.2523441-1-praneethb2002@gmail.com/ 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. The v2 changes were made with Claude Opus 5.5 after it checked the Sashiko review against the source. 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 | 21 ++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/drivers/accel/habanalabs/common/command_submission.c b/drivers/accel/habanalabs/common/command_submission.c index 8a3febc2089e..e823d3553e68 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,23 @@ 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); + + /* + * 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