Skip to content
Snippets Groups Projects
  • Qiu-ji Chen's avatar
    91d44c1a
    cdx: Fix possible UAF error in driver_override_show() · 91d44c1a
    Qiu-ji Chen authored
    
    Fixed a possible UAF problem in driver_override_show() in drivers/cdx/cdx.c
    
    This function driver_override_show() is part of DEVICE_ATTR_RW, which
    includes both driver_override_show() and driver_override_store().
    These functions can be executed concurrently in sysfs.
    
    The driver_override_store() function uses driver_set_override() to
    update the driver_override value, and driver_set_override() internally
    locks the device (device_lock(dev)). If driver_override_show() reads
    cdx_dev->driver_override without locking, it could potentially access
    a freed pointer if driver_override_store() frees the string
    concurrently. This could lead to printing a kernel address, which is a
    security risk since DEVICE_ATTR can be read by all users.
    
    Additionally, a similar pattern is used in drivers/amba/bus.c, as well
    as many other bus drivers, where device_lock() is taken in the show
    function, and it has been working without issues.
    
    This potential bug was detected by our experimental static analysis
    tool, which analyzes locking APIs and paired functions to identify
    data races and atomicity violations.
    
    Fixes: 1f86a00c ("bus/fsl-mc: add support for 'driver_override' in the mc-bus")
    Cc: stable <stable@kernel.org>
    Signed-off-by: default avatarQiu-ji Chen <chenqiuji666@gmail.com>
    Link: https://lore.kernel.org/r/20250118070833.27201-1-chenqiuji666@gmail.com
    
    
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    91d44c1a
    History
    cdx: Fix possible UAF error in driver_override_show()
    Qiu-ji Chen authored
    
    Fixed a possible UAF problem in driver_override_show() in drivers/cdx/cdx.c
    
    This function driver_override_show() is part of DEVICE_ATTR_RW, which
    includes both driver_override_show() and driver_override_store().
    These functions can be executed concurrently in sysfs.
    
    The driver_override_store() function uses driver_set_override() to
    update the driver_override value, and driver_set_override() internally
    locks the device (device_lock(dev)). If driver_override_show() reads
    cdx_dev->driver_override without locking, it could potentially access
    a freed pointer if driver_override_store() frees the string
    concurrently. This could lead to printing a kernel address, which is a
    security risk since DEVICE_ATTR can be read by all users.
    
    Additionally, a similar pattern is used in drivers/amba/bus.c, as well
    as many other bus drivers, where device_lock() is taken in the show
    function, and it has been working without issues.
    
    This potential bug was detected by our experimental static analysis
    tool, which analyzes locking APIs and paired functions to identify
    data races and atomicity violations.
    
    Fixes: 1f86a00c ("bus/fsl-mc: add support for 'driver_override' in the mc-bus")
    Cc: stable <stable@kernel.org>
    Signed-off-by: default avatarQiu-ji Chen <chenqiuji666@gmail.com>
    Link: https://lore.kernel.org/r/20250118070833.27201-1-chenqiuji666@gmail.com
    
    
    Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>