All of lore.kernel.org
 help / color / mirror / Atom feed
* buffer overflow in ip_ct_{ftp,tftp,irc}
@ 2005-09-07 23:11 Samir Bellabes
  2005-09-07 23:15 ` Samir Bellabes
  0 siblings, 1 reply; 14+ messages in thread
From: Samir Bellabes @ 2005-09-07 23:11 UTC (permalink / raw)
  To: netfilter-devel; +Cc: Harald Welte, David S. Miller

[-- Attachment #1: Type: text/plain, Size: 310 bytes --]

Hi,

when loading ip_conntrack_{ftp,tftp,irc} with 'ports=1234567890'
parameter option for example, a buffer overflow occur when :
sprintf(tmpname, "ftp-%d", ports[i]);
because of sizeof("ftp-1234567890") > 10
10 is the size of each array *_names[port][10]

Please apply this patch.

regards, 
Samir Bellabes


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: nf_bad_param_port.patch --]
[-- Type: text/x-patch, Size: 2832 bytes --]

tree f8f9de37b0294e8049a959dfa5acc2efc64ab231
parent 48bc41a49c4f3aa760dff84e7f71437f5ed520fe
author Samir Bellabes <sbellabes@mandriva.com> 1126118922 +0200
committer Samir Bellabes <sbellabes@mandriva.com> 1126118922 +0200

[NETFILTER] Check for bad parameter value of 'ports' in ip_ct_{ftp,tftp,irc}

A buffer overflow occur when parameter 'ports' value is > 65535 :
if the number of digits of ports exceeds, for the ftp example:
sizeof ftp_names[A_PORT][10] - strlen("ftp-") = 10-4 = 6 
then : sprintf(tmpname, "ftp-%d", ports[i]) produce the overflow.

This patch checks for 0 < port < 65356.

Signed-off-by: Samir Bellabes <sbellabes@mandriva.com>
------------------------------------------------------------------------------

 ip_conntrack_ftp.c  |    7 +++++++
 ip_conntrack_irc.c  |    7 +++++++
 ip_conntrack_tftp.c |    7 +++++++
 3 files changed, 21 insertions(+)

------------------------------------------------------------------------------

diff --git a/net/ipv4/netfilter/ip_conntrack_ftp.c b/net/ipv4/netfilter/ip_conntrack_ftp.c
--- a/net/ipv4/netfilter/ip_conntrack_ftp.c
+++ b/net/ipv4/netfilter/ip_conntrack_ftp.c
@@ -478,6 +478,13 @@ static int __init init(void)
 		ports[ports_c++] = FTP_PORT;
 
 	for (i = 0; i < ports_c; i++) {
+		/* don't allow bad port values */
+		if (ports[i] < 1 || ports[i] > 65535) {
+			printk(KERN_WARNING "ip_ct_ftp: ERROR port"
+			       "should be between 1 and 65535\n");
+			fini();
+			return -EINVAL;
+		}
 		ftp[i].tuple.src.u.tcp.port = htons(ports[i]);
 		ftp[i].tuple.dst.protonum = IPPROTO_TCP;
 		ftp[i].mask.src.u.tcp.port = 0xFFFF;
diff --git a/net/ipv4/netfilter/ip_conntrack_irc.c b/net/ipv4/netfilter/ip_conntrack_irc.c
--- a/net/ipv4/netfilter/ip_conntrack_irc.c
+++ b/net/ipv4/netfilter/ip_conntrack_irc.c
@@ -268,6 +268,13 @@ static int __init init(void)
 		ports[ports_c++] = IRC_PORT;
 
 	for (i = 0; i < ports_c; i++) {
+		/* don't allow bad port values */
+		if (ports[i] < 1 || ports[i] > 65535) {
+			printk(KERN_WARNING "ip_conntrack_irc: ERROR port"
+			       "should be between 1 and 65535\n");
+			fini();
+			return -EINVAL;
+		}
 		hlpr = &irc_helpers[i];
 		hlpr->tuple.src.u.tcp.port = htons(ports[i]);
 		hlpr->tuple.dst.protonum = IPPROTO_TCP;
diff --git a/net/ipv4/netfilter/ip_conntrack_tftp.c b/net/ipv4/netfilter/ip_conntrack_tftp.c
--- a/net/ipv4/netfilter/ip_conntrack_tftp.c
+++ b/net/ipv4/netfilter/ip_conntrack_tftp.c
@@ -122,6 +122,13 @@ static int __init init(void)
 		ports[ports_c++] = TFTP_PORT;
 
 	for (i = 0; i < ports_c; i++) {
+		/* don't allow bad port values */
+		if (ports[i] < 1 || ports[i] > 65535) {
+			printk(KERN_WARNING
+			       "ERROR port should be between 1 and 65535\n");
+			fini();
+			return -EINVAL;
+		}
 		/* Create helper structure */
 		memset(&tftp[i], 0, sizeof(struct ip_conntrack_helper));
 

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

end of thread, other threads:[~2005-09-24  8:43 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2005-09-07 23:11 buffer overflow in ip_ct_{ftp,tftp,irc} Samir Bellabes
2005-09-07 23:15 ` Samir Bellabes
2005-09-07 23:43   ` Pablo Neira
2005-09-07 23:48     ` Pablo Neira
2005-09-09 22:59       ` Patrick McHardy
2005-09-12  8:44         ` Amin Azez
2005-09-12  8:49           ` Patrick McHardy
2005-09-20  7:11         ` Yasuyuki KOZAKAI
     [not found]         ` <200509200711.j8K7Bw3x002184@toshiba.co.jp>
2005-09-20  8:10           ` Pablo Neira
2005-09-20  9:35           ` Harald Welte
2005-09-20 12:48             ` Yasuyuki KOZAKAI
     [not found]             ` <200509201248.j8KCmNi9009046@toshiba.co.jp>
2005-09-20 14:15               ` Harald Welte
2005-09-24  8:43                 ` Yasuyuki KOZAKAI
2005-09-10  7:38       ` [PATCH] " Harald Welte

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.