Skip to content

Commit 332f179

Browse files
committed
Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression
The patch d0be834: "Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put" from Jul 21, 2022, leads to the following Smatch static checker warning: net/bluetooth/l2cap_core.c:1977 l2cap_global_chan_by_psm() error: we previously assumed 'c' could be null (see line 1996) Fixes: d0be834 ("Bluetooth: L2CAP: Fix use-after-free caused by l2cap_chan_put") Reported-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
1 parent 2e64fe4 commit 332f179

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

net/bluetooth/l2cap_core.c

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1970,11 +1970,11 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
19701970
bdaddr_t *dst,
19711971
u8 link_type)
19721972
{
1973-
struct l2cap_chan *c, *c1 = NULL;
1973+
struct l2cap_chan *c, *tmp, *c1 = NULL;
19741974

19751975
read_lock(&chan_list_lock);
19761976

1977-
list_for_each_entry(c, &chan_list, global_l) {
1977+
list_for_each_entry_safe(c, tmp, &chan_list, global_l) {
19781978
if (state && c->state != state)
19791979
continue;
19801980

@@ -1993,11 +1993,10 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
19931993
dst_match = !bacmp(&c->dst, dst);
19941994
if (src_match && dst_match) {
19951995
c = l2cap_chan_hold_unless_zero(c);
1996-
if (!c)
1997-
continue;
1998-
1999-
read_unlock(&chan_list_lock);
2000-
return c;
1996+
if (c) {
1997+
read_unlock(&chan_list_lock);
1998+
return c;
1999+
}
20012000
}
20022001

20032002
/* Closest match */

0 commit comments

Comments
 (0)