stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free
       [not found] <20211207102420.120131-1-mkl@pengutronix.de>
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 18:40   ` patchwork-bot+netdevbpf
  2021-12-07 10:24 ` [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card() Marc Kleine-Budde
                   ` (4 subsequent siblings)
  5 siblings, 1 reply; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Vincent Mailhol, stable,
	Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

After calling netif_receive_skb(skb), dereferencing skb is unsafe.
Especially, the can_frame cf which aliases skb memory is dereferenced
just after the call netif_receive_skb(skb).

Reordering the lines solves the issue.

Fixes: b21d18b51b31 ("can: Topcliff: Add PCH_CAN driver.")
Link: https://lore.kernel.org/all/20211123111654.621610-1-mailhol.vincent@wanadoo.fr
Cc: stable@vger.kernel.org
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/pch_can.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/pch_can.c b/drivers/net/can/pch_can.c
index 92a54a5fd4c5..964c8a09226a 100644
--- a/drivers/net/can/pch_can.c
+++ b/drivers/net/can/pch_can.c
@@ -692,11 +692,11 @@ static int pch_can_rx_normal(struct net_device *ndev, u32 obj_num, int quota)
 			cf->data[i + 1] = data_reg >> 8;
 		}
 
-		netif_receive_skb(skb);
 		rcv_pkts++;
 		stats->rx_packets++;
 		quota--;
 		stats->rx_bytes += cf->len;
+		netif_receive_skb(skb);
 
 		pch_fifo_thresh(priv, obj_num);
 		obj_num++;

base-commit: 4dbb0dad8e63fcd0b5a117c2861d2abe7ff5f186
-- 
2.33.0



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

* [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card()
       [not found] <20211207102420.120131-1-mkl@pengutronix.de>
  2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt Marc Kleine-Budde
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Dan Carpenter, stable,
	Oliver Hartkopp, Marc Kleine-Budde

From: Dan Carpenter <dan.carpenter@oracle.com>

If the last channel is not available then "dev" is freed.  Fortunately,
we can just use "pdev->irq" instead.

Also we should check if at least one channel was set up.

Fixes: fd734c6f25ae ("can/sja1000: add driver for EMS PCMCIA card")
Link: https://lore.kernel.org/all/20211124145041.GB13656@kili
Cc: stable@vger.kernel.org
Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com>
Acked-by: Oliver Hartkopp <socketcan@hartkopp.net>
Tested-by: Oliver Hartkopp <socketcan@hartkopp.net>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/sja1000/ems_pcmcia.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/sja1000/ems_pcmcia.c b/drivers/net/can/sja1000/ems_pcmcia.c
index e21b169c14c0..4642b6d4aaf7 100644
--- a/drivers/net/can/sja1000/ems_pcmcia.c
+++ b/drivers/net/can/sja1000/ems_pcmcia.c
@@ -234,7 +234,12 @@ static int ems_pcmcia_add_card(struct pcmcia_device *pdev, unsigned long base)
 			free_sja1000dev(dev);
 	}
 
-	err = request_irq(dev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
+	if (!card->channels) {
+		err = -ENODEV;
+		goto failure_cleanup;
+	}
+
+	err = request_irq(pdev->irq, &ems_pcmcia_interrupt, IRQF_SHARED,
 			  DRV_NAME, card);
 	if (!err)
 		return 0;
-- 
2.33.0



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

* [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt
       [not found] <20211207102420.120131-1-mkl@pengutronix.de>
  2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card() Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch Marc Kleine-Budde
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Brian Silverman, stable,
	Marc Kleine-Budde

From: Brian Silverman <brian.silverman@bluerivertech.com>

With the design of this driver, this condition is often triggered.
However, the counter that this interrupt indicates an overflow is never
read either, so overflowing is harmless.

On my system, when a CAN bus starts flapping up and down, this locks up
the whole system with lots of interrupts and printks.

Specifically, this interrupt indicates the CEL field of ECR has
overflowed. All reads of ECR mask out CEL.

Fixes: e0d1f4816f2a ("can: m_can: add Bosch M_CAN controller support")
Link: https://lore.kernel.org/all/20211129222628.7490-1-brian.silverman@bluerivertech.com
Cc: stable@vger.kernel.org
Signed-off-by: Brian Silverman <brian.silverman@bluerivertech.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 2470c47b2e31..91be87c4f4d3 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -204,16 +204,16 @@ enum m_can_reg {
 
 /* Interrupts for version 3.0.x */
 #define IR_ERR_LEC_30X	(IR_STE	| IR_FOE | IR_ACKE | IR_BE | IR_CRCE)
-#define IR_ERR_BUS_30X	(IR_ERR_LEC_30X | IR_WDI | IR_ELO | IR_BEU | \
-			 IR_BEC | IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | \
-			 IR_RF1L | IR_RF0L)
+#define IR_ERR_BUS_30X	(IR_ERR_LEC_30X | IR_WDI | IR_BEU | IR_BEC | \
+			 IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | IR_RF1L | \
+			 IR_RF0L)
 #define IR_ERR_ALL_30X	(IR_ERR_STATE | IR_ERR_BUS_30X)
 
 /* Interrupts for version >= 3.1.x */
 #define IR_ERR_LEC_31X	(IR_PED | IR_PEA)
-#define IR_ERR_BUS_31X      (IR_ERR_LEC_31X | IR_WDI | IR_ELO | IR_BEU | \
-			 IR_BEC | IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | \
-			 IR_RF1L | IR_RF0L)
+#define IR_ERR_BUS_31X      (IR_ERR_LEC_31X | IR_WDI | IR_BEU | IR_BEC | \
+			 IR_TOO | IR_MRAF | IR_TSW | IR_TEFL | IR_RF1L | \
+			 IR_RF0L)
 #define IR_ERR_ALL_31X	(IR_ERR_STATE | IR_ERR_BUS_31X)
 
 /* Interrupt Line Select (ILS) */
@@ -810,8 +810,6 @@ static void m_can_handle_other_err(struct net_device *dev, u32 irqstatus)
 {
 	if (irqstatus & IR_WDI)
 		netdev_err(dev, "Message RAM Watchdog event due to missing READY\n");
-	if (irqstatus & IR_ELO)
-		netdev_err(dev, "Error Logging Overflow\n");
 	if (irqstatus & IR_BEU)
 		netdev_err(dev, "Bit Error Uncorrected\n");
 	if (irqstatus & IR_BEC)
-- 
2.33.0



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

* [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch
       [not found] <20211207102420.120131-1-mkl@pengutronix.de>
                   ` (2 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo() Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate Marc Kleine-Budde
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Vincent Mailhol, stable,
	Matt Kline, Marc Kleine-Budde

From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>

In m_can_read_fifo(), if the second call to m_can_fifo_read() fails,
the function jump to the out_fail label and returns without calling
m_can_receive_skb(). This means that the skb previously allocated by
alloc_can_skb() is not freed. In other terms, this is a memory leak.

This patch adds a goto label to destroy the skb if an error occurs.

Issue was found with GCC -fanalyzer, please follow the link below for
details.

Fixes: e39381770ec9 ("can: m_can: Disable IRQs on FIFO bus errors")
Link: https://lore.kernel.org/all/20211107050755.70655-1-mailhol.vincent@wanadoo.fr
Cc: stable@vger.kernel.org
Cc: Matt Kline <matt@bitbashing.io>
Signed-off-by: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can.c b/drivers/net/can/m_can/m_can.c
index 91be87c4f4d3..e330b4c121bf 100644
--- a/drivers/net/can/m_can/m_can.c
+++ b/drivers/net/can/m_can/m_can.c
@@ -517,7 +517,7 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
 		err = m_can_fifo_read(cdev, fgi, M_CAN_FIFO_DATA,
 				      cf->data, DIV_ROUND_UP(cf->len, 4));
 		if (err)
-			goto out_fail;
+			goto out_free_skb;
 	}
 
 	/* acknowledge rx fifo 0 */
@@ -532,6 +532,8 @@ static int m_can_read_fifo(struct net_device *dev, u32 rxfs)
 
 	return 0;
 
+out_free_skb:
+	kfree_skb(skb);
 out_fail:
 	netdev_err(dev, "FIFO read returned %d\n", err);
 	return err;
-- 
2.33.0



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

* [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo()
       [not found] <20211207102420.120131-1-mkl@pengutronix.de>
                   ` (3 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  2021-12-07 10:24 ` [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate Marc Kleine-Budde
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Matthias Schiffer, stable,
	Matt Kline, Jarkko Nikula, Marc Kleine-Budde

From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>

The same fix that was previously done in m_can_platform in commit
99d173fbe894 ("can: m_can: fix iomap_read_fifo() and iomap_write_fifo()")
is required in m_can_pci as well to make iomap_read_fifo() and
iomap_write_fifo() work for val_count > 1.

Fixes: 812270e5445b ("can: m_can: Batch FIFO writes during CAN transmit")
Fixes: 1aa6772f64b4 ("can: m_can: Batch FIFO reads during CAN receive")
Link: https://lore.kernel.org/all/20211118144011.10921-1-matthias.schiffer@ew.tq-group.com
Cc: stable@vger.kernel.org
Cc: Matt Kline <matt@bitbashing.io>
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Tested-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can_pci.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/net/can/m_can/m_can_pci.c b/drivers/net/can/m_can/m_can_pci.c
index 89cc3d41e952..d72c294ac4d3 100644
--- a/drivers/net/can/m_can/m_can_pci.c
+++ b/drivers/net/can/m_can/m_can_pci.c
@@ -42,8 +42,13 @@ static u32 iomap_read_reg(struct m_can_classdev *cdev, int reg)
 static int iomap_read_fifo(struct m_can_classdev *cdev, int offset, void *val, size_t val_count)
 {
 	struct m_can_pci_priv *priv = cdev_to_priv(cdev);
+	void __iomem *src = priv->base + offset;
 
-	ioread32_rep(priv->base + offset, val, val_count);
+	while (val_count--) {
+		*(unsigned int *)val = ioread32(src);
+		val += 4;
+		src += 4;
+	}
 
 	return 0;
 }
@@ -61,8 +66,13 @@ static int iomap_write_fifo(struct m_can_classdev *cdev, int offset,
 			    const void *val, size_t val_count)
 {
 	struct m_can_pci_priv *priv = cdev_to_priv(cdev);
+	void __iomem *dst = priv->base + offset;
 
-	iowrite32_rep(priv->base + offset, val, val_count);
+	while (val_count--) {
+		iowrite32(*(unsigned int *)val, dst);
+		val += 4;
+		dst += 4;
+	}
 
 	return 0;
 }
-- 
2.33.0



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

* [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate
       [not found] <20211207102420.120131-1-mkl@pengutronix.de>
                   ` (4 preceding siblings ...)
  2021-12-07 10:24 ` [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo() Marc Kleine-Budde
@ 2021-12-07 10:24 ` Marc Kleine-Budde
  5 siblings, 0 replies; 7+ messages in thread
From: Marc Kleine-Budde @ 2021-12-07 10:24 UTC (permalink / raw)
  To: netdev
  Cc: davem, kuba, linux-can, kernel, Matthias Schiffer, stable,
	Jarkko Nikula, Marc Kleine-Budde

From: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>

When testing the CAN controller on our Ekhart Lake hardware, we
determined that all communication was running with twice the configured
bitrate. Changing the reference clock rate from 100MHz to 200MHz fixed
this. Intel's support has confirmed to us that 200MHz is indeed the
correct clock rate.

Fixes: cab7ffc0324f ("can: m_can: add PCI glue driver for Intel Elkhart Lake")
Link: https://lore.kernel.org/all/c9cf3995f45c363e432b3ae8eb1275e54f009fc8.1636967198.git.matthias.schiffer@ew.tq-group.com
Cc: stable@vger.kernel.org
Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com>
Acked-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Reviewed-by: Jarkko Nikula <jarkko.nikula@linux.intel.com>
Signed-off-by: Marc Kleine-Budde <mkl@pengutronix.de>
---
 drivers/net/can/m_can/m_can_pci.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/net/can/m_can/m_can_pci.c b/drivers/net/can/m_can/m_can_pci.c
index d72c294ac4d3..8f184a852a0a 100644
--- a/drivers/net/can/m_can/m_can_pci.c
+++ b/drivers/net/can/m_can/m_can_pci.c
@@ -18,7 +18,7 @@
 
 #define M_CAN_PCI_MMIO_BAR		0
 
-#define M_CAN_CLOCK_FREQ_EHL		100000000
+#define M_CAN_CLOCK_FREQ_EHL		200000000
 #define CTL_CSR_INT_CTL_OFFSET		0x508
 
 struct m_can_pci_priv {
-- 
2.33.0



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

* Re: [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free
  2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
@ 2021-12-07 18:40   ` patchwork-bot+netdevbpf
  0 siblings, 0 replies; 7+ messages in thread
From: patchwork-bot+netdevbpf @ 2021-12-07 18:40 UTC (permalink / raw)
  To: Marc Kleine-Budde
  Cc: netdev, davem, kuba, linux-can, kernel, mailhol.vincent, stable

Hello:

This series was applied to netdev/net.git (master)
by Marc Kleine-Budde <mkl@pengutronix.de>:

On Tue,  7 Dec 2021 11:24:12 +0100 you wrote:
> From: Vincent Mailhol <mailhol.vincent@wanadoo.fr>
> 
> After calling netif_receive_skb(skb), dereferencing skb is unsafe.
> Especially, the can_frame cf which aliases skb memory is dereferenced
> just after the call netif_receive_skb(skb).
> 
> Reordering the lines solves the issue.
> 
> [...]

Here is the summary with links:
  - [net,1/9] can: pch_can: pch_can_rx_normal: fix use after free
    https://git.kernel.org/netdev/net/c/94cddf1e9227
  - [net,2/9] can: sja1000: fix use after free in ems_pcmcia_add_card()
    https://git.kernel.org/netdev/net/c/3ec6ca6b1a8e
  - [net,3/9] can: m_can: Disable and ignore ELO interrupt
    https://git.kernel.org/netdev/net/c/f58ac1adc76b
  - [net,4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch
    https://git.kernel.org/netdev/net/c/31cb32a590d6
  - [net,5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo()
    https://git.kernel.org/netdev/net/c/d737de2d7cc3
  - [net,6/9] can: m_can: pci: fix incorrect reference clock rate
    https://git.kernel.org/netdev/net/c/8c03b8bff765
  - [net,7/9] Revert "can: m_can: remove support for custom bit timing"
    https://git.kernel.org/netdev/net/c/ea768b2ffec6
  - [net,8/9] can: m_can: make custom bittiming fields const
    https://git.kernel.org/netdev/net/c/ea22ba40debe
  - [net,9/9] can: m_can: pci: use custom bit timings for Elkhart Lake
    https://git.kernel.org/netdev/net/c/ea4c1787685d

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



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

end of thread, other threads:[~2021-12-07 18:40 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <20211207102420.120131-1-mkl@pengutronix.de>
2021-12-07 10:24 ` [PATCH net 1/9] can: pch_can: pch_can_rx_normal: fix use after free Marc Kleine-Budde
2021-12-07 18:40   ` patchwork-bot+netdevbpf
2021-12-07 10:24 ` [PATCH net 2/9] can: sja1000: fix use after free in ems_pcmcia_add_card() Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 3/9] can: m_can: Disable and ignore ELO interrupt Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 4/9] can: m_can: m_can_read_fifo: fix memory leak in error branch Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 5/9] can: m_can: pci: fix iomap_read_fifo() and iomap_write_fifo() Marc Kleine-Budde
2021-12-07 10:24 ` [PATCH net 6/9] can: m_can: pci: fix incorrect reference clock rate Marc Kleine-Budde

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