From: Petr Machata <petrm@mellanox.com>
To: Colin Ian King <colin.king@canonical.com>
Cc: Jiri Pirko <jiri@mellanox.com>,
Ido Schimmel <idosch@mellanox.com>,
"David S. Miller" <davem@davemloft.net>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: mlxsw: spectrum: PTP: Support timestamping on Spectrum-1 - potential null ptr dereference
Date: Tue, 2 Jul 2019 15:51:17 +0000 [thread overview]
Message-ID: <87r278sado.fsf@mellanox.com> (raw)
In-Reply-To: <4fb676a6-1de8-8bcf-5f2e-3157827546c8@canonical.com>
Colin Ian King <colin.king@canonical.com> writes:
> Hi,
>
> Static analysis with Coverity on today's linux-next has found a
> potential null pointer dereference bug with the following commit:
>
> commit d92e4e6e33c8b19635be70fb8935b627d2e4f8fe
> Author: Petr Machata <petrm@mellanox.com>
> Date: Sun Jun 30 09:04:56 2019 +0300
>
> mlxsw: spectrum: PTP: Support timestamping on Spectrum-1
>
>
> In function: mlxsw_sp1_ptp_packet_finish the offending code is as follows:
>
> /* Between capturing the packet and finishing it, there is a
> window of
> * opportunity for the originating port to go away (e.g. due to a
> * split). Also make sure the SKB device reference is still valid.
> */
> mlxsw_sp_port = mlxsw_sp->ports[local_port];
> if (!mlxsw_sp_port && (!skb->dev || skb->dev == mlxsw_sp_port->dev)) {
> dev_kfree_skb_any(skb);
> return;
> }
>
> If mlxsw_sp_port is null and skb->dev is not-null then the comparison
> "skb->dev == mlxsw_sp_port->dev" ends up with a null pointer dereference.
>
> I think the if statement should be:
>
> if (mlxsw_sp_port && (!skb->dev || skb->dev == mlxsw_sp_port->dev))
>
> ..but I'm not 100% sure as I may be missing something a bit more subtle
> here.
Yes, that line is wrong. It's missing a pair of parens, it should be:
if (!(mlxsw_sp_port && (!skb->dev || skb->dev == mlxsw_sp_port->dev))) {
I.e. I need a port && I need the skb->dev to still refer to that port
(or else be NULL). If that doesn't hold, bail out.
Thanks for the report, I'll spin a fix!
next prev parent reply other threads:[~2019-07-02 15:51 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-07-02 15:01 mlxsw: spectrum: PTP: Support timestamping on Spectrum-1 - potential null ptr dereference Colin Ian King
2019-07-02 15:51 ` Petr Machata [this message]
2019-07-02 15:52 ` Colin Ian King
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=87r278sado.fsf@mellanox.com \
--to=petrm@mellanox.com \
--cc=colin.king@canonical.com \
--cc=davem@davemloft.net \
--cc=idosch@mellanox.com \
--cc=jiri@mellanox.com \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
/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