Skip to contentSkip to conversation

bug list: range checking issues 2.6.34-rc1

DISCUSSION Dan Carpenter 3 participants 4 messages Mar 15, 2010 – Mar 18, 2010 1 message not in the archive Kernel janitors

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): [email protected]

#1 lore raw
Quoted 4 lines · Toralf Förster

Hello,

I'm wondering about these entries :

No problem, I'm happy to explain.

Quoted 1 line

drivers/infiniband/core/user_mad.c +646 ib_umad_reg_agent() 'umm' 4 <= 6

641 u32 *umm = (u32 *) ureq.method_mask;
642 int i;
643
644 for (i = 0; i < BITS_TO_LONGS(IB_MGMT_MAX_METHODS); ++i)
645 req.method_mask[i] 646 umm[i * 2] | ((u64) umm[i * 2 + 1] << 32);
"umm" points to a array with 4 elements.
i can be 0 to 3, so "i * 2" goes up to 6
And 4 <= 6 so it's a problem.
Smatch also complained about "i * 2 + 1" but I didn't include that.

Quoted 1 line

drivers/media/dvb/frontends/cx24110.c +210 cx24110_set_fec() 'rate' 7 <= 8

   184          static const int rate[]={-1,1,2,3,5,7,-1};
	[snip]
   192          if (fec>FEC_AUTO)
   193                  fecþC_AUTO;
   194  
   195          if (fec=FEC_AUTO) { /* (re-)establish AutoAcq behaviour */
	[snip]
   207          } else {
   208                  cx24110_writereg(state,0x37,cx24110_readreg(state,0x37)|0x20);
   209                  /* set AcqVitDis bit */
   210                  if(rate[fec]>0) {
"rate" has 7 elements.  FEC_AUTO - 1 is 8.  7 <= 8.
Quoted 1 line

drivers/video/cyber2000fb.c +330 cyber2000fb_setcolreg() 'cfb->palette' 256 <= 504

316 if (var->green.length = 6 && regno < 64) {

   317                          cfb->palette[regno << 2].green = green;
	[snip]

330 green = cfb->palette[regno << 3].green;
"cfb->palette" is an array with 256 elements. "regno" can be 63. 63 << 3 is 504.

Quoted 1 line

sound/drivers/opl3/opl3_midi.c +652 snd_opl3_kill_voice() 'opl3->voices' 18 <= 20

626 if (snd_BUG_ON(voice >= MAX_OPL3_VOICES))

   627                  return;
	[snip]

651 if (vp->state = SNDRV_OPL3_ST_ON_4OP) {
652 vp2 = &opl3->voices[voice + 3];
"opl3->voices" has 18 elements. "voice" can be 17. 17 + 3 is 20.

Quoted 1 line

sound/i2c/other/ak4113.c +94 snd_ak4113_create() 'pgm' 5 <= 6

    93          for (reg = 0; reg < AK4113_WRITABLE_REGS ; reg++)
    94                  chip->regmap[reg] = pgm[reg];

"pgm" has 5 elements. AK4113_WRITABLE_REGS is 7.

Quoted 1 line

sound/soc/codecs/wm8994.c +1703 wm8994_write() 'wm8994->reg_cache' 1570 <= 12799

1700 BUG_ON(reg > WM8994_MAX_REGISTER);
1701
1702 if (!wm8994_volatile(reg))
1703 wm8994->reg_cache[reg] = value;
"wm8994->reg_cache" has 1570 elements. WM8994_MAX_REGISTER is 12799.

Obviously that last one is not the most serious bug in the world...

regards,
dan carpenter

Quoted 8 lines

b/c the range end shouldn't be reached, or ?

Signature · 4 lines
MfG/Sincerely
Toralf Förster

pgp finger print: 7B1A 07F4 EC82 0F90 D4C2 8936 872A E508 7DB6 9DA3

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

#2 lore raw

Dan Carpenter wrote at 11:45:23

Quoted 2 lines

No problem, I'm happy to explain.

Thx for the quick response :-)

Signature · 9 lines
MfG/Sincerely
Toralf Förster

pgp finger print: 7B1A 07F4 EC82 0F90 D4C2 8936 872A E508 7DB6 9DA3

--
To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
#3 lore raw
In reply to Dan Carpenter
Quoted 10 lines
Quoted 1 line

drivers/infiniband/core/user_mad.c +646 ib_umad_reg_agent() 'umm' 4 <= 6

   641                          u32 *umm = (u32 *) ureq.method_mask;
   642                          int i;
   643  
   644                          for (i = 0; i < BITS_TO_LONGS(IB_MGMT_MAX_METHODS); ++i)
   645                                  req.method_mask[i]  >    646                                          umm[i * 2] | ((u64) umm[i * 2 + 1] << 32);

"umm" points to a array with 4 elements.
i can be 0 to 3, so "i * 2" goes up to 6
And 4 <= 6 so it's a problem.
Smatch also complained about "i * 2 + 1" but I didn't include that.

It's a bit tricky, but I believe this is a false positive. The code in question is compatibility handling for 32-bit userspace on a 64-bit kernel. In that case the range of i will be 0 to 1 (IB_MGMT_MAX_METHODS is 128, so BITS_TO_LONGS on that is 2), and so we will only access elements 0, 1, 2, and 3 of umm[], which is OK.

(Not sure how easily a static checker could find this; the code in question is guarded by test of compat_method_mask, which can only be 1 if ib_umad_reg_agent() is called from ib_umad_compat_ioctl(), which will only be built with CONFIG_COMPAT set, which can only happen on a 64-bit architecture -- but it seems a bit hard for a checker to follow all that)

Signature · 3 lines
Roland Dreier  <[email protected]>
For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html
#4 lore raw
Quoted 17 lines · Roland Dreier
Quoted 10 lines
Quoted 1 line

drivers/infiniband/core/user_mad.c +646 ib_umad_reg_agent() 'umm' 4 <= 6

   641                          u32 *umm = (u32 *) ureq.method_mask;
   642                          int i;
   643  
   644                          for (i = 0; i < BITS_TO_LONGS(IB_MGMT_MAX_METHODS); ++i)
   645                                  req.method_mask[i] >  >    646                                          umm[i * 2] | ((u64) umm[i * 2 + 1] << 32);

"umm" points to a array with 4 elements.
i can be 0 to 3, so "i * 2" goes up to 6
And 4 <= 6 so it's a problem.
Smatch also complained about "i * 2 + 1" but I didn't include that.

It's a bit tricky, but I believe this is a false positive. The code in question is compatibility handling for 32-bit userspace on a 64-bit kernel. In that case the range of i will be 0 to 1 (IB_MGMT_MAX_METHODS is 128, so BITS_TO_LONGS on that is 2), and so we will only access elements 0, 1, 2, and 3 of umm[], which is OK.

Quoted 5 lines

(Not sure how easily a static checker could find this; the code in question is guarded by test of compat_method_mask, which can only be 1 if ib_umad_reg_agent() is called from ib_umad_compat_ioctl(), which will only be built with CONFIG_COMPAT set, which can only happen on a 64-bit architecture -- but it seems a bit hard for a checker to follow all that)

Smatch doesn't handle anything between functions yet. Once it does you could do something like:

compat_method_mask = get_possible_range(this parameter); That would only be zero, because the other code is #ifdefed out. Then the rest is simple enough.

It will take some months to get the inter-function stuff working though.

regards,
dan carpenter

Quoted 4 lines
Signature · 3 lines
Roland Dreier  <[email protected]>
For corporate legal information go to:
http://www.cisco.com/web/about/doing_business/legal/cri/index.html