Netdev List
 help / color / mirror / Atom feed
From: Yu Gao <SuperSkidder@qq.com>
To: Martin Schiller <ms@dev.tdt.de>, netdev@vger.kernel.org
Cc: linux-x25@vger.kernel.org, Andrew Lunn <andrew+netdev@lunn.ch>,
	"David S . Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@kernel.org>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>,
	Xie He <xie.he.0141@gmail.com>, Hillf Danton <hdanton@sina.com>,
	syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com,
	syzbot+8328573e4d0514392471@syzkaller.appspotmail.com,
	Yu Gao <SuperSkidder@qq.com>
Subject: [PATCH net 1/2] net: lapbether: don't hold up_lock while calling into LAPB
Date: Wed, 25 Nov 2026 12:59:08 +0800	[thread overview]
Message-ID: <tencent_81EE31BA79E5206415DCD8EE76690A171D08@qq.com> (raw)
In-Reply-To: <20261125045909.77644-1-SuperSkidder@qq.com>

lapbeth_xmit() and lapbeth_rcv() hold up_lock while they call into
LAPB, which looks up the device under lapb_list_lock.
lapb_unregister() takes lapb->lock with lapb_list_lock held for
writing, and LAPB transmits frames through lapbeth_data_transmit() with
lapb->lock held. When the Ethernet device under a lapbeth device is a
tunnel whose packets are routed through a lapbeth device, such a frame
reaches lapbeth_xmit() again, under the TX lock of that device and
with its up_lock taken. syzbot reports the resulting cycle as a
possible deadlock in lapb_data_received():

  lapb_list_lock --> _xmit_X25#2 --> &lapbeth->up_lock

up_lock only makes sure that lapbeth_xmit() and lapbeth_rcv() see the
device as up and finish their LAPB calls before lapbeth_close() calls
lapb_unregister(). The same can be had without holding a lock across
the LAPB calls. Both functions run inside an RCU read-side critical
section: lapbeth_rcv() takes rcu_read_lock() and ndo_start_xmit is
called with BH disabled. So clear "up" in lapbeth_close() and wait for
them with synchronize_net() before calling lapb_unregister(), and drop
up_lock.

This also keeps lapbeth_rcv() from deadlocking on up_lock when a frame
that LAPB sends in reply is routed back into the same lapbeth device.

The core still takes the TX lock around lapbeth_xmit(), so a cycle
through _xmit_X25 remains. The next patch removes it.

Fixes: 5acd0cfbfbb5 ("net: lapbether: Prevent racing when checking whether the netif is running")
Reported-by: syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=059a2795ad4cff2a2695
Signed-off-by: Yu Gao <SuperSkidder@qq.com>
---
 drivers/net/wan/lapbether.c | 37 +++++++++++++------------------------
 1 file changed, 13 insertions(+), 24 deletions(-)

diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index c3630a8..b4dde9b 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -53,8 +53,7 @@ struct lapbethdev {
 	struct list_head	node;
 	struct net_device	*ethdev;	/* link to ethernet device */
 	struct net_device	*axdev;		/* lapbeth device (lapb#) */
-	bool			up;
-	spinlock_t		up_lock;	/* Protects "up" */
+	bool			up;		/* See lapbeth_close() */
 	struct sk_buff_head	rx_queue;
 	struct napi_struct	napi;
 };
@@ -126,11 +125,8 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev,
 
 	rcu_read_lock();
 	lapbeth = lapbeth_get_x25_dev(dev);
-	if (!lapbeth)
+	if (!lapbeth || !READ_ONCE(lapbeth->up))
 		goto drop_unlock_rcu;
-	spin_lock_bh(&lapbeth->up_lock);
-	if (!lapbeth->up)
-		goto drop_unlock;
 
 	len = skb->data[0] + skb->data[1] * 256;
 	dev->stats.rx_packets++;
@@ -142,15 +138,10 @@ static int lapbeth_rcv(struct sk_buff *skb, struct net_device *dev,
 	err = lapb_data_received(lapbeth->axdev, skb);
 	if (err != LAPB_OK) {
 		printk(KERN_DEBUG "lapbether: lapb_data_received err - %d\n", err);
-		goto drop_unlock;
+		goto drop_unlock_rcu;
 	}
-out:
-	spin_unlock_bh(&lapbeth->up_lock);
 	rcu_read_unlock();
 	return 0;
-drop_unlock:
-	kfree_skb(skb);
-	goto out;
 drop_unlock_rcu:
 	rcu_read_unlock();
 drop:
@@ -188,8 +179,7 @@ static netdev_tx_t lapbeth_xmit(struct sk_buff *skb,
 	struct lapbethdev *lapbeth = netdev_priv(dev);
 	int err;
 
-	spin_lock_bh(&lapbeth->up_lock);
-	if (!lapbeth->up)
+	if (!READ_ONCE(lapbeth->up))
 		goto drop;
 
 	/* There should be a pseudo header of 1 byte added by upper layers.
@@ -226,12 +216,10 @@ static netdev_tx_t lapbeth_xmit(struct sk_buff *skb,
 		pr_err("lapb_data_request error - %d\n", err);
 		goto drop;
 	}
-out:
-	spin_unlock_bh(&lapbeth->up_lock);
 	return NETDEV_TX_OK;
 drop:
 	kfree_skb(skb);
-	goto out;
+	return NETDEV_TX_OK;
 }
 
 static void lapbeth_data_transmit(struct net_device *ndev, struct sk_buff *skb)
@@ -331,9 +319,7 @@ static int lapbeth_open(struct net_device *dev)
 		return -ENODEV;
 	}
 
-	spin_lock_bh(&lapbeth->up_lock);
-	lapbeth->up = true;
-	spin_unlock_bh(&lapbeth->up_lock);
+	WRITE_ONCE(lapbeth->up, true);
 
 	return 0;
 }
@@ -343,9 +329,13 @@ static int lapbeth_close(struct net_device *dev)
 	struct lapbethdev *lapbeth = netdev_priv(dev);
 	int err;
 
-	spin_lock_bh(&lapbeth->up_lock);
-	lapbeth->up = false;
-	spin_unlock_bh(&lapbeth->up_lock);
+	/* lapbeth_xmit() and lapbeth_rcv() only call into LAPB after seeing
+	 * "up" set, from within an RCU read-side critical section. Wait for
+	 * them to finish so that none of these calls races with
+	 * lapb_unregister().
+	 */
+	WRITE_ONCE(lapbeth->up, false);
+	synchronize_net();
 
 	err = lapb_unregister(dev);
 	if (err != LAPB_OK)
@@ -411,7 +401,6 @@ static int lapbeth_new_device(struct net_device *dev)
 	lapbeth->ethdev = dev;
 
 	lapbeth->up = false;
-	spin_lock_init(&lapbeth->up_lock);
 
 	skb_queue_head_init(&lapbeth->rx_queue);
 	netif_napi_add_weight(ndev, &lapbeth->napi, lapbeth_napi_poll, 16);
-- 
2.54.0 (Apple Git-157)


       reply	other threads:[~2026-11-25  4:59 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20261125045909.77644-1-SuperSkidder@qq.com>
2026-11-25  4:59 ` Yu Gao [this message]
2026-11-25  9:27   ` [PATCH net 1/2] net: lapbether: don't hold up_lock while calling into LAPB Martin Schiller
2026-11-25  4:59 ` [PATCH net 2/2] net: lapbether: use lockless TX Yu Gao
2026-11-25  9:28   ` Martin Schiller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=tencent_81EE31BA79E5206415DCD8EE76690A171D08@qq.com \
    --to=superskidder@qq.com \
    --cc=andrew+netdev@lunn.ch \
    --cc=davem@davemloft.net \
    --cc=edumazet@kernel.org \
    --cc=hdanton@sina.com \
    --cc=kuba@kernel.org \
    --cc=linux-x25@vger.kernel.org \
    --cc=ms@dev.tdt.de \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com \
    --cc=syzbot+8328573e4d0514392471@syzkaller.appspotmail.com \
    --cc=xie.he.0141@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox