Re: [PATCH] Bluetooth: L2CAP: don't check for out-of-bounds value

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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?

> 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.

Perhaps the system you propose above would be useful for silencing
warnings about such problems? They seem to be a subset of the problem
at hand.

> I can do that on Monday if you want.  Other static checkers might
> complain still though.

No rush from my side.



[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux