All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH iptables] extensions: libxt_connlabel: fix crash when connlabel.conf is empty
@ 2016-07-16 11:39 Liping Zhang
  2016-07-16 11:47 ` Florian Westphal
  0 siblings, 1 reply; 2+ messages in thread
From: Liping Zhang @ 2016-07-16 11:39 UTC (permalink / raw)
  To: pablo; +Cc: netfilter-devel, Liping Zhang

From: Liping Zhang <liping.zhang@spreadtrum.com>

When connlabel.conf is empty, nfct_labelmap_new will return NULL and
set errno to 0. So we will miss to check this situation, and cause NULL
deference in nfct_labelmap_get_bit.

Input the following commands will reproduce this crash:
  # echo > /etc/xtables/connlabel.conf
  # iptables -A INPUT -m connlabel --label abc
  Segmentation fault (core dumped)

Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
---
 extensions/libxt_connlabel.c | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/extensions/libxt_connlabel.c b/extensions/libxt_connlabel.c
index 96b9aec..7e4ff26 100644
--- a/extensions/libxt_connlabel.c
+++ b/extensions/libxt_connlabel.c
@@ -38,9 +38,16 @@ static void connlabel_open(void)
 		return;
 
 	map = nfct_labelmap_new(NULL);
-	if (!map && errno)
-		xtables_error(RESOURCE_PROBLEM, "cannot open connlabel.conf: %s\n",
-			strerror(errno));
+	if (map != NULL)
+		return;
+
+	if (errno) {
+		xtables_error(RESOURCE_PROBLEM,
+			"cannot open connlabel.conf: %s", strerror(errno));
+	} else {
+		xtables_error(RESOURCE_PROBLEM,
+			"cannot parse label, maybe valid label map is empty");
+	}
 }
 
 static void connlabel_mt_parse(struct xt_option_call *cb)
-- 
2.5.5



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

* Re: [PATCH iptables] extensions: libxt_connlabel: fix crash when connlabel.conf is empty
  2016-07-16 11:39 [PATCH iptables] extensions: libxt_connlabel: fix crash when connlabel.conf is empty Liping Zhang
@ 2016-07-16 11:47 ` Florian Westphal
  0 siblings, 0 replies; 2+ messages in thread
From: Florian Westphal @ 2016-07-16 11:47 UTC (permalink / raw)
  To: Liping Zhang; +Cc: pablo, netfilter-devel, Liping Zhang

Liping Zhang <zlpnobody@163.com> wrote:
> From: Liping Zhang <liping.zhang@spreadtrum.com>
> 
> When connlabel.conf is empty, nfct_labelmap_new will return NULL and
> set errno to 0. So we will miss to check this situation, and cause NULL
> deference in nfct_labelmap_get_bit.
> 
> Input the following commands will reproduce this crash:
>   # echo > /etc/xtables/connlabel.conf
>   # iptables -A INPUT -m connlabel --label abc
>   Segmentation fault (core dumped)

Applied, thanks!

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

end of thread, other threads:[~2016-07-16 11:48 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-16 11:39 [PATCH iptables] extensions: libxt_connlabel: fix crash when connlabel.conf is empty Liping Zhang
2016-07-16 11:47 ` Florian Westphal

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.