* [PATCH net] net: hdlc_ppp: Fix issues when mod_timer is called while timer is running
@ 2020-12-28 0:14 Xie He
0 siblings, 0 replies; only message in thread
From: Xie He @ 2020-12-28 0:14 UTC (permalink / raw)
To: David S. Miller, Jakub Kicinski, netdev, linux-kernel, Krzysztof Halasa
Cc: Xie He
ppp_cp_event is called directly or indirectly by ppp_rx with "ppp->lock"
held. It may call mod_timer to add a new timer. However, at the same time
ppp_timer may be already running and waiting for "ppp->lock". In this
case, there's no need for ppp_timer to continue running and it can just
exit.
If we let ppp_timer continue running, it may call add_timer. This causes
kernel panic because add_timer can't be called with a timer pending.
This patch fixes this problem.
Cc: Krzysztof Halasa <khc@pm.waw.pl>
Signed-off-by: Xie He <xie.he.0141@gmail.com>
---
drivers/net/wan/hdlc_ppp.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/wan/hdlc_ppp.c b/drivers/net/wan/hdlc_ppp.c
index 64f855651336..261b53fc8e04 100644
--- a/drivers/net/wan/hdlc_ppp.c
+++ b/drivers/net/wan/hdlc_ppp.c
@@ -569,6 +569,13 @@ static void ppp_timer(struct timer_list *t)
unsigned long flags;
spin_lock_irqsave(&ppp->lock, flags);
+ /* mod_timer could be called after we entered this function but
+ * before we got the lock.
+ */
+ if (timer_pending(&proto->timer)) {
+ spin_unlock_irqrestore(&ppp->lock, flags);
+ return;
+ }
switch (proto->state) {
case STOPPING:
case REQ_SENT:
--
2.27.0
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2020-12-28 0:15 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-28 0:14 [PATCH net] net: hdlc_ppp: Fix issues when mod_timer is called while timer is running Xie He
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®