netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* removing gotos considered harmful...
@ 2006-12-22 20:04 David Miller
  2006-12-22 21:11 ` Arnaldo Carvalho de Melo
  2007-01-03  8:08 ` Gerrit Renker
  0 siblings, 2 replies; 6+ messages in thread
From: David Miller @ 2006-12-22 20:04 UTC (permalink / raw)
  To: netdev; +Cc: gerrit, arnaldo.melo


Because of massively painful regressions like the following,
I absolutely refuse to apply "cleanup" patches to remove gotos
for "clarity".  All such patches do is change the code and
potentially add bugs, they don't help in any way at all.

Gerrit, please be more careful next time, and resist the urge to "fix"
stuff that isn't broken just to satisfy your own personal coding
tastes during a conversion.  This is a locally exploitable hole,
all someone has to do is open a few hundred UDP sockets to a
particular destination port and then nobody, not even root, can
so much as run ping successfully.

Arnaldo, sorry I originally thought this bug was added by you, you're
totally innocent this time :-)))

I've submitted this fix to Linus and 2.6.19-stable.

Thanks.

[UDP]: Fix reversed logic in udp_get_port().

When this code was converted to use sk_for_each() the
logic for the "best hash chain length" code was reversed,
breaking everything.

The original code was of the form:

			size = 0;
			do {
				if (++size >= best_size_so_far)
					goto next;
			} while ((sk = sk->next) != NULL);
			best_size_so_far = size;
			best = result;
		next:;

and this got converted into:

			sk_for_each(sk2, node, head)
				if (++size < best_size_so_far) {
					best_size_so_far = size;
					best = result;
				}

Which does something very very different from the original.

Signed-off-by: David S. Miller <davem@davemloft.net>

diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
index 9e1bd37..404dd21 100644
--- a/net/ipv4/udp.c
+++ b/net/ipv4/udp.c
@@ -167,11 +167,14 @@ int udp_get_port(struct sock *sk, unsigned short snum,
 				goto gotit;
 			}
 			size = 0;
-			sk_for_each(sk2, node, head)
-				if (++size < best_size_so_far) {
-					best_size_so_far = size;
-					best = result;
-				}
+			sk_for_each(sk2, node, head) {
+				if (++size >= best_size_so_far)
+					goto next;
+			}
+			best_size_so_far = size;
+			best = result;
+		next:
+			;
 		}
 		result = best;
 		for(i = 0; i < (1 << 16) / UDP_HTABLE_SIZE; i++, result += UDP_HTABLE_SIZE) {

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

end of thread, other threads:[~2007-01-04 10:02 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-12-22 20:04 removing gotos considered harmful David Miller
2006-12-22 21:11 ` Arnaldo Carvalho de Melo
2007-01-03  8:08 ` Gerrit Renker
2007-01-04  0:35   ` Herbert Xu
2007-01-04  1:25   ` David Miller
2007-01-04 10:02     ` Gerrit Renker

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).