Skip to content

Commit

Permalink
llc: use refcount_inc_not_zero() for llc_sap_find()
Browse files Browse the repository at this point in the history
llc_sap_put() decreases the refcnt before deleting sap
from the global list. Therefore, there is a chance
llc_sap_find() could find a sap with zero refcnt
in this global list.

Close this race condition by checking if refcnt is zero
or not in llc_sap_find(), if it is zero then it is being
removed so we can just treat it as gone.

Reported-by: <[email protected]>
Signed-off-by: Cong Wang <[email protected]>
Signed-off-by: David S. Miller <[email protected]>
  • Loading branch information
congwang authored and davem330 committed Aug 7, 2018
1 parent 61ef4b0 commit 0dcb822
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
5 changes: 5 additions & 0 deletions include/net/llc.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,11 @@ static inline void llc_sap_hold(struct llc_sap *sap)
refcount_inc(&sap->refcnt);
}

static inline bool llc_sap_hold_safe(struct llc_sap *sap)
{
return refcount_inc_not_zero(&sap->refcnt);
}

void llc_sap_close(struct llc_sap *sap);

static inline void llc_sap_put(struct llc_sap *sap)
Expand Down
4 changes: 2 additions & 2 deletions net/llc/llc_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,8 @@ struct llc_sap *llc_sap_find(unsigned char sap_value)

rcu_read_lock_bh();
sap = __llc_sap_find(sap_value);
if (sap)
llc_sap_hold(sap);
if (!sap || !llc_sap_hold_safe(sap))
sap = NULL;
rcu_read_unlock_bh();
return sap;
}
Expand Down

0 comments on commit 0dcb822

Please sign in to comment.