<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-stable.git/drivers/net/can, branch v5.4.78</title>
<subtitle>Linux kernel stable tree</subtitle>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/'/>
<entry>
<title>can: flexcan: flexcan_remove(): disable wakeup completely</title>
<updated>2020-11-18T18:20:20+00:00</updated>
<author>
<name>Joakim Zhang</name>
<email>qiangqing.zhang@nxp.com</email>
</author>
<published>2020-10-20T18:45:27+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=66ce8bfad6f65e63cddeba7b358e3227a6776c3b'/>
<id>66ce8bfad6f65e63cddeba7b358e3227a6776c3b</id>
<content type='text'>
[ Upstream commit ab07ff1c92fa60f29438e655a1b4abab860ed0b6 ]

With below sequence, we can see wakeup default is enabled after re-load module,
if it was enabled before, so we need disable wakeup in flexcan_remove().

| # cat /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| disabled
| # echo enabled &gt; /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| # cat /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| enabled
| # rmmod flexcan
| # modprobe flexcan
| # cat /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| enabled

Fixes: de3578c198c6 ("can: flexcan: add self wakeup support")
Fixes: 915f9666421c ("can: flexcan: add support for DT property 'wakeup-source'")
Signed-off-by: Joakim Zhang &lt;qiangqing.zhang@nxp.com&gt;
Link: https://lore.kernel.org/r/20201020184527.8190-1-qiangqing.zhang@nxp.com
[mkl: streamlined commit message]
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit ab07ff1c92fa60f29438e655a1b4abab860ed0b6 ]

With below sequence, we can see wakeup default is enabled after re-load module,
if it was enabled before, so we need disable wakeup in flexcan_remove().

| # cat /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| disabled
| # echo enabled &gt; /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| # cat /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| enabled
| # rmmod flexcan
| # modprobe flexcan
| # cat /sys/bus/platform/drivers/flexcan/5a8e0000.can/power/wakeup
| enabled

Fixes: de3578c198c6 ("can: flexcan: add self wakeup support")
Fixes: 915f9666421c ("can: flexcan: add support for DT property 'wakeup-source'")
Signed-off-by: Joakim Zhang &lt;qiangqing.zhang@nxp.com&gt;
Link: https://lore.kernel.org/r/20201020184527.8190-1-qiangqing.zhang@nxp.com
[mkl: streamlined commit message]
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: flexcan: remove FLEXCAN_QUIRK_DISABLE_MECR quirk for LS1021A</title>
<updated>2020-11-18T18:20:20+00:00</updated>
<author>
<name>Joakim Zhang</name>
<email>qiangqing.zhang@nxp.com</email>
</author>
<published>2020-10-20T15:53:55+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=0b657367309e617be56bcef12ddcd3a5add6b06f'/>
<id>0b657367309e617be56bcef12ddcd3a5add6b06f</id>
<content type='text'>
[ Upstream commit 018799649071a1638c0c130526af36747df4355a ]

After double check with Layerscape CAN owner (Pankaj Bansal), confirm that
LS1021A doesn't support ECC feature, so remove FLEXCAN_QUIRK_DISABLE_MECR
quirk.

Fixes: 99b7668c04b27 ("can: flexcan: adding platform specific details for LS1021A")
Cc: Pankaj Bansal &lt;pankaj.bansal@nxp.com&gt;
Signed-off-by: Joakim Zhang &lt;qiangqing.zhang@nxp.com&gt;
Link: https://lore.kernel.org/r/20201020155402.30318-4-qiangqing.zhang@nxp.com
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 018799649071a1638c0c130526af36747df4355a ]

After double check with Layerscape CAN owner (Pankaj Bansal), confirm that
LS1021A doesn't support ECC feature, so remove FLEXCAN_QUIRK_DISABLE_MECR
quirk.

Fixes: 99b7668c04b27 ("can: flexcan: adding platform specific details for LS1021A")
Cc: Pankaj Bansal &lt;pankaj.bansal@nxp.com&gt;
Signed-off-by: Joakim Zhang &lt;qiangqing.zhang@nxp.com&gt;
Link: https://lore.kernel.org/r/20201020155402.30318-4-qiangqing.zhang@nxp.com
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: peak_canfd: pucan_handle_can_rx(): fix echo management when loopback is on</title>
<updated>2020-11-18T18:20:20+00:00</updated>
<author>
<name>Stephane Grosjean</name>
<email>s.grosjean@peak-system.com</email>
</author>
<published>2020-10-13T15:39:47+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=56c56af0a3a185fcff17d42f8b1f38fdfc3a4d86'/>
<id>56c56af0a3a185fcff17d42f8b1f38fdfc3a4d86</id>
<content type='text'>
[ Upstream commit 93ef65e5a6357cc7381f85fcec9283fe29970045 ]

Echo management is driven by PUCAN_MSG_LOOPED_BACK bit, while loopback
frames are identified with PUCAN_MSG_SELF_RECEIVE bit. Those bits are set
for each outgoing frame written to the IP core so that a copy of each one
will be placed into the rx path. Thus,

- when PUCAN_MSG_LOOPED_BACK is set then the rx frame is an echo of a
  previously sent frame,
- when PUCAN_MSG_LOOPED_BACK+PUCAN_MSG_SELF_RECEIVE are set, then the rx
  frame is an echo AND a loopback frame. Therefore, this frame must be
  put into the socket rx path too.

This patch fixes how CAN frames are handled when these are sent while the
can interface is configured in "loopback on" mode.

Signed-off-by: Stephane Grosjean &lt;s.grosjean@peak-system.com&gt;
Link: https://lore.kernel.org/r/20201013153947.28012-1-s.grosjean@peak-system.com
Fixes: 8ac8321e4a79 ("can: peak: add support for PEAK PCAN-PCIe FD CAN-FD boards")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 93ef65e5a6357cc7381f85fcec9283fe29970045 ]

Echo management is driven by PUCAN_MSG_LOOPED_BACK bit, while loopback
frames are identified with PUCAN_MSG_SELF_RECEIVE bit. Those bits are set
for each outgoing frame written to the IP core so that a copy of each one
will be placed into the rx path. Thus,

- when PUCAN_MSG_LOOPED_BACK is set then the rx frame is an echo of a
  previously sent frame,
- when PUCAN_MSG_LOOPED_BACK+PUCAN_MSG_SELF_RECEIVE are set, then the rx
  frame is an echo AND a loopback frame. Therefore, this frame must be
  put into the socket rx path too.

This patch fixes how CAN frames are handled when these are sent while the
can interface is configured in "loopback on" mode.

Signed-off-by: Stephane Grosjean &lt;s.grosjean@peak-system.com&gt;
Link: https://lore.kernel.org/r/20201013153947.28012-1-s.grosjean@peak-system.com
Fixes: 8ac8321e4a79 ("can: peak: add support for PEAK PCAN-PCIe FD CAN-FD boards")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: peak_usb: peak_usb_get_ts_time(): fix timestamp wrapping</title>
<updated>2020-11-18T18:20:20+00:00</updated>
<author>
<name>Stephane Grosjean</name>
<email>s.grosjean@peak-system.com</email>
</author>
<published>2020-10-14T08:56:31+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=a23ee99566122f407ab0d7d950c689442d0472c6'/>
<id>a23ee99566122f407ab0d7d950c689442d0472c6</id>
<content type='text'>
[ Upstream commit ecc7b4187dd388549544195fb13a11b4ea8e6a84 ]

Fabian Inostroza &lt;fabianinostrozap@gmail.com&gt; has discovered a potential
problem in the hardware timestamp reporting from the PCAN-USB USB CAN interface
(only), related to the fact that a timestamp of an event may precede the
timestamp used for synchronization when both records are part of the same USB
packet. However, this case was used to detect the wrapping of the time counter.

This patch details and fixes the two identified cases where this problem can
occur.

Reported-by: Fabian Inostroza &lt;fabianinostrozap@gmail.com&gt;
Signed-off-by: Stephane Grosjean &lt;s.grosjean@peak-system.com&gt;
Link: https://lore.kernel.org/r/20201014085631.15128-1-s.grosjean@peak-system.com
Fixes: bb4785551f64 ("can: usb: PEAK-System Technik USB adapters driver core")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit ecc7b4187dd388549544195fb13a11b4ea8e6a84 ]

Fabian Inostroza &lt;fabianinostrozap@gmail.com&gt; has discovered a potential
problem in the hardware timestamp reporting from the PCAN-USB USB CAN interface
(only), related to the fact that a timestamp of an event may precede the
timestamp used for synchronization when both records are part of the same USB
packet. However, this case was used to detect the wrapping of the time counter.

This patch details and fixes the two identified cases where this problem can
occur.

Reported-by: Fabian Inostroza &lt;fabianinostrozap@gmail.com&gt;
Signed-off-by: Stephane Grosjean &lt;s.grosjean@peak-system.com&gt;
Link: https://lore.kernel.org/r/20201014085631.15128-1-s.grosjean@peak-system.com
Fixes: bb4785551f64 ("can: usb: PEAK-System Technik USB adapters driver core")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: peak_usb: add range checking in decode operations</title>
<updated>2020-11-18T18:20:19+00:00</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2020-08-13T14:06:04+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=44b2c4beff8aff69c2823296ad99cd38b8c34dc0'/>
<id>44b2c4beff8aff69c2823296ad99cd38b8c34dc0</id>
<content type='text'>
[ Upstream commit a6921dd524fe31d1f460c161d3526a407533b6db ]

These values come from skb-&gt;data so Smatch considers them untrusted.  I
believe Smatch is correct but I don't have a way to test this.

The usb_if-&gt;dev[] array has 2 elements but the index is in the 0-15
range without checks.  The cfd-&gt;len can be up to 255 but the maximum
valid size is CANFD_MAX_DLEN (64) so that could lead to memory
corruption.

Fixes: 0a25e1f4f185 ("can: peak_usb: add support for PEAK new CANFD USB adapters")
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Link: https://lore.kernel.org/r/20200813140604.GA456946@mwanda
Acked-by: Stephane Grosjean &lt;s.grosjean@peak-system.com&gt;
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit a6921dd524fe31d1f460c161d3526a407533b6db ]

These values come from skb-&gt;data so Smatch considers them untrusted.  I
believe Smatch is correct but I don't have a way to test this.

The usb_if-&gt;dev[] array has 2 elements but the index is in the 0-15
range without checks.  The cfd-&gt;len can be up to 255 but the maximum
valid size is CANFD_MAX_DLEN (64) so that could lead to memory
corruption.

Fixes: 0a25e1f4f185 ("can: peak_usb: add support for PEAK new CANFD USB adapters")
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Link: https://lore.kernel.org/r/20200813140604.GA456946@mwanda
Acked-by: Stephane Grosjean &lt;s.grosjean@peak-system.com&gt;
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: xilinx_can: handle failure cases of pm_runtime_get_sync</title>
<updated>2020-11-18T18:20:19+00:00</updated>
<author>
<name>Navid Emamdoost</name>
<email>navid.emamdoost@gmail.com</email>
</author>
<published>2020-06-05T03:32:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=d6c34afab0ed93343726c34a8f6a63718979b0f7'/>
<id>d6c34afab0ed93343726c34a8f6a63718979b0f7</id>
<content type='text'>
[ Upstream commit 79c43333bdd5a7026a5aab606b53053b643585e7 ]

Calling pm_runtime_get_sync increments the counter even in case of
failure, causing incorrect ref count. Call pm_runtime_put if
pm_runtime_get_sync fails.

Signed-off-by: Navid Emamdoost &lt;navid.emamdoost@gmail.com&gt;
Link: https://lore.kernel.org/r/20200605033239.60664-1-navid.emamdoost@gmail.com
Fixes: 4716620d1b62 ("can: xilinx: Convert to runtime_pm")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 79c43333bdd5a7026a5aab606b53053b643585e7 ]

Calling pm_runtime_get_sync increments the counter even in case of
failure, causing incorrect ref count. Call pm_runtime_put if
pm_runtime_get_sync fails.

Signed-off-by: Navid Emamdoost &lt;navid.emamdoost@gmail.com&gt;
Link: https://lore.kernel.org/r/20200605033239.60664-1-navid.emamdoost@gmail.com
Fixes: 4716620d1b62 ("can: xilinx: Convert to runtime_pm")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: ti_hecc: ti_hecc_probe(): add missed clk_disable_unprepare() in error path</title>
<updated>2020-11-18T18:20:19+00:00</updated>
<author>
<name>Zhang Changzhong</name>
<email>zhangchangzhong@huawei.com</email>
</author>
<published>2020-07-17T08:04:39+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=51920ca7519c4f546cd30cc66bb569999c6a2579'/>
<id>51920ca7519c4f546cd30cc66bb569999c6a2579</id>
<content type='text'>
[ Upstream commit e002103b36a695f7cb6048b96da73e66c86ddffb ]

The driver forgets to call clk_disable_unprepare() in error path after
a success calling for clk_prepare_enable().

Fix it by adding a clk_disable_unprepare() in error path.

Signed-off-by: Zhang Changzhong &lt;zhangchangzhong@huawei.com&gt;
Link: https://lore.kernel.org/r/1594973079-27743-1-git-send-email-zhangchangzhong@huawei.com
Fixes: befa60113ce7 ("can: ti_hecc: add missing prepare and unprepare of the clock")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit e002103b36a695f7cb6048b96da73e66c86ddffb ]

The driver forgets to call clk_disable_unprepare() in error path after
a success calling for clk_prepare_enable().

Fix it by adding a clk_disable_unprepare() in error path.

Signed-off-by: Zhang Changzhong &lt;zhangchangzhong@huawei.com&gt;
Link: https://lore.kernel.org/r/1594973079-27743-1-git-send-email-zhangchangzhong@huawei.com
Fixes: befa60113ce7 ("can: ti_hecc: add missing prepare and unprepare of the clock")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: dev: __can_get_echo_skb(): fix real payload length return value for RTR frames</title>
<updated>2020-11-18T18:20:19+00:00</updated>
<author>
<name>Oliver Hartkopp</name>
<email>socketcan@hartkopp.net</email>
</author>
<published>2020-10-20T06:44:43+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=183f1af506fe0317dfda966f5ceb21619d726947'/>
<id>183f1af506fe0317dfda966f5ceb21619d726947</id>
<content type='text'>
[ Upstream commit ed3320cec279407a86bc4c72edc4a39eb49165ec ]

The can_get_echo_skb() function returns the number of received bytes to
be used for netdev statistics. In the case of RTR frames we get a valid
(potential non-zero) data length value which has to be passed for further
operations. But on the wire RTR frames have no payload length. Therefore
the value to be used in the statistics has to be zero for RTR frames.

Reported-by: Vincent Mailhol &lt;mailhol.vincent@wanadoo.fr&gt;
Signed-off-by: Oliver Hartkopp &lt;socketcan@hartkopp.net&gt;
Link: https://lore.kernel.org/r/20201020064443.80164-1-socketcan@hartkopp.net
Fixes: cf5046b309b3 ("can: dev: let can_get_echo_skb() return dlc of CAN frame")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit ed3320cec279407a86bc4c72edc4a39eb49165ec ]

The can_get_echo_skb() function returns the number of received bytes to
be used for netdev statistics. In the case of RTR frames we get a valid
(potential non-zero) data length value which has to be passed for further
operations. But on the wire RTR frames have no payload length. Therefore
the value to be used in the statistics has to be zero for RTR frames.

Reported-by: Vincent Mailhol &lt;mailhol.vincent@wanadoo.fr&gt;
Signed-off-by: Oliver Hartkopp &lt;socketcan@hartkopp.net&gt;
Link: https://lore.kernel.org/r/20201020064443.80164-1-socketcan@hartkopp.net
Fixes: cf5046b309b3 ("can: dev: let can_get_echo_skb() return dlc of CAN frame")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: dev: can_get_echo_skb(): prevent call to kfree_skb() in hard IRQ context</title>
<updated>2020-11-18T18:20:18+00:00</updated>
<author>
<name>Vincent Mailhol</name>
<email>mailhol.vincent@wanadoo.fr</email>
</author>
<published>2020-10-02T15:41:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=ab46748bf98864f9c3f5559060bf8caf9df2b41e'/>
<id>ab46748bf98864f9c3f5559060bf8caf9df2b41e</id>
<content type='text'>
[ Upstream commit 2283f79b22684d2812e5c76fc2280aae00390365 ]

If a driver calls can_get_echo_skb() during a hardware IRQ (which is often, but
not always, the case), the 'WARN_ON(in_irq)' in
net/core/skbuff.c#skb_release_head_state() might be triggered, under network
congestion circumstances, together with the potential risk of a NULL pointer
dereference.

The root cause of this issue is the call to kfree_skb() instead of
dev_kfree_skb_irq() in net/core/dev.c#enqueue_to_backlog().

This patch prevents the skb to be freed within the call to netif_rx() by
incrementing its reference count with skb_get(). The skb is finally freed by
one of the in-irq-context safe functions: dev_consume_skb_any() or
dev_kfree_skb_any(). The "any" version is used because some drivers might call
can_get_echo_skb() in a normal context.

The reason for this issue to occur is that initially, in the core network
stack, loopback skb were not supposed to be received in hardware IRQ context.
The CAN stack is an exeption.

This bug was previously reported back in 2017 in [1] but the proposed patch
never got accepted.

While [1] directly modifies net/core/dev.c, we try to propose here a
smoother modification local to CAN network stack (the assumption
behind is that only CAN devices are affected by this issue).

[1] http://lore.kernel.org/r/57a3ffb6-3309-3ad5-5a34-e93c3fe3614d@cetitec.com

Signed-off-by: Vincent Mailhol &lt;mailhol.vincent@wanadoo.fr&gt;
Link: https://lore.kernel.org/r/20201002154219.4887-2-mailhol.vincent@wanadoo.fr
Fixes: 39549eef3587 ("can: CAN Network device driver and Netlink interface")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 2283f79b22684d2812e5c76fc2280aae00390365 ]

If a driver calls can_get_echo_skb() during a hardware IRQ (which is often, but
not always, the case), the 'WARN_ON(in_irq)' in
net/core/skbuff.c#skb_release_head_state() might be triggered, under network
congestion circumstances, together with the potential risk of a NULL pointer
dereference.

The root cause of this issue is the call to kfree_skb() instead of
dev_kfree_skb_irq() in net/core/dev.c#enqueue_to_backlog().

This patch prevents the skb to be freed within the call to netif_rx() by
incrementing its reference count with skb_get(). The skb is finally freed by
one of the in-irq-context safe functions: dev_consume_skb_any() or
dev_kfree_skb_any(). The "any" version is used because some drivers might call
can_get_echo_skb() in a normal context.

The reason for this issue to occur is that initially, in the core network
stack, loopback skb were not supposed to be received in hardware IRQ context.
The CAN stack is an exeption.

This bug was previously reported back in 2017 in [1] but the proposed patch
never got accepted.

While [1] directly modifies net/core/dev.c, we try to propose here a
smoother modification local to CAN network stack (the assumption
behind is that only CAN devices are affected by this issue).

[1] http://lore.kernel.org/r/57a3ffb6-3309-3ad5-5a34-e93c3fe3614d@cetitec.com

Signed-off-by: Vincent Mailhol &lt;mailhol.vincent@wanadoo.fr&gt;
Link: https://lore.kernel.org/r/20201002154219.4887-2-mailhol.vincent@wanadoo.fr
Fixes: 39549eef3587 ("can: CAN Network device driver and Netlink interface")
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>can: rx-offload: don't call kfree_skb() from IRQ context</title>
<updated>2020-11-18T18:20:18+00:00</updated>
<author>
<name>Marc Kleine-Budde</name>
<email>mkl@pengutronix.de</email>
</author>
<published>2020-06-18T10:47:06+00:00</published>
<link rel='alternate' type='text/html' href='https://git.tavy.me/linux-stable.git/commit/?id=3d095476791840529385f03ef437f183d0ac805e'/>
<id>3d095476791840529385f03ef437f183d0ac805e</id>
<content type='text'>
[ Upstream commit 2ddd6bfe7bdbb6c661835c3ff9cab8e0769940a6 ]

A CAN driver, using the rx-offload infrastructure, is reading CAN frames
(usually in IRQ context) from the hardware and placing it into the rx-offload
queue to be delivered to the networking stack via NAPI.

In case the rx-offload queue is full, trying to add more skbs results in the
skbs being dropped using kfree_skb(). If done from hard-IRQ context this
results in the following warning:

[  682.552693] ------------[ cut here ]------------
[  682.557360] WARNING: CPU: 0 PID: 3057 at net/core/skbuff.c:650 skb_release_head_state+0x74/0x84
[  682.566075] Modules linked in: can_raw can coda_vpu flexcan dw_hdmi_ahb_audio v4l2_jpeg imx_vdoa can_dev
[  682.575597] CPU: 0 PID: 3057 Comm: cansend Tainted: G        W         5.7.0+ #18
[  682.583098] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[  682.589657] [&lt;c0112628&gt;] (unwind_backtrace) from [&lt;c010c1c4&gt;] (show_stack+0x10/0x14)
[  682.597423] [&lt;c010c1c4&gt;] (show_stack) from [&lt;c06c481c&gt;] (dump_stack+0xe0/0x114)
[  682.604759] [&lt;c06c481c&gt;] (dump_stack) from [&lt;c0128f10&gt;] (__warn+0xc0/0x10c)
[  682.611742] [&lt;c0128f10&gt;] (__warn) from [&lt;c0129314&gt;] (warn_slowpath_fmt+0x5c/0xc0)
[  682.619248] [&lt;c0129314&gt;] (warn_slowpath_fmt) from [&lt;c0b95dec&gt;] (skb_release_head_state+0x74/0x84)
[  682.628143] [&lt;c0b95dec&gt;] (skb_release_head_state) from [&lt;c0b95e08&gt;] (skb_release_all+0xc/0x24)
[  682.636774] [&lt;c0b95e08&gt;] (skb_release_all) from [&lt;c0b95eac&gt;] (kfree_skb+0x74/0x1c8)
[  682.644479] [&lt;c0b95eac&gt;] (kfree_skb) from [&lt;bf001d1c&gt;] (can_rx_offload_queue_sorted+0xe0/0xe8 [can_dev])
[  682.654051] [&lt;bf001d1c&gt;] (can_rx_offload_queue_sorted [can_dev]) from [&lt;bf001d6c&gt;] (can_rx_offload_get_echo_skb+0x48/0x94 [can_dev])
[  682.666007] [&lt;bf001d6c&gt;] (can_rx_offload_get_echo_skb [can_dev]) from [&lt;bf01efe4&gt;] (flexcan_irq+0x194/0x5dc [flexcan])
[  682.676734] [&lt;bf01efe4&gt;] (flexcan_irq [flexcan]) from [&lt;c019c1ec&gt;] (__handle_irq_event_percpu+0x4c/0x3ec)
[  682.686322] [&lt;c019c1ec&gt;] (__handle_irq_event_percpu) from [&lt;c019c5b8&gt;] (handle_irq_event_percpu+0x2c/0x88)
[  682.695993] [&lt;c019c5b8&gt;] (handle_irq_event_percpu) from [&lt;c019c64c&gt;] (handle_irq_event+0x38/0x5c)
[  682.704887] [&lt;c019c64c&gt;] (handle_irq_event) from [&lt;c01a1058&gt;] (handle_fasteoi_irq+0xc8/0x180)
[  682.713432] [&lt;c01a1058&gt;] (handle_fasteoi_irq) from [&lt;c019b2c0&gt;] (generic_handle_irq+0x30/0x44)
[  682.722063] [&lt;c019b2c0&gt;] (generic_handle_irq) from [&lt;c019b8f8&gt;] (__handle_domain_irq+0x64/0xdc)
[  682.730783] [&lt;c019b8f8&gt;] (__handle_domain_irq) from [&lt;c06df4a4&gt;] (gic_handle_irq+0x48/0x9c)
[  682.739158] [&lt;c06df4a4&gt;] (gic_handle_irq) from [&lt;c0100b30&gt;] (__irq_svc+0x70/0x98)
[  682.746656] Exception stack(0xe80e9dd8 to 0xe80e9e20)
[  682.751725] 9dc0:                                                       00000001 e80e8000
[  682.759922] 9de0: e820cf80 00000000 ffffe000 00000000 eaf08fe4 00000000 600d0013 00000000
[  682.768117] 9e00: c1732e3c c16093a8 e820d4c0 e80e9e28 c018a57c c018b870 600d0013 ffffffff
[  682.776315] [&lt;c0100b30&gt;] (__irq_svc) from [&lt;c018b870&gt;] (lock_acquire+0x108/0x4e8)
[  682.783821] [&lt;c018b870&gt;] (lock_acquire) from [&lt;c0e938e4&gt;] (down_write+0x48/0xa8)
[  682.791242] [&lt;c0e938e4&gt;] (down_write) from [&lt;c02818dc&gt;] (unlink_file_vma+0x24/0x40)
[  682.798922] [&lt;c02818dc&gt;] (unlink_file_vma) from [&lt;c027a258&gt;] (free_pgtables+0x34/0xb8)
[  682.806858] [&lt;c027a258&gt;] (free_pgtables) from [&lt;c02835a4&gt;] (exit_mmap+0xe4/0x170)
[  682.814361] [&lt;c02835a4&gt;] (exit_mmap) from [&lt;c01248e0&gt;] (mmput+0x5c/0x110)
[  682.821171] [&lt;c01248e0&gt;] (mmput) from [&lt;c012e910&gt;] (do_exit+0x374/0xbe4)
[  682.827892] [&lt;c012e910&gt;] (do_exit) from [&lt;c0130888&gt;] (do_group_exit+0x38/0xb4)
[  682.835132] [&lt;c0130888&gt;] (do_group_exit) from [&lt;c0130914&gt;] (__wake_up_parent+0x0/0x14)
[  682.843063] irq event stamp: 1936
[  682.846399] hardirqs last  enabled at (1935): [&lt;c02938b0&gt;] rmqueue+0xf4/0xc64
[  682.853553] hardirqs last disabled at (1936): [&lt;c0100b20&gt;] __irq_svc+0x60/0x98
[  682.860799] softirqs last  enabled at (1878): [&lt;bf04cdcc&gt;] raw_release+0x108/0x1f0 [can_raw]
[  682.869256] softirqs last disabled at (1876): [&lt;c0b8f478&gt;] release_sock+0x18/0x98
[  682.876753] ---[ end trace 7bca4751ce44c444 ]---

This patch fixes the problem by replacing the kfree_skb() by
dev_kfree_skb_any(), as rx-offload might be called from threaded IRQ handlers
as well.

Fixes: ca913f1ac024 ("can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem leak")
Fixes: 6caf8a6d6586 ("can: rx-offload: can_rx_offload_queue_tail(): fix error handling, avoid skb mem leak")
Link: http://lore.kernel.org/r/20201019190524.1285319-3-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
[ Upstream commit 2ddd6bfe7bdbb6c661835c3ff9cab8e0769940a6 ]

A CAN driver, using the rx-offload infrastructure, is reading CAN frames
(usually in IRQ context) from the hardware and placing it into the rx-offload
queue to be delivered to the networking stack via NAPI.

In case the rx-offload queue is full, trying to add more skbs results in the
skbs being dropped using kfree_skb(). If done from hard-IRQ context this
results in the following warning:

[  682.552693] ------------[ cut here ]------------
[  682.557360] WARNING: CPU: 0 PID: 3057 at net/core/skbuff.c:650 skb_release_head_state+0x74/0x84
[  682.566075] Modules linked in: can_raw can coda_vpu flexcan dw_hdmi_ahb_audio v4l2_jpeg imx_vdoa can_dev
[  682.575597] CPU: 0 PID: 3057 Comm: cansend Tainted: G        W         5.7.0+ #18
[  682.583098] Hardware name: Freescale i.MX6 Quad/DualLite (Device Tree)
[  682.589657] [&lt;c0112628&gt;] (unwind_backtrace) from [&lt;c010c1c4&gt;] (show_stack+0x10/0x14)
[  682.597423] [&lt;c010c1c4&gt;] (show_stack) from [&lt;c06c481c&gt;] (dump_stack+0xe0/0x114)
[  682.604759] [&lt;c06c481c&gt;] (dump_stack) from [&lt;c0128f10&gt;] (__warn+0xc0/0x10c)
[  682.611742] [&lt;c0128f10&gt;] (__warn) from [&lt;c0129314&gt;] (warn_slowpath_fmt+0x5c/0xc0)
[  682.619248] [&lt;c0129314&gt;] (warn_slowpath_fmt) from [&lt;c0b95dec&gt;] (skb_release_head_state+0x74/0x84)
[  682.628143] [&lt;c0b95dec&gt;] (skb_release_head_state) from [&lt;c0b95e08&gt;] (skb_release_all+0xc/0x24)
[  682.636774] [&lt;c0b95e08&gt;] (skb_release_all) from [&lt;c0b95eac&gt;] (kfree_skb+0x74/0x1c8)
[  682.644479] [&lt;c0b95eac&gt;] (kfree_skb) from [&lt;bf001d1c&gt;] (can_rx_offload_queue_sorted+0xe0/0xe8 [can_dev])
[  682.654051] [&lt;bf001d1c&gt;] (can_rx_offload_queue_sorted [can_dev]) from [&lt;bf001d6c&gt;] (can_rx_offload_get_echo_skb+0x48/0x94 [can_dev])
[  682.666007] [&lt;bf001d6c&gt;] (can_rx_offload_get_echo_skb [can_dev]) from [&lt;bf01efe4&gt;] (flexcan_irq+0x194/0x5dc [flexcan])
[  682.676734] [&lt;bf01efe4&gt;] (flexcan_irq [flexcan]) from [&lt;c019c1ec&gt;] (__handle_irq_event_percpu+0x4c/0x3ec)
[  682.686322] [&lt;c019c1ec&gt;] (__handle_irq_event_percpu) from [&lt;c019c5b8&gt;] (handle_irq_event_percpu+0x2c/0x88)
[  682.695993] [&lt;c019c5b8&gt;] (handle_irq_event_percpu) from [&lt;c019c64c&gt;] (handle_irq_event+0x38/0x5c)
[  682.704887] [&lt;c019c64c&gt;] (handle_irq_event) from [&lt;c01a1058&gt;] (handle_fasteoi_irq+0xc8/0x180)
[  682.713432] [&lt;c01a1058&gt;] (handle_fasteoi_irq) from [&lt;c019b2c0&gt;] (generic_handle_irq+0x30/0x44)
[  682.722063] [&lt;c019b2c0&gt;] (generic_handle_irq) from [&lt;c019b8f8&gt;] (__handle_domain_irq+0x64/0xdc)
[  682.730783] [&lt;c019b8f8&gt;] (__handle_domain_irq) from [&lt;c06df4a4&gt;] (gic_handle_irq+0x48/0x9c)
[  682.739158] [&lt;c06df4a4&gt;] (gic_handle_irq) from [&lt;c0100b30&gt;] (__irq_svc+0x70/0x98)
[  682.746656] Exception stack(0xe80e9dd8 to 0xe80e9e20)
[  682.751725] 9dc0:                                                       00000001 e80e8000
[  682.759922] 9de0: e820cf80 00000000 ffffe000 00000000 eaf08fe4 00000000 600d0013 00000000
[  682.768117] 9e00: c1732e3c c16093a8 e820d4c0 e80e9e28 c018a57c c018b870 600d0013 ffffffff
[  682.776315] [&lt;c0100b30&gt;] (__irq_svc) from [&lt;c018b870&gt;] (lock_acquire+0x108/0x4e8)
[  682.783821] [&lt;c018b870&gt;] (lock_acquire) from [&lt;c0e938e4&gt;] (down_write+0x48/0xa8)
[  682.791242] [&lt;c0e938e4&gt;] (down_write) from [&lt;c02818dc&gt;] (unlink_file_vma+0x24/0x40)
[  682.798922] [&lt;c02818dc&gt;] (unlink_file_vma) from [&lt;c027a258&gt;] (free_pgtables+0x34/0xb8)
[  682.806858] [&lt;c027a258&gt;] (free_pgtables) from [&lt;c02835a4&gt;] (exit_mmap+0xe4/0x170)
[  682.814361] [&lt;c02835a4&gt;] (exit_mmap) from [&lt;c01248e0&gt;] (mmput+0x5c/0x110)
[  682.821171] [&lt;c01248e0&gt;] (mmput) from [&lt;c012e910&gt;] (do_exit+0x374/0xbe4)
[  682.827892] [&lt;c012e910&gt;] (do_exit) from [&lt;c0130888&gt;] (do_group_exit+0x38/0xb4)
[  682.835132] [&lt;c0130888&gt;] (do_group_exit) from [&lt;c0130914&gt;] (__wake_up_parent+0x0/0x14)
[  682.843063] irq event stamp: 1936
[  682.846399] hardirqs last  enabled at (1935): [&lt;c02938b0&gt;] rmqueue+0xf4/0xc64
[  682.853553] hardirqs last disabled at (1936): [&lt;c0100b20&gt;] __irq_svc+0x60/0x98
[  682.860799] softirqs last  enabled at (1878): [&lt;bf04cdcc&gt;] raw_release+0x108/0x1f0 [can_raw]
[  682.869256] softirqs last disabled at (1876): [&lt;c0b8f478&gt;] release_sock+0x18/0x98
[  682.876753] ---[ end trace 7bca4751ce44c444 ]---

This patch fixes the problem by replacing the kfree_skb() by
dev_kfree_skb_any(), as rx-offload might be called from threaded IRQ handlers
as well.

Fixes: ca913f1ac024 ("can: rx-offload: can_rx_offload_queue_sorted(): fix error handling, avoid skb mem leak")
Fixes: 6caf8a6d6586 ("can: rx-offload: can_rx_offload_queue_tail(): fix error handling, avoid skb mem leak")
Link: http://lore.kernel.org/r/20201019190524.1285319-3-mkl@pengutronix.de
Signed-off-by: Marc Kleine-Budde &lt;mkl@pengutronix.de&gt;
Signed-off-by: Sasha Levin &lt;sashal@kernel.org&gt;
</pre>
</div>
</content>
</entry>
</feed>
