From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796140192; b=OzaUhAE2hjQT1V+9cR1VZWZrF9SCiUfQwQW3juOkSaBrt1/azHUeiXdg+b3XaAboiyBc mAKC1Ax+hLPO9P/BAtufD80QszDjqJI2Wkw1TQBrKJnC9/zJyhwa6mJTeOZVD625ROVBc j5+eXoG4+OGhgM92axazQ1GxUFhPUFe+UX2NiriHg+fTj8+jtpoCmBAIHcGcXtzofMGU1 zUmmHy22WLXsdrqovgpepFgipk7lgDQ0Ah/wz8FrBgUN9fpMPiZdXtILq1hyoOJEwOR5r KBnRLbCM9QDI8qp9KO2ZLViUo+nxRrB6fiqITYzrOWWW+BSXW0Yl4AxdGUeJtZHti2w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796140192; 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-Type: Content-Transfer-Encoding; bh=y5FU9oF6DrQU3ZcjCD1DpHY5GMURPSIZ4zsBM1NONh0=; b=xZP+tlo2TKDH0bYxx5mB4Cx9dz11He2WM8vBpsoB9wIePVu7TcB3x7OHycjJjPOM8p02 u3JCPArs0Khzb2sAzg7LPeFBHMeXF6/+wP8aXF5ZKgeuVeYG4GbaXwUutHhoPbxKt8GkL SnEi7xaZpe3MoswNKi8t1hKI6Z4I2Jk9kdfmA7uG0UZiZdWefym7A14KcMu/TT8M7s15i EBYtG5+AQMsVR1tSA1QKAewRkYC10By1JK0M9ARER8Kb7IIGz+BdKpBaTTbfNdQRiNyyC k33pSDe46+YzeTj0Fxcyz5KQjvIeisGC7w8l2tQUAYjGuEEG01WxMlezibF34egCjfQ== 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=jyGRDh0O; arc=none smtp.remote-ip=209.85.215.182 Received: from mail-pg1-f182.google.com (mail-pg1-f182.google.com [209.85.215.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 5CE88606A31A for ; Tue, 1 Dec 2026 15:49:52 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 5CE88606A31A 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=jyGRDh0O Received: by mail-pg1-f182.google.com with SMTP id 41be03b00d2f7-cdeaf4ea5e0so3045902a12.1 for ; Tue, 01 Dec 2026 07:49:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796140191; x=1796744991; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id:date :subject:cc:to:from:from:to:cc:subject:date:message-id:reply-to :content-type; bh=y5FU9oF6DrQU3ZcjCD1DpHY5GMURPSIZ4zsBM1NONh0=; b=jyGRDh0OpECx3Eq1thxoG8UakTd2OkBUCgNPvImi1UF1RVuv9qTeamcpzMR6Y0D0YE wdcHsZGwv1H6WkHPxTJ1dHc1sEhOBowIxNqmQsbU8Uo0XrUJ2Wt7evFdrDkgnILHZTzP 0XhnrK4kaogC12oUK8bqqvGNRe3TprmuUdPfAVud9qJBXuBiCOW/XbFCovR0yniNMZS/ n7Q2nYiteMUEs3cPCTKvcmO3fWAxNqc4Dp8QunqarZTFZPFkY+daqvgWvWAQEXsNgGs0 Y8rUBuqhZCDbpmz2Mij2Ad7NLqQgtBXoXr5Nq2Ht9w7h7fn06adj4A2hvne6pB+t25J/ i1Ag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796140191; x=1796744991; h=content-transfer-encoding:content-type: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=y5FU9oF6DrQU3ZcjCD1DpHY5GMURPSIZ4zsBM1NONh0=; b=qt/mQA65ryT0Wn36HENZ3L9QMfl0aQK2LHjyFRCM+XQ0uumrqbucQ7Iq3PZ0wfefzW boljEDLvkDfRWrGwrke6olDtSJaSLtVMME2R6/HxIH5xAGlJRSvLGstVvSmVz+5GPdLJ rZXWdVC2DqaSoC/LJCVK6kRgGZOUmOXg0R+EaP2MpL/BpLvcF7f/exho0wo53jTDMVtc JNmfyheoUHFkX0a45UYV43xLqki4jZkm2/x4tY4Hz1YtUCC1jbrEtEpj58D5tO9mFRSk a3w5s8S/ik/OLWEaet6K4nqdYQs306ULKOHSEu8GhZvnTDLI9fXzO1JfrwCpCRXP541d shDQ== X-Forwarded-Encrypted: i=1; AL+hErH1f5FJSSXRXUeetV5fWYcNwWfaN4F2GMtCUqSndYZTLTFLES4oRxvgv9/BpPT7viUu8E6WYIJQxX3uOnw=@vger.kernel.org X-Gm-Message-State: APuU4Z+Oq+ZlaNTekAZdJQMuqZcQi7RQ6lBIgVtXLIXxH6px0AxMgKxC seitHPxbs8ghwBM4teLun/wxkUZesgBSybT+ANLwgJSN6NNncLViv6St X-Gm-Gg: AZFdTZcHEPy7uoH7nNR7EKm1MTdSyVJyaQAmHb07fnsLlFKLnnyxFVhSUlgGRWqy74i yLp3a57mHyaab1dfteKkO7W1NxzkAgr0+EUm2TEFoHqrxAc7+TGjD8IF3wB3FnwLTSD8OfOobfo 26IaazwuT3Vu0+3vvG4qeX4fD7mR8Z5Fyonil3o25lmgkuQQb4MZeatIwr2yJ263p1CVOBwb81X Mr6B01ho1hFuL8ckOqfQV5xsNEdB6rvqaCwH7OZXkRM4zmxk9ouiHyG/yrevQPHFpwY7RL8qbPP D48IoURDiiLqxu88TeFco4CPt04bamxRbIixuvpgMUQr/DUHVMibtHNDWKOQq/Y5mC6bO7fyPRP eOxCoXkGN8jF51NWnT8lKwM4rvOxvdQVT+8/F8hwnDa9UypCa0wAWfjl6AHAU38X9COzOxr5Z5d RbsPN/g8YyIq4L/DcLHPvhyuUxOwHbZzq1uLSONM43nONFSZWGP4HGPKOrOFQyL7g7cv2YSxxlb RK7LX2tVCa7dQrQcUHbEHsQpAF9t6mQPRMaosjMeHF1Q6U9zVppHAavCwe0BPEAUbEf8zUhjiax COVkbdb2+vHzChurIYHTIEyrijyCdzDsz+1ZFUxQCtCvL8DjoQiwsbmFg5x4VrJSchF39WOOL3r BBPnAWcjb6WVJ2Ol1NG1Cr3ir+bzv X-Received: by 2002:a05:6a21:4eb2:b0:3e1:a402:680c with SMTP id adf61e73a8af0-400ad778159mr30927299637.21.1796140191123; Tue, 01 Dec 2026 07:49:51 -0800 (PST) Received: from DESKTOP-TPPBPA1 (36-226-254-86.dynamic-ip.hinet.net. [36.226.254.86]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-cde6d002a77sm19814444a12.16.2026.12.01.07.49.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Dec 2026 07:49:50 -0800 (PST) From: Lin Tzu Yang To: Jonathan Cameron Cc: David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , Changyul Lee , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: iio: trigger: hrtimer: use-after-free when the trigger is removed while a buffer uses it Date: Tue, 1 Dec 2026 23:49:46 +0800 Message-ID: <20261201154946.904264-1-rongh7426@gmail.com> X-Mailer: git-send-email 2.51.1.windows.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-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Hi, Removing an hrtimer trigger through configfs while a device's buffer is using it leaves the device pointing at the trigger, and the trigger's iio_hrtimer_info is freed under it. This is with 8fb20cdf9c86 ("iio: trigger: free hrtimer and loop triggers on configfs release") from fixes-togreg applied, which fixes the plain mkdir/rmdir case. Without that commit, the buffer disable step below gives the same hrtimer_active() reports. Reproducer (QEMU arm64, KASAN, iio_simple_dummy with buffer support): cd /sys/kernel/config/iio mkdir devices/dummy/d0 triggers/hrtimer/t0 D=/sys/bus/iio/devices/iio:device0 echo 1000 > /sys/bus/iio/devices/trigger0/sampling_frequency for f in $D/scan_elements/*_en; do echo 1 > $f; done echo t0 > $D/trigger/current_trigger echo 1 > $D/buffer/enable rmdir triggers/hrtimer/t0 # succeeds cat $D/trigger/current_trigger # still "t0" echo 0 > $D/buffer/enable # 5 KASAN reports, hrtimer_active() echo 1 > $D/buffer/enable # 22 more, from the timer interrupt After the re-enable, the freed hrtimer is started again and the timer interrupt walks it: BUG: KASAN: slab-use-after-free in timerqueue_linked_add+0x2d4/0x344 Read of size 8 at addr ffff0000117036b0 by task swapper/0/0 timerqueue_linked_add+0x2d4/0x344 enqueue_hrtimer+0x1bc/0x480 __hrtimer_run_queues+0x5fc/0x8e4 hrtimer_interrupt+0x320/0xb20 arch_timer_handler_virt+0x48/0x6c ... Allocated by task 102: iio_trig_hrtimer_probe+0x4c/0x25c iio_sw_trigger_create+0x100/0x200 trigger_make_group+0x38/0x80 configfs_mkdir+0x3a0/0xc60 ... Freed by task 118: kfree+0x1e0/0x590 iio_hrtimer_release+0x14/0x20 config_item_cleanup+0xf4/0x174 config_item_put+0x84/0xa8 ... As far as I can tell, iio_trig_hrtimer_remove() unregisters and puts the iio_trigger, but the consumer still holds its reference through indio_dev->trig, so the trigger outlives the removal while its iio_hrtimer_info does not. Disabling the buffer then calls iio_trig_hrtimer_set_state() on freed memory, and enabling it again re-arms the freed hrtimer. I am not sure what the right fix is: refusing the rmdir while the trigger is in use (drop_item can't fail, so this would need something like configfs_depend_item() when the trigger is attached), or keeping iio_hrtimer_info alive until the iio_trigger itself is released. I have not checked the loop trigger in the same way yet. I am happy to test patches. This was found with a configfs/sysfs fuzzing script; the analysis was done with the help of an AI coding assistant (Claude), and I ran the reproducer above. Thanks, Lin Tzu Yang