From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
alan@lxorguk.ukuu.org.uk, Gao feng <gaofeng@cn.fujitsu.com>,
"David S. Miller" <davem@davemloft.net>
Subject: [ 29/42] netlink: add reference of module in netlink_dump_start
Date: Thu, 25 Oct 2012 17:05:37 -0700 [thread overview]
Message-ID: <20121026000127.713288502@linuxfoundation.org> (raw)
In-Reply-To: <20121026000124.790781113@linuxfoundation.org>
3.4-stable review patch. If anyone has any objections, please let me know.
------------------
From: Gao feng <gaofeng@cn.fujitsu.com>
[ Upstream commit 6dc878a8ca39e93f70c42f3dd7260bde10c1e0f1 ]
I get a panic when I use ss -a and rmmod inet_diag at the
same time.
It's because netlink_dump uses inet_diag_dump which belongs to module
inet_diag.
I search the codes and find many modules have the same problem. We
need to add a reference to the module which the cb->dump belongs to.
Thanks for all help from Stephen,Jan,Eric,Steffen and Pablo.
Change From v3:
change netlink_dump_start to inline,suggestion from Pablo and
Eric.
Change From v2:
delete netlink_dump_done,and call module_put in netlink_dump
and netlink_sock_destruct.
Signed-off-by: Gao feng <gaofeng@cn.fujitsu.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
include/linux/netlink.h | 21 +++++++++++++++++----
net/netlink/af_netlink.c | 29 +++++++++++++++++++++--------
2 files changed, 38 insertions(+), 12 deletions(-)
--- a/include/linux/netlink.h
+++ b/include/linux/netlink.h
@@ -153,6 +153,7 @@ struct nlattr {
#include <linux/capability.h>
#include <linux/skbuff.h>
+#include <linux/export.h>
struct net;
@@ -226,6 +227,8 @@ struct netlink_callback {
struct netlink_callback *cb);
int (*done)(struct netlink_callback *cb);
void *data;
+ /* the module that dump function belong to */
+ struct module *module;
u16 family;
u16 min_dump_alloc;
unsigned int prev_seq, seq;
@@ -251,14 +254,24 @@ __nlmsg_put(struct sk_buff *skb, u32 pid
struct netlink_dump_control {
int (*dump)(struct sk_buff *skb, struct netlink_callback *);
- int (*done)(struct netlink_callback*);
+ int (*done)(struct netlink_callback *);
void *data;
+ struct module *module;
u16 min_dump_alloc;
};
-extern int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
- const struct nlmsghdr *nlh,
- struct netlink_dump_control *control);
+extern int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
+ const struct nlmsghdr *nlh,
+ struct netlink_dump_control *control);
+static inline int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
+ const struct nlmsghdr *nlh,
+ struct netlink_dump_control *control)
+{
+ if (!control->module)
+ control->module = THIS_MODULE;
+
+ return __netlink_dump_start(ssk, skb, nlh, control);
+}
#define NL_NONROOT_RECV 0x1
--- a/net/netlink/af_netlink.c
+++ b/net/netlink/af_netlink.c
@@ -156,6 +156,8 @@ static void netlink_sock_destruct(struct
if (nlk->cb) {
if (nlk->cb->done)
nlk->cb->done(nlk->cb);
+
+ module_put(nlk->cb->module);
netlink_destroy_callback(nlk->cb);
}
@@ -1728,6 +1730,7 @@ static int netlink_dump(struct sock *sk)
nlk->cb = NULL;
mutex_unlock(nlk->cb_mutex);
+ module_put(cb->module);
netlink_destroy_callback(cb);
return 0;
@@ -1737,9 +1740,9 @@ errout_skb:
return err;
}
-int netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
- const struct nlmsghdr *nlh,
- struct netlink_dump_control *control)
+int __netlink_dump_start(struct sock *ssk, struct sk_buff *skb,
+ const struct nlmsghdr *nlh,
+ struct netlink_dump_control *control)
{
struct netlink_callback *cb;
struct sock *sk;
@@ -1754,6 +1757,7 @@ int netlink_dump_start(struct sock *ssk,
cb->done = control->done;
cb->nlh = nlh;
cb->data = control->data;
+ cb->module = control->module;
cb->min_dump_alloc = control->min_dump_alloc;
atomic_inc(&skb->users);
cb->skb = skb;
@@ -1764,19 +1768,28 @@ int netlink_dump_start(struct sock *ssk,
return -ECONNREFUSED;
}
nlk = nlk_sk(sk);
- /* A dump is in progress... */
+
mutex_lock(nlk->cb_mutex);
+ /* A dump is in progress... */
if (nlk->cb) {
mutex_unlock(nlk->cb_mutex);
netlink_destroy_callback(cb);
- sock_put(sk);
- return -EBUSY;
+ ret = -EBUSY;
+ goto out;
}
+ /* add reference of module which cb->dump belongs to */
+ if (!try_module_get(cb->module)) {
+ mutex_unlock(nlk->cb_mutex);
+ netlink_destroy_callback(cb);
+ ret = -EPROTONOSUPPORT;
+ goto out;
+ }
+
nlk->cb = cb;
mutex_unlock(nlk->cb_mutex);
ret = netlink_dump(sk);
-
+out:
sock_put(sk);
if (ret)
@@ -1787,7 +1800,7 @@ int netlink_dump_start(struct sock *ssk,
*/
return -EINTR;
}
-EXPORT_SYMBOL(netlink_dump_start);
+EXPORT_SYMBOL(__netlink_dump_start);
void netlink_ack(struct sk_buff *in_skb, struct nlmsghdr *nlh, int err)
{
next prev parent reply other threads:[~2012-10-26 0:07 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-26 0:05 [ 00/42] 3.4.16-stable review Greg Kroah-Hartman
2012-10-26 0:05 ` [ 01/42] ext4: race-condition protection for ext4_convert_unwritten_extents_endio Greg Kroah-Hartman
2012-10-26 0:05 ` [ 02/42] ext4: Avoid underflow in ext4_trim_fs() Greg Kroah-Hartman
2012-10-26 0:05 ` [ 03/42] nohz: Fix idle ticks in cpu summary line of /proc/stat Greg Kroah-Hartman
2012-10-26 0:05 ` [ 04/42] arch/tile: avoid generating .eh_frame information in modules Greg Kroah-Hartman
2012-10-26 0:05 ` [ 05/42] NLM: nlm_lookup_file() may return NLMv4-specific error codes Greg Kroah-Hartman
2012-10-26 0:05 ` [ 06/42] oprofile, x86: Fix wrapping bug in op_x86_get_ctrl() Greg Kroah-Hartman
2012-10-26 0:05 ` [ 07/42] s390: fix linker script for 31 bit builds Greg Kroah-Hartman
2012-10-26 0:05 ` [ 08/42] SUNRPC: Prevent kernel stack corruption on long values of flush Greg Kroah-Hartman
2012-10-26 0:05 ` [ 09/42] SUNRPC: Fix a UDP transport regression Greg Kroah-Hartman
2012-10-26 0:05 ` [ 10/42] pcmcia: sharpsl: dont discard sharpsl_pcmcia_ops Greg Kroah-Hartman
2012-10-26 0:05 ` [ 11/42] kernel/sys.c: fix stack memory content leak via UNAME26 Greg Kroah-Hartman
2012-10-26 0:05 ` [ 12/42] use clamp_t in UNAME26 fix Greg Kroah-Hartman
2012-10-26 0:05 ` [ 13/42] x86: Exclude E820_RESERVED regions and memory holes above 4 GB from direct mapping Greg Kroah-Hartman
2012-10-26 0:05 ` [ 14/42] xen/x86: dont corrupt %eip when returning from a signal handler Greg Kroah-Hartman
2012-10-26 0:05 ` [ 15/42] USB: cdc-acm: fix pipe type of write endpoint Greg Kroah-Hartman
2012-10-26 0:05 ` [ 16/42] usb: acm: fix the computation of the number of data bits Greg Kroah-Hartman
2012-10-26 0:05 ` [ 17/42] usb: host: xhci: New system added for Compliance Mode Patch on SN65LVPE502CP Greg Kroah-Hartman
2012-10-26 0:05 ` [ 18/42] USB: option: blacklist net interface on ZTE devices Greg Kroah-Hartman
2012-10-26 0:05 ` [ 19/42] USB: option: add more " Greg Kroah-Hartman
2012-10-26 0:05 ` [ 20/42] cgroup: notify_on_release may not be triggered in some cases Greg Kroah-Hartman
2012-10-26 0:05 ` [ 21/42] Revert "cgroup: Remove task_lock() from cgroup_post_fork()" Greg Kroah-Hartman
2012-10-26 0:05 ` [ 22/42] Revert "cgroup: Drop task_lock(parent) on cgroup_fork()" Greg Kroah-Hartman
2012-10-26 0:05 ` [ 23/42] pinctrl: tegra: correct bank for pingroup and drv pingroup Greg Kroah-Hartman
2012-10-26 0:05 ` [ 24/42] pinctrl: tegra: set low power mode bank width to 2 Greg Kroah-Hartman
2012-10-26 0:05 ` [ 25/42] iommu/tegra: smmu: Fix deadly typo Greg Kroah-Hartman
2012-10-26 0:05 ` [ 26/42] amd64_edac:__amd64_set_scrub_rate(): avoid overindexing scrubrates[] Greg Kroah-Hartman
2012-10-26 0:05 ` [ 27/42] usb: dwc3: gadget: fix endpoint always busy bug Greg Kroah-Hartman
2012-10-26 0:05 ` [ 28/42] media: au0828: fix case where STREAMOFF being called on stopped stream causes BUG() Greg Kroah-Hartman
2012-10-26 0:05 ` Greg Kroah-Hartman [this message]
2012-10-26 0:05 ` [ 30/42] infiniband: pass rdma_cm module to netlink_dump_start Greg Kroah-Hartman
2012-10-26 0:05 ` [ 31/42] net: Fix skb_under_panic oops in neigh_resolve_output Greg Kroah-Hartman
2012-10-26 0:05 ` [ 32/42] skge: Add DMA mask quirk for Marvell 88E8001 on ASUS P5NSLI motherboard Greg Kroah-Hartman
2012-10-26 0:05 ` [ 33/42] vlan: dont deliver frames for unknown vlans to protocols Greg Kroah-Hartman
2012-10-26 0:05 ` [ 34/42] RDS: fix rds-ping spinlock recursion Greg Kroah-Hartman
2012-10-26 0:05 ` [ 35/42] tcp: resets are misrouted Greg Kroah-Hartman
2012-10-26 0:05 ` [ 36/42] ipv6: addrconf: fix /proc/net/if_inet6 Greg Kroah-Hartman
2012-10-26 0:05 ` [ 37/42] sparc64: fix ptrace interaction with force_successful_syscall_return() Greg Kroah-Hartman
2012-10-26 0:05 ` [ 38/42] sparc64: Like x86 we should check current->mm during perf backtrace generation Greg Kroah-Hartman
2012-10-26 0:05 ` [ 39/42] sparc64: Fix bit twiddling in sparc_pmu_enable_event() Greg Kroah-Hartman
2012-10-26 0:05 ` [ 40/42] sparc64: do not clobber personality flags in sys_sparc64_personality() Greg Kroah-Hartman
2012-10-26 0:05 ` [ 41/42] sparc64: Be less verbose during vmemmap population Greg Kroah-Hartman
2012-10-26 0:05 ` [ 42/42] mtd: nand: allow NAND_NO_SUBPAGE_WRITE to be set from driver Greg Kroah-Hartman
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=20121026000127.713288502@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=davem@davemloft.net \
--cc=gaofeng@cn.fujitsu.com \
--cc=linux-kernel@vger.kernel.org \
--cc=stable@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 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.