* [PATCH net v2 1/2] net: lapb: drop lapb_list_lock before waiting for users
[not found] <20261130-lapb-unlock-v2-0-6b2e44e3f69a@qq.com>
@ 2026-11-30 12:14 ` Yu Gao
2026-12-01 13:37 ` Martin Schiller
2026-11-30 12:14 ` [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock Yu Gao
1 sibling, 1 reply; 5+ messages in thread
From: Yu Gao @ 2026-11-30 12:14 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: syzbot+8328573e4d0514392471, Eric Dumazet, Simon Horman,
linux-x25, Paolo Abeni, David S. Miller, Jakub Kicinski,
Andrew Lunn, Hillf Danton, Willem de Bruijn, Xie He,
syzbot+059a2795ad4cff2a2695
lapb_unregister() sleeps in usleep_range() under
write_lock_bh(&lapb_list_lock) while waiting for other users of the
control block, and then takes lapb->lock under that lock, which adds
lapb_list_lock --> &lapb->lock
to the cycle syzbot reports in lapb_connect_request().
Unlink the block and drop lapb_list_lock before waiting. Once the
block is unlinked, nothing can look it up and take a new reference.
Found by code inspection. With this patch alone, the syzbot
reproducers still report a cycle; the next patch removes it.
Fixes: b491e6a7391e ("net: lapb: Add locking to the lapb module")
Suggested-by: Willem de Bruijn <willemb@google.com>
Signed-off-by: Yu Gao <SuperSkidder@qq.com>
---
net/lapb/lapb_iface.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index 670e085..1af36fd 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -179,9 +179,11 @@ int lapb_unregister(struct net_device *dev)
if (!lapb)
goto out;
lapb_put(lapb);
+ __lapb_remove_cb(lapb);
+ write_unlock_bh(&lapb_list_lock);
/* Wait for other refs to "lapb" to drop */
- while (refcount_read(&lapb->refcnt) > 2)
+ while (refcount_read(&lapb->refcnt) > 1)
usleep_range(1, 10);
spin_lock_bh(&lapb->lock);
@@ -197,10 +199,8 @@ int lapb_unregister(struct net_device *dev)
timer_delete_sync(&lapb->t1timer);
timer_delete_sync(&lapb->t2timer);
- __lapb_remove_cb(lapb);
-
lapb_put(lapb);
- rc = LAPB_OK;
+ return LAPB_OK;
out:
write_unlock_bh(&lapb_list_lock);
return rc;
--
Git-157)
^ permalink raw reply related [flat|nested] 5+ messages in thread* [PATCH net v2 2/2] net: lapb: transmit frames outside the protocol lock
[not found] <20261130-lapb-unlock-v2-0-6b2e44e3f69a@qq.com>
2026-11-30 12:14 ` [PATCH net v2 1/2] net: lapb: drop lapb_list_lock before waiting for users Yu Gao
@ 2026-11-30 12:14 ` Yu Gao
2026-12-01 12:57 ` netdev-bot+sashiko
1 sibling, 1 reply; 5+ messages in thread
From: Yu Gao @ 2026-11-30 12:14 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: syzbot+8328573e4d0514392471, Eric Dumazet, Simon Horman,
linux-x25, Paolo Abeni, David S. Miller, Jakub Kicinski,
Andrew Lunn, Hillf Danton, Willem de Bruijn, Xie He,
syzbot+059a2795ad4cff2a2695
LAPB calls the data_transmit() callback with lapb->lock held. lapbeth
passes the frame to dev_queue_xmit(), and if the underlying device is
a tunnel routed back through a lapbeth device, the frame re-enters
lapbeth_xmit() and LAPB under the TX lock and up_lock. syzbot reports:
lapb_list_lock --> &lapb->lock --> _xmit_X25#2
lapb_list_lock --> _xmit_X25#2 --> &lapbeth->up_lock
Queue frames on a per-instance FIFO under lapb->lock and pass them to
the driver after the lock is dropped. One caller drains the FIFO at a
time, which keeps the frames in order.
hdlc_x25 sends the frames right after the lock is dropped. lapbeth
calls into LAPB with its TX lock and up_lock held, so it sets the new
schedule_tx() callback and sends them from its NAPI poll instead.
Each frame records the TX recursion level at which it was queued, and
that level is restored around data_transmit(), so a looped frame still
counts against XMIT_RECURSION_LIMIT.
On NETDEV_GOING_DOWN, LAPB flushes the queued frames, including the
final DISC, and waits for a running sender before ndo_stop. Frames
produced after that are dropped.
With both patches, the syzbot reproducers and tunnel loops through one
or two lapbeth devices no longer report lock cycles. hdlc_x25 was only
build-tested.
Fixes: b491e6a7391e ("net: lapb: Add locking to the lapb module")
Suggested-by: Willem de Bruijn <willemb@google.com>
Reported-by: syzbot+059a2795ad4cff2a2695@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=059a2795ad4cff2a2695
Reported-by: syzbot+8328573e4d0514392471@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?extid=8328573e4d0514392471
Signed-off-by: Yu Gao <SuperSkidder@qq.com>
---
drivers/net/wan/lapbether.c | 10 +++++
include/linux/lapb.h | 3 ++
include/net/lapb.h | 6 +++
net/lapb/lapb_iface.c | 94 +++++++++++++++++++++++++++++++++++++++------
net/lapb/lapb_timer.c | 4 +-
5 files changed, 103 insertions(+), 14 deletions(-)
diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index c3630a8..698d1ae 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -93,6 +93,8 @@ static int lapbeth_napi_poll(struct napi_struct *napi, int budget)
struct sk_buff *skb;
int processed = 0;
+ lapb_transmit_pending(lapbeth->axdev);
+
for (; processed < budget; ++processed) {
skb = skb_dequeue(&lapbeth->rx_queue);
if (!skb)
@@ -306,6 +308,13 @@ static int lapbeth_set_mac_address(struct net_device *dev, void *addr)
return 0;
}
+static void lapbeth_schedule_tx(struct net_device *dev)
+{
+ struct lapbethdev *lapbeth = netdev_priv(dev);
+
+ napi_schedule(&lapbeth->napi);
+}
+
static const struct lapb_register_struct lapbeth_callbacks = {
.connect_confirmation = lapbeth_connected,
.connect_indication = lapbeth_connected,
@@ -313,6 +322,7 @@ static const struct lapb_register_struct lapbeth_callbacks = {
.disconnect_indication = lapbeth_disconnected,
.data_indication = lapbeth_data_indication,
.data_transmit = lapbeth_data_transmit,
+ .schedule_tx = lapbeth_schedule_tx,
};
/* open/close a device
diff --git a/include/linux/lapb.h b/include/linux/lapb.h
index b5333f9..06e050d 100644
--- a/include/linux/lapb.h
+++ b/include/linux/lapb.h
@@ -36,6 +36,8 @@ struct lapb_register_struct {
void (*disconnect_indication)(struct net_device *dev, int reason);
int (*data_indication)(struct net_device *dev, struct sk_buff *skb);
void (*data_transmit)(struct net_device *dev, struct sk_buff *skb);
+ /* If set, schedule lapb_transmit_pending() outside the device TX lock. */
+ void (*schedule_tx)(struct net_device *dev);
};
struct lapb_parms_struct {
@@ -57,6 +59,7 @@ extern int lapb_getparms(struct net_device *dev, struct lapb_parms_struct *parms
extern int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms);
extern int lapb_connect_request(struct net_device *dev);
extern int lapb_disconnect_request(struct net_device *dev);
+void lapb_transmit_pending(struct net_device *dev);
extern int lapb_data_request(struct net_device *dev, struct sk_buff *skb);
extern int lapb_data_received(struct net_device *dev, struct sk_buff *skb);
diff --git a/include/net/lapb.h b/include/net/lapb.h
index 6c07420..08cb5ae 100644
--- a/include/net/lapb.h
+++ b/include/net/lapb.h
@@ -3,6 +3,7 @@
#define _LAPB_H
#include <linux/lapb.h>
#include <linux/refcount.h>
+#include <linux/wait.h>
#define LAPB_HEADER_LEN MAX_HEADER /* LAPB over Ethernet + a bit more */
@@ -97,6 +98,10 @@ struct lapb_cb {
/* Internal control information */
struct sk_buff_head write_queue;
struct sk_buff_head ack_queue;
+ struct sk_buff_head tx_queue;
+ wait_queue_head_t tx_wait;
+ bool tx_running;
+ bool tx_stopped;
unsigned char window;
const struct lapb_register_struct *callbacks;
@@ -109,6 +114,7 @@ struct lapb_cb {
};
/* lapb_iface.c */
+void lapb_tx_unlock(struct lapb_cb *lapb);
void lapb_connect_confirmation(struct lapb_cb *lapb, int);
void lapb_connect_indication(struct lapb_cb *lapb, int);
void lapb_disconnect_confirmation(struct lapb_cb *lapb, int);
diff --git a/net/lapb/lapb_iface.c b/net/lapb/lapb_iface.c
index 1af36fd..7f17200 100644
--- a/net/lapb/lapb_iface.c
+++ b/net/lapb/lapb_iface.c
@@ -117,6 +117,8 @@ static struct lapb_cb *lapb_create_cb(void)
skb_queue_head_init(&lapb->write_queue);
skb_queue_head_init(&lapb->ack_queue);
+ __skb_queue_head_init(&lapb->tx_queue);
+ init_waitqueue_head(&lapb->tx_wait);
timer_setup(&lapb->t1timer, NULL, 0);
timer_setup(&lapb->t2timer, NULL, 0);
@@ -199,6 +201,7 @@ int lapb_unregister(struct net_device *dev)
timer_delete_sync(&lapb->t1timer);
timer_delete_sync(&lapb->t2timer);
+ __skb_queue_purge(&lapb->tx_queue);
lapb_put(lapb);
return LAPB_OK;
out:
@@ -282,6 +285,61 @@ int lapb_setparms(struct net_device *dev, struct lapb_parms_struct *parms)
}
EXPORT_SYMBOL(lapb_setparms);
+/* Preserve the TX nesting level if another caller sends the frame. */
+#define LAPB_TX_DEPTH(skb) ((skb)->cb[0])
+
+/* One caller drains the FIFO. Other producers leave their frames to it. */
+static void lapb_xmit_queued(struct lapb_cb *lapb)
+{
+ struct sk_buff *skb;
+
+ lockdep_assert_held(&lapb->lock);
+ if (lapb->tx_running)
+ return;
+
+ WRITE_ONCE(lapb->tx_running, true);
+ while ((skb = __skb_dequeue(&lapb->tx_queue))) {
+ int depth = LAPB_TX_DEPTH(skb) - dev_recursion_level();
+ int i;
+
+ spin_unlock(&lapb->lock);
+ for (i = 0; i < depth; i++)
+ dev_xmit_recursion_inc();
+ lapb->callbacks->data_transmit(lapb->dev, skb);
+ for (i = 0; i < depth; i++)
+ dev_xmit_recursion_dec();
+ spin_lock(&lapb->lock);
+ }
+ WRITE_ONCE(lapb->tx_running, false);
+ if (lapb->tx_stopped)
+ wake_up_all(&lapb->tx_wait);
+}
+
+void lapb_transmit_pending(struct net_device *dev)
+{
+ struct lapb_cb *lapb = lapb_devtostruct(dev);
+
+ if (!lapb)
+ return;
+ spin_lock_bh(&lapb->lock);
+ lapb_xmit_queued(lapb);
+ spin_unlock_bh(&lapb->lock);
+ lapb_put(lapb);
+}
+EXPORT_SYMBOL(lapb_transmit_pending);
+
+void lapb_tx_unlock(struct lapb_cb *lapb)
+ __releases(&lapb->lock)
+{
+ if (!skb_queue_empty(&lapb->tx_queue)) {
+ if (lapb->callbacks->schedule_tx)
+ lapb->callbacks->schedule_tx(lapb->dev);
+ else
+ lapb_xmit_queued(lapb);
+ }
+ spin_unlock_bh(&lapb->lock);
+}
+
int lapb_connect_request(struct net_device *dev)
{
struct lapb_cb *lapb = lapb_devtostruct(dev);
@@ -307,7 +365,7 @@ int lapb_connect_request(struct net_device *dev)
rc = LAPB_OK;
out_put:
- spin_unlock_bh(&lapb->lock);
+ lapb_tx_unlock(lapb);
lapb_put(lapb);
out:
return rc;
@@ -357,7 +415,7 @@ int lapb_disconnect_request(struct net_device *dev)
rc = __lapb_disconnect_request(lapb);
- spin_unlock_bh(&lapb->lock);
+ lapb_tx_unlock(lapb);
lapb_put(lapb);
out:
return rc;
@@ -378,11 +436,12 @@ int lapb_data_request(struct net_device *dev, struct sk_buff *skb)
if (lapb->state != LAPB_STATE_3 && lapb->state != LAPB_STATE_4)
goto out_put;
+ LAPB_TX_DEPTH(skb) = dev_recursion_level();
skb_queue_tail(&lapb->write_queue, skb);
lapb_kick(lapb);
rc = LAPB_OK;
out_put:
- spin_unlock_bh(&lapb->lock);
+ lapb_tx_unlock(lapb);
lapb_put(lapb);
out:
return rc;
@@ -397,7 +456,7 @@ int lapb_data_received(struct net_device *dev, struct sk_buff *skb)
if (lapb) {
spin_lock_bh(&lapb->lock);
lapb_data_input(lapb, skb);
- spin_unlock_bh(&lapb->lock);
+ lapb_tx_unlock(lapb);
lapb_put(lapb);
rc = LAPB_OK;
}
@@ -441,14 +500,13 @@ int lapb_data_indication(struct lapb_cb *lapb, struct sk_buff *skb)
int lapb_data_transmit(struct lapb_cb *lapb, struct sk_buff *skb)
{
- int used = 0;
-
- if (lapb->callbacks->data_transmit) {
- lapb->callbacks->data_transmit(lapb->dev, skb);
- used = 1;
- }
+ lockdep_assert_held(&lapb->lock);
+ if (lapb->tx_stopped || !lapb->callbacks->data_transmit)
+ return 0;
- return used;
+ LAPB_TX_DEPTH(skb) = max_t(int, LAPB_TX_DEPTH(skb), dev_recursion_level());
+ __skb_queue_tail(&lapb->tx_queue, skb);
+ return 1;
}
/* Handle device status changes. */
@@ -457,6 +515,7 @@ static int lapb_device_event(struct notifier_block *this, unsigned long event,
{
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct lapb_cb *lapb;
+ bool quiesce = false;
if (!net_eq(dev_net(dev), &init_net))
return NOTIFY_DONE;
@@ -490,6 +549,11 @@ static int lapb_device_event(struct notifier_block *this, unsigned long event,
case NETDEV_GOING_DOWN:
if (netif_carrier_ok(dev))
__lapb_disconnect_request(lapb);
+ /* Hand the final frames to the driver before it closes.
+ * ndo_stop unregisters this block, so this is not undone.
+ */
+ lapb->tx_stopped = true;
+ quiesce = true;
break;
case NETDEV_DOWN:
lapb_dbg(0, "(%p) Interface down: %s\n", dev, dev->name);
@@ -524,7 +588,13 @@ static int lapb_device_event(struct notifier_block *this, unsigned long event,
break;
}
- spin_unlock_bh(&lapb->lock);
+ if (quiesce) {
+ lapb_xmit_queued(lapb);
+ spin_unlock_bh(&lapb->lock);
+ wait_event(lapb->tx_wait, !READ_ONCE(lapb->tx_running));
+ } else {
+ lapb_tx_unlock(lapb);
+ }
lapb_put(lapb);
return NOTIFY_DONE;
}
diff --git a/net/lapb/lapb_timer.c b/net/lapb/lapb_timer.c
index 9fde6cf..6acfdd7 100644
--- a/net/lapb/lapb_timer.c
+++ b/net/lapb/lapb_timer.c
@@ -89,7 +89,7 @@ static void lapb_t2timer_expiry(struct timer_list *t)
lapb->t2timer_running = false;
out:
- spin_unlock_bh(&lapb->lock);
+ lapb_tx_unlock(lapb);
}
static void lapb_t1timer_expiry(struct timer_list *t)
@@ -202,5 +202,5 @@ static void lapb_t1timer_expiry(struct timer_list *t)
lapb_start_t1timer(lapb);
out:
- spin_unlock_bh(&lapb->lock);
+ lapb_tx_unlock(lapb);
}
--
Git-157)
^ permalink raw reply related [flat|nested] 5+ messages in thread