Skip to content

Commit e03af71

Browse files
committed
Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression
jira VULN-155016 cve-pre CVE-2023-53305 commit-author Luiz Augusto von Dentz <luiz.von.dentz@intel.com> commit 332f179 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> (cherry picked from commit 332f179) Signed-off-by: Roxana Nicolescu <rnicolescu@ciq.com>
1 parent 09581b8 commit e03af71

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
@@ -1969,11 +1969,11 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
19691969
bdaddr_t *dst,
19701970
u8 link_type)
19711971
{
1972-
struct l2cap_chan *c, *c1 = NULL;
1972+
struct l2cap_chan *c, *tmp, *c1 = NULL;
19731973

19741974
read_lock(&chan_list_lock);
19751975

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

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

20022001
/* Closest match */

0 commit comments

Comments
 (0)