netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* re: mlxsw: spectrum: PTP: Support timestamping on Spectrum-1 - potential null ptr dereference
@ 2019-07-02 15:01 Colin Ian King
  2019-07-02 15:51 ` Petr Machata
  0 siblings, 1 reply; 3+ messages in thread
From: Colin Ian King @ 2019-07-02 15:01 UTC (permalink / raw)
  To: Petr Machata, Jiri Pirko, Ido Schimmel, David S. Miller, netdev,
	linux-kernel

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.

Colin


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

* Re: mlxsw: spectrum: PTP: Support timestamping on Spectrum-1 - potential null ptr dereference
  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
  2019-07-02 15:52   ` Colin Ian King
  0 siblings, 1 reply; 3+ messages in thread
From: Petr Machata @ 2019-07-02 15:51 UTC (permalink / raw)
  To: Colin Ian King
  Cc: Jiri Pirko, Ido Schimmel, David S. Miller, netdev, linux-kernel


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!

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

* Re: mlxsw: spectrum: PTP: Support timestamping on Spectrum-1 - potential null ptr dereference
  2019-07-02 15:51 ` Petr Machata
@ 2019-07-02 15:52   ` Colin Ian King
  0 siblings, 0 replies; 3+ messages in thread
From: Colin Ian King @ 2019-07-02 15:52 UTC (permalink / raw)
  To: Petr Machata
  Cc: Jiri Pirko, Ido Schimmel, David S. Miller, netdev, linux-kernel

On 02/07/2019 16:51, Petr Machata wrote:
> 
> 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.

Ah, that makes sense.

> 
> Thanks for the report, I'll spin a fix!
> 
OK, thanks!

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

end of thread, other threads:[~2019-07-02 15:52 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2019-07-02 15:52   ` Colin Ian King

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