• Jason Gunthorpe's avatar
    RDMA/core: Split port and device counter sysfs attributes · 467f432a
    Jason Gunthorpe authored
    This code creates a 'struct hw_stats_attribute' for each sysfs entry that
    contains a naked 'struct attribute' inside.
    
    It then proceeds to attach this same structure to a 'struct device' kobj
    and a 'struct ib_port' kobj. However, this violates the typing
    requirements.  'struct device' requires the attribute to be a 'struct
    device_attribute' and 'struct ib_port' requires the attribute to be
    'struct port_attribute'.
    
    This happens to work because the show/store function pointers in all three
    structures happen to be at the same offset and happen to be nearly the
    same signature. This means when container_of() was used to go between the
    wrong two types it still managed to work.
    
    However clang CFI detection notices that the function pointers have a
    slightly different signature. As with show/store this was only working
    because the device and port struct layouts happened to have the kobj at
    the front.
    
    Correct this by have two independent sets of data structures for the port
    and device case. The two different attributes correctly include the
    port/device_attribute struct and everything from there up is kept
    split. The show/store function call chains start with device/port unique
    functions that invoke a common show/store function pointer.
    
    Link: https://lore.kernel.org/r/a8b3864b4e722aed3657512af6aa47dc3c5033be.1623427137.git.leonro@nvidia.comReported-by: default avatarNathan Chancellor <nathan@kernel.org>
    Tested-by: default avatarNathan Chancellor <nathan@kernel.org>
    Cc: Kees Cook <keescook@chromium.org>
    Signed-off-by: default avatarLeon Romanovsky <leonro@nvidia.com>
    Signed-off-by: default avatarJason Gunthorpe <jgg@nvidia.com>
    467f432a
sysfs.c 41 KB