From: Michal Swiatkowski <michal.swiatkowski@linux.intel.com>
To: Sagi Maimon <maimon.sagi@gmail.com>
Cc: jonathan.lemon@gmail.com, vadim.fedorenko@linux.dev,
richardcochran@gmail.com, andrew+netdev@lunn.ch,
davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com, linux-kernel@vger.kernel.org,
netdev@vger.kernel.org
Subject: Re: [PATCH v2] ptp: ocp: fix NULL deref in __handle_s for irig/dcf
Date: Tue, 15 Apr 2025 08:59:43 +0200 [thread overview]
Message-ID: <Z/4D3/PW9FkxQSdo@mev-dev.igk.intel.com> (raw)
In-Reply-To: <20250415064638.130453-1-maimon.sagi@gmail.com>
On Tue, Apr 15, 2025 at 09:46:38AM +0300, Sagi Maimon wrote:
> 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)
Why not irig_in? Can we asssume that "in" isn't NULL if "out" isn't?
> + ptp_ocp_irig_in(bp, val & 0x00100010);
> + if (bp->dcf_out)
The same here.
> + 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.
> }
>
> static u32
> --
> 2.47.0
next prev parent reply other threads:[~2025-04-15 7:00 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
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 [this message]
2025-04-15 9:22 ` Sagi Maimon
2025-04-15 9:58 ` Vadim Fedorenko
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Z/4D3/PW9FkxQSdo@mev-dev.igk.intel.com \
--to=michal.swiatkowski@linux.intel.com \
--cc=andrew+netdev@lunn.ch \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=jonathan.lemon@gmail.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=maimon.sagi@gmail.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=richardcochran@gmail.com \
--cc=vadim.fedorenko@linux.dev \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).