lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Date:	Thu, 06 Mar 2008 05:53:45 -0500
From:	Andrew Schulman <andrex@...mni.utexas.net>
To:	linux-kernel@...r.kernel.org
Subject:  [PATCH] fix xt_time_match() never matches on Sundays

xt_time_match() in net/netfilter/xt_time.c in kernel 2.6.24 never matches on
Sundays.  On my host I have a rule like

    iptables -A OUTPUT -m time --weekdays Sun -j REJECT

and it never matches.  The problem is in localtime_2(), which uses

    r->weekday = (4 + r->dse) % 7;

to map the epoch day onto a weekday in {0,...,6}.  In particular this gives 0
for Sundays.  But 0 has to be wrong; a weekday of 0 can never match.
xt_time_match() has

    if (!(info->weekdays_match & (1 << current_time.weekday)))
        return false;

and when current_time.weekday = 0, the result of the & is always zero, even when
info->weekdays_match = XT_TIME_ALL_WEEKDAYS = 0xFE.

The solution is to map Sunday onto 7, not 0.  Either of the following patches
does it; they're equivalent.  The first is more compact, the second is probably
clearer.  With the patch (#1) installed, I've confirmed on my host that
'iptables -m time --weekdays Sun' matches again.

Andrew.

Only in linux-source-2.6.24/net/netfilter: .#xt_time.c
Only in linux-source-2.6.24/net/netfilter: #xt_time.c#
diff -ur linux-source-2.6.24.orig/net/netfilter/xt_time.c linux-source-2.6.24/net/netfilter/xt_time.c
--- linux-source-2.6.24.orig/net/netfilter/xt_time.c	2008-01-24 17:58:37.000000000 -0500
+++ linux-source-2.6.24/net/netfilter/xt_time.c	2008-03-05 20:01:37.000000000 -0500
@@ -96,7 +96,8 @@
 	r->dse = time / 86400;
 
 	/* 1970-01-01 (w=0) was a Thursday (4). */
-	r->weekday = (4 + r->dse) % 7;
+	/* -1 and +1 map Sunday onto 7, instead of 0. */
+	r->weekday = (4 + r->dse - 1) % 7 + 1;
 }
 
 static void localtime_3(struct xtm *r, time_t time)
diff -ur linux-source-2.6.24.orig/net/netfilter/xt_time.c linux-source-2.6.24/net/netfilter/xt_time.c
--- linux-source-2.6.24.orig/net/netfilter/xt_time.c	2008-01-24 17:58:37.000000000 -0500
+++ linux-source-2.6.24/net/netfilter/xt_time.c	2008-03-05 20:03:15.000000000 -0500
@@ -97,6 +97,9 @@
 
 	/* 1970-01-01 (w=0) was a Thursday (4). */
 	r->weekday = (4 + r->dse) % 7;
+	/* Map Sunday onto 7, not 0. */
+	if (r->weekday == 0)
+		r->weekday = 7;
 }
 
 static void localtime_3(struct xtm *r, time_t time)

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ