From: Pavel Emelyanov <xemul@openvz.org>
To: David Miller <davem@davemloft.net>
Cc: Linux Netdev List <netdev@vger.kernel.org>, devel@openvz.org
Subject: [PATCH 5/8] Move some core sock setup into sk_prot_alloc
Date: Wed, 31 Oct 2007 16:51:51 +0300 [thread overview]
Message-ID: <47288877.10803@openvz.org> (raw)
In-Reply-To: <472885B1.7090103@openvz.org>
The security_sk_alloc() and the module_get is a part of the
object allocations - move it in the proper place.
Note, that since we do not reset the newly allocated sock
in the sk_alloc() (memset() is removed with the previous
patch) we can safely do this.
Also fix the error path in sk_prot_alloc() - release the security
context if needed.
Signed-off-by: Pavel Emelyanov <xemul@openvz.org>
---
diff --git a/net/core/sock.c b/net/core/sock.c
index 21fc79b..e7537e4 100644
--- a/net/core/sock.c
+++ b/net/core/sock.c
@@ -870,7 +870,8 @@ static void sock_copy(struct sock *nsk, const struct sock *osk)
#endif
}
-static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority)
+static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority,
+ int family)
{
struct sock *sk;
struct kmem_cache *slab;
@@ -881,18 +882,40 @@ static struct sock *sk_prot_alloc(struct proto *prot, gfp_t priority)
else
sk = kmalloc(prot->obj_size, priority);
+ if (sk != NULL) {
+ if (security_sk_alloc(sk, family, priority))
+ goto out_free;
+
+ if (!try_module_get(prot->owner))
+ goto out_free_sec;
+ }
+
return sk;
+
+out_free_sec:
+ security_sk_free(sk);
+out_free:
+ if (slab != NULL)
+ kmem_cache_free(slab, sk);
+ else
+ kfree(sk);
+ return NULL;
}
static void sk_prot_free(struct proto *prot, struct sock *sk)
{
struct kmem_cache *slab;
-
+ struct module *owner;
+
+ owner = prot->owner;
slab = prot->slab;
+
+ security_sk_free(sk);
if (slab != NULL)
kmem_cache_free(slab, sk);
else
kfree(sk);
+ module_put(owner);
}
/**
@@ -911,7 +934,7 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
if (zero_it)
priority |= __GFP_ZERO;
- sk = sk_prot_alloc(prot, priority);
+ sk = sk_prot_alloc(prot, priority, family);
if (sk) {
if (zero_it) {
sk->sk_family = family;
@@ -923,24 +946,14 @@ struct sock *sk_alloc(struct net *net, int family, gfp_t priority,
sock_lock_init(sk);
sk->sk_net = get_net(net);
}
-
- if (security_sk_alloc(sk, family, priority))
- goto out_free;
-
- if (!try_module_get(prot->owner))
- goto out_free;
}
- return sk;
-out_free:
- sk_prot_free(prot, sk);
- return NULL;
+ return sk;
}
void sk_free(struct sock *sk)
{
struct sk_filter *filter;
- struct module *owner = sk->sk_prot_creator->owner;
if (sk->sk_destruct)
sk->sk_destruct(sk);
@@ -957,10 +970,8 @@ void sk_free(struct sock *sk)
printk(KERN_DEBUG "%s: optmem leakage (%d bytes) detected.\n",
__FUNCTION__, atomic_read(&sk->sk_omem_alloc));
- security_sk_free(sk);
put_net(sk->sk_net);
sk_prot_free(sk->sk_prot_creator, sk);
- module_put(owner);
}
struct sock *sk_clone(const struct sock *sk, const gfp_t priority)
--
1.5.3.4
next prev parent reply other threads:[~2007-10-31 12:49 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-10-31 13:40 [PATCH 0/8] Cleanup/fix the sk_alloc() call Pavel Emelyanov
2007-10-31 13:15 ` Arnaldo Carvalho de Melo
2007-10-31 14:32 ` Pavel Emelyanov
2007-10-31 14:14 ` Arnaldo Carvalho de Melo
2007-10-31 13:42 ` [PATCH 1/8] Move the sock_copy() from the header Pavel Emelyanov
2007-11-01 7:30 ` David Miller
2007-10-31 13:44 ` [PATCH 2/8] Move the get_net() from sock_copy() Pavel Emelyanov
2007-11-01 7:32 ` David Miller
2007-10-31 13:47 ` [PATCH 3/8] Cleanup the allocation/freeing of the sock object Pavel Emelyanov
2007-11-01 7:34 ` David Miller
2007-10-31 13:48 ` [PATCH 4/8] Auto-zero the allocated " Pavel Emelyanov
2007-11-01 7:35 ` David Miller
2007-10-31 13:51 ` Pavel Emelyanov [this message]
2007-11-01 7:36 ` [PATCH 5/8] Move some core sock setup into sk_prot_alloc David Miller
2007-10-31 13:54 ` [PATCH 6/8] Make the sk_clone() lighter Pavel Emelyanov
2007-11-01 7:26 ` David Miller
2007-11-01 8:46 ` Pavel Emelyanov
2007-11-01 7:38 ` David Miller
2007-10-31 13:56 ` [PATCH 7/8] Remove bogus zero_it argument from sk_alloc Pavel Emelyanov
2007-11-01 7:38 ` David Miller
2007-10-31 13:59 ` [PATCH 8/8] Forget the zero_it argument of sk_alloc() Pavel Emelyanov
2007-11-01 7:41 ` 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=47288877.10803@openvz.org \
--to=xemul@openvz.org \
--cc=davem@davemloft.net \
--cc=devel@openvz.org \
--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;
as well as URLs for NNTP newsgroup(s).