Skip to content

Commit

Permalink
qed: Fix potential use-after-free in qed_spq_post()
Browse files Browse the repository at this point in the history
We need to check if p_ent->comp_mode is QED_SPQ_MODE_EBLOCK before
calling qed_spq_add_entry().  The test is fine is the mode is EBLOCK,
but if it isn't then qed_spq_add_entry() might kfree(p_ent).

Signed-off-by: Roland Dreier <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
rolandd authored and davem330 committed Jan 16, 2018
1 parent 0d9c9f0 commit 70eeff6
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion drivers/net/ethernet/qlogic/qed/qed_spq.c
Original file line number Diff line number Diff line change
Expand Up @@ -776,6 +776,7 @@ int qed_spq_post(struct qed_hwfn *p_hwfn,
int rc = 0;
struct qed_spq *p_spq = p_hwfn ? p_hwfn->p_spq : NULL;
bool b_ret_ent = true;
bool eblock;

if (!p_hwfn)
return -EINVAL;
Expand All @@ -794,6 +795,11 @@ int qed_spq_post(struct qed_hwfn *p_hwfn,
if (rc)
goto spq_post_fail;

/* Check if entry is in block mode before qed_spq_add_entry,
* which might kfree p_ent.
*/
eblock = (p_ent->comp_mode == QED_SPQ_MODE_EBLOCK);

/* Add the request to the pending queue */
rc = qed_spq_add_entry(p_hwfn, p_ent, p_ent->priority);
if (rc)
Expand All @@ -811,7 +817,7 @@ int qed_spq_post(struct qed_hwfn *p_hwfn,

spin_unlock_bh(&p_spq->lock);

if (p_ent->comp_mode == QED_SPQ_MODE_EBLOCK) {
if (eblock) {
/* For entries in QED BLOCK mode, the completion code cannot
* perform the necessary cleanup - if it did, we couldn't
* access p_ent here to see whether it's successful or not.
Expand Down

0 comments on commit 70eeff6

Please sign in to comment.