ptp: ocp: fix NULL deref in __handle_s for irig/dcf
PATCH v2 1/1 ptp: ocp: fix NULL deref in __handle_s for irig/dcf
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.
---
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(-)
drivers/ptp/ptp_ocp.c +8 -4
@@ -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
Signature · 1 line
2.47.0
Quoted 29 lines · Sagi Maimon
SMA store/get operations via sysfs can call
__handle_signal_outputsor__handle_signal_inputswhile 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 <[email protected]>Signed-off-by Sagi Maimon <[email protected]>---
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(-)drivers/ptp/ptp_ocp.c +2
-2@@ -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 );
drivers/ptp/ptp_ocp.c ptp_ocp_dcf_in(struct ptp_ocp *bp, bool enable) · line 2446
Quoted 10 lines
drivers/ptp/ptp_ocp.c +3
-2+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)
Why not irig_in? Can we asssume that "in" isn't NULL if "out" isn't?
drivers/ptp/ptp_ocp.c ptp_ocp_dcf_in(struct ptp_ocp *bp, bool enable) · line 2448
Quoted 2 lines
drivers/ptp/ptp_ocp.c +2
-0+ptp_ocp_irig_in (bp, val &0x00100010 ); +if (bp->dcf_out)
The same here.
drivers/ptp/ptp_ocp.c ptp_ocp_dcf_in(struct ptp_ocp *bp, bool enable) · line 2449
Quoted 1 line
drivers/ptp/ptp_ocp.c +1
-0+ptp_ocp_dcf_in (bp, val &0x00200020 );
Just my opinion, I will move these checks into ptp_ocp_...() functions as bp is passed to a function not bp->sth.
Quoted 5 lines
drivers/ptp/ptp_ocp.c +0
-0} static u32Signature · 1 line
2.47.0
Quoted 35 lines · Michal Swiatkowski
Quoted 33 lines · Sagi Maimon
SMA store/get operations via sysfs can call
__handle_signal_outputsor__handle_signal_inputswhile 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 <[email protected]>Signed-off-by Sagi Maimon <[email protected]>---
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(-)drivers/ptp/ptp_ocp.c +4
-2@@ -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 ); }
Quoted 8 lines
drivers/ptp/ptp_ocp.c ptp_ocp_dcf_in(struct ptp_ocp *bp, bool enable) · line 2446
Quoted 6 lines
drivers/ptp/ptp_ocp.c +1
-2static 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)Why not
irig_in? Can we asssume that "in" isn't NULL if "out" isn't?
Ss part of ocp_resource initiation, irig_in and irig_out initiated separately (one can be initiated and the other not ) so we can't assume that
Quoted 14 lines
drivers/ptp/ptp_ocp.c ptp_ocp_dcf_in(struct ptp_ocp *bp, bool enable) · line 2448
Quoted 2 lines
drivers/ptp/ptp_ocp.c +2
-0+ptp_ocp_irig_in (bp, val &0x00100010 ); +if (bp->dcf_out)The same here.
drivers/ptp/ptp_ocp.c ptp_ocp_dcf_in(struct ptp_ocp *bp, bool enable) · line 2449
Quoted 1 line
drivers/ptp/ptp_ocp.c +1
-0+ptp_ocp_dcf_in (bp, val &0x00200020 );Just my opinion, I will move these checks into ptp_ocp_...() functions as bp is passed to a function not
bp->sth.Quoted 5 lines
drivers/ptp/ptp_ocp.c +0
-1} static u32 --2.47.0
Vadim Fedorenko
maintainerQuoted 4 lines · Sagi Maimon
SMA store/get operations via sysfs can call
__handle_signal_outputsor__handle_signal_inputswhile 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.
Ok, looks like I misread the patch previously. IRIG and DCF registers are mapped unconditionally for OCP TimeCard. The functions you are trying to fix are HW-specific functions which you decided to reuse for your hardware. If your hardware doesn't support this function, you have to implement your own HW-specific callbacks used in ocp_adva_sma_op structure. I have to take back my Rb tag, and for this patch it's definitely NAck.
Quoted 41 lines
Fixes b286f4e87e32 ("serial: core: Move tty and serdev to be children of serial core port device")Reviewed-by Vadim Fedorenko <[email protected]>Signed-off-by Sagi Maimon <[email protected]>---
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(-)drivers/ptp/ptp_ocp.c +8
-4@@ -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