From: Chengfeng Ye <dg573847474@gmail.com>
To: davem@davemloft.net, edumazet@google.com, kuba@kernel.org,
pabeni@redhat.com
Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org,
Chengfeng Ye <dg573847474@gmail.com>
Subject: [PATCH] net/802/garp: fix potential deadlock on &app->lock
Date: Tue, 27 Jun 2023 10:52:09 +0000 [thread overview]
Message-ID: <20230627105209.15163-1-dg573847474@gmail.com> (raw)
As &app->lock is also acquired by the timer garp_join_timer() which
which executes under soft-irq context, code executing under process
context should disable irq before acquiring the lock, otherwise
deadlock could happen if the process context hold the lock then
preempt by the interruption.
garp_pdu_rcv() is one such function that acquires &app->lock, but I
am not sure whether it is called with irq disable outside thus the
patch could be false.
Possible deadlock scenario:
garp_pdu_rcv()
-> spin_lock(&app->lock)
<timer interrupt>
-> garp_join_timer()
-> spin_lock(&app->lock)
This flaw was found using an experimental static analysis tool we are
developing for irq-related deadlock.
The tentative patch fix the potential deadlock by spin_lock_irqsave(),
or it should be fixed with spin_lock_bh() if it is a real bug? I am
not very sure.
Signed-off-by: Chengfeng Ye <dg573847474@gmail.com>
---
net/802/garp.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/net/802/garp.c b/net/802/garp.c
index ab24b21fbb49..acc6f2f847a6 100644
--- a/net/802/garp.c
+++ b/net/802/garp.c
@@ -515,6 +515,7 @@ static void garp_pdu_rcv(const struct stp_proto *proto, struct sk_buff *skb,
struct garp_port *port;
struct garp_applicant *app;
const struct garp_pdu_hdr *gp;
+ unsigned long flags;
port = rcu_dereference(dev->garp_port);
if (!port)
@@ -530,14 +531,14 @@ static void garp_pdu_rcv(const struct stp_proto *proto, struct sk_buff *skb,
goto err;
skb_pull(skb, sizeof(*gp));
- spin_lock(&app->lock);
+ spin_lock_irqsave(&app->lock, flags);
while (skb->len > 0) {
if (garp_pdu_parse_msg(app, skb) < 0)
break;
if (garp_pdu_parse_end_mark(skb) < 0)
break;
}
- spin_unlock(&app->lock);
+ spin_unlock_irqrestore(&app->lock, flags);
err:
kfree_skb(skb);
}
--
2.17.1
next reply other threads:[~2023-06-27 10:52 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-27 10:52 Chengfeng Ye [this message]
2023-06-27 13:55 ` Eric Dumazet
2023-06-27 14:36 ` Chengfeng Ye
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=20230627105209.15163-1-dg573847474@gmail.com \
--to=dg573847474@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--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
all inboxes | Powered by JetHome®