Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3478062imu; Sun, 11 Nov 2018 16:01:49 -0800 (PST) X-Google-Smtp-Source: AJdET5cQPtJCT3HkCymYMf//S/dzSHVWQwgYfsdUOEIXh4Dh54fukVhRLp31DnxgIBHTlR0ylqtj X-Received: by 2002:a63:5816:: with SMTP id m22-v6mr15285397pgb.332.1541980909451; Sun, 11 Nov 2018 16:01:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980909; cv=none; d=google.com; s=arc-20160816; b=SHHqP8eLhblEJED0ZfOWIRs1htWPj0gB8ebANbC8quxD8kWexacj9xnAd+raIbhpIC 72n7YMJ2VnxIOli8717GF5dJgoTc6eTy8Btk+w8/GOn3KQjVMAfn5dSCqLOpUHLZY4Pl XTSHxENIexPA5RcygOYnNJbGVEbhgvo5BJt39n0JeLC9qEpHzOXhw61DA/qIng88rZvw rLaVCim6fQsiubBy/fv+m+KcdG4wJeDgZPF1rlxOQv8PJ39C0zvKC2cZqOpw65ZjbHl8 CVudYhMrGDwEZNwy511rRwUsG2GCdDFlpBGsr1e+KwJe7N8lXB7jfyDTeRAbDezJf+XA Lxkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=neaWkMAIRS5K61gBp7J5ezFCOSjS6TORiD7JJCQfAXw=; b=X2eG6AAzCy4pptVvmzhiDqPQrrO2mVj1pk+QHpU00xmtKkLHxNlbfMqNta6Ivvtsyl udXZIpmHyebC1NT+hfDylk1sspDqXqHKYOg7Se1L0TttphhM2rGha5Zluyq5rYRGgehM KRBdX2xMpsuDGbeKCX5jOPViIWC67j7dzfo7wN2WcWwcbQgL1I26K8kC307YBjP1jC8D bV9tFx8mRZtqMqT+2ZGiinyBcurEHMIX7Jt6zMw5DKTBjeSR//QizGvg2qiJeFWjlxdK 6GLwpxzrgHE7JuMBdfpyTT3ISnGsJUI2K5Kaqzpmq7dkuH3CGHtcDF4U4Go4U/JdAmLC M4og== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=IfmCuYJd; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id o1-v6si15210198plk.304.2018.11.11.16.01.34; Sun, 11 Nov 2018 16:01:49 -0800 (PST) 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=IfmCuYJd; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732338AbeKLISB (ORCPT + 99 others); Mon, 12 Nov 2018 03:18:01 -0500 Received: from mail.kernel.org ([198.145.29.99]:35336 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732312AbeKLISA (ORCPT ); Mon, 12 Nov 2018 03:18:00 -0500 Received: from localhost (unknown [206.108.79.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id EE2D7216FD; Sun, 11 Nov 2018 22:28:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975285; bh=LjEI2AEX8MurREg1m68x3mmVRAdZbzIsPfrN7LPL7rM=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=IfmCuYJdGmQtA1g0YnOIk/X08zQXqdidMlBwgzi8oaQMMbfutdmSujhyzfioJEUQh A9CfYUHBO72dFbrHvyZG9Mjx+SFrcwt4pQe88Ehn0s69FUb0aZ9BUJnV4Voype6bO0 PT9csV1+mdR+TgqfF8600Frdkyo/CzL6sCP2Ue38= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Alexandre Belloni , Sasha Levin Subject: [PATCH 4.19 180/361] uio: ensure class is registered before devices Date: Sun, 11 Nov 2018 14:18:47 -0800 Message-Id: <20181111221645.428114674@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221619.915519183@linuxfoundation.org> References: <20181111221619.915519183@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.19-stable review patch. If anyone has any objections, please let me know. ------------------ 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 Signed-off-by: Greg Kroah-Hartman --- drivers/uio/uio.c | 9 +++++++++ 1 file changed, 9 insertions(+) --- 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 @@ exit: 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 struct uio_device *idev; int ret = 0; + if (!uio_class_registered) + return -EPROBE_DEFER; + if (!parent || !info || !info->name || !info->version) return -EINVAL;