Bluetooth: Fix consistency of local vs remote PSM reporting
Subsystems (2)
PATCH 1/1 Bluetooth: Fix consistency of local vs remote PSM reporting
From: Johan Hedberg <[email protected]>
When we're the initiators of a connection the PSM resides on the remote side and when we're acceptors on the local side. Since the PSM isn't defined for the initiating side for all practical purposes it should have the value 0 if requested by user space.
The l2cap_chan structure contains two values for a PSM, psm and sport, which are used to return the value for getsockname() and getpeername(). However, the values returned haven't really been consistent. When we initiate an outgoing connection the sport value should be set to 0, and when we receive an incoming connect request the sport of the newly created l2cap_chan should reflect the targetted PSM.
It's important the chan->psm has always a valid value since there are several code paths that rely on it being set regardless of acceptor or initiator use cases.
This patch updates the relevant outgoing and incoming connection paths to ensure that the psm and sport l2cap_chan members have the appropriate values in all cases.
--- net/bluetooth/l2cap_core.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-)
net/bluetooth/l2cap_core.c +5 -2
@@ -3774,7 +3774,8 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,bacpy (&chan->dst, &conn->hcon->dst); chan->src_type =bdaddr_type (conn->hcon, conn->hcon->src_type); chan->dst_type =bdaddr_type (conn->hcon, conn->hcon->dst_type); - chan->psm = psm; + chan->psm = psm; + chan->sport = psm; chan->dcid = scid; chan->local_amp_id = amp_id;
@@ -5421,7 +5422,8 @@ static int l2cap_le_connect_req(struct l2cap_conn *conn,bacpy (&chan->dst, &conn->hcon->dst); chan->src_type =bdaddr_type (conn->hcon, conn->hcon->src_type); chan->dst_type =bdaddr_type (conn->hcon, conn->hcon->dst_type); - chan->psm = psm; + chan->psm = psm; + chan->sport = psm; chan->dcid = scid; chan->omtu = mtu; chan->remote_mps = mps;
@@ -7083,6 +7085,7 @@ int l2cap_chan_connect(struct l2cap_chan *chan, __le16 psm, u16 cid, chan->dst_type = dst_type; chan->psm = psm; + chan->sport =0 ; chan->dcid = cid; auth_type =l2cap_get_auth_type (chan);
Signature · 1 line
1.8.5.3