From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wr1-f53.google.com (mail-wr1-f53.google.com [209.85.221.53]) (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 213E13C3441 for ; Mon, 13 Apr 2026 12:37:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.53 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776083821; cv=none; b=rG9wx1nawVMT292tRJkiQIW1jhAobvdbWwjPwBMFA9f3gzViU8wc9qB7/L8h2mezjWqWrjrkkpNV6A9NkpPSTiEiQjfOy9AbdRWXPKsL1zJ4ewhwelmIfE9ETVetEexk4FEHVc40WLbOsppJoWuAiuyKFcodsFf3XzDAKMToLOg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776083821; c=relaxed/simple; bh=mgeEoe6AtB49kywapoFP3GPBJeS2SOQhv89gRBsFD7M=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=prd0ae8z7XSPrY2NsNHbr5l8pBCvGLDavKgGTgdVFap0sgvDfR2k6WparDomHrh8Wu/B7LpGnEFnr05dx11t5JUVhBtdcrB9PJ+wK27CdOnilUcdpwY+MOoJwSTygVPzr7T5sosV1q9nU8KoL7XzEymQpYB062LPhbyuYeUmR04= 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=YfIQKpiA; arc=none smtp.client-ip=209.85.221.53 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="YfIQKpiA" Received: by mail-wr1-f53.google.com with SMTP id ffacd0b85a97d-43cfac48bc7so2956980f8f.0 for ; Mon, 13 Apr 2026 05:36:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776083818; x=1776688618; darn=vger.kernel.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=x+X/xGhJvuBPL4tYv8hEPxNZ5/GB2yObANZwMOQLBRg=; b=YfIQKpiAMYRpoekTXJOt6MGKYr2YUr8BP5kqJjhds1DM6/xAmWvcjj5kp4K/2X3pDM tBNy3nmdrjjf+Edt6IajkCEJONqaNA1fqfiLDugk57fRC9gxE+8zdqaW6KUzt9xAwESx bLH6kMTWKbDsQbT6+pY1HX64AEPzgKWolRfP9pZ0JyLCtlhZk7qzA72l3+RZLn0bpTc9 yjGq3rqOyEPuEz2ewd+CoimMXjLGn5T/jFEQstwIePKLrYVDhLkX6C7/kXlGqyR8IzQb dh6Xy9qjFWqEzSiMjDOZ6tzh5Be3Z63+SoI0DiGiJNQMcC8ey7/Yh07sA9fRxuMjvwYK JrqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776083818; x=1776688618; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=x+X/xGhJvuBPL4tYv8hEPxNZ5/GB2yObANZwMOQLBRg=; b=mPgL86aSaLNdwdKBypt8ZnJw+0qhS4G0Xc3qpIuwqrysnCowZ3Zmjvtw8VSrvW/PfV tpDVb7cNCgKraejfKdglRlNT74H+G4bjEQBl2p6Sug/Bgwy5ZrR9I5rum6WEr2qri2o1 APLXxnsV7zdBXO3BbZ0HWwJFyw4JFA3UOzFm7gBApHT+wLZ/JFsRT1PczdtEc6DG74vd 8k+2i88Tp6CsvvHQlSgY4TxEvU9UT5k8EEXJZQDW0rw3KhL0u5iUfBu87FhFkWlIXOTL vvPZ02UE/aGJbXLJYiePpZR/+3X6n6hHaPRP+iOJWrArflOWVs1YalJHb6Vn2H4lzWjj gPeQ== X-Forwarded-Encrypted: i=1; AFNElJ8lIhDQ/6+AzSOn83FSqOQKs7U0kVdkMuOUSj1UADx0D6NwhNUA+8E2hV0HDzT8VQ/T3hbg4ZdjMr/Ns+U=@vger.kernel.org X-Gm-Message-State: AOJu0YwNs6a7kAbFiMt9iF5ZkTPjYrdzKu2flm+pG3OO8v+vMrhOzfF+ WnD4nTKFq9Y6xkhq9gC/QU9MUxIeePt4iCcasD4+pa+AGIYlRm3FnCkb X-Gm-Gg: AeBDieuqqbQZNt8wOR7Bswn/f5oNNgoLT2bG0zsRFtpeY88ekJ+UULpcnZqv0pc0D6W z7aCoaASNVgTMlH4bBeTOYS+I2SZXU8wBFrsiid1MHQoYlk4qDyxYNIm3pg0nE5ZgsaGmt7ZJYY glSUsR1omXgB6d+INsidI3OTXCGn3nMIvlAMF2thOZmCfFvc5ZU/SbUk5f+NhQnd5VMnpiOQ8Yt DjF43qsiNfdp9Ul+uBLdWNrx02PlBLW8y8eFA/usCLf6WXeAQTcp0hsJsewPyq6uiFHWZ+a1ima wSMxjaxBuE80bLI8UTu6ft/kRYh7awTcQOIP02ko22tPhD3ZRMJb0Nz+pbzLvpJLzJEf3lhtXv7 PPqZuh7hU8PS7OQPybzl5cuWLo+9ZPXKHRyAj9wNmIQ0lwbAtH5cwG7uVWyN6DCsHxxehWdGWPF i9mO2Sq3/2Bx+c1IXDaDs= X-Received: by 2002:a5d:64e6:0:b0:43d:7887:9f36 with SMTP id ffacd0b85a97d-43d7887a15fmr5464550f8f.2.1776083818336; Mon, 13 Apr 2026 05:36:58 -0700 (PDT) Received: from localhost ([196.207.164.177]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-43d6a1203b8sm28098391f8f.16.2026.04.13.05.36.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Apr 2026 05:36:57 -0700 (PDT) Date: Mon, 13 Apr 2026 15:36:54 +0300 From: Dan Carpenter To: Guangshuo Li 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 v2] iio: trigger: Fix refcount leak in viio_trigger_alloc() error path Message-ID: References: <20260413115656.2789049-1-lgs201920130244@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20260413115656.2789049-1-lgs201920130244@gmail.com> On Mon, Apr 13, 2026 at 07:56:56PM +0800, Guangshuo Li wrote: > After device_initialize(), the lifetime of the embedded struct device > is expected to be managed through the device core reference counting. > > In viio_trigger_alloc(), if irq_alloc_descs() or kvasprintf() fails, > the error path frees trig directly with kfree() rather than releasing > the device reference with put_device(). This bypasses the normal device > lifetime rules and may leave the reference count of the embedded struct > device unbalanced, resulting in a refcount leak and potentially leading > to a use-after-free. > > The issue was identified by a static analysis tool I developed and > confirmed by manual review. > > Fix this by using put_device(&trig->dev) in the failure path and let > iio_trig_release() handle the final cleanup. Also update the subirq_base > check in iio_trig_release() to test for >= 0, so that a negative error > code from irq_alloc_descs() is not treated as a valid IRQ descriptor > base during cleanup. > > Fixes: 2c99f1a09da3 ("iio: trigger: clean up viio_trigger_alloc()") > Cc: stable@vger.kernel.org > Signed-off-by: Guangshuo Li > --- > v2: > - note that the issue was identified by my static analysis tool > - and confirmed by manual review No, the issue is that you are working against old code. This bug was already fixed a different way upstream. regards, dan carpenter