Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp169238imd; Wed, 31 Oct 2018 16:42:56 -0700 (PDT) X-Google-Smtp-Source: AJdET5d6C1CRmklfzpQ7s760nDO3DhnmkfyLNC4baCDso5h5FvXe/pqS7mlRLGIb+9O5eDXB+5di X-Received: by 2002:a63:9e58:: with SMTP id r24mr5142241pgo.264.1541029376214; Wed, 31 Oct 2018 16:42:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1541029376; cv=none; d=google.com; s=arc-20160816; b=bYDB+cGZeUydx4DpxNkB2SvozzXWJr0tAONyW4wZ0sWdL+ZeXLVnCCTNs67cro952I bD7cRj79wlb3wicjRwok9K82YQNZoZma8u5SZS2vLfwHUnfPeoVqExvArt66UKoqCBKT eFHTwlBz93scFejMKHe94R5O96ZA6BLEzKxwBfB13mbZh0UsvxIjabJS7JSGBK0HGVW5 nwur3bSlugA+jZq62P8aW7/t/xpHM2qVA5T7yOZVpsXvI2ef/NIzQ6Yx4/zvAPTRH6We G0h5CTRKp+fyE+/g92MYbkiyqCq6404+JK9KeGURZpKGkEZcot7BteGY9+b7/L1E1XfS bQXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=zzq+cd5xIvV4P5rLt5M8QN0bQKIRmTheCwIbnLZplZo=; b=t4E9w9Ka84RHGABnRxlK72Tw2/aqwnpZ6GFR+cAylWWhHBfqovNT/MfS5huJXDeyYB 4Mn1tAIS24b5awi5am7qqoE4eNv/H/msSyk9INL3FPCqrNaYKMG4AasAhr0sYzbLMZDo OtvjxgZBiS5hesy1lOrX7SBHz0CjZhGEwr4nqPjvZ7/AGASc1iaDxPX0eiJuW4K59qRR w+1CU6acKIED7I4MNnvrFbefGghhrunrDaRv8WLYh7uHQmEMdPXIZt8fsjGI8sOTWThq HK+psbyCxLQzYphK8uCwFKK4auL0opAFo0tHLq71ov0Y6A+Mpe4Qj+MCikhI29q0hXQu Ihew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bngs8zo1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id l12-v6si1976789pff.126.2018.10.31.16.42.41; Wed, 31 Oct 2018 16:42:56 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=bngs8zo1; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729516AbeKAImn (ORCPT + 99 others); Thu, 1 Nov 2018 04:42:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:56204 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729243AbeKAIHz (ORCPT ); Thu, 1 Nov 2018 04:07:55 -0400 Received: from sasha-vm.mshome.net (c-73-47-72-35.hsd1.nh.comcast.net [73.47.72.35]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0B18720830; Wed, 31 Oct 2018 23:07:43 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541027264; bh=oQW7/+91pB5IPa48WxfQnqlmmyDbDeDbFnpAky1I2ME=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bngs8zo1pDmHI3utZaPqUaJKzWH89vDj98AeudATOhePRcIHx/QSiq7JQu1BHwDBL Kvjz3V6pq4UG8qAw6752Ct2OSbZxf2pHrvV4GUsYrj30mOsFfbDGFK6v1UG1tjIacL dF3Hi/O+rIoVB8O9riaWf7MvILv5HDtWCvHnABKw= From: Sasha Levin To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Alexandre Belloni , Greg Kroah-Hartman , Sasha Levin Subject: [PATCH AUTOSEL 4.19 136/146] uio: ensure class is registered before devices Date: Wed, 31 Oct 2018 19:05:31 -0400 Message-Id: <20181031230541.28822-136-sashal@kernel.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20181031230541.28822-1-sashal@kernel.org> References: <20181031230541.28822-1-sashal@kernel.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Belloni [ Upstream commit ae61cf5b9913027c6953a79ed3894da4f47061bd ] When both uio and the uio drivers are built in the kernel, it is possible for a driver to register devices before the uio class is registered. This may result in a NULL pointer dereference later on in get_device_parent() when accessing the class glue_dirs spinlock. The trace looks like that: Unable to handle kernel NULL pointer dereference at virtual address 00000140 [...] [] _raw_spin_lock+0x14/0x48 [] device_add+0x154/0x6a0 [] device_create_groups_vargs+0x120/0x128 [] device_create+0x54/0x60 [] __uio_register_device+0x120/0x4a8 [] jaguar2_pci_probe+0x2d4/0x558 [] local_pci_probe+0x3c/0xb8 [] pci_device_probe+0x11c/0x180 [] driver_probe_device+0x22c/0x2d8 [] __driver_attach+0xbc/0xc0 [] bus_for_each_dev+0x4c/0x98 [] driver_attach+0x20/0x28 [] bus_add_driver+0x1b8/0x228 [] driver_register+0x60/0xf8 [] __pci_register_driver+0x40/0x48 Return EPROBE_DEFER in that case so the driver can register the device later. Signed-off-by: Alexandre Belloni Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/uio/uio.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c index 70a7981b94b3..9916edda5271 100644 --- a/drivers/uio/uio.c +++ b/drivers/uio/uio.c @@ -274,6 +274,8 @@ static struct class uio_class = { .dev_groups = uio_groups, }; +bool uio_class_registered; + /* * device functions */ @@ -876,6 +878,9 @@ static int init_uio_class(void) printk(KERN_ERR "class_register failed for uio\n"); goto err_class_register; } + + uio_class_registered = true; + return 0; err_class_register: @@ -886,6 +891,7 @@ static int init_uio_class(void) static void release_uio_class(void) { + uio_class_registered = false; class_unregister(&uio_class); uio_major_cleanup(); } @@ -912,6 +918,9 @@ int __uio_register_device(struct module *owner, struct uio_device *idev; int ret = 0; + if (!uio_class_registered) + return -EPROBE_DEFER; + if (!parent || !info || !info->name || !info->version) return -EINVAL; -- 2.17.1