Subject: Re: [Bug 60669] Kernel panic when using negative priority for HTB class

From: Stephen Hemminger <[email-masked]>
Date: Thu, 1 Aug 2013 22:31:15 -0700

On Fri, 2 Aug 2013 04:50:16 +0000 (UTC)
Cong Wang <[email-masked]> wrote:

> On Fri, 02 Aug 2013 at 04:12 GMT, Stephen Hemminger <[email-masked]> wrote:
> >
> > --- Comment #2 from _Vi <[email-masked]> ---
> > Reproducible on 3.11.0-rc3
> >
> > Looks like negative priority value is essential for the kernel panic.
> >
> 
> There is a check for prio:
> 
>                 if ((cl->prio = hopt->prio) >= TC_HTB_NUMPRIO)
> 		                        cl->prio = TC_HTB_NUMPRIO - 1;
> 					

This maybe related to or old bugs, 64 bit with current
iproute2 the error is caught at the command level.

The issue is that hopt->prio is u32 but cl->prio is int.

Example:
int main()
{
	int x = -1;
	uint32_t prio = x;
	int cl;

	if ((cl = prio) >= TC_HTB_NUMPRIO)
		cl = TC_HTB_NUMPRIO - 1;

	printf("%d %u %d\n", x, prio, cl);
	return 0;
}
-1 4294967295 -1

Signed/unsigned conversions can bite.