From: Patrick McHardy <kaber@trash.net>
To: Johannes Berg <johannes@sipsolutions.net>
Cc: hadi@cyberus.ca, Zhang Rui <rui.zhang@intel.com>,
netdev@vger.kernel.org,
"linux-acpi@vger" <linux-acpi@vger.kernel.org>,
lenb@kernel.org, Thomas Graf <tgraf@suug.ch>
Subject: Re: [PATCH] netlink: allocate group bitmaps dynamically
Date: Tue, 03 Jul 2007 14:05:57 +0200 [thread overview]
Message-ID: <468A3BA5.9050909@trash.net> (raw)
In-Reply-To: <1183457329.3841.0.camel@johannes.berg>
Johannes Berg wrote:
> Allow changing the number of groups for a netlink family
> after it has been created.
>
> Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
>
> ---
> include/linux/netlink.h | 1
> net/netlink/af_netlink.c | 61 +++++++++++++++++++++++++++++++++++------------
> 2 files changed, 47 insertions(+), 15 deletions(-)
>
> --- wireless-dev.orig/net/netlink/af_netlink.c 2007-07-03 00:10:31.617889695 +0200
> +++ wireless-dev/net/netlink/af_netlink.c 2007-07-03 00:31:30.267889695 +0200
> @@ -316,8 +316,11 @@ netlink_update_listeners(struct sock *sk
>
> for (i = 0; i < NLGRPSZ(tbl->groups)/sizeof(unsigned long); i++) {
> mask = 0;
> - sk_for_each_bound(sk, node, &tbl->mc_list)
> - mask |= nlk_sk(sk)->groups[i];
> + sk_for_each_bound(sk, node, &tbl->mc_list) {
> + if (nlk_sk(sk)->ngroups >=
> + (i + 1) * sizeof(unsigned long))
This condition implies that a socket can bind to a non-existant
group, which shouldn't be possible.
> + mask |= nlk_sk(sk)->groups[i];
> + }
> tbl->listeners[i] = mask;
> }
> /* this function is only called with the netlink table "grabbed", which
> @@ -555,10 +558,11 @@ netlink_update_subscriptions(struct sock
> nlk->subscriptions = subscriptions;
> }
>
> -static int netlink_alloc_groups(struct sock *sk)
> +static int netlink_realloc_groups(struct sock *sk)
> {
> struct netlink_sock *nlk = nlk_sk(sk);
> unsigned int groups;
> + unsigned long *new_groups;
> int err = 0;
>
> netlink_lock_table();
> @@ -570,9 +574,15 @@ static int netlink_alloc_groups(struct s
> if (err)
> return err;
>
> - nlk->groups = kzalloc(NLGRPSZ(groups), GFP_KERNEL);
> - if (nlk->groups == NULL)
> + if (nlk->ngroups >= groups)
> + return 0;
> +
> + new_groups = krealloc(nlk->groups, NLGRPSZ(groups), GFP_KERNEL);
> + if (new_groups == NULL)
> return -ENOMEM;
> + memset((char*)new_groups + NLGRPSZ(nlk->ngroups), 0,
> + NLGRPSZ(groups) - NLGRPSZ(nlk->ngroups));
> + nlk->groups = new_groups;
This should probably happen with the table grabbed to avoid races
with concurrent broadcasts.
> @@ -1332,6 +1338,31 @@ out_sock_release:
> return NULL;
> }
>
> +int netlink_change_ngroups(int unit, unsigned int groups)
> +{
> + unsigned long *listeners;
> + int err = 0;
> +
> + netlink_table_grab();
Unfortunately that doesn't prevent races with netlink_has_listeners
since its lockless (and should really stay that way).
> + if (NLGRPSZ(nl_table[unit].groups) < NLGRPSZ(groups)) {
> + listeners = krealloc(nl_table[unit].listeners,
> + NLGRPSZ(groups), GFP_KERNEL);
> + if (!listeners) {
> + err = -ENOMEM;
> + goto out_ungrab;
> + }
> + memset((char*) listeners + NLGRPSZ(nl_table[unit].groups),
> + 0, NLGRPSZ(groups) - NLGRPSZ(nl_table[unit].groups));
> + nl_table[unit].listeners = listeners;
> + }
> + nl_table[unit].groups = groups;
> +
> + out_ungrab:
> + netlink_table_ungrab();
> + return err;
> +}
> +EXPORT_SYMBOL(netlink_change_ngroups);
> +
> void netlink_set_nonroot(int protocol, unsigned int flags)
> {
> if ((unsigned int)protocol < MAX_LINKS)
> --- wireless-dev.orig/include/linux/netlink.h 2007-07-03 00:09:13.047889695 +0200
> +++ wireless-dev/include/linux/netlink.h 2007-07-03 00:31:30.267889695 +0200
> @@ -161,6 +161,7 @@ extern struct sock *netlink_kernel_creat
> void (*input)(struct sock *sk, int len),
> struct mutex *cb_mutex,
> struct module *module);
> +extern int netlink_change_ngroups(int unit, unsigned int groups);
> extern void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err);
> extern int netlink_has_listeners(struct sock *sk, unsigned int group);
> extern int netlink_unicast(struct sock *ssk, struct sk_buff *skb, __u32 pid, int nonblock);
>
>
next prev parent reply other threads:[~2007-07-03 12:06 UTC|newest]
Thread overview: 71+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-05-22 9:47 [PATCH] [-mm] ACPI: export ACPI events via netlink Zhang Rui
2007-05-22 10:05 ` Samuel Ortiz
2007-05-22 10:10 ` Evgeniy Polyakov
2007-05-22 11:03 ` jamal
2007-05-23 1:17 ` Zhang Rui
2007-05-27 9:40 ` Zhang Rui
[not found] ` <4466a10705270629h31977813hd2fc8330bcd87f78@mail.gmail.com>
2007-05-27 13:34 ` Fwd: " jamal
2007-06-14 8:59 ` Zhang Rui
2007-06-14 11:28 ` jamal
2007-06-15 1:01 ` Zhang Rui
2007-06-15 10:26 ` jamal
2007-06-18 15:01 ` jamal
2007-06-19 3:32 ` Zhang Rui
2007-06-25 22:40 ` Johannes Berg
2007-06-26 13:33 ` jamal
2007-06-26 13:42 ` Johannes Berg
2007-06-27 23:24 ` jamal
2007-06-28 9:45 ` Johannes Berg
2007-06-29 11:17 ` jamal
2007-06-29 11:28 ` Johannes Berg
2007-06-29 11:48 ` jamal
2007-06-29 11:58 ` Johannes Berg
2007-06-29 11:51 ` Patrick McHardy
2007-06-29 11:59 ` Johannes Berg
2007-06-29 12:04 ` Patrick McHardy
2007-06-29 12:01 ` jamal
2007-06-29 12:09 ` Patrick McHardy
2007-06-29 12:46 ` Johannes Berg
2007-06-29 12:48 ` Patrick McHardy
2007-06-29 12:51 ` Johannes Berg
2007-06-29 13:02 ` jamal
2007-06-29 13:12 ` Patrick McHardy
2007-06-29 13:27 ` jamal
2007-06-29 13:32 ` Patrick McHardy
2007-06-29 13:13 ` Johannes Berg
2007-06-29 12:57 ` Johannes Berg
2007-06-29 13:11 ` Patrick McHardy
2007-06-29 13:15 ` Johannes Berg
2007-06-29 13:23 ` Patrick McHardy
2007-06-29 13:34 ` Johannes Berg
2007-06-29 13:44 ` Patrick McHardy
2007-06-29 13:49 ` Johannes Berg
2007-06-29 13:53 ` Patrick McHardy
2007-06-29 14:05 ` Johannes Berg
2007-06-29 14:18 ` Johannes Berg
2007-06-29 14:56 ` Johannes Berg
2007-06-30 15:32 ` jamal
2007-07-02 8:43 ` Johannes Berg
2007-07-02 12:56 ` Patrick McHardy
2007-07-02 14:34 ` Johannes Berg
2007-07-02 14:38 ` Patrick McHardy
2007-07-02 14:48 ` Johannes Berg
2007-07-02 22:12 ` Johannes Berg
2007-07-03 10:08 ` [PATCH] netlink: allocate group bitmaps dynamically Johannes Berg
2007-07-03 12:05 ` Patrick McHardy [this message]
2007-07-03 14:09 ` Johannes Berg
2007-07-03 14:11 ` Patrick McHardy
2007-07-03 14:32 ` Johannes Berg
2007-07-03 23:13 ` Johannes Berg
2007-07-03 10:09 ` [PATCH] netlink: allow removing multicast groups Johannes Berg
2007-07-03 10:10 ` [PATCH] generic netlink: dynamic " Johannes Berg
2007-07-03 11:56 ` Fwd: [PATCH] [-mm] ACPI: export ACPI events via netlink Patrick McHardy
2007-06-29 13:24 ` jamal
2007-06-29 13:11 ` jamal
2007-06-19 11:30 ` Johannes Berg
2007-06-19 16:20 ` jamal
2007-06-20 11:25 ` Johannes Berg
2007-06-21 15:47 ` jamal
2007-06-22 10:09 ` Johannes Berg
2007-06-25 17:08 ` jamal
2007-06-26 8:50 ` Johannes Berg
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=468A3BA5.9050909@trash.net \
--to=kaber@trash.net \
--cc=hadi@cyberus.ca \
--cc=johannes@sipsolutions.net \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=rui.zhang@intel.com \
--cc=tgraf@suug.ch \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.