Skip to contentSkip to conversation

ptp: ocp: fix sprintf overflow in ptp_ocp_verify()

PATCH In review Dan Carpenter 2 participants 3 messages Mar 17, 2022 – Mar 18, 2022

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ptp: ocp: fix sprintf overflow in ptp_ocp_verify()

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")
---
 drivers/ptp/ptp_ocp.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
drivers/ptp/ptp_ocp.c +3 -3
index 56b04a7bba3a..f0565c4a85df 100644
@@ -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);
 }
Signature · 1 line
2.20.1
#1 lore raw
Quoted 6 lines · Dan Carpenter

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")

This needs to be respun to catch up with the last patch.

Signature · 1 line
Jonathan
#2 lore raw
Quoted 9 lines · Jonathan Lemon
Quoted 6 lines · Dan Carpenter

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")

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