• Kirill Tkhai's avatar
    files: Fix test and set endianess problem · b20780d6
    Kirill Tkhai authored
    Andrew Vagin reported the problem found by a checker:
    
        CID 174702 (#1 of 1): Out-of-bounds access (INCOMPATIBLE_CAST)
        incompatible_cast: Pointer &f->raw.counter points to an object whose
        effective type is int (32 bits, signed) but is dereferenced as a wider
        unsigned long (64 bits, unsigned). This may lead to memory corruption.
    
    It looks like, this points to real problem, which may happen on big-endian
    platforms. In the code I relay on the fact, that FDS_EVENT_BIT has a small
    number and the value, it determines, fits into int type without problems.
    But it's correct only for little-endian.
    
    In case of big-endian, if the word size is 8 bytes, then FDS_EVENT value
    is in the last bytes, so there is an access to wrong memory.
    
    To fix the problem, I suggest to use little-endian byte order to work
    with task_st futex. Then, the bits from 0 to 31 will be in the low adresses,
    i.e. in task_st futex. There is new primitives test_and_set_bit_le() and
    set_bit_le() borrowed from the linux kernel for that.
    
    This fixes the problem, but I suppose, the checker does not see the problem
    so deep, and just compares the types size, so it will fail again.
    So, let's enlarge the bit field size to silence it.
    Signed-off-by: 's avatarKirill Tkhai <ktkhai@virtuozzo.com>
    Signed-off-by: 's avatarPavel Emelyanov <xemul@virtuozzo.com>
    b20780d6
Name
Last commit
Last update
Documentation Loading commit data...
contrib Loading commit data...
coredump Loading commit data...
crit Loading commit data...
criu Loading commit data...
images Loading commit data...
include/common Loading commit data...
lib Loading commit data...
scripts Loading commit data...
soccr Loading commit data...
test Loading commit data...
.gitignore Loading commit data...
.mailmap Loading commit data...
.travis.yml Loading commit data...
COPYING Loading commit data...
CREDITS Loading commit data...
INSTALL.md Loading commit data...
Makefile Loading commit data...
Makefile.config Loading commit data...
Makefile.install Loading commit data...
Makefile.versions Loading commit data...
README.md Loading commit data...