From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.210.182 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796411365; b=ziOnu5YSspZU8by8tl0ybQiif3/y+ly/lER7Kl+R+xQhgWEkYgDkPwvs5LUr5LGssAR0 tbaOT3SGZQYJNWNdotOND3PC778Tqnvuv06N/1ZUF/s06NtndtYoriMJ803tNzhyX0tUM zCUay82s/MNNHSvJT9db6AV9aeWDQwd7COVSpz5HH4+AmPRaEAxUaXhuQPPJagN4+2tf7 Mz1xtdt1OD114Zuq0ETNyu2PhZFP+Ora7szKXWdPIoAc3XsK5zNwVUZPdW/Gnef5FheMF S6HfRjjx9YsOxSj3apRaTZfvPVCTkFnBJ69N6THq+IJrSxOTjQ+zxUI/lPXby8PbNsQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796411365; 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:In-Reply-To:References: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=7EgKNu9aXOXmDWMBAscMRWO8XKf7x7m55Wm+ahonF4A=; b=rSvz3XKSXIxHUKtMKHW5ZxLsxOIsGtl2j/m3ZzAYyxDxYx9A69NHAnlJNF8Fd9dFJaeO qdxcQu3M1nMOnm2cFSPdUOIfExIWHMvxV9KNhxRJ2XMnXEGSUybxSVaHokICza854j2JF CQXqwfp2K8x0VUFRMhdyb5d5NaKoZu5z60psybGet+cME5ECGeno3IMSsNU8fo6WO4Bg/ f9b4G6ap1LLkdsWuCcwpPgzO2L78XrSKQGamQ8OO0/26UQuN20wh6jJMkpMq1fgoai2Ib q7rH145BbT6H37KigHrmQZmvlH2f3ng1onbnkUaaoMgRh0+Ltr//+TMIDSUCxeBQ+qw== 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=OFAG+xMr; arc=none smtp.remote-ip=209.85.210.182 Received: from mail-pf1-f182.google.com (mail-pf1-f182.google.com [209.85.210.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 62571606A32F for ; Fri, 4 Dec 2026 19:09:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 62571606A32F 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=OFAG+xMr Received: by mail-pf1-f182.google.com with SMTP id d2e1a72fcca58-8c6c06b3321so753867b3a.3 for ; Fri, 04 Dec 2026 11:09:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796411364; x=1797016164; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to:message-id:date:subject:cc:to:from:from:to:cc:subject :date:message-id:reply-to:content-type; bh=7EgKNu9aXOXmDWMBAscMRWO8XKf7x7m55Wm+ahonF4A=; b=OFAG+xMr+vTs8Yei/ZEMTJ8XzNf6m+Ibou5jpRrOngt8mERGN73fvrfr6vjA9Taoxn /UDtGza4YnkpBiCxcVrDu3kquJ+rMhOm0TvgPW/NYM4IhAcyzqUfIL3v5OqJCoBWBo4A Nnm4TndJ4x6Z28W8I1ijKRWGqQBrxQi74h6lbfbFAEC4VzoRDbsqUGpxgOyNruGLjacj yD9NiA82wxCLakjX8exG9kihVUQ0e62QLlVBtfO+n1FaAsM098s6K/BXoKufALiChtAS A6iZ+r0HheYF5g8DAZ+Cnqpn/SIyU6GjQEJ9Q8pagyZ3HZEXPA2i9nuApG4EmyRYCvwg fHpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796411364; x=1797016164; h=content-transfer-encoding:content-type:mime-version:references :in-reply-to: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=7EgKNu9aXOXmDWMBAscMRWO8XKf7x7m55Wm+ahonF4A=; b=2Bx3zvHhzC3sKaRcxxKhe+ISRZ4b0qsF/Xs+n9Cq09ehoejHE2Wzeq6bCV8ULVymYU nwxZFi3XJj0SAuy81shrDREq7wAWdUefRC0GuVppNy/2XPcuil7xYPyW58YjtGK4ENbu ab0YoZTtHa1FGimV/qWkGDqDKSSb2xDuJwFR+RfrH3tCUbIq1njx+d+EsoQtnBw27fVE unz3iiWNTtxXWHgqDgEZ7Px4JvHEAqjRSy8n8eZ7jT7wxr06X1hKDETYPZQEVCUlHoWO oh9EBJ2BoA/2qMjaz4w+mcYjm8Fmrq9Jm6qfYHsL5I00lreyGNYfjRzdFILX4SRT0jab bUkA== X-Forwarded-Encrypted: i=1; AL+hErEIz/fu41sANbbo1C3uQfshfnpOs3X8ZIPFLlEbG8xs17epXn0qY0FKil3492Adk18v/qG/8yV+eY8=@vger.kernel.org X-Gm-Message-State: AB4q+uGUniKlci1Gv9sYAfEp+swLx7Yc4qTkMChrDnV+3WHPykCeIdG4 Kh64Np2UAm0Y+MFR697uy+CkUdBUDY9eqTALjMt6heAWvY6fae/8hi40 X-Gm-Gg: AZFdTZc6yP/79HzXmWnQuJT5T0nA3/PhzH733ppy5SMkfJIWbTTiZc+3w2bO6CaFMNh AQbaizqiYsyWregLHEqwXdMHn9srj0sYDoBy5PvkfaMVa8kSTIoWIYfPAvnApDj+i1lwNnus7tc MRpsBJQRfbFti079jTF80kCRE4vY7X+a73ya8TWrgQo/fGm8e9rnPkbWRxka0QYxAcSTobo7S3k LNqr3KxInIlIdtZ1kL0kXWwICyFDWgUjL+/saCO6gJcGAT35pjbfyWjwP8h6hhqGQH+ej/iZaD9 3RVEynRtwe7tnxkm5Gw2M/RjN7riE7WEVO0rF0dD43nUtpUG+HvWw9E64hALdjoNgBAsxIcTdps oDxMFPDg0/qWc/gZ20bZdkF2wOIVQSss0y9lreRJbpdxexO9vuBtAEva09kzwkMrjuCxyupEysH UbD8KdLS9JqAFNR4jbqhJ7TG9LMy8CxSuM0jWy+sgKsGwaPYPrb8bwq5d+EgjpazmJuYnsXVFEg qNDDenrpISm16PGeqePEYBtDe27fIJQMBFGWYVs6bZauQOI1nijOJxmLKPm9HN5dZV1lW2d1FPn wxKvpbqO0m3wFOR1KrycYTkcx/YwROr0GomVM0ac4dBP+/26PMjFAg== X-Received: by 2002:a17:90a:e704:b0:3b4:f92:ade8 with SMTP id 98e67ed59e1d1-3b5e05493fdmr2657962a91.7.1796411364460; Fri, 04 Dec 2026 11:09:24 -0800 (PST) Received: from dell (pdf8686c5.kngwnt01.ap.so-net.ne.jp. [223.134.134.197]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-3b5c7843862sm10567759a91.2.2026.12.04.11.09.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Dec 2026 11:09:24 -0800 (PST) From: Yuansheng Yang <0xbeac@gmail.com> To: Andy Shevchenko Cc: Jonathan Cameron , David Lechner , =?UTF-8?q?Nuno=20S=C3=A1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org Subject: Re: [PATCH v2] iio: trigger: loop: fix use-after-free on configfs removal Date: Sat, 5 Dec 2026 03:09:18 +0800 Message-ID: <20261204190918.1355662-1-0xbeac@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: References: <20261203193202.550807-1-0xbeac@gmail.com> X-Mailing-List: linux-iio@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 On Fri, Dec 04, 2026 at 06:50:20PM +0200, Andy Shevchenko wrote: > On Fri, Dec 04, 2026 at 03:32:02AM +0800, Yuansheng Yang wrote: ... > > Gemini was used to assist with code path verification, QEMU KASAN > > reproduction, and drafting the initial patch; the final code and this > > changelog were reviewed and edited by me. > > This should be moved to the comment block. Sure, will move this below the '---' line in v3. > > static int iio_loop_trigger_set_state(struct iio_trigger *trig, bool state) > > { > > - struct iio_loop_info *loop_trig = iio_trigger_get_drvdata(trig); > > + struct iio_loop_info *loop_trig; > > + struct task_struct *task; > > + > > + guard(mutex)(&iio_loop_lock); > > > + loop_trig = iio_trigger_get_drvdata(trig); > > Leave this line as it was before... > > > + if (!loop_trig) > > + return state ? -ENODEV : 0; > > ...and just add two conditionals to each of the existing if (state) branches > below. Folding the NULL checks into the two if (state) branches makes sense and I'll do that in v3. However, iio_trigger_get_drvdata(trig) needs to stay after guard(mutex)(&iio_loop_lock). There is no outer lock shared between enable_store() -> iio_loop_trigger_set_state() and configfs rmdir -> iio_trig_loop_remove(). If iio_trigger_get_drvdata(trig) is called before acquiring iio_loop_lock: 1. Thread A (set_trigger_state) reads a non-NULL loop_trig before taking iio_loop_lock. 2. Thread B (rmdir) takes iio_loop_lock in iio_trig_loop_remove(), stops any running kthread, clears drvdata to NULL, drops iio_loop_lock, and config_item_put() frees loop_trig via iio_loop_release(). 3. Thread A acquires iio_loop_lock with its cached non-NULL loop_trig now dangling, bypasses the NULL check, and dereferences freed loop_trig->task. So in v3 it would look like: guard(mutex)(&iio_loop_lock); loop_trig = iio_trigger_get_drvdata(trig); if (state) { if (!loop_trig) return -ENODEV; if (loop_trig->task) return -EBUSY; ... } else if (loop_trig && loop_trig->task) { kthread_stop(loop_trig->task); loop_trig->task = NULL; } Does that look good to you before I send v3? Thanks, Yuansheng