* [PATCH net 1/2] net: lapbether: don't hold up_lock while calling into LAPB
[not found] <20261125045909.77644-1-SuperSkidder@qq.com>
@ 2026-11-25 4:59 ` Yu Gao
2026-11-25 9:27 ` Martin Schiller
2026-11-25 4:59 ` [PATCH net 2/2] net: lapbether: use lockless TX Yu Gao
1 sibling, 1 reply; 4+ messages in thread
From: Yu Gao @ 2026-11-25 4:59 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: linux-x25, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Xie He, Hillf Danton,
syzbot+059a2795ad4cff2a2695, syzbot+8328573e4d0514392471, Yu Gao
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)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH net 2/2] net: lapbether: use lockless TX
[not found] <20261125045909.77644-1-SuperSkidder@qq.com>
2026-11-25 4:59 ` [PATCH net 1/2] net: lapbether: don't hold up_lock while calling into LAPB Yu Gao
@ 2026-11-25 4:59 ` Yu Gao
2026-11-25 9:28 ` Martin Schiller
1 sibling, 1 reply; 4+ messages in thread
From: Yu Gao @ 2026-11-25 4:59 UTC (permalink / raw)
To: Martin Schiller, netdev
Cc: linux-x25, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Xie He, Hillf Danton,
syzbot+059a2795ad4cff2a2695, syzbot+8328573e4d0514392471, Yu Gao
The core calls lapbeth_xmit() with the TX lock of the lapbeth device
held, and lapbeth_xmit() calls 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 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
is passed to dev_queue_xmit() on that device, which takes its TX lock
under lapb->lock. With up_lock gone, the syzbot reproducer for a
possible deadlock in lapb_connect_request() still reports this cycle:
lapb_list_lock --> &lapb->lock --> _xmit_X25#2
lapbeth_xmit() does not need the TX lock. Data frames are handed to
LAPB, which serializes each device with lapb->lock, and connect and
disconnect notifications are queued on the locked rx_queue. Set lltx
so that the core does not take the TX lock around lapbeth_xmit().
Without the TX lock, the core no longer detects a frame that loops
back into the same lapbeth device on the TX path. If such a frame
reaches LAPB, it now deadlocks on lapb->lock, as it already does when
LAPB sends it from a timer or from the receive path. Only frames that
start with 0x00, 0x01 or 0x02 reach LAPB, so a frame looped back
through IPv4 or IPv6 routing is simply dropped.
Fixes: b491e6a7391e ("net: lapb: Add locking to the lapb module")
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 | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/drivers/net/wan/lapbether.c b/drivers/net/wan/lapbether.c
index b4dde9b..c7496c7 100644
--- a/drivers/net/wan/lapbether.c
+++ b/drivers/net/wan/lapbether.c
@@ -364,6 +364,11 @@ static void lapbeth_setup(struct net_device *dev)
dev->hard_header_len = 0;
dev->mtu = 1000;
dev->addr_len = 0;
+ /* LAPB serializes transmission under its own lock and may transmit
+ * through another lapbeth device while holding it, so the TX lock
+ * must not be taken around lapbeth_xmit().
+ */
+ dev->lltx = true;
}
/* Setup a new device.
--
2.54.0 (Apple Git-157)
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net 1/2] net: lapbether: don't hold up_lock while calling into LAPB
2026-11-25 4:59 ` [PATCH net 1/2] net: lapbether: don't hold up_lock while calling into LAPB Yu Gao
@ 2026-11-25 9:27 ` Martin Schiller
0 siblings, 0 replies; 4+ messages in thread
From: Martin Schiller @ 2026-11-25 9:27 UTC (permalink / raw)
To: Yu Gao
Cc: netdev, linux-x25, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Xie He, Hillf Danton,
syzbot+059a2795ad4cff2a2695, syzbot+8328573e4d0514392471
The cover letter and the patches are not threaded together: the mail
server seems to have replaced the Message-IDs, so both patches point
to a cover letter ID that doesn't exist. My ack on the cover letter
therefore doesn't reach the patches, so here it is per patch.
Acked-by: Martin Schiller <ms@dev.tdt.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net 2/2] net: lapbether: use lockless TX
2026-11-25 4:59 ` [PATCH net 2/2] net: lapbether: use lockless TX Yu Gao
@ 2026-11-25 9:28 ` Martin Schiller
0 siblings, 0 replies; 4+ messages in thread
From: Martin Schiller @ 2026-11-25 9:28 UTC (permalink / raw)
To: Yu Gao
Cc: netdev, linux-x25, Andrew Lunn, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Xie He, Hillf Danton,
syzbot+059a2795ad4cff2a2695, syzbot+8328573e4d0514392471
Acked-by: Martin Schiller <ms@dev.tdt.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2026-11-25 9:28 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <20261125045909.77644-1-SuperSkidder@qq.com>
2026-11-25 4:59 ` [PATCH net 1/2] net: lapbether: don't hold up_lock while calling into LAPB Yu Gao
2026-11-25 9:27 ` 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox