octeontx2-af: debugfs: don't corrupt user memory
Subsystems (4)
PATCH 1/1 octeontx2-af: debugfs: don't corrupt user memory
The user supplies the "count" value to say how big its read buffer is. The rvu_dbg_lmtst_map_table_display() function does not take the "count" into account but instead just copies the whole table, potentially corrupting the user's data.
Introduce the "ret" variable to store how many bytes we can copy. Also I changed the type of "off" to size_t to make using min() simpler.
--- .../ethernet/marvell/octeontx2/af/rvu_debugfs.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-)
drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c +10 -7
@@ -236,10 +236,11 @@ static ssize_t rvu_dbg_lmtst_map_table_display(struct file *filp,u64 lmt_addr, val, tbl_base;int pf, vf, num_vfs, hw_vfs;void __iomem *lmt_map_base; -int index =0 , off =0 ; -int bytes_not_copied;int buf_size =10240 ; +size_t off =0 ; +int index =0 ;char *buf; +int ret;/* don't allow partial reads */ if (*ppos !=0 )
@@ -303,15 +304,17 @@ static ssize_t rvu_dbg_lmtst_map_table_display(struct file *filp, } off +=scnprintf (&buf[off], buf_size -1 - off,"\n" ); - bytes_not_copied =copy_to_user (buffer, buf, off); + ret =min (off, count); +if (copy_to_user (buffer, buf, ret)) + ret = -EFAULT ;kfree (buf);iounmap (lmt_map_base); -if (bytes_not_copied) -return -EFAULT ; +if (ret <0 ) +return ret; - *ppos = off; -return off; + *ppos = ret; +return ret; }RVU_DEBUG_FOPS (lmtst_map_table, lmtst_map_table_display,NULL );
Signature · 1 line
2.20.1
This patch was applied to netdev/net.git (master) by Jakub Kicinski <[email protected]>:
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <[email protected]>:
Quoted 9 lines · On Wed, 17 Nov 2021 10:34:54 +0300 you wrote:
The user supplies the "count" value to say how big its read buffer is. The
rvu_dbg_lmtst_map_table_display()function does not take the "count" into account but instead just copies the whole table, potentially corrupting the user's data.Introduce the "ret" variable to store how many bytes we can copy. Also I changed the type of "off" to
size_tto make usingmin()simpler.[...]
Here is the summary with links:
- [net] octeontx2-af: debugfs: don't corrupt user memory
https://git.kernel.org/netdev/net/c/a280ef90af01
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html