Skip to contentSkip to conversation

core: Fix wrong expectations for the return of recv()

PATCH Applied Vinicius Costa Gomes 2 participants 2 messages Aug 10, 2016 – Aug 12, 2016 Bluetooth drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 core: Fix wrong expectations for the return of recv()

Since commit b5f34f9420b50 "Bluetooth: Fix bt_sock_recvmsg return value" in the kernel, Bluetooth sockets of type SOCK_SEQPACKET, when read() will return the size of the packet received, which can be larger than the the buffer passed by user space.

In this case the problem was causing a disconnection soon after the reception of an SDP request.

Reported by: Alban Browaeys <[email protected]>

---
 src/sdpd-server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/sdpd-server.c +1 -1
index c863508..b8190da 100644
@@ -164,7 +164,7 @@ static gboolean io_session_event(GIOChannel *chan, GIOCondition cond, gpointer d
 	}
 
 	len = recv(sk, &hdr, sizeof(sdp_pdu_hdr_t), MSG_PEEK);
-	if (len != sizeof(sdp_pdu_hdr_t)) {
+	if (len < sizeof(sdp_pdu_hdr_t)) {
 		sdp_svcdb_collect_all(sk);
 		return FALSE;
 	}
Signature · 1 line
2.9.2
maintainer Applied
#1 lore raw

Hi Vinicius,

Quoted 27 lines · Vinicius Costa Gomes

Since commit b5f34f9420b50 "Bluetooth: Fix bt_sock_recvmsg return value" in the kernel, Bluetooth sockets of type SOCK_SEQPACKET, when read() will return the size of the packet received, which can be larger than the the buffer passed by user space.

In this case the problem was causing a disconnection soon after the reception of an SDP request.

Reported by: Alban Browaeys <[email protected]>

---
 src/sdpd-server.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/sdpd-server.c +1 -2
index c863508..b8190da 100644
@@ -164,7 +164,7 @@ static gboolean io_session_event(GIOChannel *chan, GIOCondition cond, gpointer d
        }
 
        len = recv(sk, &hdr, sizeof(sdp_pdu_hdr_t), MSG_PEEK);
-       if (len != sizeof(sdp_pdu_hdr_t)) {
+       if (len < sizeof(sdp_pdu_hdr_t)) {
                sdp_svcdb_collect_all(sk);
                return FALSE;
        }
--
Quoted 1 line

2.9.2

Applied, note that I did have to include a cast since it was causing and signess comparison error.

Signature · 1 line
Luiz Augusto von Dentz