From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.215.174 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796411365; b=OR4PDy2ni8lXbhLuq8tlkPHIfq/RcgoBTw6CAwDi4WOluNSr6O0dR5lBDKXwNxRII6Nl DOqiZilxHxolZxt0zDUQtrxTFrorUh3JbPdw7TZWDPh5niUBT1u/Nz4atoIMVshhKA5uA zDk8SbNRPGo78lDcCMC7v9ASWVAnfqBb15I7FmrNC0hc71WwQMX1/u5OmHKcQWFIk5ExJ +rBOsxHZVTSIvh7cuEtPgctwWzmf7GI9JGIgFDr+z4QLKZqYHjRmmQzGxiRl8WGsRSaoa p7C4+dEuJX09Wl5IuRhKphzuTW2exP83ugFJ6wMxx4W93hUBBzR54/iwJnpCvT6wiqw== 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=ubvy05JclO4gVZylFOjEjTH/SXx+zWqCmXeaeSIij7Xlln3UGoLXpTCAn8K9UwUknNKF IKtoYeSGkQPgKYYl49TyP2r5y/mMF7T2nEsiIf2cFVGvqvttZXyE+1BjktBRoxOYE/Du7 /Ti20oFbJ43zTI1Wp5xHfTTdcpYEW7lq2FgOStYRPrwZFvNq8ZeDdH0EzvKD6DHN5Nifj 4R0y37jQ5xPurOv+rCtp7XyRTxXJFHsVeBmq2c+l+mlEW79dGNVDaO5hrQhUgDEsMcuOC acdb75hQKAYJzkKhLW5Icn4vU2E6g0HxAgynDwe2N1FqWOsxEkt4KDmNnhkIJJwsKwA== 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.215.174 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 704D4606A322 for ; Fri, 4 Dec 2026 19:09:25 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 704D4606A322 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-pg1-f174.google.com with SMTP id 41be03b00d2f7-cdb2893531bso665738a12.1 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=jXbNyw/NhWl/+DNRX0yiE5Qzo20KUn+87mOcoSEt6KMNbICD86va5dw5rm0AOYGH7Z G+UaNESiwW5c1DhfoKjVumkDbAl3IsM5a1Gx2/QZs98+NjCyB5OyI8TUcAi/fTR1cCKV 9d98/n6hk4TFNrrlJVWNEgMMTxt0LsxV3+wGbT5J3W/rxST11hnwjtxB77Mq9s7Hh9tM 32+EMsLntnp0yjkXhZe1iXaj/GF1ysURJ1NetiHIttCe2BRYVs9CbKGbREOrWt6YXyYQ /9/3QJrVcKW+fGMGHHWjBhHjfwNRnrvGzLj+68b6t3NIVr+aFuQfw/SjW+Rj2DEJ2tEl 1YUg== X-Forwarded-Encrypted: i=1; AL+hErFGgXeWRjSOQuplNM/EX2g53+oZ+P5izz8M2gsg+xKmaeNI5MnUi8vzB33dRoaD7xFeLLjR6JPSa1iXtA0=@vger.kernel.org X-Gm-Message-State: AB4q+uFFsbnJt7EVQtCNmua7pHVeWV/3h2Y0d+Mpf8cAdj/vW6qNxTkR M1+qsIwnI47KYh2NmGaoK+s5QYRAkWUHCBvlMmNsBlK1TXfTq9BHDeVkGeMAq+VbBJvxaQ== X-Gm-Gg: AZFdTZcJl9/OiR2laTIBgSNDY93M8/jySe4ikAWln3H7LI6VIfu6mEIUBLbucMDWHdD 7WsJCOhH1FgOAVMriRhtl+mBCND3EEndS0GUesK6774MrSX+ykR9bd9tafjL9G0lE8C10ca2jhf qXwHQhK4zkmp6RKGZzdt9DfxkXa//ftmmfeHiWorPzRc+seWRKkhCxY3JhL05+Tp8P48DpDe2aB vP7X2cwNTKebki5EwAHtHqfj8aXWznq0Ow4EunZ4n3dje4oBWv3jNSo+E0a+IrbFAVp2TY+5vkD LEH6G81Z6M6T2QynvGP0YE06HRSXfsuvxr1hIlRXyis4OYUGKATHrtwwAJbMVnvQx1pDcWedh7D 4IXITT3Q0DX+wREvdxYlRbjJPugvyYj0/DgTCf5uOUVEoPuyu8L7eoW+yye0Q6fY33SSWWyqNdi 9MvXxWidr1VOo4SqnK4gLhFbhj7Uqp0ZLaQO63A+MUP7BY0qCI3jXg19X/EVXwYtIdxCZMUIfY2 zEzve0w9jKgohIjwIhU3uE13GaVsLPKvBZBesPyXGvfmvGZPWvox5lFirOzj0MG5dAgGGdOMtw4 UXiZ2WBJsG1inEVJ+gbJeIRsEbdM+XoFyv03wtWYpJvanx7KZSW2LQ== 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-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 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