Skip to content
  • Alex Chiang's avatar
    sysfs: only allow one scheduled removal callback per kobj · 66942064
    Alex Chiang authored
    The only way for a sysfs attribute to remove itself (without
    deadlock) is to use the sysfs_schedule_callback() interface.
    Vegard Nossum discovered that a poorly written sysfs ->store
    callback can repeatedly schedule remove callbacks on the same
    device over and over, e.g.
    	$ while true ; do echo 1 > /sys/devices/.../remove ; done
    If the 'remove' attribute uses the sysfs_schedule_callback API
    and also does not protect itself from concurrent accesses, its
    callback handler will be called multiple times, and will
    eventually attempt to perform operations on a freed kobject,
    leading to many problems.
    Instead of requiring all callers of sysfs_schedule_callback to
    implement their own synchronization, provide the protection in
    the infrastructure.
    Now, sysfs_schedule_callback will only allow one scheduled
    callback per kobject. On subsequent calls with the same kobject,
    return -EAGAIN.
    This is a short term fix. The long term fix is to allow sysfs
    attributes to remove themselves directly, without any of this
    callback hokey pokey.
    [ s390 ccwgroup bits]
    Reported-by: default avatar <>
    Signed-off-by: default avatarAlex Chiang <>
    Acked-by: default avatarCornelia Huck <>
    Signed-off-by: default avatarGreg Kroah-Hartman <>