From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (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 C1D641FC7 for ; Sun, 15 Feb 2026 11:32:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771155174; cv=none; b=uOE24HrRPiCbbLKsMzavyJGbIenlAUIxZe2dDQRSqHXrctvPH0jviTIYwWGNQVyeb0+V1wY0Ns8Nx2KLenKlvXOKShSbnmQNB5be0pUp117GYaEokHLgVwpgjjTw3i1/AZii0ZwmGGt+LV1PyyzKX8gtyxJNnslzuYRMM2HjUjU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771155174; c=relaxed/simple; bh=EiGztezg+QdrwfJTYNGicc2srVuiP//23AD6hVKMSNw=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=kNsLIGdMh+Iv/8IHGdkiJcq5tQqbmj/nq1feRzU0esEhy/oR8iJRP8+3teycfTkuplPdPjRFwnB5zpH4MqXQBEymez1uA4xtbSN3zz+SLHZzOv3II47lO209454OhEPSaD4p0mqR3M+Z2hwlIPkxhCPsMZ96S8S3pgGJ5fdovfY= 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=Z9Eu7kx5; arc=none smtp.client-ip=209.85.214.181 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="Z9Eu7kx5" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-2a90055b9e9so9228505ad.1 for ; Sun, 15 Feb 2026 03:32:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1771155173; x=1771759973; 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=7ZyKqDnvoX+DGQQ7E9chqL4FWW/ISzd19EF4hzC4/To=; b=Z9Eu7kx5j5RyZEeAPlR3W+qB8amPo0/40NVytD1Y9TJgfyPUMkc46kns7DsU5v2g9h 0nVb4PG4jKLlHIpkjEIJAigRWoay8LpxNF0kSyUtD/hWTy2cOYfKQwzsQJ/6wLLKfQ08 TjrhcEzxJ+R8EC5tv3L39jG+w+vhh4kPv7JnicvA3lmRu/uk/KrBRt4XL+Y0WaePGR2u AsUdSFquJTv1UqhylJXQi/h7mHL+92jhP+mZXyvESxDVFJSSN0QDO3PZBqX7HyCWpMR6 JqioEU1bVEUsynQ6g8fAWW5EytwKDex3Fy+HQcQXzBIG7EFu6KdqbvHmTB9GRRHPMPmj GSew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771155173; x=1771759973; 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=7ZyKqDnvoX+DGQQ7E9chqL4FWW/ISzd19EF4hzC4/To=; b=ENZWWi1sOs/7j6t1UW+xt0HZhzzGSyQcLderRuMWDxJ6Ue/zcGPYtEz/dcxKF8VEhN kzp0w/G/LAE+N64VtvcsGFT0bkdMrIQqmKmcR1VLp4F3W0N2lXcxxIyMDCbyT0CRF3QF P6sInGiu4XUDdpaG+ShCgh5zvhRlAk14l/BeTHZsOXZc6K99p1ddTV4KicGICYem1ns6 51FX32v7fzjDCNCFltJj+P8tRu0K6F9bUE0k+q6kjMfQPHozCDv3oFIoBx+k/RPizApg yoVJSswyvCLbpst8YivOPO9a6JCc5TPKJ1ln/BCa4imHnBEq1TjyoVBIyV7b4PuMTNMo BFmQ== X-Forwarded-Encrypted: i=1; AJvYcCU9qN/Rr5eWhSuuNvGmwAnFjO0YI6N6CowDAn9gfRXmJ+njVpNKI3Is9q4eDw9MZaMyM3xaT4Evo2NMfzk=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0DZL8a6XqVTu6JkTwhbiH4XeRm9da+CM3cojKvtkkjcXi8mMD ZuKdChfHSLy/4w7Z2W9NR3qzJRXiFCIFfDbPdUfr7vDLYsTqVnuIzCnI X-Gm-Gg: AZuq6aJRvGVyWLicvZxeMoQm0mpJ8EY5ELNPfYDjWDHYU14MoTajGnhNvOEBciDfeZV zVYxawXuEoWFcLQjCHOuTKv0806Dhql+vnEH7YrYqO4bWBnN2NjYPWUfIg67e8Qkib6hZ3BU1mA cB01MQGEkkRefjNkN/BK5isESd0lMHG1MVcncMiDKlUDGZfIxo9iY9IvqaH34gvT3eozE/m71QN qtsL5AwnM8+mbiYvp4Y6jY7nDVLsxD0Y+1jhFXbucW3esGlexasdYrrDQVz6U4BuESNvNEO2aIn Z3HwCh3n++vYT4r9Nb6iCxhUkdl5l8ZexC/33iR6oRhRk9UjjcXL2IXLGwotAuT5YES6GO6GEDm 6mqDPZkMTez1GSUYlU9mBnhnOx4dofLkJnhUNS7xOq2l4qtXXPbfrCpm1eV72qKB0EJuBa7UPMr 6rPQIwIxI8dwXGvxQbRSobcF8IoY6gBkd9vSk5abyN/XoBi6nqAA== X-Received: by 2002:a17:902:ecca:b0:2a8:a133:dfed with SMTP id d9443c01a7336-2ab5061f123mr75612935ad.55.1771155173089; Sun, 15 Feb 2026 03:32:53 -0800 (PST) Received: from rigel (27-32-126-215.static.tpgi.com.au. [27.32.126.215]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ad1a9d5c4csm42209045ad.53.2026.02.15.03.32.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 15 Feb 2026 03:32:52 -0800 (PST) Date: Sun, 15 Feb 2026 19:32:46 +0800 From: Kent Gibson To: Douglas Anderson Cc: Linus Walleij , Christian Brauner , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] gpio: Avoid NULL dereference in linehandle_create() Message-ID: <20260215113246.GA46983@rigel> References: <20260213092930.1.I77c3eb563271c21870379eefd16ebbc4e09635bb@changeid> 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: <20260213092930.1.I77c3eb563271c21870379eefd16ebbc4e09635bb@changeid> On Fri, Feb 13, 2026 at 09:29:31AM -0800, Douglas Anderson wrote: > In linehandle_create(), there is a statement like this: > retain_and_null_ptr(lh); > > Soon after, there is a debug printout that dereferences "lh", which > will crash things. > > Avoid the crash by reading value needed by the printout before making > "lh" NULL. > > Fixes: da7e394bf58f ("gpio: convert linehandle_create() to FD_PREPARE()") > Signed-off-by: Douglas Anderson > --- > > drivers/gpio/gpiolib-cdev.c | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/drivers/gpio/gpiolib-cdev.c b/drivers/gpio/gpiolib-cdev.c > index 2adc3c070908..13ab6a5ebb76 100644 > --- a/drivers/gpio/gpiolib-cdev.c > +++ b/drivers/gpio/gpiolib-cdev.c > @@ -304,6 +304,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) > { > struct gpiohandle_request handlereq; > struct linehandle_state *lh __free(linehandle_free) = NULL; > + u32 num_descs; > int i, ret; > u32 lflags; > > @@ -379,6 +380,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) > lh, O_RDONLY | O_CLOEXEC)); > if (fdf.err) > return fdf.err; > + num_descs = lh->num_descs; > retain_and_null_ptr(lh); > > handlereq.fd = fd_prepare_fd(fdf); > @@ -388,7 +390,7 @@ static int linehandle_create(struct gpio_device *gdev, void __user *ip) > fd_publish(fdf); > > dev_dbg(&gdev->dev, "registered chardev handle for %d lines\n", > - lh->num_descs); > + num_descs); > Use handlereq.lines rather than creating another local shadow. Cheers, Kent.