From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 22F61C433DB for ; Mon, 1 Mar 2021 08:45:52 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D931064DE0 for ; Mon, 1 Mar 2021 08:45:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233421AbhCAIpf (ORCPT ); Mon, 1 Mar 2021 03:45:35 -0500 Received: from mail.kernel.org ([198.145.29.99]:57340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233319AbhCAIpK (ORCPT ); Mon, 1 Mar 2021 03:45:10 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4773A64DEF; Mon, 1 Mar 2021 08:44:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614588269; bh=yI9vk7/j1WOYnOHUSAxSo33Gf4b9ogltKOcygaxgC/A=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=AwU+infUiSF+eRxYlr3iF3Nhty9BbOR3OFHSqz0/Xw9d9LTaxrngHHfGWJvirKuJH KWq6z5dhctFSfAJL1Pmfmq/zNSwv57U2iFnfAfAmq9K+VNBKbKc/XX2KBZN9NNuW06 fqthBzcLxzrCoHozjj/iAJnjCizyJJwk3ATIhIwRgV7f0WBj9MZHeYVtUk0GOlKIAL 9fmoq3Lsup02yWimweaIH5dzNx1PhE8s88zWWjvvcwlLZHoNYlwXoXEKesGRp6fxWl uvGeYPRacjNptGp8pHpyEJn9ymAyzWYDkuBP9t/rTS4K4QvOhfbjeRG6szB9R/jwS4 0aVel+tqYRxUQ== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lGeAY-00017E-1A; Mon, 01 Mar 2021 09:44:46 +0100 Date: Mon, 1 Mar 2021 09:44:46 +0100 From: Johan Hovold To: Saravana Kannan Cc: Linus Walleij , Bartosz Golaszewski , Greg Kroah-Hartman , "open list:GPIO SUBSYSTEM" , LKML , syzbot+d27b4c8adbbff70fbfde@syzkaller.appspotmail.com Subject: Re: [PATCH 1/2] gpio: fix NULL-deref-on-deregistration regression Message-ID: References: <20210226145246.1171-1-johan@kernel.org> <20210226145246.1171-2-johan@kernel.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Feb 26, 2021 at 01:54:12PM -0800, Saravana Kannan wrote: > On Fri, Feb 26, 2021 at 6:55 AM Johan Hovold wrote: > > > > Fix a NULL-pointer deference when deregistering the gpio character > > device that was introduced by the recent stub-driver hack. When the new > > "driver" is unbound as part of deregistration, driver core clears the > > driver-data pointer which is used to retrieve the struct gpio_device in > > its release callback. > > > > Fix this by using container_of() in the release callback as should have > > been done all along. > > > > Fixes: 4731210c09f5 ("gpiolib: Bind gpio_device to a driver to enable fw_devlink=on by default") > > Cc: Saravana Kannan > > Cc: Greg Kroah-Hartman > > Reported-by: syzbot+d27b4c8adbbff70fbfde@syzkaller.appspotmail.com > > Signed-off-by: Johan Hovold > > --- > > drivers/gpio/gpiolib.c | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c > > index adf55db080d8..e1016bc8cf14 100644 > > --- a/drivers/gpio/gpiolib.c > > +++ b/drivers/gpio/gpiolib.c > > @@ -474,7 +474,7 @@ EXPORT_SYMBOL_GPL(gpiochip_line_is_valid); > > > > static void gpiodevice_release(struct device *dev) > > { > > - struct gpio_device *gdev = dev_get_drvdata(dev); > > + struct gpio_device *gdev = container_of(dev, struct gpio_device, dev); > > Can you also delete the dev_set_drvdata() in > gpiochip_add_data_with_key() if the drvdata is not used > elsewhere anymore? I skimmed the code and it doesn't look like it, but > I could be wrong. Yeah, I considered it but didn't want to risk introducing any new regressions just to clean up a redundant store. But looking at it again today, I agree that it looks like it isn't used anywhere else. I'll send a v2. Thanks. Johan