From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oa1-f49.google.com (mail-oa1-f49.google.com [209.85.160.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E0D8519D065 for ; Fri, 1 May 2026 01:27:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777598851; cv=none; b=ShDT50OmJtQ5Zpmvwvo5d4CMxA7F3Cv9F1hcVgwVSqMwZbO1Y8zooiRjZMqgdTRd05wKaHGD2Mobf8ab59FIvUL2SjFdMyE6B4cljuOctw1uv0x/X6s/PnBgrYjFjouBMi8jlEPPJzc2rBdjrJp9c3jRsjEhzrPP4b/ATTqJM10= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777598851; c=relaxed/simple; bh=ximWOOGUhYu0AuqVhj7e0KEXupWyOFsU+riykOPRL4c=; h=Mime-Version:Content-Type:Date:Message-Id:Cc:Subject:From:To: References:In-Reply-To; b=bFZ23nqT2Gg/hKkPf5IhtupaA1K/sxFAu4NUcT8sbJRsyLeYiI9St7ia4G97ak359lcsvBN/CRNQWOORGls0XH6KlYrR9cJrDw8dSMfxJ2xypnAucYfgJDs903OpeaUHqc4zWpceNAmC8zSduQpPwI/GjAeUGub2pk8sA5+F0HM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=M1kGKSs8; arc=none smtp.client-ip=209.85.160.49 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.b="M1kGKSs8" Received: by mail-oa1-f49.google.com with SMTP id 586e51a60fabf-42fc6923f38so1608495fac.1 for ; Thu, 30 Apr 2026 18:27:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1777598849; x=1778203649; darn=vger.kernel.org; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=EFHRmmGVaDdKGA/DxTTnD3WtdQDoxj+78I0fv/vXXAM=; b=M1kGKSs8BIxwt2+vUqZ2Du5wRIhnXsALcxRRZlOYZ5KopeqOhmiX6fMEL2wQn4dCln is71JlY7UXKpE45y9R1qHd3D4I+yhrFvs0oEJXBsCWPAVyF29S8eN7jd5zhppcPC9Bre diHXdWPl2S9+fkJGQ/+m1JF+IaZPXtO/pERGd0w2613oIUZsJIIMk9xXt1f7GTTJiHwU ZmPMbFvC/8NS8Jb9zY5BEJFznbnDXStFzezMXy8OsvkQsN4qUqRUqr9lFdVrssO4izZt Utb4zOJ9H7GOlMJOpwSoW9RdA0j0AFdztg4dTqx1YZLuGXSvsajhwJV6L5BxInfrF8iP t/2g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777598849; x=1778203649; h=in-reply-to:references:to:from:subject:cc:message-id:date :content-transfer-encoding:mime-version:x-gm-gg:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=EFHRmmGVaDdKGA/DxTTnD3WtdQDoxj+78I0fv/vXXAM=; b=RR1lDdnQXFTWRSUm0qwlW837GxzobXbAH+faKsLB3gEvCCP/YffIj9+6ollTVxMGNY Aadzu/pc+werNn7L0qfQsJGRe6Xu58pQZHaIChguR62oBV3oBlI81d5IPlZwh67B8guk 7bQZLlNkMU18ZlTtOUbFiY1rkip26DIX13JVV9NHHW2Uiy3AUwDFVdwy3k1QndWlE/HZ smtMMZLC6Fv3sXBeVGi9idAAPlTCM91ZX93NzcKgtXi6GDcSNAAT1RXDPAQK6QtUaDcy vu0hkEzrlFsiWORaHdw3gFLZrn69ZhUXAj1RhPioccgdsMDQ8lOXkqZROEVrfnF2gf3I m9JQ== X-Forwarded-Encrypted: i=1; AFNElJ/6x1whUYsCda8sQZxZvTXmgOZIvi4gMLkFPo0Qna8mceMQ5ff2EnD73HoJsGG3JcazTfdo2fPCjQeYcoY=@vger.kernel.org X-Gm-Message-State: AOJu0Yx5cDj5q5pV0ByutNzOa3dFA3adwTzwd7LOcr8cHW2hyKpcC3N2 V6TL16JV8o4gjrLivR7ep+etCepzaQz8UdOPMd6ZyGnCzTGDHyWYsi7F X-Gm-Gg: AeBDietAcuncVb5FAThexZg56CzkIoX2gKM7ZRWLAvNGHZB48MrPS6a1T6IPu9qofw4 /wUvqxfM6HwQc13M2BhbV4u12ZNTkyE+bz9dQzV53lNLlm01il45t2p/SPSeeCXRxGJ2sGqyVro ExAPcmdD8uB1pTgy/vhQaYoLEnvetVHpIi6z+R42SuVQf4ldVggRfv9F7uK/fFgWQ3RSwqICjxX gfkPG2yg//2BDtoMt7zMbrOmIsocOmYHy8cyKt5b8z/bpaGs4R6RE63Sa4QNxbb/xppqMq4ined kR01awIyv3gT0qCj1us/pDFxAAgtQIzCEeiz3fKQsgdP3bMvFnhkjCDJd82/I5K02vbAhMHP4y0 BiYqS0xl11Gh0aUKXedbktV5QSnVhSBxWE3+lEFyylvbUoxDrDuydvArupxDlFcgXHPiZEOJ7t9 eFxaaxwCtGU2IqPkHAg95LnvjEwb8gHSAeL9/ekMC125gsY8YJNL7rdCJa9g69 X-Received: by 2002:a05:6870:a78e:b0:417:455a:2c01 with SMTP id 586e51a60fabf-43438980daamr2292973fac.1.1777598848904; Thu, 30 Apr 2026 18:27:28 -0700 (PDT) Received: from localhost (23-88-128-2.fttp.usinternet.com. [23.88.128.2]) by smtp.gmail.com with ESMTPSA id 586e51a60fabf-43454d324a4sm1322802fac.14.2026.04.30.18.27.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 30 Apr 2026 18:27:28 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=UTF-8 Date: Thu, 30 Apr 2026 20:27:27 -0500 Message-Id: Cc: , , "sashiko" Subject: Re: [PATCH v2] iio: buffer: hw-consumer: fix use-after-free in error path From: "Maxwell Doose" To: "Felix Gu" , "Jonathan Cameron" , "David Lechner" , =?utf-8?q?Nuno_S=C3=A1?= , "Andy Shevchenko" , "Lars-Peter Clausen" , "Arnaud Pouliquen" , "Mark Brown" X-Mailer: aerc 0.21.0-0-g5549850facc2 References: <20260430-iio-buf-v2-1-84c2231dea5e@gmail.com> In-Reply-To: <20260430-iio-buf-v2-1-84c2231dea5e@gmail.com> On Thu Apr 30, 2026 at 8:29 AM CDT, Felix Gu wrote: > In the err_put_buffers cleanup path of iio_hw_consumer_alloc(), the code > was using list_for_each_entry() to iterate through buffers while calling > iio_buffer_put() which can free the current buffer if refcount drops to 0= =3D . > The list_for_each_entry() loop macro then evaluates buf->head.next to > continue iteration, accessing the freed buffer. > > Fix this by using list_for_each_entry_safe(). > > Fixes: 48b66f8f936f ("iio: Add hardware consumer buffer support") > Reported-by: sashiko > Closes: https://sashiko.dev/#/patchset/20260427-iio_buf-v1-1-2bbdac844647= @gmail.com > Signed-off-by: Felix Gu > --- > Changes in v2: > - Fix Andy's comment. > - Add Reported-by tag. > - Link to v1: https://lore.kernel.org/r/20260428-iio-buf-v1-1-dcc63ff7b80= @gmail.com > --- > drivers/iio/buffer/industrialio-hw-consumer.c | 4 ++-- > 1 file changed, 2 insertions(+), 2 deletions(-) > Looks fine to me. Reviewed-by: Maxwell Doose best regards, maxwell > Best regards, > --=3D > Felix Gu