Skip to content

Commit f97f647

Browse files
LGA1150gregkh
authored andcommitted
ppp: fix race conditions in ppp_fill_forward_path
[ Upstream commit 0417adf ] ppp_fill_forward_path() has two race conditions: 1. The ppp->channels list can change between list_empty() and list_first_entry(), as ppp_lock() is not held. If the only channel is deleted in ppp_disconnect_channel(), list_first_entry() may access an empty head or a freed entry, and trigger a panic. 2. pch->chan can be NULL. When ppp_unregister_channel() is called, pch->chan is set to NULL before pch is removed from ppp->channels. Fix these by using a lockless RCU approach: - Use list_first_or_null_rcu() to safely test and access the first list entry. - Convert list modifications on ppp->channels to their RCU variants and add synchronize_net() after removal. - Check for a NULL pch->chan before dereferencing it. Fixes: f6efc67 ("net: ppp: resolve forwarding path for bridge pppoe devices") Signed-off-by: Qingfang Deng <dqfext@gmail.com> Link: https://patch.msgid.link/20250814012559.3705-2-dqfext@gmail.com Signed-off-by: Paolo Abeni <pabeni@redhat.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent d5cdb78 commit f97f647

File tree

1 file changed

+11
-6
lines changed

1 file changed

+11
-6
lines changed

drivers/net/ppp/ppp_generic.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include <linux/ppp_channel.h>
3434
#include <linux/ppp-comp.h>
3535
#include <linux/skbuff.h>
36+
#include <linux/rculist.h>
3637
#include <linux/rtnetlink.h>
3738
#include <linux/if_arp.h>
3839
#include <linux/ip.h>
@@ -1612,11 +1613,14 @@ static int ppp_fill_forward_path(struct net_device_path_ctx *ctx,
16121613
if (ppp->flags & SC_MULTILINK)
16131614
return -EOPNOTSUPP;
16141615

1615-
if (list_empty(&ppp->channels))
1616+
pch = list_first_or_null_rcu(&ppp->channels, struct channel, clist);
1617+
if (!pch)
1618+
return -ENODEV;
1619+
1620+
chan = READ_ONCE(pch->chan);
1621+
if (!chan)
16161622
return -ENODEV;
16171623

1618-
pch = list_first_entry(&ppp->channels, struct channel, clist);
1619-
chan = pch->chan;
16201624
if (!chan->ops->fill_forward_path)
16211625
return -EOPNOTSUPP;
16221626

@@ -2999,7 +3003,7 @@ ppp_unregister_channel(struct ppp_channel *chan)
29993003
*/
30003004
down_write(&pch->chan_sem);
30013005
spin_lock_bh(&pch->downl);
3002-
pch->chan = NULL;
3006+
WRITE_ONCE(pch->chan, NULL);
30033007
spin_unlock_bh(&pch->downl);
30043008
up_write(&pch->chan_sem);
30053009
ppp_disconnect_channel(pch);
@@ -3509,7 +3513,7 @@ ppp_connect_channel(struct channel *pch, int unit)
35093513
hdrlen = pch->file.hdrlen + 2; /* for protocol bytes */
35103514
if (hdrlen > ppp->dev->hard_header_len)
35113515
ppp->dev->hard_header_len = hdrlen;
3512-
list_add_tail(&pch->clist, &ppp->channels);
3516+
list_add_tail_rcu(&pch->clist, &ppp->channels);
35133517
++ppp->n_channels;
35143518
pch->ppp = ppp;
35153519
refcount_inc(&ppp->file.refcnt);
@@ -3539,10 +3543,11 @@ ppp_disconnect_channel(struct channel *pch)
35393543
if (ppp) {
35403544
/* remove it from the ppp unit's list */
35413545
ppp_lock(ppp);
3542-
list_del(&pch->clist);
3546+
list_del_rcu(&pch->clist);
35433547
if (--ppp->n_channels == 0)
35443548
wake_up_interruptible(&ppp->file.rwait);
35453549
ppp_unlock(ppp);
3550+
synchronize_net();
35463551
if (refcount_dec_and_test(&ppp->file.refcnt))
35473552
ppp_destroy_interface(ppp);
35483553
err = 0;

0 commit comments

Comments
 (0)