Received: by 10.223.185.116 with SMTP id b49csp5960689wrg; Wed, 7 Mar 2018 22:42:27 -0800 (PST) X-Google-Smtp-Source: AG47ELsGUyoTSD8ZCEboV7a2j3wTZ+9LybS9+WHl4OgkoCSCSlUTESS0sy2+Tu2SZ/5d/8CkGSDC X-Received: by 10.98.215.2 with SMTP id b2mr25016831pfh.87.1520491347845; Wed, 07 Mar 2018 22:42:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1520491347; cv=none; d=google.com; s=arc-20160816; b=h745oueO/2bkBm1O1vNNglVo1skonY0cKT+AT2oW0Y8w5oqKIEy6nGh/+VW4aqPmaz DCk3KT8gGZXUs2rxl44oD4Fk6KenASA2rXLJRPJwUJgL3y01IKE+DyjmQfLpx3zUL5Ly igjKvRFbaAwEyd9biRqe1Q8NTXhmNWRu3a0YEFRKDVdpTcKQ63fnh053rrFCLh3FgEkC OWvhc5GHOgfygTuuIMrJ7iETKts5GhqcL1thsmOZ0Bx3RvWjmsGa8I6aCGlpcLr9dl/F MvUc8DxQCCkwxMNnuvIPDaTTdDjEOGz4RS4Diay9luAxTiDBQNjYuhSSm6kIVL3kocip RqqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :spamdiagnosticmetadata:spamdiagnosticoutput:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=kV56e1pNxGQRU0/0NhRpBxorcQb3BCoyXTZ1LLE6M2w=; b=NglXfP1ENQB109Ad/Ruk8AeE/MpkW780TlOEflhxqQFviAtEtSNWw/p6W7rfz3kmk9 XosuhlbWrT19+CV4JVIwihCJifuMkJSKPctLNp8fAJaZxe1t/PfjNydLUTvHye7An2+T syWmS4l4S6XG7TSk2xTU1ICtXH33cAJ64Dec+MLgPKxjy0Y3IVPiokNiZBjKAZzi/4Si WqCdqZdHeCdai8nOruIDOWGxYb0uwuIrFq94Kza0vfEDw9T9O3Q58+N5Y+CgQUMuNtab xFGSAtdtYPwLPmYW5Jd6eG7FBb9Mze4mMwQ0U1f8FXY1mhgmfP3iknJ7gKAbmVMNG5ka jdzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@microsoft.com header.s=selector1 header.b=LkWQr8AQ; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id z13-v6si3215044plo.614.2018.03.07.22.42.13; Wed, 07 Mar 2018 22:42:27 -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=@microsoft.com header.s=selector1 header.b=LkWQr8AQ; 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=REJECT sp=REJECT dis=NONE) header.from=microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S935373AbeCHE7H (ORCPT + 99 others); Wed, 7 Mar 2018 23:59:07 -0500 Received: from mail-sn1nam01on0102.outbound.protection.outlook.com ([104.47.32.102]:61147 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S935349AbeCHE66 (ORCPT ); Wed, 7 Mar 2018 23:58:58 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=kV56e1pNxGQRU0/0NhRpBxorcQb3BCoyXTZ1LLE6M2w=; b=LkWQr8AQpq+CBFxutDyH4mXl7b00hBdAAtwjV6C6SX5VxLdQmeWRT7rnuazQ1Rq6M7ztC7s40qK+jLIWXDRFake+EPmJZ5R8R475c7Abxk4gvUjQRiA4Q2fhzGFPzqtu+HbbWG3IIM2qfLIf+N1gf8evFET54UUpel3+nxQnSjg= Received: from DM5PR2101MB1032.namprd21.prod.outlook.com (52.132.128.13) by DM5PR2101MB1015.namprd21.prod.outlook.com (52.132.133.37) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.588.3; Thu, 8 Mar 2018 04:58:54 +0000 Received: from DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446]) by DM5PR2101MB1032.namprd21.prod.outlook.com ([fe80::8063:c68a:b210:7446%2]) with mapi id 15.20.0588.008; Thu, 8 Mar 2018 04:58:54 +0000 From: Sasha Levin To: "linux-kernel@vger.kernel.org" , "stable@vger.kernel.org" CC: Alexandre Belloni , Sasha Levin Subject: [PATCH AUTOSEL for 4.14 35/67] rtc: ac100: Fix multiple race conditions Thread-Topic: [PATCH AUTOSEL for 4.14 35/67] rtc: ac100: Fix multiple race conditions Thread-Index: AQHTtpoAPaMm9JHUoEyrk+Hr3yY26Q== Date: Thu, 8 Mar 2018 04:57:46 +0000 Message-ID: <20180308045641.7814-35-alexander.levin@microsoft.com> References: <20180308045641.7814-1-alexander.levin@microsoft.com> In-Reply-To: <20180308045641.7814-1-alexander.levin@microsoft.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [52.168.54.252] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;DM5PR2101MB1015;7:e7HMGuQGe9Ht4Ys1xgqkj3I3jor4Y4vqmojLkJPOZS1FpIoMJS5PDYlzu3Yrk0aL5a4JbjTsbFdmYno25UFJbqaCU1AmJT7E3AQ+XxeSkhaRfOeV0FVRoCs5ajQIWtXc+TFhyqnfZKvu/S1Wu9ytJvQWNZxeGik/kGFSwJZog9sNhShkqspQFKUw8Zwv3ol0EmWlFgqwem1KuPj0kuaLJsF+KjqlM9P7PsaAld/GcsW1eNBopfvFZzi3/zFrvmfR;20:3Dhv8M3WEfmYR8xHMUORSkXSJjM/zeWaquqIOEYGw1AAKVaD0OHfW3TT6zfkCYPZmHK3bE8JS47A3IhCWjLF2HLdTKcbHA6yrCaGgSI+VA268X4rMdPU1go9kSMB62sC/Z920uA/aAX7XUib2w6lQd3hG0gqVAwJc2WpBwxyS5w= x-ms-office365-filtering-ht: Tenant x-ms-office365-filtering-correlation-id: 37093c68-977c-4fd6-8992-08d584b14b44 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(48565401081)(5600026)(4604075)(3008032)(4534165)(4627221)(201703031133081)(201702281549075)(2017052603328)(7193020);SRVR:DM5PR2101MB1015; x-ms-traffictypediagnostic: DM5PR2101MB1015: authentication-results: spf=none (sender IP is ) smtp.mailfrom=Alexander.Levin@microsoft.com; x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(28532068793085)(89211679590171)(58145275503218); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(8211001083)(61425038)(6040501)(2401047)(8121501046)(5005006)(93006095)(93001095)(3231220)(944501244)(52105095)(10201501046)(3002001)(6055026)(61426038)(61427038)(6041288)(20161123560045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123562045)(20161123564045)(20161123558120)(6072148)(201708071742011);SRVR:DM5PR2101MB1015;BCL:0;PCL:0;RULEID:;SRVR:DM5PR2101MB1015; x-forefront-prvs: 060503E79B x-forefront-antispam-report: SFV:NSPM;SFS:(10019020)(376002)(396003)(366004)(39860400002)(39380400002)(346002)(189003)(199004)(6116002)(53936002)(1076002)(107886003)(3846002)(3660700001)(10090500001)(6666003)(2950100002)(2906002)(6512007)(99286004)(8936002)(6486002)(76176011)(6506007)(68736007)(59450400001)(316002)(110136005)(81156014)(81166006)(8676002)(54906003)(3280700002)(2900100001)(6436002)(97736004)(72206003)(25786009)(10290500003)(86612001)(4326008)(305945005)(7736002)(66066001)(22452003)(478600001)(5660300001)(86362001)(575784001)(14454004)(106356001)(36756003)(102836004)(5250100002)(105586002)(26005)(2501003)(186003)(22906009)(217873001);DIR:OUT;SFP:1102;SCL:1;SRVR:DM5PR2101MB1015;H:DM5PR2101MB1032.namprd21.prod.outlook.com;FPR:;SPF:None;PTR:InfoNoRecords;MX:1;A:1;LANG:en; received-spf: None (protection.outlook.com: microsoft.com does not designate permitted sender hosts) x-microsoft-antispam-message-info: gCQ9BsKra/lztqRFvGTWeCjknespYKKkUJW2sI0KGIqUPmBd+tNpXeXq5TM9nrtoyGVjBlqiAWa94GnI7FOi7OjGAljy442atg+uFgX9vWpqMwbVRxXZ/y2RiNTfDtmjj2oC+I0wCq3fSdq7tvlPuhcMolCqqXOqhqGyVlKbeVJOrvtoiZsczelat9h23RDAXtC6jwXiHC2gNlaKo3S03B7ixsSaIKsM2ycUudOWNoi8F8DLubbUo1hk76EfdjYH0Di4EWxCWfVho9UZhAQPTJAPr0YMf+kqUuPi63TbGgao6+G3jNbxtanCPBDLdbeguOTYghwVwuNp/VU+NyPoLw== spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: microsoft.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37093c68-977c-4fd6-8992-08d584b14b44 X-MS-Exchange-CrossTenant-originalarrivaltime: 08 Mar 2018 04:57:46.8545 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 72f988bf-86f1-41af-91ab-2d7cd011db47 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM5PR2101MB1015 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Alexandre Belloni [ Upstream commit 994ec64c0a193940be7a6fd074668b9446d3b6c3 ] The probe function is not allowed to fail after registering the RTC 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 =3D 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* */ Also, the interrupt handler: ac100_rtc_irq() is dereferencing chip->rtc but this may still be NULL when it is called, resulting in: Unable to handle kernel NULL pointer dereference at virtual address 0000019= 4 pgd =3D (ptrval) [00000194] *pgd=3D00000000 Internal error: Oops: 5 [#1] SMP ARM Modules linked in: CPU: 0 PID: 72 Comm: irq/71-ac100-rt Not tainted 4.15.0-rc1-next-20171201-d= irty #120 Hardware name: Allwinner sun8i Family task: (ptrval) task.stack: (ptrval) PC is at mutex_lock+0x14/0x3c LR is at ac100_rtc_irq+0x38/0xc8 pc : [] lr : [] psr: 60000053 sp : ee9c9f28 ip : 00000000 fp : ee9adfdc r10: 00000000 r9 : c0a04c48 r8 : c015ed18 r7 : ee9bd600 r6 : ee9c9f28 r5 : ee9af590 r4 : c0a04c48 r3 : ef3cb3c0 r2 : 00000000 r1 : ee9af590 r0 : 00000194 Flags: nZCv IRQs on FIQs off Mode SVC_32 ISA ARM Segment none Control: 10c5387d Table: 4000406a DAC: 00000051 Process irq/71-ac100-rt (pid: 72, stack limit =3D 0x(ptrval)) Stack: (0xee9c9f28 to 0xee9ca000) 9f20: 00000000 7c2fd1be c015ed18 ee9adf40 ee9c0400 ee9c04= 00 9f40: ee9adf40 c015ed34 ee9c8000 ee9adf64 ee9c0400 c015f040 ee9adf80 000000= 00 9f60: c015ee24 7c2fd1be ee9adfc0 ee9adf80 00000000 ee9c8000 ee9adf40 c015ee= f4 9f80: ef1eba34 c0138f14 ee9c8000 ee9adf80 c0138df4 00000000 00000000 000000= 00 9fa0: 00000000 00000000 00000000 c01010e8 00000000 00000000 00000000 000000= 00 9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 000000= 00 9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 ffffffff ffffff= ff [] (mutex_lock) from [] (ac100_rtc_irq+0x38/0xc8) [] (ac100_rtc_irq) from [] (irq_thread_fn+0x1c/0x54) [] (irq_thread_fn) from [] (irq_thread+0x14c/0x214) [] (irq_thread) from [] (kthread+0x120/0x150) [] (kthread) from [] (ret_from_fork+0x14/0x2c) Solve both issues by moving to devm_rtc_allocate_device()/rtc_register_device() Reported-by: Quentin Schulz Tested-by: Quentin Schulz Signed-off-by: Alexandre Belloni Signed-off-by: Sasha Levin --- drivers/rtc/rtc-ac100.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/drivers/rtc/rtc-ac100.c b/drivers/rtc/rtc-ac100.c index 9e336184491c..0e358d4b6738 100644 --- a/drivers/rtc/rtc-ac100.c +++ b/drivers/rtc/rtc-ac100.c @@ -567,6 +567,12 @@ static int ac100_rtc_probe(struct platform_device *pde= v) return chip->irq; } =20 + chip->rtc =3D devm_rtc_allocate_device(&pdev->dev); + if (IS_ERR(chip->rtc)) + return PTR_ERR(chip->rtc); + + chip->rtc->ops =3D &ac100_rtc_ops; + ret =3D devm_request_threaded_irq(&pdev->dev, chip->irq, NULL, ac100_rtc_irq, IRQF_SHARED | IRQF_ONESHOT, @@ -586,17 +592,16 @@ static int ac100_rtc_probe(struct platform_device *pd= ev) /* clear counter alarm pending interrupts */ regmap_write(chip->regmap, AC100_ALM_INT_STA, AC100_ALM_INT_ENABLE); =20 - chip->rtc =3D devm_rtc_device_register(&pdev->dev, "rtc-ac100", - &ac100_rtc_ops, THIS_MODULE); - if (IS_ERR(chip->rtc)) { - dev_err(&pdev->dev, "unable to register device\n"); - return PTR_ERR(chip->rtc); - } - ret =3D ac100_rtc_register_clks(chip); if (ret) return ret; =20 + ret =3D rtc_register_device(chip->rtc); + if (ret) { + dev_err(&pdev->dev, "unable to register device\n"); + return ret; + } + dev_info(&pdev->dev, "RTC enabled\n"); =20 return 0; --=20 2.14.1