From: Chengyu Liu <lui2012qwq@gmail.com>
To: netdev@vger.kernel.org
Cc: pabeni@redhat.com, horms@kernel.org, khc@pm.waw.pl,
Chengyu Liu <lui2012qwq@gmail.com>
Subject: [PATCH net-next v3 2/2] hdlc_fr: shut down the LMI timer in fr_destroy()
Date: Tue, 3 Nov 2026 22:20:15 +0800 [thread overview]
Message-ID: <20261103142015.1588144-3-lui2012qwq@gmail.com> (raw)
In-Reply-To: <20261103142015.1588144-1-lui2012qwq@gmail.com>
fr_start() arms state(hdlc)->timer when LMI is enabled
(settings.lmi != LMI_NONE). The only deletion lives in fr_stop(), which
is unreachable on the protocol-detach path: detach_hdlc_protocol() calls
only ->detach() (never ->stop()) and then kfree()s hdlc->state. FR's
->detach, fr_destroy(), tears down the PVC list but never touches the
timer, so unregistering an up FR device with LMI enabled leaves the timer
armed on top of freed memory; fr_timer() then fires into the dead
frad_state.
Shut the timer down at the top of fr_destroy(). Use
timer_shutdown_sync() so the timer cannot be re-armed afterwards,
matching the CVE-2026-63803 ppp fix (ppp_timer_release()).
Initialize the timer in fr_ioctl() when the protocol is attached and
drop the timer_setup() from fr_start(): attach_hdlc_protocol() uses
kmalloc() (not kzalloc), so state(hdlc)->timer is uninitialized garbage
until the first timer_setup() and fr_destroy() must never run
timer_shutdown_sync() on it.
This bug was found by static analysis and confirmed with a KASAN
reproducer: slab-use-after-free in the timer softirq after rmmod of an
up Frame Relay HDLC device with LMI enabled.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Signed-off-by: Chengyu Liu <lui2012qwq@gmail.com>
Reviewed-by: Simon Horman <horms@kernel.org>
---
v2: retarget to net-next and drop Cc: stable per maintainer guidance;
no code change. v1: https://lore.kernel.org/netdev/
drivers/net/wan/hdlc_fr.c | 5 ++++-
1 file changed, 4 insertions(+), 1 deletion(-)
diff --git a/drivers/net/wan/hdlc_fr.c b/drivers/net/wan/hdlc_fr.c
index 5f0e54ed1e..2086ff85b5 100644
--- a/drivers/net/wan/hdlc_fr.c
+++ b/drivers/net/wan/hdlc_fr.c
@@ -1009,7 +1009,6 @@ static void fr_start(struct net_device *dev)
state(hdlc)->txseq = state(hdlc)->rxseq = 0;
state(hdlc)->dev = dev;
- timer_setup(&state(hdlc)->timer, fr_timer, 0);
/* First poll after 1 s */
state(hdlc)->timer.expires = jiffies + HZ;
add_timer(&state(hdlc)->timer);
@@ -1153,6 +1152,9 @@ static void fr_destroy(struct net_device *frad)
hdlc_device *hdlc = dev_to_hdlc(frad);
struct pvc_device *pvc = state(hdlc)->first_pvc;
+ /* The LMI timer must not outlive the state being torn down. */
+ timer_shutdown_sync(&state(hdlc)->timer);
+
state(hdlc)->first_pvc = NULL; /* All PVCs destroyed */
state(hdlc)->dce_pvc_count = 0;
state(hdlc)->dce_changed = 1;
@@ -1242,6 +1244,7 @@ static int fr_ioctl(struct net_device *dev, struct if_settings *ifs)
return result;
state(hdlc)->first_pvc = NULL;
state(hdlc)->dce_pvc_count = 0;
+ timer_setup(&state(hdlc)->timer, fr_timer, 0);
}
memcpy(&state(hdlc)->settings, &new_settings, size);
dev->type = ARPHRD_FRAD;
--
2.25.1
prev parent reply other threads:[~2026-11-03 14:20 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-03 14:20 [PATCH net-next v3 0/2] hdlc_cisco/hdlc_fr: shut down protocol timers on ->detach Chengyu Liu
2026-11-03 14:20 ` [PATCH net-next v3 1/2] hdlc_cisco: shut down the keepalive timer " Chengyu Liu
2026-11-03 14:20 ` Chengyu Liu [this message]
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=20261103142015.1588144-3-lui2012qwq@gmail.com \
--to=lui2012qwq@gmail.com \
--cc=horms@kernel.org \
--cc=khc@pm.waw.pl \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.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