• Jann Horn's avatar
    firmware: xilinx: fix debugfs write handler · b9472f7d
    Jann Horn authored
     - Userspace wants to write a string with `len` bytes, not counting the
       terminating NULL, so we should allocate `len+1` bytes. It looks like the
       current code relied on having a nullbyte directly behind `kern_buff`,
       which happens to work reliably as long as `len` isn't one of the kmalloc
       size classes.
     - strncpy_from_user() is completely wrong here; userspace is giving us a
       (not necessarily null-terminated) buffer and its length.
       strncpy_from_user() is for cases in which we don't know the length.
     - Don't let broken userspace allocate arbitrarily big kmalloc allocations.
    
    Just use memdup_user_nul(), which is designed precisely for things like
    this.
    Signed-off-by: default avatarJann Horn <jannh@google.com>
    Acked-by: default avatarJolly Shah <jolly.shah@xilinx.com>
    Signed-off-by: default avatarMichal Simek <michal.simek@xilinx.com>
    b9472f7d
zynqmp-debug.c 5.67 KB