Skip to contentSkip to conversation

net: macb: fix NULL dereference due to no pcs_config method

PATCH RESEND Applied Parshuram Thombare 4 participants 4 messages Nov 5, 2020 – Nov 7, 2020

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH RESEND 1/1 net: macb: fix NULL dereference due to no pcs_config method

This patch fixes NULL pointer dereference due to NULL pcs_config in pcs_ops.

---
 drivers/net/ethernet/cadence/macb_main.c | 17 +++++++++++++++--
 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +15 -2
index b7bc160..130a5af 100644
@@ -633,6 +633,15 @@ static void macb_pcs_an_restart(struct phylink_pcs *pcs)
 	/* Not supported */
 }
 
+static int macb_pcs_config(struct phylink_pcs *pcs,
+			   unsigned int mode,
+			   phy_interface_t interface,
+			   const unsigned long *advertising,
+			   bool permit_pause_to_mac)
+{
+	return 0;
+}
+
 static const struct phylink_pcs_ops macb_phylink_usx_pcs_ops = {
 	.pcs_get_state = macb_usx_pcs_get_state,
 	.pcs_config = macb_usx_pcs_config,
@@ -642,6 +651,7 @@ static const struct phylink_pcs_ops macb_phylink_usx_pcs_ops = {
 static const struct phylink_pcs_ops macb_phylink_pcs_ops = {
 	.pcs_get_state = macb_pcs_get_state,
 	.pcs_an_restart = macb_pcs_an_restart,
+	.pcs_config = macb_pcs_config,
 };
 
 static void macb_mac_config(struct phylink_config *config, unsigned int mode,
@@ -776,10 +786,13 @@ static int macb_mac_prepare(struct phylink_config *config, unsigned int mode,
 
 	if (interface == PHY_INTERFACE_MODE_10GBASER)
 		bp->phylink_pcs.ops = &macb_phylink_usx_pcs_ops;
-	else
+	else if (interface == PHY_INTERFACE_MODE_SGMII)
 		bp->phylink_pcs.ops = &macb_phylink_pcs_ops;
+	else
+		bp->phylink_pcs.ops = NULL;
 
-	phylink_set_pcs(bp->phylink, &bp->phylink_pcs);
+	if (bp->phylink_pcs.ops)
+		phylink_set_pcs(bp->phylink, &bp->phylink_pcs);
 
 	return 0;
 }
Signature · 1 line
2.7.4
Acked-by on v1 1/1
#1 lore raw
Quoted 6 lines · Parshuram Thombare

This patch fixes NULL pointer dereference due to NULL pcs_config in pcs_ops.

Thanks Parshuram, best regards,
Nicolas

Quoted 51 lines
---
  drivers/net/ethernet/cadence/macb_main.c | 17 +++++++++++++++--
  1 file changed, 15 insertions(+), 2 deletions(-)
drivers/net/ethernet/cadence/macb_main.c +15 -3
index b7bc160..130a5af 100644
@@ -633,6 +633,15 @@ static void macb_pcs_an_restart(struct phylink_pcs *pcs)
         /* Not supported */
  }
 
+static int macb_pcs_config(struct phylink_pcs *pcs,
+                          unsigned int mode,
+                          phy_interface_t interface,
+                          const unsigned long *advertising,
+                          bool permit_pause_to_mac)
+{
+       return 0;
+}
+
  static const struct phylink_pcs_ops macb_phylink_usx_pcs_ops = {
         .pcs_get_state = macb_usx_pcs_get_state,
         .pcs_config = macb_usx_pcs_config,
@@ -642,6 +651,7 @@ static const struct phylink_pcs_ops macb_phylink_usx_pcs_ops = {
  static const struct phylink_pcs_ops macb_phylink_pcs_ops = {
         .pcs_get_state = macb_pcs_get_state,
         .pcs_an_restart = macb_pcs_an_restart,
+       .pcs_config = macb_pcs_config,
  };
 
  static void macb_mac_config(struct phylink_config *config, unsigned int mode,
@@ -776,10 +786,13 @@ static int macb_mac_prepare(struct phylink_config *config, unsigned int mode,
 
         if (interface == PHY_INTERFACE_MODE_10GBASER)
                 bp->phylink_pcs.ops = &macb_phylink_usx_pcs_ops;
-       else
+       else if (interface == PHY_INTERFACE_MODE_SGMII)
                 bp->phylink_pcs.ops = &macb_phylink_pcs_ops;
+       else
+               bp->phylink_pcs.ops = NULL;
 
-       phylink_set_pcs(bp->phylink, &bp->phylink_pcs);
+       if (bp->phylink_pcs.ops)
+               phylink_set_pcs(bp->phylink, &bp->phylink_pcs);
 
         return 0;
  }
--

2.7.4

Signature · 1 line
Nicolas Ferre
maintainer Applied
#2 lore raw
Quoted 9 lines · On Fri, 6 Nov 2020 10:26:59 +0100 Nicolas Ferre wrote:
Quoted 6 lines · Parshuram Thombare

This patch fixes NULL pointer dereference due to NULL pcs_config in pcs_ops.

Applied.

I brought back the fixes tag from the first posting. It's entirely reasonable to add fixes tags from the tree you're targeting as long as that tree guarantees commit hashes are stable and won't change on their way upstream. Which is the case for net and net-next trees.

Thanks!

#3 lore raw
In reply to Parshuram Thombare
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 8 lines · On Thu, 5 Nov 2020 18:58:33 +0100 you wrote:

This patch fixes NULL pointer dereference due to NULL pcs_config in pcs_ops.

[...]

Here is the summary with links:
- [RESEND] net: macb: fix NULL dereference due to no pcs_config method

    https://git.kernel.org/netdev/net-next/c/0012eeb370f8

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html