Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3434144imu; Sun, 11 Nov 2018 15:01:53 -0800 (PST) X-Google-Smtp-Source: AJdET5euq9D7SgRJmfWcvcS70DTRclMBVAYi70RtLkKHemBaFD6ng0fV3J2UbUlmF7X9Efj9dlcq X-Received: by 2002:a63:3c44:: with SMTP id i4mr15216111pgn.286.1541977313809; Sun, 11 Nov 2018 15:01:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541977313; cv=none; d=google.com; s=arc-20160816; b=iCbFzXk6ADQMPYz82PiMoGbDo2ticNP0Fv7j1i4nyDICTJeiTowDJdegGrReX7HEqA j9qjrqPtGoZj6c/bDqfMoiYpVzWDgVUcs7ZdjNcLG8a8PB3aSlLoY91UpwQkTlQpdiFR zr4Vf1rT0dcSBvqiJ745DvayHhYL8fAaEA5oAnkMW/8d61rGM6kHHjEEJrFTXQGt1QZH DDZ7rBwwFT4WKGMGxCWWOhw8zXGdYcQsBqqNqBQhPi1nVhy7OQwnpzdqARn+Q+whJWhl 0QUbf3XT9QBkzJqGdhoVZaACqK90FFSupbn84+AmD2Xo4D2ee7JPUpvyW73vrt578ZKO /i9A== 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=27INAR8EL4KeGUP1jQKuZaZjQ01J68w5gvODL/hGNks=; b=Fe2nYcMPLShAKaNh6nsRkYbXBFRVdcBIyr/MDQXNJ50HmgrS18zq53HgkiFiVbfHRn 0fZETvgeyXUxNnOh+kFeujK/8sptnBSQty+p6fV3aTByfngV9w95SdgXhr2aL9wsw6fJ rW0RugN05LeGeIBaOMJXatEFjuw1k/bgRcTkDDeJPIUOTguzNhindBNeeLzN2iUq5GSf 2X7a1QG/L1DUwQkVY7bSJmEfux2yd6GJThpDQFAE2HXfkf1s61OmNN1ZVtC7JqfX+7Tn xzSMuLNPmFiyxndzW3n4O8ySaMtssge6fGMB3Gc6pQFpycFCSsb1RWaEZPkTvzJLWSvw nIcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PcEg7Txc; 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 t191si14359320pgd.579.2018.11.11.15.01.38; Sun, 11 Nov 2018 15:01:53 -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=PcEg7Txc; 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 S2390751AbeKLIWg (ORCPT + 99 others); Mon, 12 Nov 2018 03:22:36 -0500 Received: from mail.kernel.org ([198.145.29.99]:51200 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390677AbeKLIWd (ORCPT ); Mon, 12 Nov 2018 03:22:33 -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 161C1223C6; Sun, 11 Nov 2018 22:32:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541975556; bh=IavFq8beVnODPHKxhCQZwLjcUHr797kB4c4B92Evg3Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=PcEg7TxcWv28YmDTcTI1zV1zFDTdWu5nZPlO5OODp6ycUidpuP8Rv+Mg2ZKVQTE52 sI/OYMnwgGjaOGxFoNxcFDMZbYlkZN23XWN+sTXpnERlVkhtUFKgaoIM8ODKsSsMM/ bL9+S5WNstRisxbycir4KSJs6TSuFoqCW7yVPi6w= 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.14 100/222] uio: ensure class is registered before devices Date: Sun, 11 Nov 2018 14:23:17 -0800 Message-Id: <20181111221656.883182326@linuxfoundation.org> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181111221647.665769131@linuxfoundation.org> References: <20181111221647.665769131@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.14-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 @@ -249,6 +249,8 @@ static struct class uio_class = { .dev_groups = uio_groups, }; +bool uio_class_registered; + /* * device functions */ @@ -780,6 +782,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: @@ -790,6 +795,7 @@ exit: static void release_uio_class(void) { + uio_class_registered = false; class_unregister(&uio_class); uio_major_cleanup(); } @@ -809,6 +815,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;