netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: kaber@trash.net
To: davem@davemloft.net
Cc: netfilter-devel@vger.kernel.org, netdev@vger.kernel.org
Subject: [PATCH 02/37] netfilter: x_tables: misuse of try_then_request_module
Date: Tue, 15 Mar 2011 20:43:42 +0100	[thread overview]
Message-ID: <1300218257-26953-3-git-send-email-kaber@trash.net> (raw)
In-Reply-To: <1300218257-26953-1-git-send-email-kaber@trash.net>

From: Stephen Hemminger <shemminger@vyatta.com>

Since xt_find_match() returns ERR_PTR(xx) on error not NULL,
the macro try_then_request_module won't work correctly here.
The macro expects its first argument will be zero if condition
fails. But ERR_PTR(-ENOENT) is not zero.

The correct solution is to propagate the error value
back.

Found by inspection, and compile tested only.

Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
Signed-off-by: Patrick McHardy <kaber@trash.net>
---
 net/netfilter/x_tables.c |   22 +++++++++++++++-------
 1 files changed, 15 insertions(+), 7 deletions(-)

diff --git a/net/netfilter/x_tables.c b/net/netfilter/x_tables.c
index 0a77d2f..271eed3 100644
--- a/net/netfilter/x_tables.c
+++ b/net/netfilter/x_tables.c
@@ -183,7 +183,7 @@ EXPORT_SYMBOL(xt_unregister_matches);
 /*
  * These are weird, but module loading must not be done with mutex
  * held (since they will register), and we have to have a single
- * function to use try_then_request_module().
+ * function to use.
  */
 
 /* Find match, grabs ref.  Returns ERR_PTR() on error. */
@@ -221,9 +221,13 @@ xt_request_find_match(uint8_t nfproto, const char *name, uint8_t revision)
 {
 	struct xt_match *match;
 
-	match = try_then_request_module(xt_find_match(nfproto, name, revision),
-					"%st_%s", xt_prefix[nfproto], name);
-	return (match != NULL) ? match : ERR_PTR(-ENOENT);
+	match = xt_find_match(nfproto, name, revision);
+	if (IS_ERR(match)) {
+		request_module("%st_%s", xt_prefix[nfproto], name);
+		match = xt_find_match(nfproto, name, revision);
+	}
+
+	return match;
 }
 EXPORT_SYMBOL_GPL(xt_request_find_match);
 
@@ -261,9 +265,13 @@ struct xt_target *xt_request_find_target(u8 af, const char *name, u8 revision)
 {
 	struct xt_target *target;
 
-	target = try_then_request_module(xt_find_target(af, name, revision),
-					 "%st_%s", xt_prefix[af], name);
-	return (target != NULL) ? target : ERR_PTR(-ENOENT);
+	target = xt_find_target(af, name, revision);
+	if (IS_ERR(target)) {
+		request_module("%st_%s", xt_prefix[af], name);
+		target = xt_find_target(af, name, revision);
+	}
+
+	return target;
 }
 EXPORT_SYMBOL_GPL(xt_request_find_target);
 
-- 
1.7.2.3


  parent reply	other threads:[~2011-03-15 19:43 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-03-15 19:43 [PATCH 00/37] netfilter: netfilter update kaber
2011-03-15 19:43 ` [PATCH 01/37] netfilter: ipset: fix the compile warning in ip_set_create kaber
2011-03-15 19:43 ` kaber [this message]
2011-03-15 19:43 ` [PATCH 03/37] netfilter: x_tables: return -ENOENT for non-existant matches/targets kaber
2011-03-15 19:43 ` [PATCH 04/37] netfilter: nf_conntrack: fix sysctl memory leak kaber
2011-03-15 19:43 ` [PATCH 05/37] ipvs: avoid lookup for fwmark 0 kaber
2011-03-15 19:43 ` [PATCH 06/37] ipvs: remove _bh from percpu stats reading kaber
2011-03-15 19:43 ` [PATCH 07/37] netfilter:ipvs: use kmemdup kaber
2011-03-15 19:43 ` [PATCH 08/37] IPVS: Fix variable assignment in ip_vs_notrack kaber
2011-03-15 19:43 ` [PATCH 09/37] ipvs: move struct netns_ipvs kaber
2011-03-15 19:43 ` [PATCH 10/37] ipvs: reorganize tot_stats kaber
2011-03-15 19:43 ` [PATCH 11/37] ipvs: properly zero stats and rates kaber
2011-03-15 19:43 ` [PATCH 12/37] ipvs: remove unused seqcount stats kaber
2011-03-15 19:43 ` [PATCH 13/37] ipvs: optimize rates reading kaber
2011-03-15 19:43 ` [PATCH 14/37] ipvs: rename estimator functions kaber
2011-03-15 19:43 ` [PATCH 15/37] IPVS: Add ip_vs_route_me_harder() kaber
2011-03-15 19:43 ` [PATCH 16/37] IPVS: Add sysctl_snat_reroute() kaber
2011-03-15 19:43 ` [PATCH 17/37] IPVS: Add sysctl_nat_icmp_send() kaber
2011-03-15 19:43 ` [PATCH 18/37] IPVS: Add {sysctl_sync_threshold,period}() kaber
2011-03-15 19:43 ` [PATCH 19/37] IPVS: Add sysctl_sync_ver() kaber
2011-03-15 19:44 ` [PATCH 20/37] IPVS: Add sysctl_expire_nodest_conn() kaber
2011-03-15 19:44 ` [PATCH 21/37] IPVS: Add expire_quiescent_template() kaber
2011-03-15 19:44 ` [PATCH 22/37] IPVS: Conditinally use sysctl_lblc{r}_expiration kaber
2011-03-15 19:44 ` [PATCH 23/37] IPVS: ip_vs_todrop() becomes a noop when CONFIG_SYSCTL is undefined kaber
2011-03-15 19:44 ` [PATCH 24/37] IPVS: Conditional ip_vs_conntrack_enabled() kaber
2011-03-15 19:44 ` [PATCH 25/37] IPVS: Minimise ip_vs_leave when CONFIG_SYSCTL is undefined kaber
2011-03-15 19:44 ` [PATCH 26/37] IPVS: Conditionally define and use ip_vs_lblc{r}_table kaber
2011-03-15 19:44 ` [PATCH 27/37] IPVS: Add __ip_vs_control_{init,cleanup}_sysctl() kaber
2011-03-15 19:44 ` [PATCH 28/37] IPVS: Conditionally include sysctl members of struct netns_ipvs kaber
2011-03-15 19:44 ` [PATCH 29/37] netfilter: xt_connlimit: fix daddr connlimit in SNAT scenario kaber
2011-03-15 19:44 ` [PATCH 30/37] netfilter: xt_connlimit: use kmalloc() instead of kzalloc() kaber
2011-03-15 19:44 ` [PATCH 31/37] netfilter: xt_connlimit: use hlist instead kaber
2011-03-15 19:44 ` [PATCH 32/37] netfilter: xt_connlimit: remove connlimit_rnd_inited kaber
2011-03-15 19:44 ` [PATCH 33/37] netfilter: arp_tables: fix infoleak to userspace kaber
2011-03-15 19:44 ` [PATCH 34/37] netfilter: ip_tables: " kaber
2011-03-15 19:44 ` [PATCH 35/37] ipv6: netfilter: ip6_tables: " kaber
2011-03-15 19:44 ` [PATCH 36/37] netfilter: ipt_addrtype: rename to xt_addrtype kaber
2011-03-15 19:44 ` [PATCH 37/37] netfilter: xt_addrtype: ipv6 support kaber
2011-03-15 19:58 ` [PATCH 00/37] netfilter: netfilter update 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=1300218257-26953-3-git-send-email-kaber@trash.net \
    --to=kaber@trash.net \
    --cc=davem@davemloft.net \
    --cc=netdev@vger.kernel.org \
    --cc=netfilter-devel@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).