netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2] ptp: ocp: fix NULL deref in __handle_s for irig/dcf
@ 2025-04-15  6:46 Sagi Maimon
  2025-04-15  6:59 ` Michal Swiatkowski
  2025-04-15  9:58 ` Vadim Fedorenko
  0 siblings, 2 replies; 4+ messages in thread
From: Sagi Maimon @ 2025-04-15  6:46 UTC (permalink / raw)
  To: jonathan.lemon, vadim.fedorenko, richardcochran, andrew+netdev,
	davem, edumazet, kuba, pabeni
  Cc: linux-kernel, netdev, Sagi Maimon

SMA store/get operations via sysfs can call __handle_signal_outputs
or __handle_signal_inputs while irig and dcf pointers remain
uninitialized. This leads to a NULL pointer dereference in
__handle_s. Add NULL checks for irig and dcf to prevent crashes.

Fixes: b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")
Reviewed-by: Vadim Fedorenko <vadim.fedorenko@linux.dev>
Signed-off-by: Sagi Maimon <maimon.sagi@gmail.com>
---
Addressed comments from Paolo Abeni:
 - https://www.spinics.net/lists/netdev/msg1082406.html
Changes since v1:
 - Expanded commit message to clarify the NULL dereference scenario.
---
 drivers/ptp/ptp_ocp.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index 7945c6be1f7c..4e4a6f465b01 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2434,15 +2434,19 @@ ptp_ocp_dcf_in(struct ptp_ocp *bp, bool enable)
 static void
 __handle_signal_outputs(struct ptp_ocp *bp, u32 val)
 {
-	ptp_ocp_irig_out(bp, val & 0x00100010);
-	ptp_ocp_dcf_out(bp, val & 0x00200020);
+	if (bp->irig_out)
+		ptp_ocp_irig_out(bp, val & 0x00100010);
+	if (bp->dcf_out)
+		ptp_ocp_dcf_out(bp, val & 0x00200020);
 }
 
 static void
 __handle_signal_inputs(struct ptp_ocp *bp, u32 val)
 {
-	ptp_ocp_irig_in(bp, val & 0x00100010);
-	ptp_ocp_dcf_in(bp, val & 0x00200020);
+	if (bp->irig_out)
+		ptp_ocp_irig_in(bp, val & 0x00100010);
+	if (bp->dcf_out)
+		ptp_ocp_dcf_in(bp, val & 0x00200020);
 }
 
 static u32
-- 
2.47.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2025-04-15  9:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-15  6:46 [PATCH v2] ptp: ocp: fix NULL deref in __handle_s for irig/dcf Sagi Maimon
2025-04-15  6:59 ` Michal Swiatkowski
2025-04-15  9:22   ` Sagi Maimon
2025-04-15  9:58 ` Vadim Fedorenko

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