From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=198.175.65.14 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796296687; b=FnLG5umIlWMLDn195IshKSi99IpWS/Ph+cSyCepIQqRsEUbhn7aZ8VEKftBX6oPIXqzg GOKVGTd84C84//fW7/7ZaqNsdPoRDv575vba/pMrPACmdqXaHrXsCaLxH24Yy5FzbLnrN C2V3Qk1xi9SQms4yLSCMZVVE+VXtuDz3TLK22eBz2llzX7wMvezSlMkcaBwklb3uTHCSZ 5JTD/rQey0V17SRazvrjA6TV/6aEXa4UhbTAyaEWaA+Xobv5y5WdWshZGJq4vb6iYe1fH 143DuDmXHPAndpnD+u8bCujjtHWxu+I70LIFd4chxMpqjf0uqeVOxdVhj9IM9kN7YmQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796296687; h=DMARC-Filter:DKIM-Signature:X-CSE-ConnectionGUID:X-CSE-MsgGUID: X-IronPort-AV:X-IronPort-AV:Received:X-CSE-ConnectionGUID: X-CSE-MsgGUID:X-ExtLoop1:X-IronPort-AV:Received:Date:From:To:Cc: Subject:Message-ID:References:MIME-Version:Content-Type: Content-Disposition:In-Reply-To:Organization; bh=0DFjoB9UDU1B6UthfZl3bLCT8+h7KfxdZ3+SkVoYib4=; b=p7od4Jt+GEezphNUl3MCjBbMfOQw1i2QnNuR/PtvNqf85NUclARIkjNrTNKBIup2g5BQ iS6dsD4XzUHSBlR7JUjr8jsUxymS9KDFLSSGh+OtZm4uU4WZDsHYK/I7217qmmXzVy+vr 6CnKhccWl2wDpLPZ17m3gqXS+V0qO6Xp8efsZyvMM2G7rpCxH1z3KV0VYrZHcw0jD1ujC /eXWDKVGNOUQQhGYRhKGRF+w+WUEwbZo4bOHeyvIjjY6465zGJPsOYFQFhoaYA9Ja3bz3 YImyeWHeVqZA54IBWeHusy5tyzaGNXXCbcryu/BQyIvOAxnAT38EFuD6FrrkFh8/f9Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=intel.com; spf=pass smtp.mailfrom=intel.com; dkim=pass header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GantUqW8; arc=none smtp.remote-ip=198.175.65.14 Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.14]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6785D606A684; Thu, 3 Dec 2026 11:18:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 6785D606A684 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=intel.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.a=rsa-sha256 header.s=Intel header.b=GantUqW8 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1796296687; x=1827832687; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=0DFjoB9UDU1B6UthfZl3bLCT8+h7KfxdZ3+SkVoYib4=; b=GantUqW89/b0viY87sbxK7oDtB9l2YdKL79xg7vGXPRK7P7K406MfBN/ S+TAEZnS9rsWoJv2uCd5DVjiNvVogamnU0q5l66iufamZ0ndY9d/mtrz5 uDFa431scE8rW9jXKUBWfk9Ab+2KCQAXHXHl2g1ZOYsMG+3Sp5Y+JZGrb nwn+33aonM00ILeo//M1zHvgX3GDR+5e7A+jszIoFfhPP1IUfaptZ8RQv qLI4h/2k7AIjIGo85uJqYjC7s9xSqlytBwS73KD60j9+TRS/hTo2aS60p Ro7sNy7x8W4RmlXRFceI19UrnCKN9eSett67v5kdtEgNpgmI5wOHHTxbc A==; X-CSE-ConnectionGUID: WU2ER3/YT8OZ5c8NdjvWcg== X-CSE-MsgGUID: rt8ICpGqTc+T9QDF553KLg== X-IronPort-AV: E=McAfee;i="6800,10657,11984"; a="5166686" X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="5166686" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by orvoesa106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 03:18:07 -0800 X-CSE-ConnectionGUID: fF2gbXPiQrSdxRyvfnQuOA== X-CSE-MsgGUID: 6BdSlST5TJqwVmrkkaaeTQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.27,248,1787036400"; d="scan'208";a="13825007" Received: from inaky-mobl1.amr.corp.intel.com (HELO localhost) ([10.245.244.115]) by smtpauth.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2026 03:18:03 -0800 Date: Thu, 3 Dec 2026 13:18:01 +0200 From: Andy Shevchenko To: Yuansheng Yang <0xbeac@gmail.com> Cc: Jonathan Cameron , David Lechner , Nuno =?iso-8859-1?Q?S=E1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH] iio: trigger: loop: fix use-after-free on configfs removal Message-ID: References: <20261202034718.2917551-1-0xbeac@gmail.com> 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=us-ascii Content-Disposition: inline In-Reply-To: <20261202034718.2917551-1-0xbeac@gmail.com> Organization: Intel Finland Oy - BIC 0357606-4 - c/o Alberga Business Park, 6 krs, Bertel Jungin Aukio 5, 02600 Espoo On Wed, Dec 02, 2026 at 11:47:18AM +0800, Yuansheng Yang wrote: > Removing a tight-loop trigger directory via configfs while an IIO > consumer still holds a reference to its iio_trigger frees iio_loop_info > underneath the consumer: > > 1. iio_trig_loop_probe() allocates struct iio_loop_info (embedding > struct iio_sw_trigger swt and storing struct task_struct *task) and > sets it as the trigger's drvdata. > 2. Attaching the trigger to a device's current_trigger acquires a > reference on struct iio_trigger via iio_trigger_get(). > 3. rmdir on the configfs trigger directory invokes > iio_trig_loop_remove(), which calls iio_trigger_unregister() and > iio_trigger_free() (only dropping one device reference), then > configfs drops the last config_item reference and iio_loop_release() > frees iio_loop_info. Any active loop kthread is also left running. > 4. Disabling or re-enabling the consumer's buffer calls > iio_loop_trigger_set_state(), which retrieves the freed > iio_loop_info via iio_trigger_get_drvdata() and reads or writes > loop_trig->task. > > On an x86_64 KASAN QEMU guest with commit 8fb20cdf9c86 applied, > disabling the buffer after rmdir triggers: > > BUG: KASAN: slab-use-after-free in iio_loop_trigger_set_state+0x138/0x150 > Read of size 8 at addr ffff888008b25a98 by task bash/336 > Call Trace: > iio_loop_trigger_set_state+0x138/0x150 > iio_trigger_detach_poll_func+0x23a/0x2d0 > iio_disable_buffers+0x38e/0x490 > __iio_update_buffers+0x1dfc/0x2470 > enable_store+0x1c1/0x1f0 > Allocated by task 344: > iio_trig_loop_probe+0x47/0x1d0 > iio_sw_trigger_create+0x156/0x260 > trigger_make_group+0x33/0x90 > configfs_mkdir+0x521/0xe90 > Freed by task 354: > kfree+0x154/0x420 > config_item_cleanup+0x143/0x1e0 > config_item_put+0x91/0xa0 > configfs_rmdir+0x881/0xac0 > > Re-enabling the buffer afterwards also triggers a slab-use-after-free > write of size 8 at iio_loop_trigger_set_state+0x149/0x150. > > Commit 8fb20cdf9c86 ("iio: trigger: free hrtimer and loop triggers on > configfs release") moved kfree(trig_info) from iio_trig_loop_remove() > to iio_loop_release(), fixing the plain mkdir/rmdir config_item UAF, > but left the consumer-outlives-rmdir lifetime mismatch intact. > > Serialize iio_loop_trigger_set_state() and iio_trig_loop_remove() with a > static mutex. In iio_trig_loop_remove(), stop any running kthread > after iio_trigger_unregister() and clear the trigger's drvdata to NULL > before iio_trigger_free(). In iio_loop_trigger_set_state(), return 0 on > disable or -ENODEV on enable once drvdata has been cleared. > > Discovered by manual code inspection following the sibling hrtimer > trigger UAF report, with Gemini assisting in path verification, QEMU > reproduction, and preparing this patch and changelog. Read Submitting Patches documentation about backtraces in the commit messages and use *your own words* to make this commit message readable. This is no-go in this form. -- With Best Regards, Andy Shevchenko