From: Xi Wang <xi.wang@gmail.com>
To: netdev@vger.kernel.org
Cc: "David S. Miller" <davem@davemloft.net>,
Xi Wang <xi.wang@gmail.com>, Eric Dumazet <edumazet@google.com>
Subject: [PATCH] af_unix: fix unix_nr_socks check in unix_create1()
Date: Sat, 25 Aug 2012 02:05:53 -0400 [thread overview]
Message-ID: <1345874753-7214-1-git-send-email-xi.wang@gmail.com> (raw)
This patch complements 518de9b3 ("fs: allow for more than 2^31 files").
get_max_files() returns files_stat.max_files, which can be set to any
value from user space via /proc/sys/fs/file-max. A large file-max will
cause an integer overflow in the following check:
if (atomic_long_read(&unix_nr_socks) > 2 * get_max_files())
goto out;
The kernel will then fail to create a unix domain socket.
Rewrite the check using "/ 2" on the left-hand side.
Signed-off-by: Xi Wang <xi.wang@gmail.com>
Cc: Eric Dumazet <edumazet@google.com>
---
net/unix/af_unix.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
index c5ee4ff..99a8bc9 100644
--- a/net/unix/af_unix.c
+++ b/net/unix/af_unix.c
@@ -630,9 +630,9 @@ static struct sock *unix_create1(struct net *net, struct socket *sock)
{
struct sock *sk = NULL;
struct unix_sock *u;
+ unsigned long nr_socks = atomic_long_inc_return(&unix_nr_socks);
- atomic_long_inc(&unix_nr_socks);
- if (atomic_long_read(&unix_nr_socks) > 2 * get_max_files())
+ if (nr_socks / 2 > get_max_files())
goto out;
sk = sk_alloc(net, PF_UNIX, GFP_KERNEL, &unix_proto);
--
1.7.9.5
next reply other threads:[~2012-08-25 6:06 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-08-25 6:05 Xi Wang [this message]
2012-08-25 6:43 ` [PATCH] af_unix: fix unix_nr_socks check in unix_create1() Eric Dumazet
2012-08-25 16:17 ` Xi Wang
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=1345874753-7214-1-git-send-email-xi.wang@gmail.com \
--to=xi.wang@gmail.com \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--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