Skip to content

Commit c58da0b

Browse files
Dan Carpentermichalsimek
authored andcommitted
driver: soc: xilinx: use _safe loop iterator to avoid a use after free
The hash_for_each_possible() loop dereferences "eve_data" to get the next item on the list. However the loop frees eve_data so it leads to a use after free. Use hash_for_each_possible_safe() instead. Fixes: c7fdb24 ("drivers: soc: xilinx: add xilinx event management driver") Signed-off-by: Dan Carpenter <dan.carpenter@linaro.org> Link: https://lore.kernel.org/r/761e0e4a-4caf-4a71-8f47-1c6ad908a848@kili.mountain Signed-off-by: Michal Simek <michal.simek@amd.com>
1 parent be11d67 commit c58da0b

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

drivers/soc/xilinx/xlnx_event_manager.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,12 @@ static int xlnx_remove_cb_for_suspend(event_cb_func_t cb_fun)
192192
struct registered_event_data *eve_data;
193193
struct agent_cb *cb_pos;
194194
struct agent_cb *cb_next;
195+
struct hlist_node *tmp;
195196

196197
is_need_to_unregister = false;
197198

198199
/* Check for existing entry in hash table for given cb_type */
199-
hash_for_each_possible(reg_driver_map, eve_data, hentry, PM_INIT_SUSPEND_CB) {
200+
hash_for_each_possible_safe(reg_driver_map, eve_data, tmp, hentry, PM_INIT_SUSPEND_CB) {
200201
if (eve_data->cb_type == PM_INIT_SUSPEND_CB) {
201202
/* Delete the list of callback */
202203
list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list) {
@@ -228,11 +229,12 @@ static int xlnx_remove_cb_for_notify_event(const u32 node_id, const u32 event,
228229
u64 key = ((u64)node_id << 32U) | (u64)event;
229230
struct agent_cb *cb_pos;
230231
struct agent_cb *cb_next;
232+
struct hlist_node *tmp;
231233

232234
is_need_to_unregister = false;
233235

234236
/* Check for existing entry in hash table for given key id */
235-
hash_for_each_possible(reg_driver_map, eve_data, hentry, key) {
237+
hash_for_each_possible_safe(reg_driver_map, eve_data, tmp, hentry, key) {
236238
if (eve_data->key == key) {
237239
/* Delete the list of callback */
238240
list_for_each_entry_safe(cb_pos, cb_next, &eve_data->cb_list_head, list) {

0 commit comments

Comments
 (0)