All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] net: Remove state argument from skb_find_text()
@ 2015-02-18 23:16 Bojan Prtvar
  2015-02-19  0:05 ` Pablo Neira Ayuso
  2015-02-20 22:22 ` David Miller
  0 siblings, 2 replies; 5+ messages in thread
From: Bojan Prtvar @ 2015-02-18 23:16 UTC (permalink / raw)
  To: netdev; +Cc: tgraf, netfilter-devel, netfilter, dan.carpenter, Bojan Prtvar

Although it is clear that textsearch state is intentionally passed to skb_find_text() as uninitialized argument, it was never used by the callers. Therefore, we can simplify skb_find_text() by making it local variable.

Signed-off-by: Bojan Prtvar <prtvar.b@gmail.com>
---
 include/linux/skbuff.h              |    3 +--
 net/core/skbuff.c                   |    9 ++++-----
 net/netfilter/nf_conntrack_amanda.c |   10 +++-------
 net/netfilter/xt_string.c           |    4 +---
 net/sched/em_text.c                 |    3 +--
 5 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 08074a8..6cc1b7d 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -776,8 +776,7 @@ unsigned int skb_seq_read(unsigned int consumed, const u8 **data,
 void skb_abort_seq_read(struct skb_seq_state *st);
 
 unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
-			   unsigned int to, struct ts_config *config,
-			   struct ts_state *state);
+			   unsigned int to, struct ts_config *config);
 
 /*
  * Packet hash types specify the type of hash in skb_set_hash.
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 1b62343..c0e64f7 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2747,7 +2747,6 @@ static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)
  * @from: search offset
  * @to: search limit
  * @config: textsearch configuration
- * @state: uninitialized textsearch state variable
  *
  * Finds a pattern in the skb data according to the specified
  * textsearch configuration. Use textsearch_next() to retrieve
@@ -2755,17 +2754,17 @@ static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)
  * to the first occurrence or UINT_MAX if no match was found.
  */
 unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
-			   unsigned int to, struct ts_config *config,
-			   struct ts_state *state)
+			   unsigned int to, struct ts_config *config)
 {
+	struct ts_state state;
 	unsigned int ret;
 
 	config->get_next_block = skb_ts_get_next_block;
 	config->finish = skb_ts_finish;
 
-	skb_prepare_seq_read(skb, from, to, TS_SKB_CB(state));
+	skb_prepare_seq_read(skb, from, to, TS_SKB_CB(&state));
 
-	ret = textsearch_find(config, state);
+	ret = textsearch_find(config, &state);
 	return (ret <= to - from ? ret : UINT_MAX);
 }
 EXPORT_SYMBOL(skb_find_text);
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
index b8b95f4..57a26cc 100644
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -88,7 +88,6 @@ static int amanda_help(struct sk_buff *skb,
 		       struct nf_conn *ct,
 		       enum ip_conntrack_info ctinfo)
 {
-	struct ts_state ts;
 	struct nf_conntrack_expect *exp;
 	struct nf_conntrack_tuple *tuple;
 	unsigned int dataoff, start, stop, off, i;
@@ -113,23 +112,20 @@ static int amanda_help(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	memset(&ts, 0, sizeof(ts));
 	start = skb_find_text(skb, dataoff, skb->len,
-			      search[SEARCH_CONNECT].ts, &ts);
+			      search[SEARCH_CONNECT].ts);
 	if (start == UINT_MAX)
 		goto out;
 	start += dataoff + search[SEARCH_CONNECT].len;
 
-	memset(&ts, 0, sizeof(ts));
 	stop = skb_find_text(skb, start, skb->len,
-			     search[SEARCH_NEWLINE].ts, &ts);
+			     search[SEARCH_NEWLINE].ts);
 	if (stop == UINT_MAX)
 		goto out;
 	stop += start;
 
 	for (i = SEARCH_DATA; i <= SEARCH_INDEX; i++) {
-		memset(&ts, 0, sizeof(ts));
-		off = skb_find_text(skb, start, stop, search[i].ts, &ts);
+		off = skb_find_text(skb, start, stop, search[i].ts);
 		if (off == UINT_MAX)
 			continue;
 		off += start + search[i].len;
diff --git a/net/netfilter/xt_string.c b/net/netfilter/xt_string.c
index d3c48b1..0bc3460 100644
--- a/net/netfilter/xt_string.c
+++ b/net/netfilter/xt_string.c
@@ -26,14 +26,12 @@ static bool
 string_mt(const struct sk_buff *skb, struct xt_action_param *par)
 {
 	const struct xt_string_info *conf = par->matchinfo;
-	struct ts_state state;
 	bool invert;
 
-	memset(&state, 0, sizeof(struct ts_state));
 	invert = conf->u.v1.flags & XT_STRING_FLAG_INVERT;
 
 	return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
-			     conf->to_offset, conf->config, &state)
+			     conf->to_offset, conf->config)
 			     != UINT_MAX) ^ invert;
 }
 
diff --git a/net/sched/em_text.c b/net/sched/em_text.c
index 15d353d..21bc53f 100644
--- a/net/sched/em_text.c
+++ b/net/sched/em_text.c
@@ -34,7 +34,6 @@ static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
 {
 	struct text_match *tm = EM_TEXT_PRIV(m);
 	int from, to;
-	struct ts_state state;
 
 	from = tcf_get_base_ptr(skb, tm->from_layer) - skb->data;
 	from += tm->from_offset;
@@ -42,7 +41,7 @@ static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
 	to = tcf_get_base_ptr(skb, tm->to_layer) - skb->data;
 	to += tm->to_offset;
 
-	return skb_find_text(skb, from, to, tm->config, &state) != UINT_MAX;
+	return skb_find_text(skb, from, to, tm->config) != UINT_MAX;
 }
 
 static int em_text_change(struct tcf_proto *tp, void *data, int len,
-- 
1.7.9.5

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: Remove state argument from skb_find_text()
  2015-02-18 23:16 [PATCH] net: Remove state argument from skb_find_text() Bojan Prtvar
@ 2015-02-19  0:05 ` Pablo Neira Ayuso
  2015-02-20 22:22 ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: Pablo Neira Ayuso @ 2015-02-19  0:05 UTC (permalink / raw)
  To: Bojan Prtvar; +Cc: netdev, tgraf, netfilter-devel, netfilter, dan.carpenter

On Thu, Feb 19, 2015 at 12:16:48AM +0100, Bojan Prtvar wrote:
> Although it is clear that textsearch state is intentionally passed
> to skb_find_text() as uninitialized argument, it was never used by
> the callers. Therefore, we can simplify skb_find_text() by making it
> local variable.

This infrastructure was conceived to allow keeping the state between
chunk of data, I don't find a good reason to restrict this.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: Remove state argument from skb_find_text()
  2015-02-18 23:16 [PATCH] net: Remove state argument from skb_find_text() Bojan Prtvar
  2015-02-19  0:05 ` Pablo Neira Ayuso
@ 2015-02-20 22:22 ` David Miller
  1 sibling, 0 replies; 5+ messages in thread
From: David Miller @ 2015-02-20 22:22 UTC (permalink / raw)
  To: prtvar.b; +Cc: netdev, tgraf, netfilter-devel, netfilter, dan.carpenter

From: Bojan Prtvar <prtvar.b@gmail.com>
Date: Thu, 19 Feb 2015 00:16:48 +0100

> Although it is clear that textsearch state is intentionally passed
> to skb_find_text() as uninitialized argument, it was never used by
> the callers. Therefore, we can simplify skb_find_text() by making it
> local variable.
> 
> Signed-off-by: Bojan Prtvar <prtvar.b@gmail.com>

Although I partially agree with Pablo's response these interfaces were
designed to be able to hold state across calls, nobody uses them this
way yet.  So this change is fine and we can resurrect the argument
if a use appears in the future.

However, your patch doesn't apply cleanly, please respin.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] net: Remove state argument from skb_find_text()
  2015-02-17 14:49 Bojan Prtvar
@ 2015-02-18  9:50 ` Dan Carpenter
  0 siblings, 0 replies; 5+ messages in thread
From: Dan Carpenter @ 2015-02-18  9:50 UTC (permalink / raw)
  To: kernel-janitors

On Tue, Feb 17, 2015 at 03:49:52PM +0100, Bojan Prtvar wrote:
> No need to pass textsearch state as argument to skb_find_text().
> Instead, it can be local variable.
> 
> Signed-off-by: Bojan Prtvar <prtvar.b@gmail.com>
> ---
> This patch changes internal kernel API. I am sending it here first in hope to get some friendly review.

Hm...  That's odd.

This was added in commit 3fc7e8a6d842f ('[NET]: skb_find_text() -
Find a text pattern in skb data') and it's pretty clear that we're
deliberately passing an uninitialized struct.  Make sure that you CC
Thomas Graf <tgraf@suug.ch> on your email.

The only thing I can think of is that originally, we didn't do it your
way because we thought this would be called recursively and didn't want
to run out of stack space.  But it never has been called recursively so
your patch seems ok.

I hope you have tested this patch.  :)

Anyway, it seems like it should work to me.  I say forward it to netdev.
The worst that can happen is that you learn something.  :)

Maybe flesh out the commit message a bit.

regards,
dan carpenter


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH] net: Remove state argument from skb_find_text()
@ 2015-02-17 14:49 Bojan Prtvar
  2015-02-18  9:50 ` Dan Carpenter
  0 siblings, 1 reply; 5+ messages in thread
From: Bojan Prtvar @ 2015-02-17 14:49 UTC (permalink / raw)
  To: kernel-janitors

No need to pass textsearch state as argument to skb_find_text().
Instead, it can be local variable.

Signed-off-by: Bojan Prtvar <prtvar.b@gmail.com>
---
This patch changes internal kernel API. I am sending it here first in hope to get some friendly review.

 include/linux/skbuff.h              |    3 +--
 net/core/skbuff.c                   |    9 ++++-----
 net/netfilter/nf_conntrack_amanda.c |   10 +++-------
 net/netfilter/xt_string.c           |    4 +---
 net/sched/em_text.c                 |    3 +--
 5 files changed, 10 insertions(+), 19 deletions(-)

diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
index 08074a8..6cc1b7d 100644
--- a/include/linux/skbuff.h
+++ b/include/linux/skbuff.h
@@ -776,8 +776,7 @@ unsigned int skb_seq_read(unsigned int consumed, const u8 **data,
 void skb_abort_seq_read(struct skb_seq_state *st);
 
 unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
-			   unsigned int to, struct ts_config *config,
-			   struct ts_state *state);
+			   unsigned int to, struct ts_config *config);
 
 /*
  * Packet hash types specify the type of hash in skb_set_hash.
diff --git a/net/core/skbuff.c b/net/core/skbuff.c
index 1b62343..c0e64f7 100644
--- a/net/core/skbuff.c
+++ b/net/core/skbuff.c
@@ -2747,7 +2747,6 @@ static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)
  * @from: search offset
  * @to: search limit
  * @config: textsearch configuration
- * @state: uninitialized textsearch state variable
  *
  * Finds a pattern in the skb data according to the specified
  * textsearch configuration. Use textsearch_next() to retrieve
@@ -2755,17 +2754,17 @@ static void skb_ts_finish(struct ts_config *conf, struct ts_state *state)
  * to the first occurrence or UINT_MAX if no match was found.
  */
 unsigned int skb_find_text(struct sk_buff *skb, unsigned int from,
-			   unsigned int to, struct ts_config *config,
-			   struct ts_state *state)
+			   unsigned int to, struct ts_config *config)
 {
+	struct ts_state state;
 	unsigned int ret;
 
 	config->get_next_block = skb_ts_get_next_block;
 	config->finish = skb_ts_finish;
 
-	skb_prepare_seq_read(skb, from, to, TS_SKB_CB(state));
+	skb_prepare_seq_read(skb, from, to, TS_SKB_CB(&state));
 
-	ret = textsearch_find(config, state);
+	ret = textsearch_find(config, &state);
 	return (ret <= to - from ? ret : UINT_MAX);
 }
 EXPORT_SYMBOL(skb_find_text);
diff --git a/net/netfilter/nf_conntrack_amanda.c b/net/netfilter/nf_conntrack_amanda.c
index b8b95f4..57a26cc 100644
--- a/net/netfilter/nf_conntrack_amanda.c
+++ b/net/netfilter/nf_conntrack_amanda.c
@@ -88,7 +88,6 @@ static int amanda_help(struct sk_buff *skb,
 		       struct nf_conn *ct,
 		       enum ip_conntrack_info ctinfo)
 {
-	struct ts_state ts;
 	struct nf_conntrack_expect *exp;
 	struct nf_conntrack_tuple *tuple;
 	unsigned int dataoff, start, stop, off, i;
@@ -113,23 +112,20 @@ static int amanda_help(struct sk_buff *skb,
 		return NF_ACCEPT;
 	}
 
-	memset(&ts, 0, sizeof(ts));
 	start = skb_find_text(skb, dataoff, skb->len,
-			      search[SEARCH_CONNECT].ts, &ts);
+			      search[SEARCH_CONNECT].ts);
 	if (start = UINT_MAX)
 		goto out;
 	start += dataoff + search[SEARCH_CONNECT].len;
 
-	memset(&ts, 0, sizeof(ts));
 	stop = skb_find_text(skb, start, skb->len,
-			     search[SEARCH_NEWLINE].ts, &ts);
+			     search[SEARCH_NEWLINE].ts);
 	if (stop = UINT_MAX)
 		goto out;
 	stop += start;
 
 	for (i = SEARCH_DATA; i <= SEARCH_INDEX; i++) {
-		memset(&ts, 0, sizeof(ts));
-		off = skb_find_text(skb, start, stop, search[i].ts, &ts);
+		off = skb_find_text(skb, start, stop, search[i].ts);
 		if (off = UINT_MAX)
 			continue;
 		off += start + search[i].len;
diff --git a/net/netfilter/xt_string.c b/net/netfilter/xt_string.c
index d3c48b1..0bc3460 100644
--- a/net/netfilter/xt_string.c
+++ b/net/netfilter/xt_string.c
@@ -26,14 +26,12 @@ static bool
 string_mt(const struct sk_buff *skb, struct xt_action_param *par)
 {
 	const struct xt_string_info *conf = par->matchinfo;
-	struct ts_state state;
 	bool invert;
 
-	memset(&state, 0, sizeof(struct ts_state));
 	invert = conf->u.v1.flags & XT_STRING_FLAG_INVERT;
 
 	return (skb_find_text((struct sk_buff *)skb, conf->from_offset,
-			     conf->to_offset, conf->config, &state)
+			     conf->to_offset, conf->config)
 			     != UINT_MAX) ^ invert;
 }
 
diff --git a/net/sched/em_text.c b/net/sched/em_text.c
index 15d353d..21bc53f 100644
--- a/net/sched/em_text.c
+++ b/net/sched/em_text.c
@@ -34,7 +34,6 @@ static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
 {
 	struct text_match *tm = EM_TEXT_PRIV(m);
 	int from, to;
-	struct ts_state state;
 
 	from = tcf_get_base_ptr(skb, tm->from_layer) - skb->data;
 	from += tm->from_offset;
@@ -42,7 +41,7 @@ static int em_text_match(struct sk_buff *skb, struct tcf_ematch *m,
 	to = tcf_get_base_ptr(skb, tm->to_layer) - skb->data;
 	to += tm->to_offset;
 
-	return skb_find_text(skb, from, to, tm->config, &state) != UINT_MAX;
+	return skb_find_text(skb, from, to, tm->config) != UINT_MAX;
 }
 
 static int em_text_change(struct tcf_proto *tp, void *data, int len,
-- 
1.7.9.5


^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2015-02-20 22:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-02-18 23:16 [PATCH] net: Remove state argument from skb_find_text() Bojan Prtvar
2015-02-19  0:05 ` Pablo Neira Ayuso
2015-02-20 22:22 ` David Miller
  -- strict thread matches above, loose matches on Subject: below --
2015-02-17 14:49 Bojan Prtvar
2015-02-18  9:50 ` Dan Carpenter

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.