]> rtime.felk.cvut.cz Git - zynq/linux.git/commit
firmware: xilinx: fix debugfs write handler
authorJann Horn <jannh@google.com>
Mon, 18 Feb 2019 21:43:09 +0000 (22:43 +0100)
committerMichal Simek <michal.simek@xilinx.com>
Thu, 21 Mar 2019 14:57:07 +0000 (15:57 +0100)
commit20dc6c839a50f8a065d58c7051764c5438e47e03
tree21ce9e69ef32b900732e1cfffba56148064b26a8
parentce37bfc2d48a94c5938838f5befbb48336f556e6
firmware: xilinx: fix debugfs write handler

 - 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: Jann Horn <jannh@google.com>
Acked-by: Jolly Shah <jolly.shah@xilinx.com>
Signed-off-by: Michal Simek <michal.simek@xilinx.com>
drivers/firmware/xilinx/zynqmp-debug.c