Received: by 2002:a05:6500:1b8f:b0:1fa:5c73:8e2d with SMTP id df15csp1357806lqb; Thu, 30 May 2024 08:02:01 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWy6E+VI5PuALRslm+e7oEdTwaM2tNEHp2NmbKbby4ADa7nrtZTZBcRKdr1Cz4w9tVjO1I3yZnrCsKkVmhJ9hXIGrjwbbs5MCfV+SbejA== X-Google-Smtp-Source: AGHT+IHBD6AoUkaapa/0JI+PrjGsMZ5MbNAvVlTa0qAaOB9a2EhDxJqECmO4uKVg4XDbhCiROrtt X-Received: by 2002:a05:6a00:3007:b0:6f4:d07a:e7f0 with SMTP id d2e1a72fcca58-702311e0e38mr2416719b3a.27.1717081320983; Thu, 30 May 2024 08:02:00 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717081320; cv=pass; d=google.com; s=arc-20160816; b=U3+AwDkfQt2wF37vYxOEYYUQLofzvIr0ZC+PHOkYG5wAznd2WUUsgzDnXdXCQvlZuq kgUsMWouYbyVeAhDo+Swgq6LX9j+8u1NoictAdnaj0GDdz1RUyfbzPYp8puBxRzmJtj2 aU0RMnN6o0wDw6FLybc8ik37zTRj1NwOJpjz+CvVQV2dkKXQwQu9LrQxEn7yXoRpR37n +v3EMmw2pAoO5bexY8PbkCnhBQ3T7o+GYmcDjH4StS8M4H80tyKRTCeFsvwvsAl5e01K RH+b2OgQILyNsBTbla7io/kKmpAK+phG01YYPKU9V3OFEYGtCqSDpwYdB4fEXOpU+ztE aYaQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=VwO8yFUdaCKNc4XO18qr8bod1xQKQNwrDGNH88UC2ig=; fh=uo5u2TQK/HQlhydMwGLjBAnuDwaLxndJ/cgWTjIagS8=; b=dZ7Eq85ax0Fy2w8fwH6zo5Itm+MQoV3An8JtCPrCbBGIeIQxKRoQG9TXsITd64ntWD FwYsVC0jCjTgkLge6mqXJ/M4K8x1Hosi1wLx++rnDJ26NEXMuV91HkU3+pNsfK+gNhel CoRgRuS/8tVKFutMFX3S78fV1DtYDr6Cq8SBgipqK7rhW6w0p+OKhQY/qSpgIsc2McvE yBgRnTVrtngWrG/AMIrF4rhpXfQMV8Qjz9LveQlR8QrydrsclJOhmXucTHucGiJ2q45P 4kQ6TfKxAenSLvlDh/zbQ52tpRCPPv7bsUZlXn74otTuZtCUB66UvLgwjJKSMlW6Oa2D A2TQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-5044-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5044-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id d2e1a72fcca58-701c9788f7csi5415218b3a.88.2024.05.30.08.02.00 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 May 2024 08:02:00 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-5044-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=hadess.net); spf=pass (google.com: domain of linux-bluetooth+bounces-5044-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-5044-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 56E6528422F for ; Thu, 30 May 2024 15:01:31 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id CDB1C17C214; Thu, 30 May 2024 15:01:04 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3539D17C200 for ; Thu, 30 May 2024 15:01:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717081264; cv=none; b=ay4IC00q7HGeMK1SShx7tTmaRKU159hbQcaONKZs/JG6opxMoadwHswOHO+S4QLxH5SIRdo6S+zR99gX/YYhLFBhtdrtfZssRLOJkrU2sTsQQ5o4vFuITdrB2pSlf5jftL9+p33kUPq16NHE8QQjS7mRknbAz3LgdoFopKZvgPw= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717081264; c=relaxed/simple; bh=3Z9StN4Y3GsmIVNcVnqzHhyrNqb0jq50SknvFIp5NRw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=rW4NZwGVpNDFVZjYOa4NtfxLionYZTcd5jvwCmrPb70QYihFPj4rOPAcBKzaHwr2g4/yzpKsRyrq6/o8Saa0/AvA3iZmzR4R0VkNNe2WNfzdLqtBfNFaUW4F6XGfEV8KZmY8czcbmKKSaj4Z43e0ftSgu1qtpndG3kG3UL/gKLM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net; spf=pass smtp.mailfrom=hadess.net; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=hadess.net Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=hadess.net Received: by mail.gandi.net (Postfix) with ESMTPSA id 63A4120013; Thu, 30 May 2024 15:00:59 +0000 (UTC) From: Bastien Nocera To: linux-bluetooth@vger.kernel.org Cc: Bastien Nocera Subject: [BlueZ 6/9] sdp: Fix ineffective error guard Date: Thu, 30 May 2024 16:58:00 +0200 Message-ID: <20240530150057.444585-7-hadess@hadess.net> X-Mailer: git-send-email 2.45.1 In-Reply-To: <20240530150057.444585-1-hadess@hadess.net> References: <20240530150057.444585-1-hadess@hadess.net> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-GND-Sasl: hadess@hadess.net The return value from gen_attridseq_pdu() can be -ENOMEM or the always positive return value from sdp_gen_pdu(), but we only guard against a single negative return value "-1" (-EPERM). Check for all negative values to avoid manipulating a negative length as a valid one. Error: INTEGER_OVERFLOW (CWE-190): [#def10] [important] bluez-5.76/lib/sdp.c:4082:2: tainted_data_return: Called function "gen_attridseq_pdu(pdata, attrid_list, ((reqtype == SDP_ATTR_REQ_INDIVIDUAL) ? 9 : 10))", and a possible return value is known to be less than zero. bluez-5.76/lib/sdp.c:4082:2: assign: Assigning: "seqlen" = "gen_attridseq_pdu(pdata, attrid_list, ((reqtype == SDP_ATTR_REQ_INDIVIDUAL) ? 9 : 10))". bluez-5.76/lib/sdp.c:4091:2: overflow: The expression "t->reqsize" is considered to have possibly overflowed. bluez-5.76/lib/sdp.c:4097:2: overflow: The expression "t->reqsize + cstate_len" is deemed overflowed because at least one of its arguments has overflowed. bluez-5.76/lib/sdp.c:4097:2: overflow_sink: "t->reqsize + cstate_len", which might have underflowed, is passed to "sdp_send_req(session, t->reqbuf, t->reqsize + cstate_len)". 4095| reqhdr->plen = htons((t->reqsize + cstate_len) - sizeof(sdp_pdu_hdr_t)); 4096| 4097|-> if (sdp_send_req(session, t->reqbuf, t->reqsize + cstate_len) < 0) { 4098| SDPERR("Error sending data:%m"); 4099| t->err = errno; Error: INTEGER_OVERFLOW (CWE-190): [#def11] [important] bluez-5.76/lib/sdp.c:4466:2: tainted_data_return: Called function "gen_attridseq_pdu(pdata, attrids, ((reqtype == SDP_ATTR_REQ_INDIVIDUAL) ? 9 : 10))", and a possible return value is known to be less than zero. bluez-5.76/lib/sdp.c:4466:2: assign: Assigning: "seqlen" = "gen_attridseq_pdu(pdata, attrids, ((reqtype == SDP_ATTR_REQ_INDIVIDUAL) ? 9 : 10))". bluez-5.76/lib/sdp.c:4475:2: overflow: The expression "reqsize" is considered to have possibly overflowed. bluez-5.76/lib/sdp.c:4480:2: assign: Assigning: "_reqsize" = "reqsize". bluez-5.76/lib/sdp.c:4486:3: overflow: The expression "_reqsize + copy_cstate(_pdata, 2048U - _reqsize, cstate)" is deemed overflowed because at least one of its arguments has overflowed. bluez-5.76/lib/sdp.c:4486:3: assign: Assigning: "reqsize" = "_reqsize + copy_cstate(_pdata, 2048U - _reqsize, cstate)". bluez-5.76/lib/sdp.c:4492:3: overflow_sink: "reqsize", which might have underflowed, is passed to "sdp_send_req_w4_rsp(session, reqbuf, rspbuf, reqsize, &rspsize)". 4490| reqhdr->plen = htons(reqsize - sizeof(sdp_pdu_hdr_t)); 4491| rsphdr = (sdp_pdu_hdr_t *) rspbuf; 4492|-> status = sdp_send_req_w4_rsp(session, reqbuf, rspbuf, reqsize, &rspsize); 4493| if (rspsize < sizeof(sdp_pdu_hdr_t)) { 4494| SDPERR("Unexpected end of packet"); --- lib/sdp.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/sdp.c b/lib/sdp.c index d43bbbd2de05..2e66505b21b8 100644 --- a/lib/sdp.c +++ b/lib/sdp.c @@ -3604,7 +3604,7 @@ sdp_record_t *sdp_service_attr_req(sdp_session_t *session, uint32_t handle, /* get attr seq PDU form */ seqlen = gen_attridseq_pdu(pdata, attrids, reqtype == SDP_ATTR_REQ_INDIVIDUAL? SDP_UINT16 : SDP_UINT32); - if (seqlen == -1) { + if (seqlen < 0) { errno = EINVAL; goto end; } @@ -3959,7 +3959,7 @@ int sdp_service_attr_async(sdp_session_t *session, uint32_t handle, sdp_attrreq_ /* get attr seq PDU form */ seqlen = gen_attridseq_pdu(pdata, attrid_list, reqtype == SDP_ATTR_REQ_INDIVIDUAL? SDP_UINT16 : SDP_UINT32); - if (seqlen == -1) { + if (seqlen < 0) { t->err = EINVAL; goto end; } @@ -4081,7 +4081,7 @@ int sdp_service_search_attr_async(sdp_session_t *session, const sdp_list_t *sear /* get attr seq PDU form */ seqlen = gen_attridseq_pdu(pdata, attrid_list, reqtype == SDP_ATTR_REQ_INDIVIDUAL ? SDP_UINT16 : SDP_UINT32); - if (seqlen == -1) { + if (seqlen < 0) { t->err = EINVAL; goto end; } @@ -4465,7 +4465,7 @@ int sdp_service_search_attr_req(sdp_session_t *session, const sdp_list_t *search /* get attr seq PDU form */ seqlen = gen_attridseq_pdu(pdata, attrids, reqtype == SDP_ATTR_REQ_INDIVIDUAL ? SDP_UINT16 : SDP_UINT32); - if (seqlen == -1) { + if (seqlen < 0) { errno = EINVAL; status = -1; goto end; -- 2.45.1