Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp1109160imm; Wed, 1 Aug 2018 10:19:34 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeIja0jZ1+IISSgZhQjlQONa4M4hiuJ71gCkRk6TcGvgHcOCJKKXV7ubNHM/9MjEIMZdMYZ X-Received: by 2002:a17:902:201:: with SMTP id 1-v6mr25853410plc.310.1533143974129; Wed, 01 Aug 2018 10:19:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1533143974; cv=none; d=google.com; s=arc-20160816; b=Zq5tvoMAMpbaeLwb78o6TL8o0X5eGXrdr0oTWSfIpnXObBIoJgAMDWQYDSJFzxpwuQ 55OycIawjOIVj6Lal7c7a2BKwj8mtQDHVwFM8KWV9W8uX0dCsQ5QUdd6gOCjbI0cdl7v wAA5OYisjyTBadDYteqxF3Z1Q17Lv98Z24vouOREUWsjWcDxUaHsCY3uNFz2f0+33Aii CUkrUwIUZPO0GsOZyuJteqxjk3bAcr/DDdnYPn5XYT06xuFOL5f6O1BWD2rJp8SOd81l F7DNJ3wzQcjMH3U4h4ewgq4L4CZrmmnYfkniU4MEdKq9/goXaHQWjMQh3wj9CgvFqoOR Iw8Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=KSA/lseeT6t8LBX0DBQ3Mx699MvU5BYNeKHOCGCUy64=; b=NFApnzuKyA8UJP7RbRwLgskzLjChP7lO/lBLcZcoeVYdHLLIPILlTk60yNYiHIokb6 x8WqhROJWwFfdueAnKYpHEk6Yj/qnyBL3C89/+eEsUehCAH/ygclFYknf6RrVLj239jc 1vG+oPYUIxknCGFRM6ZjIzzFWtx4qG+mAGwZsgJfhwZbf9Y7eKMTk9zSRukN/M3sq/he PnnQDEiM5OIcJA3jEzAGkdaob9Z6wKNx1z68TPNplFwUR9jYrcCL34PBbd+4hn08NM2P LemcvxR8ZYUfEIFCIWjTzx5IwGXPAgjsvaQ3LVX3k7pB3qauDYKCB1fEMTQaMNgp8fmE v/hQ== ARC-Authentication-Results: i=1; mx.google.com; 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 q185-v6si17460003pga.322.2018.08.01.10.19.19; Wed, 01 Aug 2018 10:19:34 -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; 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 S2404811AbeHATEf (ORCPT + 99 others); Wed, 1 Aug 2018 15:04:35 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:46542 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2403856AbeHATEe (ORCPT ); Wed, 1 Aug 2018 15:04:34 -0400 Received: from localhost (D57E6652.static.ziggozakelijk.nl [213.126.102.82]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id A5095C96; Wed, 1 Aug 2018 17:17:53 +0000 (UTC) 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 123/246] rtc: vr41xx: fix possible race condition Date: Wed, 1 Aug 2018 18:50:33 +0200 Message-Id: <20180801165017.606022247@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180801165011.700991984@linuxfoundation.org> References: <20180801165011.700991984@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 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 9a99247c9c1d1c95c6e8153d013979aac6111c6e ] The probe function is not allowed to fail after the RTC is registered because the following may happen: CPU0: CPU1: sys_load_module() do_init_module() do_one_initcall() cmos_do_probe() rtc_device_register() __register_chrdev() cdev->owner = struct module* open("/dev/rtc0") rtc_device_unregister() module_put() free_module() module_free(mod->module_core) /* struct module *module is now freed */ chrdev_open() spin_lock(cdev_lock) cdev_get() try_module_get() module_is_live() /* dereferences already freed struct module* */ Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin Signed-off-by: Greg Kroah-Hartman --- drivers/rtc/rtc-vr41xx.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) --- a/drivers/rtc/rtc-vr41xx.c +++ b/drivers/rtc/rtc-vr41xx.c @@ -292,13 +292,14 @@ static int rtc_probe(struct platform_dev goto err_rtc1_iounmap; } - rtc = devm_rtc_device_register(&pdev->dev, rtc_name, &vr41xx_rtc_ops, - THIS_MODULE); + rtc = devm_rtc_allocate_device(&pdev->dev); if (IS_ERR(rtc)) { retval = PTR_ERR(rtc); goto err_iounmap_all; } + rtc->ops = &vr41xx_rtc_ops; + rtc->max_user_freq = MAX_PERIODIC_RATE; spin_lock_irq(&rtc_lock); @@ -340,6 +341,10 @@ static int rtc_probe(struct platform_dev dev_info(&pdev->dev, "Real Time Clock of NEC VR4100 series\n"); + retval = rtc_register_device(rtc); + if (retval) + goto err_iounmap_all; + return 0; err_iounmap_all: