Commit d535ca13 authored by Karsten Graul's avatar Karsten Graul Committed by Jakub Kicinski

net/smc: fix use-after-free of delayed events

When a delayed event is enqueued then the event worker will send this
event the next time it is running and no other flow is currently
active. The event handler is called for the delayed event, and the
pointer to the event keeps set in lgr->delayed_event. This pointer is
cleared later in the processing by smc_llc_flow_start().
This can lead to a use-after-free condition when the processing does not
reach smc_llc_flow_start(), but frees the event because of an error
situation. Then the delayed_event pointer is still set but the event is
freed.
Fix this by always clearing the delayed event pointer when the event is
provided to the event handler for processing, and remove the code to
clear it in smc_llc_flow_start().

Fixes: 555da9af ("net/smc: add event-based llc_flow framework")
Signed-off-by: default avatarKarsten Graul <kgraul@linux.ibm.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 1d273fcc
...@@ -233,8 +233,6 @@ static bool smc_llc_flow_start(struct smc_llc_flow *flow, ...@@ -233,8 +233,6 @@ static bool smc_llc_flow_start(struct smc_llc_flow *flow,
default: default:
flow->type = SMC_LLC_FLOW_NONE; flow->type = SMC_LLC_FLOW_NONE;
} }
if (qentry == lgr->delayed_event)
lgr->delayed_event = NULL;
smc_llc_flow_qentry_set(flow, qentry); smc_llc_flow_qentry_set(flow, qentry);
spin_unlock_bh(&lgr->llc_flow_lock); spin_unlock_bh(&lgr->llc_flow_lock);
return true; return true;
...@@ -1603,13 +1601,12 @@ static void smc_llc_event_work(struct work_struct *work) ...@@ -1603,13 +1601,12 @@ static void smc_llc_event_work(struct work_struct *work)
struct smc_llc_qentry *qentry; struct smc_llc_qentry *qentry;
if (!lgr->llc_flow_lcl.type && lgr->delayed_event) { if (!lgr->llc_flow_lcl.type && lgr->delayed_event) {
if (smc_link_usable(lgr->delayed_event->link)) { qentry = lgr->delayed_event;
smc_llc_event_handler(lgr->delayed_event); lgr->delayed_event = NULL;
} else { if (smc_link_usable(qentry->link))
qentry = lgr->delayed_event; smc_llc_event_handler(qentry);
lgr->delayed_event = NULL; else
kfree(qentry); kfree(qentry);
}
} }
again: again:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment