diff mbox series

[net] net: ethernet: mtk_wed: fix possible NULL pointer dereference in mtk_wed_wo_queue_tx_clean()

Message ID 3c1262464d215faa8acebfc08869798c81c96f4a.1702827359.git.lorenzo@kernel.org (mailing list archive)
State Accepted
Commit 7cb8cd4daacfea646cf8b5925ca2c66c98b18480
Delegated to: Netdev Maintainers
Headers show
Series [net] net: ethernet: mtk_wed: fix possible NULL pointer dereference in mtk_wed_wo_queue_tx_clean() | expand

Checks

Context Check Description
netdev/series_format success Single patches do not need cover letters
netdev/tree_selection success Clearly marked for net
netdev/ynl success SINGLE THREAD; Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag present in non-next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 1115 this patch: 1115
netdev/cc_maintainers fail 1 blamed authors not CCed: sujuan.chen@mediatek.com; 5 maintainers not CCed: linux-mediatek@lists.infradead.org matthias.bgg@gmail.com linux-arm-kernel@lists.infradead.org angelogioacchino.delregno@collabora.com sujuan.chen@mediatek.com
netdev/build_clang success Errors and warnings before: 1142 this patch: 1142
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1142 this patch: 1142
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 9 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Lorenzo Bianconi Dec. 17, 2023, 3:37 p.m. UTC
In order to avoid a NULL pointer dereference, check entry->buf pointer before running
skb_free_frag in mtk_wed_wo_queue_tx_clean routine.

Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support")
Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
---
 drivers/net/ethernet/mediatek/mtk_wed_wo.c | 3 +++
 1 file changed, 3 insertions(+)

Comments

Simon Horman Dec. 18, 2023, 5:55 p.m. UTC | #1
On Sun, Dec 17, 2023 at 04:37:40PM +0100, Lorenzo Bianconi wrote:
> In order to avoid a NULL pointer dereference, check entry->buf pointer before running
> skb_free_frag in mtk_wed_wo_queue_tx_clean routine.
> 
> Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>

Hi Lorenzo,

can I clarify that this can actually happen?
What I am getting at, is that if not, it might be net-next material.
In either case, I have no objection to the change itself.

Reviewed-by: Simon Horman <horms@kernel.org>
Lorenzo Bianconi Dec. 18, 2023, 9:16 p.m. UTC | #2
> On Sun, Dec 17, 2023 at 04:37:40PM +0100, Lorenzo Bianconi wrote:
> > In order to avoid a NULL pointer dereference, check entry->buf pointer before running
> > skb_free_frag in mtk_wed_wo_queue_tx_clean routine.
> > 
> > Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support")
> > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> 
> Hi Lorenzo,

Hi Simon,

> 
> can I clarify that this can actually happen?

I was able to trigger the crash on a real device (Banana Pi BPI-R4) but
with a wrong swiotlb configuration. I do not have a strong opinion, I am
fine to target net-next instead. What do you prefer?

Regards,
Lorenzo

> What I am getting at, is that if not, it might be net-next material.
> In either case, I have no objection to the change itself.
> 
> Reviewed-by: Simon Horman <horms@kernel.org>
Simon Horman Dec. 19, 2023, 10:52 a.m. UTC | #3
On Mon, Dec 18, 2023 at 10:16:11PM +0100, Lorenzo Bianconi wrote:
> > On Sun, Dec 17, 2023 at 04:37:40PM +0100, Lorenzo Bianconi wrote:
> > > In order to avoid a NULL pointer dereference, check entry->buf pointer before running
> > > skb_free_frag in mtk_wed_wo_queue_tx_clean routine.
> > > 
> > > Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support")
> > > Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> > 
> > Hi Lorenzo,
> 
> Hi Simon,
> 
> > 
> > can I clarify that this can actually happen?
> 
> I was able to trigger the crash on a real device (Banana Pi BPI-R4) but
> with a wrong swiotlb configuration. I do not have a strong opinion, I am
> fine to target net-next instead. What do you prefer?

I also don't have a strong opinion here.
But lean towards 'net' if you were able to trigger a crash.

> 
> Regards,
> Lorenzo
> 
> > What I am getting at, is that if not, it might be net-next material.
> > In either case, I have no objection to the change itself.
> > 
> > Reviewed-by: Simon Horman <horms@kernel.org>
patchwork-bot+netdevbpf@kernel.org Dec. 21, 2023, 7:40 a.m. UTC | #4
Hello:

This patch was applied to netdev/net.git (main)
by Paolo Abeni <pabeni@redhat.com>:

On Sun, 17 Dec 2023 16:37:40 +0100 you wrote:
> In order to avoid a NULL pointer dereference, check entry->buf pointer before running
> skb_free_frag in mtk_wed_wo_queue_tx_clean routine.
> 
> Fixes: 799684448e3e ("net: ethernet: mtk_wed: introduce wed wo support")
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
> ---
>  drivers/net/ethernet/mediatek/mtk_wed_wo.c | 3 +++
>  1 file changed, 3 insertions(+)

Here is the summary with links:
  - [net] net: ethernet: mtk_wed: fix possible NULL pointer dereference in mtk_wed_wo_queue_tx_clean()
    https://git.kernel.org/netdev/net/c/7cb8cd4daacf

You are awesome, thank you!
diff mbox series

Patch

diff --git a/drivers/net/ethernet/mediatek/mtk_wed_wo.c b/drivers/net/ethernet/mediatek/mtk_wed_wo.c
index 3bd51a3d6650..ae44ad5f8ce8 100644
--- a/drivers/net/ethernet/mediatek/mtk_wed_wo.c
+++ b/drivers/net/ethernet/mediatek/mtk_wed_wo.c
@@ -291,6 +291,9 @@  mtk_wed_wo_queue_tx_clean(struct mtk_wed_wo *wo, struct mtk_wed_wo_queue *q)
 	for (i = 0; i < q->n_desc; i++) {
 		struct mtk_wed_wo_queue_entry *entry = &q->entry[i];
 
+		if (!entry->buf)
+			continue;
+
 		dma_unmap_single(wo->hw->dev, entry->addr, entry->len,
 				 DMA_TO_DEVICE);
 		skb_free_frag(entry->buf);