* [PATCH net] octeontx2-af: debugfs: don't corrupt user memory
@ 2021-11-17 7:34 Dan Carpenter
2021-11-18 4:30 ` patchwork-bot+netdevbpf
0 siblings, 1 reply; 2+ messages in thread
From: Dan Carpenter @ 2021-11-17 7:34 UTC (permalink / raw)
To: Sunil Goutham, Harman Kalra
Cc: Linu Cherian, Geetha sowjanya, Jerin Jacob, hariprasad,
Subbaraya Sundeep, David S. Miller, Jakub Kicinski,
Bhaskara Budiredla, Rakesh Babu, netdev, kernel-janitors
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.
Fixes: 0daa55d033b0 ("octeontx2-af: cn10k: debugfs for dumping LMTST map table")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
.../ethernet/marvell/octeontx2/af/rvu_debugfs.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
index c7fd466a0efd..a09a507369ac 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
@@ -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);
--
2.20.1
^ permalink raw reply related [flat|nested] 2+ messages in thread* Re: [PATCH net] octeontx2-af: debugfs: don't corrupt user memory
2021-11-17 7:34 [PATCH net] octeontx2-af: debugfs: don't corrupt user memory Dan Carpenter
@ 2021-11-18 4:30 ` patchwork-bot+netdevbpf
0 siblings, 0 replies; 2+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-11-18 4:30 UTC (permalink / raw)
To: Dan Carpenter
Cc: sgoutham, hkalra, lcherian, gakula, jerinj, hkelam, sbhatta,
davem, kuba, bbudiredla, rsaladi2, netdev, kernel-janitors
Hello:
This patch was applied to netdev/net.git (master)
by Jakub Kicinski <kuba@kernel.org>:
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_t to make using min() 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!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2021-11-18 4:30 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-11-17 7:34 [PATCH net] octeontx2-af: debugfs: don't corrupt user memory Dan Carpenter
2021-11-18 4:30 ` patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).