Re: [PATCH] stat: don't fail if the major number is >= 256

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

 



On Mon, Apr 11, 2022 at 4:43 AM Mikulas Patocka <mpatocka@xxxxxxxxxx> wrote:
>
> If you run a program compiled with OpenWatcom for Linux on a filesystem on
> NVMe, all "stat" syscalls fail with -EOVERFLOW. The reason is that the
> NVMe driver allocates a device with the major number 259 and it doesn't
> pass the "old_valid_dev" test.

OpenWatcom? Really?

> This patch removes the tests - it's better to wrap around than to return
> an error. (note that cp_old_stat also doesn't report an error and wraps
> the number around)

Hmm. We've used majors over 256 for a long time, but some of them are
admittedly very rare (SCSI OSD?)

Unfortunate. And in this case 259 aliases to 3, which is the old
HD/IDE0 major number. That's not great - there would be other numbers
that didn't have that problem (ie 4-6 are all currently only character
device majors, I think).

Anyway, I think that check is just bogus. The cp_new_stat() thing uses
'struct stat' and it has

        unsigned long   st_dev;         /* Device.  */
        unsigned long   st_rdev;        /* Device number, if device.  */

so there's no reason to limit things to the old 8-bit behavior.

Yes, it does that

  #define valid_dev(x)  choose_32_64(old_valid_dev(x),true)
  #define encode_dev(x) choose_32_64(old_encode_dev,new_encode_dev)(x)

  static __always_inline u16 old_encode_dev(dev_t dev)
  {
        return (MAJOR(dev) << 8) | MINOR(dev);
  }

which currently drops bits, but we should just *fix* that. We can put
the high bits in the upper bits, not limit it to 16 bits when we have
more space than that.

Even the *really* old 'struct old_stat' doesn't really have a 16-bit
st_dev/rdev.

           Linus



[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux