From: Simon Horman <horms@kernel.org>
To: Marcel Holtmann <marcel@holtmann.org>,
Johan Hedberg <johan.hedberg@gmail.com>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>
Cc: Dan Carpenter <dan.carpenter@linaro.org>,
linux-bluetooth@vger.kernel.org, Simon Horman <horms@kernel.org>
Subject: [PATCH] Bluetooth: L2CAP: don't check for out-of-bounds value
Date: Fri, 26 May 2023 16:16:54 +0200 [thread overview]
Message-ID: <20230526-l2cap-16bit-v1-1-2cfb83dd28ee@kernel.org> (raw)
In l2cap_connect(), scid is an unsigned 16bit variable. Thus, it's
maximum value is L2CAP_CID_DYN_END (0xffff) and there is no need
to check for this value being exceeded.
Flagged by Smatch as:
.../l2cap_core.c:4165 l2cap_connect() warn: impossible condition '(scid > 65535) => (0-u16max > u16max)'
Signed-off-by: Simon Horman <horms@kernel.org>
---
net/bluetooth/l2cap_core.c | 8 ++++++--
1 file changed, 6 insertions(+), 2 deletions(-)
diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
index ae397c6819d9..a5d85a5f5930 100644
--- a/net/bluetooth/l2cap_core.c
+++ b/net/bluetooth/l2cap_core.c
@@ -4161,8 +4161,12 @@ static struct l2cap_chan *l2cap_connect(struct l2cap_conn *conn,
result = L2CAP_CR_NO_MEM;
- /* Check for valid dynamic CID range (as per Erratum 3253) */
- if (scid < L2CAP_CID_DYN_START || scid > L2CAP_CID_DYN_END) {
+ /* Check for valid dynamic CID range (as per Erratum 3253).
+ * As scid is an unsigned 16bit variable it's maximum
+ * value is L2CAP_CID_DYN_END (0xffff): there is no need to check
+ * if scid exceeds that value here.
+ */
+ if (scid < L2CAP_CID_DYN_START) {
result = L2CAP_CR_INVALID_SCID;
goto response;
}
next reply other threads:[~2023-05-26 14:17 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 14:16 Simon Horman [this message]
2023-05-26 14:34 ` [PATCH] Bluetooth: L2CAP: don't check for out-of-bounds value Dan Carpenter
2023-05-26 15:19 ` Simon Horman
2023-05-30 6:33 ` Dan Carpenter
2023-05-26 14:57 ` bluez.test.bot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230526-l2cap-16bit-v1-1-2cfb83dd28ee@kernel.org \
--to=horms@kernel.org \
--cc=dan.carpenter@linaro.org \
--cc=johan.hedberg@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=luiz.dentz@gmail.com \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).