From: Dan Carpenter <dan.carpenter@linaro.org>
To: Simon Horman <horms@kernel.org>
Cc: Marcel Holtmann <marcel@holtmann.org>,
Johan Hedberg <johan.hedberg@gmail.com>,
Luiz Augusto von Dentz <luiz.dentz@gmail.com>,
linux-bluetooth@vger.kernel.org
Subject: Re: [PATCH] Bluetooth: L2CAP: don't check for out-of-bounds value
Date: Tue, 30 May 2023 09:33:53 +0300 [thread overview]
Message-ID: <e4d89235-6446-4bd4-8ab8-7b53a89d0f19@kili.mountain> (raw)
In-Reply-To: <ZHDOGNhIu9pjDKVM@kernel.org>
On Fri, May 26, 2023 at 05:19:52PM +0200, Simon Horman wrote:
> On Fri, May 26, 2023 at 05:34:30PM +0300, Dan Carpenter wrote:
> > On Fri, May 26, 2023 at 04:16:54PM +0200, Simon Horman wrote:
> > > @@ -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) {
> >
> > This is a false positive. To me the warning looks reasonable. But one
> > way we could silence it would be to keep a list of macros where the
> > check is impossible but we still want to have it.
>
> Hi Dan,
>
> I do agree that the existing code is harmless.
> Is this why you feel it is a false positive?
>
Actually I was thinking of something else, but the other reason why this
is harmless is because it's part of a "clamp both upper and lower
bounds" condition. Linus doesn't like these warnings because it's clear
to a human reader what the intent is. I re-wrote this code last week to
avoid this kind of warning. I will push that so now it won't warn. I
still need to tweak the re-written code a bit.
> > I could create something where we do:
> >
> > echo "L2CAP_CID_DYN_END" >> smatch_data/kernel.allowed_impossible_limits
> >
> > I'd do the same for unsigned comparisons with zero like:
> >
> >
> > if (dpmcp_dev->obj_desc.ver_major < DPMCP_MIN_VER_MAJOR ||
> > (dpmcp_dev->obj_desc.ver_major == DPMCP_MIN_VER_MAJOR &&
> > dpmcp_dev->obj_desc.ver_minor < DPMCP_MIN_VER_MINOR)) {
> > ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> > dev_err(&dpmcp_dev->dev,
> > "ERROR: Version %d.%d of DPMCP not supported.\n",
> >
> > echo "DPMCP_MIN_VER_MINOR" >> smatch_data/kernel.allowed_impossible_limits
>
> FWIIW, I've noticed problems with comparisons to enums. Which, f.e., may in
> practice are unsigned values of a particular width for a given build.
> But in theory could be any type.
Enum types are undefined in C but I think Sparse (and thus Smatch)
follow the same rules as GCC basically so they should catch these bugs.
int x;
if (x < ENUM_ZERO) <-- x is negative but type promoted to uint
regards,
dan carpenter
next prev parent reply other threads:[~2023-05-30 6:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-05-26 14:16 [PATCH] Bluetooth: L2CAP: don't check for out-of-bounds value Simon Horman
2023-05-26 14:34 ` Dan Carpenter
2023-05-26 15:19 ` Simon Horman
2023-05-30 6:33 ` Dan Carpenter [this message]
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=e4d89235-6446-4bd4-8ab8-7b53a89d0f19@kili.mountain \
--to=dan.carpenter@linaro.org \
--cc=horms@kernel.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).