From: Jarek Poplawski <jarkao2@gmail.com>
To: Vegard Nossum <vegard.nossum@gmail.com>
Cc: "David S. Miller" <davem@davemloft.net>,
=?ISO-8859-2?Q?Martin_MOKR?= =?ISO-8859-2?Q?EJ=A9?=
<mmokrejs@ribosome.natur.cuni.cz>,
netdev@vger.kernel.org
Subject: Re: [PATCH] net: fix setsockopt() locking errors
Date: Mon, 26 Jan 2009 11:50:12 +0000 [thread overview]
Message-ID: <20090126115012.GA5620@ff.dom.local> (raw)
In-Reply-To: <20090124224930.GA4456@localhost.localdomain>
On 24-01-2009 23:49, Vegard Nossum wrote:
> Hi,
>
> This survives basic testing here, but I don't know what that counts for
> when I couldn't reproduce the lockdep report in the first place. Please
> review.
>
>
> Vegard
>
>
> From cc8bcd1c4fd219a31d6d191aefa4b4b57dadb9b0 Mon Sep 17 00:00:00 2001
> From: Vegard Nossum <vegard.nossum@gmail.com>
> Date: Sat, 24 Jan 2009 22:44:16 +0100
> Subject: [PATCH] net: fix setsockopt() locking errors
> MIME-Version: 1.0
> Content-Type: text/plain; charset=utf-8
> Content-Transfer-Encoding: 8bit
>
> Martin MOKREJ. <mmokrejs@ribosome.natur.cuni.cz> reported:
>> =======================================================
>> [ INFO: possible circular locking dependency detected ]
>> 2.6.29-rc2-git1 #1
>> -------------------------------------------------------
>> tcpdump/3734 is trying to acquire lock:
>> (&mm->mmap_sem){----}, at: [<c1053294>] might_fault+0x30/0x6b
>>
>> but task is already holding lock:
>> (sk_lock-AF_PACKET){--..}, at: [<c12798c8>] sock_setsockopt+0x12b/0x4a4
>>
>> which lock already depends on the new lock.
>
> It turns out that sock_setsockopt() is calling copy_from_user() while
> holding the lock on the socket.
I guess it has been like this for some time, so it would be nice to
mention what scenario happens here, or IOW what exactly needs to get
these locks in reverse order.
> We fix it by splitting the ioctl code
> so that one switch handles the ioctls that have their own code for
> reading from userspace, and one switch handles the cases that require
> no additional reading.
>
> Reported-by: Martin MOKREJ. <mmokrejs@ribosome.natur.cuni.cz>
> Signed-off-by: Vegard Nossum <vegard.nossum@gmail.com>
> ---
> net/core/sock.c | 134 +++++++++++++++++++++++++++++++++++-------------------
> 1 files changed, 87 insertions(+), 47 deletions(-)
>
> diff --git a/net/core/sock.c b/net/core/sock.c
> index f3a0d08..6bd618d 100644
> --- a/net/core/sock.c
> +++ b/net/core/sock.c
> @@ -424,6 +424,80 @@ out:
> return ret;
> }
>
> +static int sock_linger(struct sock *sk, char __user *optval, int optlen)
...
> +static int sock_set_rcvtimeo(struct sock *sk, char __user *optval, int optlen)
> +{
> + int ret;
> + long rcvtimeo;
> +
> + ret = sock_set_timeout(&rcvtimeo, optval, optlen);
A check for error is needed here and below.
> +
> + lock_sock(sk);
> + sk->sk_rcvtimeo = rcvtimeo;
> + release_sock(sk);
> +
> + return ret;
> +}
> +
> +static int sock_set_sndtimeo(struct sock *sk, char __user *optval, int optlen)
> +{
> + int ret;
> + long sndtimeo;
> +
> + ret = sock_set_timeout(&sndtimeo, optval, optlen);
> +
> + lock_sock(sk);
> + sk->sk_sndtimeo = sndtimeo;
> + release_sock(sk);
> +
> + return ret;
> +}
...
Jarek P.
next prev parent reply other threads:[~2009-01-26 11:50 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-24 22:49 [PATCH] net: fix setsockopt() locking errors Vegard Nossum
2009-01-26 11:50 ` Jarek Poplawski [this message]
2009-01-26 20:33 ` David Miller
2009-01-27 16:25 ` Vegard Nossum
2009-01-26 21:30 ` Martin MOKREJŠ
2009-01-27 8:45 ` Jarek Poplawski
2009-01-27 8:52 ` Peter Zijlstra
2009-01-27 9:08 ` Jarek Poplawski
2009-01-30 6:12 ` Herbert Xu
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=20090126115012.GA5620@ff.dom.local \
--to=jarkao2@gmail.com \
--cc=davem@davemloft.net \
--cc=mmokrejs@ribosome.natur.cuni.cz \
--cc=netdev@vger.kernel.org \
--cc=vegard.nossum@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.