Skip to content

Commit 59f1178

Browse files
committed
Bluetooth: L2CAP: Fix l2cap_global_chan_by_psm regression
jira VULN-155527 cve-pre CVE-2022-50386 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: Brett Mastbergen <bmastbergen@ciq.com>
1 parent 60f1692 commit 59f1178

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
@@ -1801,11 +1801,11 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
18011801
bdaddr_t *dst,
18021802
u8 link_type)
18031803
{
1804-
struct l2cap_chan *c, *c1 = NULL;
1804+
struct l2cap_chan *c, *tmp, *c1 = NULL;
18051805

18061806
read_lock(&chan_list_lock);
18071807

1808-
list_for_each_entry(c, &chan_list, global_l) {
1808+
list_for_each_entry_safe(c, tmp, &chan_list, global_l) {
18091809
if (state && c->state != state)
18101810
continue;
18111811

@@ -1824,11 +1824,10 @@ static struct l2cap_chan *l2cap_global_chan_by_psm(int state, __le16 psm,
18241824
dst_match = !bacmp(&c->dst, dst);
18251825
if (src_match && dst_match) {
18261826
c = l2cap_chan_hold_unless_zero(c);
1827-
if (!c)
1828-
continue;
1829-
1830-
read_unlock(&chan_list_lock);
1831-
return c;
1827+
if (c) {
1828+
read_unlock(&chan_list_lock);
1829+
return c;
1830+
}
18321831
}
18331832

18341833
/* Closest match */

0 commit comments

Comments
 (0)