netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Bui Quang Minh <minhquangbui99@gmail.com>
To: Jesse Brandeburg <jesse.brandeburg@intel.com>,
	 Tony Nguyen <anthony.l.nguyen@intel.com>,
	 "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	 Jakub Kicinski <kuba@kernel.org>,
	Paolo Abeni <pabeni@redhat.com>,
	 Paul M Stillwell Jr <paul.m.stillwell.jr@intel.com>,
	 Rasesh Mody <rmody@marvell.com>,
	Sudarsana Kalluru <skalluru@marvell.com>,
	 GR-Linux-NIC-Dev@marvell.com,
	Anil Gurumurthy <anil.gurumurthy@qlogic.com>,
	 Sudarsana Kalluru <sudarsana.kalluru@qlogic.com>,
	 "James E.J. Bottomley" <James.Bottomley@HansenPartnership.com>,
	 "Martin K. Petersen" <martin.petersen@oracle.com>,
	 Fabian Frederick <fabf@skynet.be>,
	Saurav Kashyap <skashyap@marvell.com>,
	 GR-QLogic-Storage-Upstream@marvell.com,
	 Nilesh Javali <nilesh.javali@cavium.com>,
	Arun Easi <arun.easi@cavium.com>,
	 Manish Rangankar <manish.rangankar@cavium.com>,
	 Vineeth Vijayan <vneethv@linux.ibm.com>,
	 Peter Oberparleiter <oberpar@linux.ibm.com>,
	 Heiko Carstens <hca@linux.ibm.com>,
	Vasily Gorbik <gor@linux.ibm.com>,
	 Alexander Gordeev <agordeev@linux.ibm.com>,
	 Christian Borntraeger <borntraeger@linux.ibm.com>,
	 Sven Schnelle <svens@linux.ibm.com>,
	Sunil Goutham <sgoutham@marvell.com>,
	 Linu Cherian <lcherian@marvell.com>,
	Geetha sowjanya <gakula@marvell.com>,
	 Jerin Jacob <jerinj@marvell.com>,
	hariprasad <hkelam@marvell.com>,
	 Subbaraya Sundeep <sbhatta@marvell.com>
Cc: intel-wired-lan@lists.osuosl.org, netdev@vger.kernel.org,
	 linux-kernel@vger.kernel.org, linux-scsi@vger.kernel.org,
	 Saurav Kashyap <saurav.kashyap@cavium.com>,
	linux-s390@vger.kernel.org,  Jens Axboe <axboe@kernel.dk>,
	Bui Quang Minh <minhquangbui99@gmail.com>
Subject: [PATCH v2 6/6] octeontx2-af: avoid off-by-one read from userspace
Date: Wed, 24 Apr 2024 21:44:23 +0700	[thread overview]
Message-ID: <20240424-fix-oob-read-v2-6-f1f1b53a10f4@gmail.com> (raw)
In-Reply-To: <20240424-fix-oob-read-v2-0-f1f1b53a10f4@gmail.com>

We try to access count + 1 byte from userspace with memdup_user(buffer,
count + 1). However, the userspace only provides buffer of count bytes and
only these count bytes are verified to be okay to access. To ensure the
copied buffer is NUL terminated, we use memdup_user_nul instead.

Fixes: 3a2eb515d136 ("octeontx2-af: Fix an off by one in rvu_dbg_qsize_write()")
Signed-off-by: Bui Quang Minh <minhquangbui99@gmail.com>
---
 drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
index 2500f5ba4f5a..881d704644fb 100644
--- a/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
+++ b/drivers/net/ethernet/marvell/octeontx2/af/rvu_debugfs.c
@@ -999,12 +999,10 @@ static ssize_t rvu_dbg_qsize_write(struct file *filp,
 	u16 pcifunc;
 	int ret, lf;
 
-	cmd_buf = memdup_user(buffer, count + 1);
+	cmd_buf = memdup_user_nul(buffer, count);
 	if (IS_ERR(cmd_buf))
 		return -ENOMEM;
 
-	cmd_buf[count] = '\0';
-
 	cmd_buf_tmp = strchr(cmd_buf, '\n');
 	if (cmd_buf_tmp) {
 		*cmd_buf_tmp = '\0';

-- 
2.34.1


  parent reply	other threads:[~2024-04-24 14:45 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-04-24 14:44 [PATCH v2 0/6] Ensure the copied buf is NUL terminated Bui Quang Minh
2024-04-24 14:44 ` [PATCH v2 1/6] ice: ensure " Bui Quang Minh
2024-04-24 14:44 ` [PATCH v2 2/6] bna: " Bui Quang Minh
2024-04-24 14:44 ` [PATCH v2 3/6] bfa: " Bui Quang Minh
2024-05-07  1:19   ` Martin K. Petersen
2024-04-24 14:44 ` [PATCH v2 4/6] qedf: " Bui Quang Minh
2024-05-07  1:20   ` Martin K. Petersen
2024-04-24 14:44 ` [PATCH v2 5/6] cio: " Bui Quang Minh
2024-04-24 14:54   ` Heiko Carstens
2024-04-24 15:16   ` Alexander Gordeev
2024-04-26 10:10     ` Alexander Gordeev
2024-04-26 14:29       ` Jakub Kicinski
2024-04-24 14:44 ` Bui Quang Minh [this message]
2024-04-26  2:30 ` [PATCH v2 0/6] Ensure " patchwork-bot+netdevbpf
2024-05-11 18:39 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240424-fix-oob-read-v2-6-f1f1b53a10f4@gmail.com \
    --to=minhquangbui99@gmail.com \
    --cc=GR-Linux-NIC-Dev@marvell.com \
    --cc=GR-QLogic-Storage-Upstream@marvell.com \
    --cc=James.Bottomley@HansenPartnership.com \
    --cc=agordeev@linux.ibm.com \
    --cc=anil.gurumurthy@qlogic.com \
    --cc=anthony.l.nguyen@intel.com \
    --cc=arun.easi@cavium.com \
    --cc=axboe@kernel.dk \
    --cc=borntraeger@linux.ibm.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=fabf@skynet.be \
    --cc=gakula@marvell.com \
    --cc=gor@linux.ibm.com \
    --cc=hca@linux.ibm.com \
    --cc=hkelam@marvell.com \
    --cc=intel-wired-lan@lists.osuosl.org \
    --cc=jerinj@marvell.com \
    --cc=jesse.brandeburg@intel.com \
    --cc=kuba@kernel.org \
    --cc=lcherian@marvell.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-s390@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=manish.rangankar@cavium.com \
    --cc=martin.petersen@oracle.com \
    --cc=netdev@vger.kernel.org \
    --cc=nilesh.javali@cavium.com \
    --cc=oberpar@linux.ibm.com \
    --cc=pabeni@redhat.com \
    --cc=paul.m.stillwell.jr@intel.com \
    --cc=rmody@marvell.com \
    --cc=saurav.kashyap@cavium.com \
    --cc=sbhatta@marvell.com \
    --cc=sgoutham@marvell.com \
    --cc=skalluru@marvell.com \
    --cc=skashyap@marvell.com \
    --cc=sudarsana.kalluru@qlogic.com \
    --cc=svens@linux.ibm.com \
    --cc=vneethv@linux.ibm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).