OSDN Git Service

drivers: thermal: int340x_thermal: Fix sysfs race condition
authorAaron Hill <aa1ronham@gmail.com>
Mon, 24 Dec 2018 19:23:36 +0000 (14:23 -0500)
committerZhang Rui <rui.zhang@intel.com>
Fri, 18 Jan 2019 07:23:04 +0000 (15:23 +0800)
commit129699bb8c7572106b5bbb2407c2daee4727ccad
treedb0c6f3b102bae69131935b851967a4cd983fa0f
parent3fe931b31a4078395c1967f0495dcc9e5ec6b5e3
drivers: thermal: int340x_thermal: Fix sysfs race condition

Changes since V1:
* Use dev_info instead of printk
* Use dev_warn instead of BUG_ON

Previously, sysfs_create_group was called before all initialization had
fully run - specifically, before pci_set_drvdata was called. Since the
sysctl group is visible to userspace as soon as sysfs_create_group
returns, a small window of time existed during which a process could read
from an uninitialized/partially-initialized device.

This commit moves the creation of the sysctl group to after all
initialized is completed. This ensures that it's impossible for
userspace to read from a sysctl file before initialization has fully
completed.

To catch any future regressions, I've added a check to ensure
that proc_thermal_emum_mode is never PROC_THERMAL_NONE when a process
tries to read from a sysctl file. Previously, the aforementioned race
condition could result in the 'else' branch
running while PROC_THERMAL_NONE was set,
leading to a null pointer deference.

Signed-off-by: Aaron Hill <aa1ronham@gmail.com>
Signed-off-by: Zhang Rui <rui.zhang@intel.com>
drivers/thermal/intel/int340x_thermal/processor_thermal_device.c