netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dan Carpenter <dan.carpenter@oracle.com>
To: Richard Cochran <richardcochran@gmail.com>,
	Jonathan Lemon <jonathan.lemon@gmail.com>
Cc: Richard Cochran <richardcochran@gmail.com>,
	"David S. Miller" <davem@davemloft.net>,
	netdev@vger.kernel.org, kernel-janitors@vger.kernel.org
Subject: [PATCH net-next] ptp: ocp: fix sprintf overflow in ptp_ocp_verify()
Date: Thu, 17 Mar 2022 10:59:57 +0300	[thread overview]
Message-ID: <20220317075957.GF25237@kili> (raw)

The "chan" value comes from the user via sysfs.  A large like UINT_MAX
could overflow the buffer by three bytes.  Make the buffer larger and
use snprintf() instead of sprintf().

Fixes: 1aa66a3a135a ("ptp: ocp: Program the signal generators via PTP_CLK_REQ_PEROUT")
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
---
 drivers/ptp/ptp_ocp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 56b04a7bba3a..f0565c4a85df 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -968,15 +968,15 @@ ptp_ocp_verify(struct ptp_clock_info *ptp_info, unsigned pin,
 	       enum ptp_pin_function func, unsigned chan)
 {
 	struct ptp_ocp *bp = container_of(ptp_info, struct ptp_ocp, ptp_info);
-	char buf[16];
+	char buf[20];
 
 	if (func != PTP_PF_PEROUT)
 		return -EOPNOTSUPP;
 
 	if (chan)
-		sprintf(buf, "OUT: GEN%d", chan);
+		snprintf(buf, sizeof(buf), "OUT: GEN%d", chan);
 	else
-		sprintf(buf, "OUT: PHC");
+		snprintf(buf, sizeof(buf), "OUT: PHC");
 
 	return ptp_ocp_sma_store(bp, buf, pin + 1);
 }
-- 
2.20.1


             reply	other threads:[~2022-03-17  8:00 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-03-17  7:59 Dan Carpenter [this message]
2022-03-17 17:04 ` [PATCH net-next] ptp: ocp: fix sprintf overflow in ptp_ocp_verify() Jonathan Lemon
2022-03-18  7:45   ` Dan Carpenter

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=20220317075957.GF25237@kili \
    --to=dan.carpenter@oracle.com \
    --cc=davem@davemloft.net \
    --cc=jonathan.lemon@gmail.com \
    --cc=kernel-janitors@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=richardcochran@gmail.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).