From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f52.google.com (mail-wr1-f52.google.com [209.85.221.52]) (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 49C55126BF1 for ; Mon, 2 Feb 2026 10:11:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.52 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770027091; cv=none; b=ZcaVAFcKU/3tsl7ZRVYT265sOtIfAch4EwMdhAb3k8XcliBaEEf6ohwgKHmsQnrL4BvjoJcj7gJeVyDOHDJkryO9iItCLrRMFs/k3yChHhsbP5OdQH3BYOBxbMc9yQUMRIttlP9UiQmLWv8bJjIHj4v4au+b+RzRD9YOOq1nVqo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1770027091; c=relaxed/simple; bh=x6D6h1D+QVALJyJ8ILdl83zNlUA9XoJiXvEQE5vzs3Q=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=JOVjKEApY8+hX6K2FPXroObnz0xvtFt3sFMVPyI0lBsm+XV1aVnuCNQ4elF/mkauAHuKbNKOtx/xGmKAARRgnygsVHrvoDILcSRHA5M/SLIf4xSF0KAqaoZCQTc/2eLGHCLktndvvK+OGFVt8IfDHcQWB5PCjYRU5u3goWqG8ik= 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=lqV+MKpe; arc=none smtp.client-ip=209.85.221.52 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="lqV+MKpe" Received: by mail-wr1-f52.google.com with SMTP id ffacd0b85a97d-435a517be33so2513510f8f.0 for ; Mon, 02 Feb 2026 02:11:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1770027089; x=1770631889; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=x6D6h1D+QVALJyJ8ILdl83zNlUA9XoJiXvEQE5vzs3Q=; b=lqV+MKpeOb1Z7wiKw/IomRxuLN24cDZEg26t0RFkSWXpn41+gzQYh8s+82IQpSogtS 0Xhjki5hxdH+Cu4Bz2nlOnlJaP1APomI0hcd50XFR6HzuPoXqFTtLjzIISVnETscObWV BqKsHDkbFWVxgrFY1xHZ6JkD0K+46+ujMQtDBpFnfgyikCRkm3uHek3JMCCv+S3xLNG/ xbB7pucQ1w2mOg5KUFjzlKri6xjFY5HMPQT2MIWf1Jw2rQVHn7PLFm0Mo9pGOoSh8j0A BefgcDMM9MMV0W5HReTFfw8yZ3kdVj8ElmQGv4ywGEO6P3p7Db8B77erDbAlLkMij4UP qqZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1770027089; x=1770631889; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=x6D6h1D+QVALJyJ8ILdl83zNlUA9XoJiXvEQE5vzs3Q=; b=b3+YPCQbIf6dk6eZMbbL2+T5scmZn9DOAtBHUtYxBMEPWGPhIfpKUAOkH+rROsmVwy /XyjI/EKX+4rgJ3aT3tTMoHheqidu6voezVUbpAtsq1wBgP8rnlOo+AiMKs+oXAjI5pa DTReV5nwvcbsz/3dNHlSakqWBS5KTT2zoSj7COoY8UteUR1RjE/x4io8ZcvteuqUARdx SIcQs7awxzzODEuSbMEe9F/QcS/8fEoqi6vefAwuqLirAOA5RkqXDfyG0Wv/Ty0a4dHh SIL2EjqwZFPXt0tdTjSVl6YAG1/ZoolGG7exBPsup6KVRWkb8PjEQ4h+Lg8g8vhmxYzL 65PA== X-Forwarded-Encrypted: i=1; AJvYcCWjeb9GbMzED0U5ze5oHVeyHZP0m1LvvbGpxvaxK98RgLg67P6h3ZKMIFlLc7W+jE28jb3LZDILUdq3M84=@vger.kernel.org X-Gm-Message-State: AOJu0Yx20ll1vh4sAwnKUaGL2JXM3Aqy0DiDC86ebHrm7vRBe46TKCqL RRVcjmxl/paPlCgRO2/L8VdTjfCK9CPFX8qYmttgaWU4ndAGVG4qGcqz X-Gm-Gg: AZuq6aLdd4Q/9/r2X7gs+DfspwicBqGCT08Q5Csnn7F+JeG5e0fTCVBstb3xJ59hhCG xchgWFmufmOsiBrvGTSZ4gCcew+O8HVvD1xaEGVRiUp2L53BJ39poQvsZqalayilkCcu41IU9It QG0yn50pkf5QOusLxPCgYt6tuzve/HvODJUSf5Zdi6VRj2+AVCgV6vbhnfy6A9Vq2FOApTS9klz K2MK5V3DgyGa6W5U+TWa0bKb5jQtq9rnruxBslb9Zs+tbEU1mURZ8FmLWe5pzfy+f4IMER/K0dU o7kFpJYIW041Ai9pe+YhGdgQNLa5J99Ayo/ypOY9VOPfZ8Njx8oc66rUoL0Odsm9cLYR16oisq2 MwTRs/XREwSc+wR7/ZfDsD0HAiJxvvsXSLvswDSfSOMfsXhuVcLWvjmPm06hfihkfB6+7x/K7OV tdOy8ztaXFEGT0osaXk+7s5F4dXUn+kw== X-Received: by 2002:adf:f2ce:0:b0:436:1b1:6cbd with SMTP id ffacd0b85a97d-43601b16ee1mr4892757f8f.6.1770027088509; Mon, 02 Feb 2026 02:11:28 -0800 (PST) Received: from [192.168.1.187] ([148.63.225.166]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-435e1323770sm44040609f8f.32.2026.02.02.02.11.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 02 Feb 2026 02:11:28 -0800 (PST) Message-ID: Subject: Re: [PATCH] iio: trigger: fix use-after-free in viio_trigger_alloc() From: Nuno =?ISO-8859-1?Q?S=E1?= To: Jonathan Cameron , Salah Triki Cc: David Lechner , Nuno =?ISO-8859-1?Q?S=E1?= , Andy Shevchenko , linux-iio@vger.kernel.org, linux-kernel@vger.kernel.org Date: Mon, 02 Feb 2026 10:12:10 +0000 In-Reply-To: <20260131124416.19576731@jic23-huawei> References: <20260131092333.247931-1-salah.triki@gmail.com> <20260131124416.19576731@jic23-huawei> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.58.2 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Hi all, On Sat, 2026-01-31 at 12:44 +0000, Jonathan Cameron wrote: > On Sat, 31 Jan 2026 10:23:33 +0100 > Salah Triki wrote: >=20 > Hi Salah, >=20 > This is a definitely case of the fix not being anywhere as simple > as it might look at first glance. >=20 > > Once `device_initialize()` is called, the reference count of the device > > is set to 1. The memory associated with the device must then be > > managed by the kobject reference counting. > >=20 > > In `viio_trigger_alloc()`, if `irq_alloc_descs()` or `kvasprintf()` fai= ls, > > the code currently calls `kfree()`. Using `kfree()` in this case bypass= es > > the device's release callback and can lead to a use-after-free or memor= y > > corruption. >=20 > In some cases yes it can cause problems, but please show me an actual > path to this in the description. It should indeed be tidied up. >=20 > >=20 > > Fix this by calling `put_device()` instead of `kfree()`. This ensures t= hat > > the memory is freed properly via `iio_trig_release()` when the referenc= e > > count drops to zero. Not the first time this pops up and I actually thought it was already fixed= . But it seems we never got v5: https://lore.kernel.org/linux-iio/20251110035838.37029-1-make24@iscas.ac.cn= / Andy already fixed it for the main iio_dev allocation: https://lore.kernel.org/linux-iio/20251112145735.2075527-3-andriy.shevchenk= o@linux.intel.com/ - Nuno S=C3=A1 >=20