Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp3094543pxb; Mon, 1 Mar 2021 01:09:54 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUwoU2koKt/+/FroIOUneqSw/xGkkkziRD5V3p727f0ZAnIImiwCzlXsMyUQMy0pP6e7Ar X-Received: by 2002:a05:6402:268f:: with SMTP id w15mr15306203edd.333.1614589794376; Mon, 01 Mar 2021 01:09:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1614589794; cv=none; d=google.com; s=arc-20160816; b=AipMXNOOTUOozendn55xcO9L5vMTEY75BSV7jOXJXvE5s3S9COXC59So+1652iAv3b 9ctHG4m53cJBHMAbfmWNLcPNNi0NFwpt/YR1lgq71wSS3WdwS+NNCr29GAhxrqFd9Zeb OI4eeOiRGpy+Kvhg7n5DA3zgDPnqfL3Ga2TTcj2aPhNhRL74wVRsVdUqC+k2Q0HwbGym ToF9hccNn9PEXCk8aUqHsyEn8ghIrifGGh5iWZ7+7nQCzciQumhhDMhH1qDwtHysI+uQ tnZYdi3xMglgD/pzzjdm5fucFhDOByolWNtWAoKdI/TevVm/o+SJNCofId6yAYasxwrd FZ1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=uuMTpj7yfoH/X3IjsjcXcGSMZxeUbtnUuNLrYCM62o0=; b=BKGRDOEpDhw2DhIYeZ1nlEEn99hYByXRP4E+k7KjkgtoSuNsXEVkepAshqZpWVsxE7 uGOsOCL2J1N9cWWVUtRxoYB5aH26xwp0WCGnfL76Kbz6fBxheq2s0J7ThLh5g66TIIji X/+ONS+yIvPTBgZnFyKwCHwO8wYTqrFwj3sa2dw3svgoqmR4t2Svj+yJIzct0hQP9ogm 8K4Fop6+azmkR1jfcasS9///478ZTKc58MuSK8/s7Q+1+KUN/L2/ugVXbCstUIbM0w9X QyLAWy0aYYRkJ3Ah++P/Ucee29hn8zaO3wX25DO1fXLODjrkrrwqtfRNC2Iu8vMwThoW yNyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L6WarvyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id bd28si2180192edb.570.2021.03.01.01.09.32; Mon, 01 Mar 2021 01:09:54 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=L6WarvyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233770AbhCAJHc (ORCPT + 99 others); Mon, 1 Mar 2021 04:07:32 -0500 Received: from mail.kernel.org ([198.145.29.99]:38038 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233698AbhCAJFt (ORCPT ); Mon, 1 Mar 2021 04:05:49 -0500 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7F47164DD0; Mon, 1 Mar 2021 09:05:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1614589508; bh=rvD6Og3rqMKfJOFjvdy0rWdmzsvs8Xe8fGn3WwO5QKI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=L6WarvySsXUtX/+T8zMSEzobUepKWJuKdjEaFW3yvmFLW/7GEyzT9O3fCKCmLDaHl DSk+Y9c+XkbsrDYoCUl5M5MPnLU5edGM8T+OaC5l+CdFd8CIerzAgxDlDI1lX2YuaD UxXqynpxMH9lAdjFRt1sIwlogFCztk9O7RK1o50TJbXQOooEli8VWq7ur0CBhX218t tCraARMPM2dUxKn9fvRZFHI0GPY27m5JMeAxYtjUFHs4hETO7qhpSOlQ2X/+25gj1T Ys41JWchsdvvkRldwU1pzCvx7aNpPFbQ22EqE0yjuAy6eceOvH9HcD/7W2czE7RDBU kRbhCThuxy+oA== Received: from johan by xi.lan with local (Exim 4.93.0.4) (envelope-from ) id 1lGeUY-0006pJ-5i; Mon, 01 Mar 2021 10:05:26 +0100 From: Johan Hovold To: Linus Walleij , Bartosz Golaszewski Cc: Greg Kroah-Hartman , Saravana Kannan , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , syzbot+d27b4c8adbbff70fbfde@syzkaller.appspotmail.com Subject: [PATCH v2 1/2] gpio: fix NULL-deref-on-deregistration regression Date: Mon, 1 Mar 2021 10:05:18 +0100 Message-Id: <20210301090519.26192-2-johan@kernel.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210301090519.26192-1-johan@kernel.org> References: <20210301090519.26192-1-johan@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index adf55db080d8..6e0572515d02 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); list_del(&gdev->list); ida_free(&gpio_ida, gdev->id); @@ -605,7 +605,6 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, goto err_free_ida; device_initialize(&gdev->dev); - dev_set_drvdata(&gdev->dev, gdev); if (gc->parent && gc->parent->driver) gdev->owner = gc->parent->driver->owner; else if (gc->owner) -- 2.26.2