]> git.proxmox.com Git - mirror_ubuntu-focal-kernel.git/commit - drivers/rtc/rtc-ab-b5ze-s3.c
rtc: ab-b5ze-s3: fix possible race conditions
authorAlexandre Belloni <alexandre.belloni@bootlin.com>
Thu, 17 May 2018 20:20:39 +0000 (22:20 +0200)
committerAlexandre Belloni <alexandre.belloni@bootlin.com>
Thu, 17 May 2018 20:23:23 +0000 (22:23 +0200)
commit8bde032b280605c21a247557de9ee71e5835cab8
treee3d739851951eea074ec52f54f4d3988eaeb8a47
parent02f3712f1f6c878c0fc4657d763272970b1013f5
rtc: ab-b5ze-s3: fix possible race conditions

The IRQ is requested before the struct rtc is allocated and registered, but
this struct is used in the IRQ handler. This may lead to a NULL pointer
dereference.

Also, 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* */

Switch to devm_rtc_allocate_device/rtc_register_device to allocate the rtc
before requesting the IRQ and register the RTC as late as possible.

Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
drivers/rtc/rtc-ab-b5ze-s3.c