From: Rainer Weikusat <rweikusat@mobileactivedefense.com>
To: Ben Hutchings <ben@decadent.org.uk>
Cc: Rainer Weikusat <rweikusat@mobileactivedefense.com>,
Philipp Hahn <pmhahn@pmhahn.de>,
Hannes Frederic Sowa <hannes@stressinduktion.org>,
Sasha Levin <sasha.levin@oracle.com>,
"David S. Miller" <davem@davemloft.net>,
linux-kernel@vger.kernel.org, Karolin Seeger <kseeger@samba.org>,
Jason Baron <jbaron@akamai.com>,
Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Arvid Requate <requate@univention.de>,
Stefan Gohmann <gohmann@univention.de>
Subject: Re: Bug 4.1.16: self-detected stall in net/unix/?
Date: Thu, 11 Feb 2016 18:31:04 +0000 [thread overview]
Message-ID: <87egcjcd5j.fsf@doppelsaurus.mobileactivedefense.com> (raw)
In-Reply-To: <87r3gjjgbu.fsf@doppelsaurus.mobileactivedefense.com> (Rainer Weikusat's message of "Thu, 11 Feb 2016 17:40:37 +0000")
Rainer Weikusat <rw@doppelsaurus.mobileactivedefense.com> writes:
> Ben Hutchings <ben@decadent.org.uk> writes:
[...]
>> unix: Fix potential double-unlock in unix_dgram_sendmsg()
>>
>> A datagram socket may be peered with itself, so that sk == other. We
>> use unix_state_double_lock() to lock sk and other in the right order,
>> which also guards against this and only locks the socket once, but we
>> then end up trying to unlock it twice. Add the check for sk != other.
[...]
> other was found via
>
> if (!other) {
> err = -ECONNRESET;
> if (sunaddr == NULL)
> goto out_free;
>
> other = unix_find_other(net, sunaddr, namelen, sk->sk_type,
> hash, &err);
> if (other == NULL)
> goto out_free;
> }
>
> and the if-block leading to the double lock should never have been
> executed as it's supposed to deal with the case where sk is connect to
> other but other not to sk (eg, /dev/log).
Test program triggering a double unlock (w/o the MSG_DONTWAIT, it blocks
which it isn't supposed to do):
--------
#include <stdio.h>
#include <sys/socket.h>
#include <sys/un.h>
#include <unistd.h>
#define SUN_NAME "\0other-is-me"
int main(int argc, char **argv)
{
struct sockaddr_un sun;
unsigned max;
int sk, rc;
sk = socket(AF_UNIX, SOCK_DGRAM, 0);
sun.sun_family = AF_UNIX;
strncpy(sun.sun_path, SUN_NAME, sizeof(sun.sun_path));
bind(sk, (struct sockaddr *)&sun, sizeof(sun));
max = 12;
do
sendto(sk, &sun, sizeof(sun), MSG_DONTWAIT,
(struct sockaddr *)&sun, sizeof(sun));
while (--max);
return 0;
}
next prev parent reply other threads:[~2016-02-11 18:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-02-02 16:25 Bug 4.1.16: self-detected stall in net/unix/? Philipp Hahn
2016-02-03 1:43 ` Hannes Frederic Sowa
2016-02-05 15:28 ` Philipp Hahn
2016-02-11 13:47 ` Philipp Hahn
2016-02-11 15:55 ` Rainer Weikusat
2016-02-11 17:03 ` Ben Hutchings
2016-02-11 17:40 ` Rainer Weikusat
2016-02-11 17:54 ` Rainer Weikusat
2016-02-11 18:31 ` Rainer Weikusat [this message]
2016-02-11 19:37 ` [PATCH net] af_unix: Guard against other == sk in unix_dgram_sendmsg Rainer Weikusat
2016-02-12 9:19 ` Philipp Hahn
2016-02-12 13:25 ` Rainer Weikusat
2016-02-12 19:54 ` Ben Hutchings
2016-02-12 20:17 ` Rainer Weikusat
2016-02-12 20:47 ` Ben Hutchings
2016-02-12 20:59 ` Rainer Weikusat
2016-02-16 17:54 ` 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=87egcjcd5j.fsf@doppelsaurus.mobileactivedefense.com \
--to=rweikusat@mobileactivedefense.com \
--cc=ben@decadent.org.uk \
--cc=davem@davemloft.net \
--cc=gohmann@univention.de \
--cc=gregkh@linuxfoundation.org \
--cc=hannes@stressinduktion.org \
--cc=jbaron@akamai.com \
--cc=kseeger@samba.org \
--cc=linux-kernel@vger.kernel.org \
--cc=pmhahn@pmhahn.de \
--cc=requate@univention.de \
--cc=sasha.levin@oracle.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;
as well as URLs for NNTP newsgroup(s).