linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH][IPv4/IPv6] Setting 0 for unused port field.
@ 2006-07-25  7:38 from-linux-kernel
  2006-07-26  0:01 ` David Miller
  0 siblings, 1 reply; 3+ messages in thread
From: from-linux-kernel @ 2006-07-25  7:38 UTC (permalink / raw)
  To: linux-kernel

Hello.

The recvmsg() for raw socket seems to return random u16 value
from the kernel stack memory since port field is not initialized.
But I'm not sure this patch is correct.
Does raw socket return any information stored in port field?

---------- Start of patch ----------
diff -ur before/net/ipv4/raw.c after/net/ipv4/raw.c
--- before/net/ipv4/raw.c       2006-06-18 10:49:35.000000000 +0900
+++ after/net/ipv4/raw.c        2006-07-25 16:15:26.000000000 +0900
@@ -609,6 +609,7 @@
        if (sin) {
                sin->sin_family = AF_INET;
                sin->sin_addr.s_addr = skb->nh.iph->saddr;
+               sin->sin_port = 0;
                memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
        }
        if (inet->cmsg_flags)
diff -ur before/net/ipv6/raw.c after/net/ipv6/raw.c
--- before/net/ipv6/raw.c       2006-06-18 10:49:35.000000000 +0900
+++ after/net/ipv6/raw.c        2006-07-25 16:16:52.000000000 +0900
@@ -411,6 +411,7 @@
        /* Copy the address. */
        if (sin6) {
                sin6->sin6_family = AF_INET6;
+               sin6->sin6_port = 0;
                ipv6_addr_copy(&sin6->sin6_addr, &skb->nh.ipv6h->saddr);
                sin6->sin6_flowinfo = 0;
                sin6->sin6_scope_id = 0;
---------- End of patch ----------

Regards.

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

* Re: [PATCH][IPv4/IPv6] Setting 0 for unused port field.
  2006-07-25  7:38 [PATCH][IPv4/IPv6] Setting 0 for unused port field from-linux-kernel
@ 2006-07-26  0:01 ` David Miller
  0 siblings, 0 replies; 3+ messages in thread
From: David Miller @ 2006-07-26  0:01 UTC (permalink / raw)
  To: from-linux-kernel; +Cc: linux-kernel, netdev


Tetsuo-san can you please use a correct "From:" field in your patch
postings?  Thank you.

This will allow me to form a correct attribution when I apply your
patches in the future.

This time I had to perform a lengthy web search to find who is behind
these strange from-${LIST_NAME}@i-love.sakura.ne.jp email addresses
:-((  Using these per-listname email addresses really makes things
painful for other developers, even though it might simplify things
for you.

Thanks again.

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

* Re: [PATCH][IPv4/IPv6] Setting 0 for unused port field.
@ 2006-07-26  3:30 from-linux-kernel
  0 siblings, 0 replies; 3+ messages in thread
From: from-linux-kernel @ 2006-07-26  3:30 UTC (permalink / raw)
  To: linux-kernel

Hello.

I ran the following programs and I confirmed that
applying the patch attached to the previous message
suppresses returning random u16 values.

As with IPv4, I found that using
"sin->sin_port = sin->sin_port = htons(skb->nh.iph->protocol);"
instead of "sin->sin_port = 0;"
seems to set protocol number in port field,
but I couldn't find appropriate field for IPv6.

Regards.
--
  Tetsuo Handa

------- send.c -------
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <linux/ip.h>

int main(int argc, char *argv[]) {
	static struct iphdr ip;
	struct sockaddr_in addr;
	const int fd = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
	memset(&addr, 0, sizeof(addr));
	addr.sin_family = AF_INET;
	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
	ip.version = 4;
	ip.ihl = sizeof(struct iphdr) / 4;
	ip.protocol = IPPROTO_RAW;
	ip.saddr = ip.daddr = addr.sin_addr.s_addr;
	while (1) {
		if (sendto(fd, &ip, sizeof(ip), 0, (struct sockaddr *) &addr, sizeof(addr)) == EOF) break;
		sleep(1);
	}
	return 0;
}

------- recv.c -------

#include <stdio.h>
#include <string.h> 
#include <stdlib.h>
#include <unistd.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>

int main(int argc, char *argv[]) {
	const int fd = socket(PF_INET, SOCK_RAW, IPPROTO_RAW);
	while (1) {
		static int counter = 0;
		static char buffer[16384];
		struct sockaddr_in addr;
		socklen_t len = sizeof(addr);
		if (counter++ % 5 == 0) {
			sendto(fd, NULL, 0, 0, (struct sockaddr *) &addr, 0);
		}
		memset(&addr, 0, sizeof(addr));
		if (recvfrom(fd, buffer, sizeof(buffer), 0, (struct sockaddr *) &addr, &len) >= 0) {
			printf("%d %08X %d\n", addr.sin_family, ntohl(addr.sin_addr.s_addr), ntohs(addr.sin_port));
		}
	}
	return 0;
}

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

end of thread, other threads:[~2006-07-26  3:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-07-25  7:38 [PATCH][IPv4/IPv6] Setting 0 for unused port field from-linux-kernel
2006-07-26  0:01 ` David Miller
2006-07-26  3:30 from-linux-kernel

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