public inbox for netdev@vger.kernel.org
 help / color / mirror / Atom feed
From: Eric Dumazet <eric.dumazet@gmail.com>
To: Lin Ming <mlin@ss.pku.edu.cn>
Cc: Fengguang Wu <fengguang.wu@intel.com>,
	David Miller <davem@davemloft.net>,
	networking <netdev@vger.kernel.org>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: IPv4 BUG: held lock freed!
Date: Sun, 19 Aug 2012 16:45:32 +0200	[thread overview]
Message-ID: <1345387532.5158.222.camel@edumazet-glaptop> (raw)
In-Reply-To: <CAF1ivSaU_ur9BkKG3eAsNw7d+ND5xgYbPKutemVqNec3X9m4SA@mail.gmail.com>

On Sun, 2012-08-19 at 22:15 +0800, Lin Ming wrote:

> Will it still has problem if code goes here without sock_hold(sk)?

Not sure of what you mean.

At the time tcp_write_timer() runs, we own one reference on the socket.
(this reference was taken in sk_reset_timer())

On old kernels, if we found the socket locked by the user, we used to
rearm the timer for a 50ms delay (and thus did sock_hold() again)

Another way to avoid the bug would to make sure sk_reset_timer()
increases refcount _before_ setting the timer, but its adding one atomic
in fast path...

diff --git a/net/core/sock.c b/net/core/sock.c
index 8f67ced..d1745b7 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -2114,8 +2114,9 @@ EXPORT_SYMBOL(sk_send_sigurg);
 void sk_reset_timer(struct sock *sk, struct timer_list* timer,
 		    unsigned long expires)
 {
-	if (!mod_timer(timer, expires))
-		sock_hold(sk);
+	sock_hold(sk);
+	if (mod_timer(timer, expires))
+		__sock_put(sk);
 }
 EXPORT_SYMBOL(sk_reset_timer);
 

  reply	other threads:[~2012-08-19 14:45 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-08-18  2:19 IPv4 BUG: held lock freed! Fengguang Wu
2012-08-19  3:39 ` Fengguang Wu
2012-08-19 12:51 ` Eric Dumazet
2012-08-19 13:04   ` Fengguang Wu
2012-08-19 14:15   ` Lin Ming
2012-08-19 14:45     ` Eric Dumazet [this message]
2012-08-19 15:05       ` Lin Ming
2012-08-19 15:55         ` Eric Dumazet
2012-08-19 16:51   ` Julian Anastasov
2012-08-20 10:22   ` [PATCH] tcp: fix possible socket refcount problem Eric Dumazet
2012-08-21  2:07     ` Fengguang Wu
2012-08-21 21:43     ` David Miller

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=1345387532.5158.222.camel@edumazet-glaptop \
    --to=eric.dumazet@gmail.com \
    --cc=davem@davemloft.net \
    --cc=fengguang.wu@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mlin@ss.pku.edu.cn \
    --cc=netdev@vger.kernel.org \
    /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