* [PATCH v1] ptp: ocp: Fix NULL dereference in Adva board SMA sysfs operations
@ 2025-04-28 14:37 Sagi Maimon
2025-04-28 15:16 ` Vadim Fedorenko
0 siblings, 1 reply; 3+ messages in thread
From: Sagi Maimon @ 2025-04-28 14:37 UTC (permalink / raw)
To: jonathan.lemon, vadim.fedorenko, richardcochran, andrew+netdev,
davem, edumazet, kuba, pabeni
Cc: linux-kernel, netdev, Sagi Maimon
From: Sagi Maimon <sagi.maimon@adtran.com>
On Adva boards, SMA sysfs store/get operations can call
__handle_signal_outputs() or __handle_signal_inputs() while the `irig`
and `dcf` pointers are uninitialized, leading to a NULL pointer
dereference in __handle_signal() and causing a kernel crash. Add
Adva-specific callbacks ptp_ocp_sma_adva_set_outputs() and
ptp_ocp_sma_adva_set_inputs() to the ptp_ocp driver, and include NULL
checks for `irig` and `dcf` to prevent crashes.
Fixes: ef61f5528fca ("ptp: ocp: add Adva timecard support")
Signed-off-by: Sagi Maimon <sagi.maimon@adtran.com>
---
drivers/ptp/ptp_ocp.c | 62 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 2 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index faf6e027f89a..3eaa2005b3b2 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2578,12 +2578,70 @@ static const struct ocp_sma_op ocp_fb_sma_op = {
.set_output = ptp_ocp_sma_fb_set_output,
};
+static int
+ptp_ocp_sma_adva_set_output(struct ptp_ocp *bp, int sma_nr, u32 val)
+{
+ u32 reg, mask, shift;
+ unsigned long flags;
+ u32 __iomem *gpio;
+
+ gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2;
+ shift = sma_nr & 1 ? 0 : 16;
+
+ mask = 0xffff << (16 - shift);
+
+ spin_lock_irqsave(&bp->lock, flags);
+
+ reg = ioread32(gpio);
+ reg = (reg & mask) | (val << shift);
+
+ if (bp->irig_out)
+ ptp_ocp_irig_out(bp, reg & 0x00100010);
+ if (bp->dcf_out)
+ ptp_ocp_dcf_out(bp, reg & 0x00200020);
+
+ iowrite32(reg, gpio);
+
+ spin_unlock_irqrestore(&bp->lock, flags);
+
+ return 0;
+}
+
+static int
+ptp_ocp_sma_adva_set_inputs(struct ptp_ocp *bp, int sma_nr, u32 val)
+{
+ u32 reg, mask, shift;
+ unsigned long flags;
+ u32 __iomem *gpio;
+
+ gpio = sma_nr > 2 ? &bp->sma_map2->gpio1 : &bp->sma_map1->gpio1;
+ shift = sma_nr & 1 ? 0 : 16;
+
+ mask = 0xffff << (16 - shift);
+
+ spin_lock_irqsave(&bp->lock, flags);
+
+ reg = ioread32(gpio);
+ reg = (reg & mask) | (val << shift);
+
+ if (bp->irig_in)
+ ptp_ocp_irig_in(bp, reg & 0x00100010);
+ if (bp->dcf_in)
+ ptp_ocp_dcf_in(bp, reg & 0x00200020);
+
+ iowrite32(reg, gpio);
+
+ spin_unlock_irqrestore(&bp->lock, flags);
+
+ return 0;
+}
+
static const struct ocp_sma_op ocp_adva_sma_op = {
.tbl = { ptp_ocp_adva_sma_in, ptp_ocp_adva_sma_out },
.init = ptp_ocp_sma_fb_init,
.get = ptp_ocp_sma_fb_get,
- .set_inputs = ptp_ocp_sma_fb_set_inputs,
- .set_output = ptp_ocp_sma_fb_set_output,
+ .set_inputs = ptp_ocp_sma_adva_set_inputs,
+ .set_output = ptp_ocp_sma_adva_set_output,
};
static int
--
2.47.0
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v1] ptp: ocp: Fix NULL dereference in Adva board SMA sysfs operations
2025-04-28 14:37 [PATCH v1] ptp: ocp: Fix NULL dereference in Adva board SMA sysfs operations Sagi Maimon
@ 2025-04-28 15:16 ` Vadim Fedorenko
0 siblings, 0 replies; 3+ messages in thread
From: Vadim Fedorenko @ 2025-04-28 15:16 UTC (permalink / raw)
To: Sagi Maimon, jonathan.lemon, richardcochran, andrew+netdev, davem,
edumazet, kuba, pabeni
Cc: linux-kernel, netdev, Sagi Maimon
On 28/04/2025 15:37, Sagi Maimon wrote:
> From: Sagi Maimon <sagi.maimon@adtran.com>
>
> On Adva boards, SMA sysfs store/get operations can call
> __handle_signal_outputs() or __handle_signal_inputs() while the `irig`
> and `dcf` pointers are uninitialized, leading to a NULL pointer
> dereference in __handle_signal() and causing a kernel crash. Add
> Adva-specific callbacks ptp_ocp_sma_adva_set_outputs() and
> ptp_ocp_sma_adva_set_inputs() to the ptp_ocp driver, and include NULL
> checks for `irig` and `dcf` to prevent crashes.
>
> Fixes: ef61f5528fca ("ptp: ocp: add Adva timecard support")
> Signed-off-by: Sagi Maimon <sagi.maimon@adtran.com>
> ---
> drivers/ptp/ptp_ocp.c | 62 +++++++++++++++++++++++++++++++++++++++++--
> 1 file changed, 60 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
> index faf6e027f89a..3eaa2005b3b2 100644
> --- a/drivers/ptp/ptp_ocp.c
> +++ b/drivers/ptp/ptp_ocp.c
> @@ -2578,12 +2578,70 @@ static const struct ocp_sma_op ocp_fb_sma_op = {
> .set_output = ptp_ocp_sma_fb_set_output,
> };
>
> +static int
> +ptp_ocp_sma_adva_set_output(struct ptp_ocp *bp, int sma_nr, u32 val)
> +{
> + u32 reg, mask, shift;
> + unsigned long flags;
> + u32 __iomem *gpio;
> +
> + gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2;
> + shift = sma_nr & 1 ? 0 : 16;
> +
> + mask = 0xffff << (16 - shift);
> +
> + spin_lock_irqsave(&bp->lock, flags);
> +
> + reg = ioread32(gpio);
> + reg = (reg & mask) | (val << shift);
> +
> + if (bp->irig_out)
> + ptp_ocp_irig_out(bp, reg & 0x00100010);
> + if (bp->dcf_out)
> + ptp_ocp_dcf_out(bp, reg & 0x00200020);
You never initialize neither irig_out nor dcf_out, both checks will
always fail. Looks like a dead code - please, remove it.
> +
> + iowrite32(reg, gpio);
> +
> + spin_unlock_irqrestore(&bp->lock, flags);
> +
> + return 0;
> +}
> +
> +static int
> +ptp_ocp_sma_adva_set_inputs(struct ptp_ocp *bp, int sma_nr, u32 val)
> +{
> + u32 reg, mask, shift;
> + unsigned long flags;
> + u32 __iomem *gpio;
> +
> + gpio = sma_nr > 2 ? &bp->sma_map2->gpio1 : &bp->sma_map1->gpio1;
> + shift = sma_nr & 1 ? 0 : 16;
> +
> + mask = 0xffff << (16 - shift);
> +
> + spin_lock_irqsave(&bp->lock, flags);
> +
> + reg = ioread32(gpio);
> + reg = (reg & mask) | (val << shift);
> +
> + if (bp->irig_in)
> + ptp_ocp_irig_in(bp, reg & 0x00100010);
> + if (bp->dcf_in)
> + ptp_ocp_dcf_in(bp, reg & 0x00200020);
The same goes here - neither irig_in, nor dcf_in will have real values
for your hardware, please remove this checks.
> +
> + iowrite32(reg, gpio);
> +
> + spin_unlock_irqrestore(&bp->lock, flags);
> +
> + return 0;
> +}
> +
> static const struct ocp_sma_op ocp_adva_sma_op = {
> .tbl = { ptp_ocp_adva_sma_in, ptp_ocp_adva_sma_out },
> .init = ptp_ocp_sma_fb_init,
> .get = ptp_ocp_sma_fb_get,
> - .set_inputs = ptp_ocp_sma_fb_set_inputs,
> - .set_output = ptp_ocp_sma_fb_set_output,
> + .set_inputs = ptp_ocp_sma_adva_set_inputs,
> + .set_output = ptp_ocp_sma_adva_set_output,
> };
>
> static int
pw-bot: cr
^ permalink raw reply [flat|nested] 3+ messages in thread
* [PATCH v1] ptp: ocp: Fix NULL dereference in Adva board SMA sysfs operations
@ 2025-04-28 14:33 Sagi Maimon
0 siblings, 0 replies; 3+ messages in thread
From: Sagi Maimon @ 2025-04-28 14:33 UTC (permalink / raw)
To: jonathan.lemon, vadim.fedorenko, richardcochran, andrew+netdev,
davem, edumazet, kuba, pabeni
Cc: linux-kernel, netdev, Sagi Maimon
On Adva boards, SMA sysfs store/get operations can call
__handle_signal_outputs() or __handle_signal_inputs() while the `irig`
and `dcf` pointers are uninitialized, leading to a NULL pointer
dereference in __handle_signal() and causing a kernel crash. Add
Adva-specific callbacks ptp_ocp_sma_adva_set_outputs() and
ptp_ocp_sma_adva_set_inputs() to the ptp_ocp driver, and include NULL
checks for `irig` and `dcf` to prevent crashes.
Fixes: ef61f5528fca ("ptp: ocp: add Adva timecard support")
Signed-off-by: Sagi Maimon <sagi.maimon@adtran.com>
---
drivers/ptp/ptp_ocp.c | 62 +++++++++++++++++++++++++++++++++++++++++--
1 file changed, 60 insertions(+), 2 deletions(-)
diff --git a/drivers/ptp/ptp_ocp.c b/drivers/ptp/ptp_ocp.c
index faf6e027f89a..3eaa2005b3b2 100644
--- a/drivers/ptp/ptp_ocp.c
+++ b/drivers/ptp/ptp_ocp.c
@@ -2578,12 +2578,70 @@ static const struct ocp_sma_op ocp_fb_sma_op = {
.set_output = ptp_ocp_sma_fb_set_output,
};
+static int
+ptp_ocp_sma_adva_set_output(struct ptp_ocp *bp, int sma_nr, u32 val)
+{
+ u32 reg, mask, shift;
+ unsigned long flags;
+ u32 __iomem *gpio;
+
+ gpio = sma_nr > 2 ? &bp->sma_map1->gpio2 : &bp->sma_map2->gpio2;
+ shift = sma_nr & 1 ? 0 : 16;
+
+ mask = 0xffff << (16 - shift);
+
+ spin_lock_irqsave(&bp->lock, flags);
+
+ reg = ioread32(gpio);
+ reg = (reg & mask) | (val << shift);
+
+ if (bp->irig_out)
+ ptp_ocp_irig_out(bp, reg & 0x00100010);
+ if (bp->dcf_out)
+ ptp_ocp_dcf_out(bp, reg & 0x00200020);
+
+ iowrite32(reg, gpio);
+
+ spin_unlock_irqrestore(&bp->lock, flags);
+
+ return 0;
+}
+
+static int
+ptp_ocp_sma_adva_set_inputs(struct ptp_ocp *bp, int sma_nr, u32 val)
+{
+ u32 reg, mask, shift;
+ unsigned long flags;
+ u32 __iomem *gpio;
+
+ gpio = sma_nr > 2 ? &bp->sma_map2->gpio1 : &bp->sma_map1->gpio1;
+ shift = sma_nr & 1 ? 0 : 16;
+
+ mask = 0xffff << (16 - shift);
+
+ spin_lock_irqsave(&bp->lock, flags);
+
+ reg = ioread32(gpio);
+ reg = (reg & mask) | (val << shift);
+
+ if (bp->irig_in)
+ ptp_ocp_irig_in(bp, reg & 0x00100010);
+ if (bp->dcf_in)
+ ptp_ocp_dcf_in(bp, reg & 0x00200020);
+
+ iowrite32(reg, gpio);
+
+ spin_unlock_irqrestore(&bp->lock, flags);
+
+ return 0;
+}
+
static const struct ocp_sma_op ocp_adva_sma_op = {
.tbl = { ptp_ocp_adva_sma_in, ptp_ocp_adva_sma_out },
.init = ptp_ocp_sma_fb_init,
.get = ptp_ocp_sma_fb_get,
- .set_inputs = ptp_ocp_sma_fb_set_inputs,
- .set_output = ptp_ocp_sma_fb_set_output,
+ .set_inputs = ptp_ocp_sma_adva_set_inputs,
+ .set_output = ptp_ocp_sma_adva_set_output,
};
static int
--
2.47.0
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2025-04-28 15:16 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-04-28 14:37 [PATCH v1] ptp: ocp: Fix NULL dereference in Adva board SMA sysfs operations Sagi Maimon
2025-04-28 15:16 ` Vadim Fedorenko
-- strict thread matches above, loose matches on Subject: below --
2025-04-28 14:33 Sagi Maimon
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).