Re: blockdev.c: getsize(): signed args, error checking

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

 



On Sat, Oct 20, 2007 at 02:57:18PM +0200, Stefan Krah wrote:
> Karel Zak <kzak@xxxxxxxxxx> wrote:
> > On Fri, Oct 19, 2007 at 01:39:38PM +0200, Stefan Krah wrote:
> > > in getsize() the BLKGETSIZE and BLKGETSIZE64 ioctls are called
> > > with signed args, see the patch below.
> > 
> >  Ah.. I've already fixed this bug in other place in blockdev
> >  (--getsize, --getsize64).
> > 
> >  I see same signed args in fdisk/disksize.c :-( We need to cleanup this
> >  code, remove all getsize() versions and create libs/blkdevsize.c
> >  (see TODO).
> 
> It would be great to have an implementation that is guaranteed to work
> with older kernels. The getsize() of e2fsprogs for example doesn't trust
> BLKGETSIZE64 for kernels < 2.6.

 OK, send patch :-)

> > > Since the EFBIG change in getsize() sz might contain garbage, so there
> > > should be additional error checks, something like (yes, this is ugly):
> > 
> >  I think you needn't extra check, you can zeroize "sz" when the first
> >  ioctl() returns an error.
> 
> I can't see that. If the second ioctl() also returns with an error, getsize()
> will return success and a sector count of sz, which then would be 0.

 Yes, you're right. I didn't read the code carefully.

> It just struck me that if you use `blockdev --getsize64 ...`, the
> BLKGETSIZE64 ioctl() is trusted without the additional (b == 0 || b == sz)
> check (workaround?).

 Yes. blockdev(8) is very simple wrapper around BLK* ioctls. It
 returns an argument and return code without any extra logic/checks.

 This is probably the reason for the --getsz option, because --getsize
 and --getsize64 are not reliable without the additional checks. It
 would be nice to explain this thing in blockdev.8 man page.

 Ah.. the --getsz option is not in blokdev.8 man page :-(


    Karel


-- 
 Karel Zak  <kzak@xxxxxxxxxx>
-
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux