Skip to content

Commit 222e05e

Browse files
congwanggregkh
authored andcommitted
llc: use refcount_inc_not_zero() for llc_sap_find()
[ Upstream commit 0dcb822 ] 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: <syzbot+278893f3f7803871f7ce@syzkaller.appspotmail.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 46be8e4 commit 222e05e

File tree

2 files changed

+7
-2
lines changed

2 files changed

+7
-2
lines changed

include/net/llc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,11 @@ static inline void llc_sap_hold(struct llc_sap *sap)
116116
refcount_inc(&sap->refcnt);
117117
}
118118

119+
static inline bool llc_sap_hold_safe(struct llc_sap *sap)
120+
{
121+
return refcount_inc_not_zero(&sap->refcnt);
122+
}
123+
119124
void llc_sap_close(struct llc_sap *sap);
120125

121126
static inline void llc_sap_put(struct llc_sap *sap)

net/llc/llc_core.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ struct llc_sap *llc_sap_find(unsigned char sap_value)
7373

7474
rcu_read_lock_bh();
7575
sap = __llc_sap_find(sap_value);
76-
if (sap)
77-
llc_sap_hold(sap);
76+
if (!sap || !llc_sap_hold_safe(sap))
77+
sap = NULL;
7878
rcu_read_unlock_bh();
7979
return sap;
8080
}

0 commit comments

Comments
 (0)