Skip to content

Commit e78e1fd

Browse files
virtuosogregkh
authored andcommitted
intel_th: Fix a NULL dereference when hub driver is not loaded
Connecting master to an output port when GTH driver module is not loaded triggers a NULL dereference: > RIP: 0010:intel_th_set_output+0x35/0x70 [intel_th] > Call Trace: > ? sth_stm_link+0x12/0x20 [intel_th_sth] > stm_source_link_store+0x164/0x270 [stm_core] > dev_attr_store+0x17/0x30 > sysfs_kf_write+0x3e/0x50 > kernfs_fop_write+0xda/0x1b0 > __vfs_write+0x1b/0x40 > vfs_write+0xb9/0x1a0 > ksys_write+0x67/0xe0 > __x64_sys_write+0x1a/0x20 > do_syscall_64+0x57/0x1d0 > entry_SYSCALL_64_after_hwframe+0x44/0xa9 Make sure the module in question is loaded and return an error if not. Signed-off-by: Alexander Shishkin <[email protected]> Fixes: 39f4034 ("intel_th: Add driver infrastructure for Intel(R) Trace Hub devices") Reviewed-by: Andy Shevchenko <[email protected]> Reported-by: Ammy Yi <[email protected]> Tested-by: Ammy Yi <[email protected]> Cc: [email protected] # v4.4 Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent fd73d74 commit e78e1fd

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

drivers/hwtracing/intel_th/core.c

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1021,15 +1021,30 @@ int intel_th_set_output(struct intel_th_device *thdev,
10211021
{
10221022
struct intel_th_device *hub = to_intel_th_hub(thdev);
10231023
struct intel_th_driver *hubdrv = to_intel_th_driver(hub->dev.driver);
1024+
int ret;
10241025

10251026
/* In host mode, this is up to the external debugger, do nothing. */
10261027
if (hub->host_mode)
10271028
return 0;
10281029

1029-
if (!hubdrv->set_output)
1030-
return -ENOTSUPP;
1030+
/*
1031+
* hub is instantiated together with the source device that
1032+
* calls here, so guaranteed to be present.
1033+
*/
1034+
hubdrv = to_intel_th_driver(hub->dev.driver);
1035+
if (!hubdrv || !try_module_get(hubdrv->driver.owner))
1036+
return -EINVAL;
1037+
1038+
if (!hubdrv->set_output) {
1039+
ret = -ENOTSUPP;
1040+
goto out;
1041+
}
1042+
1043+
ret = hubdrv->set_output(hub, master);
10311044

1032-
return hubdrv->set_output(hub, master);
1045+
out:
1046+
module_put(hubdrv->driver.owner);
1047+
return ret;
10331048
}
10341049
EXPORT_SYMBOL_GPL(intel_th_set_output);
10351050

drivers/hwtracing/intel_th/sth.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,7 @@ static int sth_stm_link(struct stm_data *stm_data, unsigned int master,
161161
{
162162
struct sth_device *sth = container_of(stm_data, struct sth_device, stm);
163163

164-
intel_th_set_output(to_intel_th_device(sth->dev), master);
165-
166-
return 0;
164+
return intel_th_set_output(to_intel_th_device(sth->dev), master);
167165
}
168166

169167
static int intel_th_sw_init(struct sth_device *sth)

0 commit comments

Comments
 (0)