• Romain Perier's avatar
    tasklet: Introduce new initialization API · 12cc923f
    Romain Perier authored
    Nowadays, modern kernel subsystems that use callbacks pass the data
    structure associated with a given callback as argument to the callback.
    The tasklet subsystem remains one which passes an arbitrary unsigned
    long to the callback function. This has several problems:
    
    - This keeps an extra field for storing the argument in each tasklet
      data structure, it bloats the tasklet_struct structure with a redundant
      .data field
    
    - No type checking can be performed on this argument. Instead of
      using container_of() like other callback subsystems, it forces callbacks
      to do explicit type cast of the unsigned long argument into the required
      object type.
    
    - Buffer overflows can overwrite the .func and the .data field, so
      an attacker can easily overwrite the function and its first argument
      to whatever it wants.
    
    Add a new tasklet initialization API, via DECLARE_TASKLET() and
    tasklet_setup(), which will replace the existing ones.
    
    This work is greatly inspired by the timer_struct conversion series,
    see commit e99e88a9 ("treewide: setup_timer() -> timer_setup()")
    
    To avoid problems with both -Wcast-function-type (which is enabled in
    the kernel via -Wextra is several subsystems), and with mismatched
    function prototypes when build with Control Flow Integrity enabled,
    this adds the "use_callback" member to let the tasklet caller choose
    which union member to call through. Once all old API uses are removed,
    this and the .data member will be removed as well. (On 64-bit this does
    not grow the struct size as the new member fills the hole after atomic_t,
    which is also "int" sized.)
    Signed-off-by: default avatarRomain Perier <romain.perier@gmail.com>
    Co-developed-by: default avatarAllen Pais <allen.lkml@gmail.com>
    Signed-off-by: default avatarAllen Pais <allen.lkml@gmail.com>
    Reviewed-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
    Acked-by: default avatarThomas Gleixner <tglx@linutronix.de>
    Co-developed-by: default avatarKees Cook <keescook@chromium.org>
    Signed-off-by: default avatarKees Cook <keescook@chromium.org>
    12cc923f
softirq.c 17.9 KB