]> git.karo-electronics.de Git - karo-tx-linux.git/commit
UNIX: Do not loop forever at unix_autobind().
authorTetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Sat, 4 Sep 2010 01:34:28 +0000 (01:34 +0000)
committerPaul Gortmaker <paul.gortmaker@windriver.com>
Thu, 6 Jan 2011 23:07:57 +0000 (18:07 -0500)
commit8e5b50661d8370fb7623bffb80a46396fe219d78
treecf05861b39bc9da5787fa233d821cd67149708b6
parent184dca11229af57c28619707615ba29ce1bd0111
UNIX: Do not loop forever at unix_autobind().

commit 8df73ff90f00f14d2c7ff7156f7ef153f7e9d3b7 upstream.

We assumed that unix_autobind() never fails if kzalloc() succeeded.
But unix_autobind() allows only 1048576 names. If /proc/sys/fs/file-max is
larger than 1048576 (e.g. systems with more than 10GB of RAM), a local user can
consume all names using fork()/socket()/bind().

If all names are in use, those who call bind() with addr_len == sizeof(short)
or connect()/sendmsg() with setsockopt(SO_PASSCRED) will continue

  while (1)
        yield();

loop at unix_autobind() till a name becomes available.
This patch adds a loop counter in order to give up after 1048576 attempts.

Calling yield() for once per 256 attempts may not be sufficient when many names
are already in use, for __unix_find_socket_byname() can take long time under
such circumstance. Therefore, this patch also adds cond_resched() call.

Note that currently a local user can consume 2GB of kernel memory if the user
is allowed to create and autobind 1048576 UNIX domain sockets. We should
consider adding some restriction for autobind operation.

Signed-off-by: Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Paul Gortmaker <paul.gortmaker@windriver.com>
net/unix/af_unix.c