Skip to contentSkip to conversation

net: wwan: t7xx: check skb_clone in control TX

PATCH Superseded Ruoyu Wang 2 participants 2 messages Jun 7 – Jun 8

Subsystems (4)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Ruoyu Wang

author
#0 lore raw

PATCH 1/1 net: wwan: t7xx: check skb_clone in control TX

t7xx_port_ctrl_tx() clones each skb fragment before passing it to the port transmit path. The clone is used immediately to set cloned->len, so an skb_clone() failure results in a NULL pointer dereference.

Check the clone before using it. If previous fragments were already queued, preserve the driver's existing partial-write behavior by returning the number of bytes submitted so far. Keep the existing byte accounting unchanged so this patch only handles the allocation failure.

---
 drivers/net/wwan/t7xx/t7xx_port_wwan.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wwan/t7xx/t7xx_port_wwan.c +2 -0
index 7fc569565..d2529df75 100644
@@ -106,6 +106,8 @@ static int t7xx_port_ctrl_tx(struct t7xx_port *port, struct sk_buff *skb)
 
 	while (cur) {
 		cloned = skb_clone(cur, GFP_KERNEL);
+		if (!cloned)
+			return cnt ? cnt : -ENOMEM;
 		cloned->len = skb_headlen(cur);
 		ret = t7xx_port_send_skb(port, cloned, 0, 0);
 		if (ret) {
Signature · 1 line
2.51.0
maintainer
#1 lore raw
Quoted 10 lines · Ruoyu Wang

t7xx_port_ctrl_tx() clones each skb fragment before passing it to the port transmit path. The clone is used immediately to set cloned->len, so an skb_clone() failure results in a NULL pointer dereference.

Check the clone before using it. If previous fragments were already queued, preserve the driver's existing partial-write behavior by returning the number of bytes submitted so far. Keep the existing byte accounting unchanged so this patch only handles the allocation failure.

Looks like it deserves a 'Fixes' tag.
https://www.kernel.org/doc/html/latest/process/submitting-patches.html

Quoted 10 lines
---
 drivers/net/wwan/t7xx/t7xx_port_wwan.c | 2 ++
 1 file changed, 2 insertions(+)
drivers/net/wwan/t7xx/t7xx_port_wwan.c +0 -0
index 7fc569565..d2529df75 100644

drivers/net/wwan/t7xx/t7xx_port_wwan.c static int t7xx_port_ctrl_tx(struct t7xx_port *port, struct sk_buff *skb) · line 110

Quoted 5 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c +2 -0
@@ -106,6 +106,8 @@ static int t7xx_port_ctrl_tx(struct t7xx_port *port, struct sk_buff *skb)
 
        while (cur) {
                cloned = skb_clone(cur, GFP_KERNEL);
+               if (!cloned)
+                       return cnt ? cnt : -ENOMEM;

This feels a bit inconsistent as the return value depends on where the clone fails in the loop.
Wouldn’t it be clearer to either return 0 (indicating no submission) or unconditionally return -ENOMEM on failure?

Quoted 6 lines
drivers/net/wwan/t7xx/t7xx_port_wwan.c +0 -1
                cloned->len = skb_headlen(cur);
                ret = t7xx_port_send_skb(port, cloned, 0, 0);
                if (ret) {
--

2.51.0