diff mbox series

[net-next] ptp: ocp: fix sprintf overflow in ptp_ocp_verify()

Message ID 20220317075957.GF25237@kili (mailing list archive)
State Changes Requested
Delegated to: Netdev Maintainers
Headers show
Series [net-next] ptp: ocp: fix sprintf overflow in ptp_ocp_verify() | expand

Checks

Context Check Description
netdev/tree_selection success Clearly marked for net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix success Link
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 0 this patch: 0
netdev/cc_maintainers success CCed 4 of 4 maintainers
netdev/build_clang success Errors and warnings before: 0 this patch: 0
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 0 this patch: 0
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 18 lines checked
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Dan Carpenter March 17, 2022, 7:59 a.m. UTC
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(-)

Comments

Jonathan Lemon March 17, 2022, 5:04 p.m. UTC | #1
On Thu, Mar 17, 2022 at 10:59:57AM +0300, Dan Carpenter wrote:
> 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>

This needs to be respun to catch up with the last patch.
Dan Carpenter March 18, 2022, 7:45 a.m. UTC | #2
On Thu, Mar 17, 2022 at 10:04:49AM -0700, Jonathan Lemon wrote:
> On Thu, Mar 17, 2022 at 10:59:57AM +0300, Dan Carpenter wrote:
> > 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>
> 
> This needs to be respun to catch up with the last patch.

Thanks.  It turns out you can't actually trigger this bug.  Still using
snprintf() is better so I will resend.

regards,
dan carpenter
diff mbox series

Patch

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);
 }