stm class: fail stm_lookup_protocol() when the protocol module is going away
PATCH 1/1 stm class: fail stm_lookup_protocol() when the protocol module is going away
stm_lookup_protocol() returns 0 whenever a protocol entry with the given name exists, even if stm_get_protocol() failed because the protocol module is being unloaded. In that case *pdrv and *node_type are left untouched and stp_policy_make() goes on to install two uninitialised stack pointers as stm->pdrv and stm->pdrv_node_type, and its error path and stp_policy_unbind() later dereference them to drop a module reference that was never taken.
Return -ENOENT unless the protocol was found and its module reference taken.
Fixes c7fd62bc69d0 ("stm class: Introduce framing protocol drivers")
Signed-off-by Yu Zhang <[email protected]>
--- drivers/hwtracing/stm/core.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
drivers/hwtracing/stm/core.c +3 -1
@@ -468,6 +468,7 @@ int stm_lookup_protocol(const char *name, const struct config_item_type **node_type) {const struct stm_pdrv_entry *pe; +int ret = -ENOENT ;mutex_lock (&stm_pdrv_mutex);
@@ -475,11 +476,12 @@ int stm_lookup_protocol(const char *name,if (pe && pe->pdrv &&stm_get_protocol (pe->pdrv)) { *pdrv = pe->pdrv; *node_type = pe->node_type; + ret =0 ; }mutex_unlock (&stm_pdrv_mutex); -return pe ?0 : -ENOENT ; +return ret; }static int stm_char_open (struct inode *inode,struct file *file)
Signature · 1 line
2.43.0