Alexandre Belloni
80ac31ac40
rtc: ac100: Fix multiple race conditions
[ Upstream commit 994ec64c0a ]
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 = 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 00000194
pgd = (ptrval)
[00000194] *pgd=00000000
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-dirty #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 : [<c06543a4>] lr : [<c04d9a2c>] 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 = 0x(ptrval))
Stack: (0xee9c9f28 to 0xee9ca000)
9f20: 00000000 7c2fd1be c015ed18 ee9adf40 ee9c0400 ee9c0400
9f40: ee9adf40 c015ed34 ee9c8000 ee9adf64 ee9c0400 c015f040 ee9adf80 00000000
9f60: c015ee24 7c2fd1be ee9adfc0 ee9adf80 00000000 ee9c8000 ee9adf40 c015eef4
9f80: ef1eba34 c0138f14 ee9c8000 ee9adf80 c0138df4 00000000 00000000 00000000
9fa0: 00000000 00000000 00000000 c01010e8 00000000 00000000 00000000 00000000
9fc0: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000
9fe0: 00000000 00000000 00000000 00000000 00000013 00000000 ffffffff ffffffff
[<c06543a4>] (mutex_lock) from [<c04d9a2c>] (ac100_rtc_irq+0x38/0xc8)
[<c04d9a2c>] (ac100_rtc_irq) from [<c015ed34>] (irq_thread_fn+0x1c/0x54)
[<c015ed34>] (irq_thread_fn) from [<c015f040>] (irq_thread+0x14c/0x214)
[<c015f040>] (irq_thread) from [<c0138f14>] (kthread+0x120/0x150)
[<c0138f14>] (kthread) from [<c01010e8>] (ret_from_fork+0x14/0x2c)
Solve both issues by moving to
devm_rtc_allocate_device()/rtc_register_device()
Reported-by: Quentin Schulz <quentin.schulz@free-electrons.com>
Tested-by: Quentin Schulz <quentin.schulz@free-electrons.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-03-24 11:02:47 +01:00
..
2017-10-30 15:03:24 -07:00
2015-04-17 09:04:02 -04:00
2017-10-25 23:05:52 +02:00
2017-11-20 22:47:50 +01:00
2017-11-22 20:58:23 -10:00
2017-07-07 13:14:14 +02:00
2015-09-05 13:19:05 +02:00
2014-10-20 16:21:31 +02:00
2015-04-03 08:18:25 +02:00
2015-11-08 14:12:25 +01:00
2015-09-05 13:19:08 +02:00
2017-10-13 00:10:12 +02:00
2018-03-24 11:02:47 +01:00
2017-10-25 23:05:52 +02:00
2016-03-14 17:08:25 +01:00
2016-10-19 08:45:48 +02:00
2016-09-02 01:24:06 +02:00
2017-11-10 16:24:32 +01:00
2013-04-05 09:36:53 -07:00
2016-07-26 00:09:18 +02:00
2017-01-11 17:23:06 +01:00
2017-01-11 17:23:06 +01:00
2017-03-09 01:29:17 +01:00
2014-10-20 16:21:31 +02:00
2018-03-19 09:09:52 +01:00
2017-05-22 20:32:05 +02:00
2016-09-02 01:24:06 +02:00
2017-11-02 11:10:55 +01:00
2017-04-14 12:08:52 +02:00
2016-07-19 18:15:21 +02:00
2016-07-19 18:15:21 +02:00
2016-01-11 20:19:57 +01:00
2016-09-02 01:24:06 +02:00
2017-11-21 15:57:07 -08:00
2016-09-02 01:24:06 +02:00
2017-08-15 08:06:14 +01:00
2016-05-20 12:33:51 +02:00
2016-07-08 16:23:11 +02:00
2016-09-02 01:24:06 +02:00
2017-10-13 00:10:06 +02:00
2017-10-26 23:00:24 +02:00
2016-07-09 10:24:45 +02:00
2016-09-22 00:14:40 +02:00
2017-05-04 14:46:25 +02:00
2017-10-27 13:11:50 +02:00
2017-10-13 00:10:17 +02:00
2016-05-20 12:33:51 +02:00
2017-09-01 01:10:11 +02:00
2016-07-09 10:24:45 +02:00
2016-05-20 12:33:51 +02:00
2016-06-27 10:48:28 +02:00
2017-07-06 22:37:16 +02:00
2017-11-02 11:10:55 +01:00
2016-06-06 17:07:33 +02:00
2017-09-01 01:10:11 +02:00
2016-05-20 12:33:51 +02:00
2015-09-05 13:19:06 +02:00
2017-07-06 22:37:15 +02:00
2016-06-04 00:23:35 +02:00
2017-09-01 01:10:18 +02:00
2017-04-22 17:56:18 +02:00
2016-07-19 18:18:06 +02:00
2017-06-20 12:19:14 +02:00
2017-03-09 01:29:27 +01:00
2016-05-20 12:33:51 +02:00
2017-10-12 14:28:14 +02:00
2016-11-04 23:31:29 +01:00
2014-10-20 16:21:31 +02:00
2015-09-05 13:19:06 +02:00
2016-01-11 20:19:59 +01:00
2017-01-11 17:23:06 +01:00
2017-11-08 07:52:24 +01:00
2015-10-28 10:30:17 +09:00
2015-10-28 10:30:17 +09:00
2016-05-20 12:33:51 +02:00
2015-09-05 13:19:10 +02:00
2017-10-13 00:10:10 +02:00
2017-09-01 01:10:11 +02:00
2015-10-28 10:30:17 +09:00
2016-06-04 16:05:59 +02:00
2014-10-20 16:21:31 +02:00
2017-07-31 00:17:48 +02:00
2015-09-05 19:37:21 +02:00
2015-06-25 01:13:36 +02:00
2016-03-14 17:08:27 +01:00
2016-05-20 12:33:51 +02:00
2016-06-26 01:20:08 +02:00
2017-01-11 17:23:04 +01:00
2015-09-05 19:37:22 +02:00
2015-09-05 19:37:22 +02:00
2016-07-09 10:24:45 +02:00
2015-04-17 09:04:02 -04:00
2016-09-02 01:24:06 +02:00
2017-10-26 10:43:29 +02:00
2015-09-05 19:37:22 +02:00
2017-08-24 16:23:16 +02:00
2017-07-06 22:37:16 +02:00
2017-11-08 07:52:15 +01:00
2018-02-22 15:40:04 +01:00
2016-09-02 01:24:06 +02:00
2014-10-20 16:21:31 +02:00
2016-08-31 18:21:34 +02:00
2017-02-23 18:38:54 +01:00
2017-10-25 23:05:52 +02:00
2017-11-09 01:16:36 +01:00
2015-09-05 13:19:06 +02:00
2016-09-02 01:24:06 +02:00
2016-11-04 23:08:59 +01:00
2017-11-08 07:52:22 +01:00
2016-08-31 18:21:35 +02:00
2013-11-13 12:09:31 +09:00
2017-10-12 16:30:30 +02:00
2016-08-31 09:33:33 +01:00
2016-01-11 20:19:55 +01:00
2014-10-20 16:21:31 +02:00
2017-08-22 12:05:21 +02:00
2017-08-24 11:03:34 +02:00
2016-12-19 00:59:21 +01:00
2015-10-28 10:30:17 +09:00
2016-07-19 18:15:21 +02:00
2015-12-20 13:39:00 +01:00
2015-09-05 13:19:10 +02:00
2016-05-20 12:33:51 +02:00
2016-05-20 12:33:51 +02:00
2017-03-09 01:29:34 +01:00
2017-09-05 09:55:02 +02:00
2017-10-12 16:24:19 +02:00
2017-07-07 13:14:19 +02:00
2015-10-28 10:30:17 +09:00
2016-09-02 01:24:06 +02:00
2017-11-09 01:16:35 +01:00
2016-09-02 01:24:06 +02:00
2017-03-09 01:29:31 +01:00
2017-06-24 22:52:43 +02:00
2013-04-19 13:51:25 +02:00
2016-03-14 17:08:18 +01:00
2017-07-31 00:17:44 +02:00
2017-08-24 11:03:35 +02:00
2017-11-02 11:10:55 +01:00
2017-11-20 22:47:50 +01:00
2017-04-22 18:01:15 +02:00
2015-09-05 13:19:06 +02:00
2017-05-05 00:43:50 +02:00
2016-09-02 01:24:06 +02:00
2017-07-09 22:32:18 +02:00
2016-11-04 23:31:31 +01:00
2016-05-20 12:33:51 +02:00
2017-07-06 22:52:54 +02:00
2016-09-02 01:24:06 +02:00
2016-11-04 23:31:33 +01:00
2017-09-01 01:10:19 +02:00
2016-01-11 20:19:57 +01:00
2017-11-10 09:57:38 +01:00
2017-01-23 00:46:55 +01:00
2015-04-03 08:18:24 +02:00
2014-10-20 16:21:31 +02:00
2016-05-21 17:07:17 +02:00
2017-01-10 01:32:51 +01:00
2016-03-14 17:08:24 +01:00
2017-09-04 14:41:02 +01:00
2015-09-05 13:19:10 +02:00
2016-07-09 10:24:21 +02:00
2017-08-24 11:03:36 +02:00
2015-09-05 19:37:22 +02:00
2013-07-03 16:07:59 -07:00
2017-03-16 22:59:54 +01:00
2016-05-20 12:33:51 +02:00
2017-11-09 01:25:47 +01:00
2016-05-20 12:33:51 +02:00
2017-10-30 15:03:24 -07:00