netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: John Dykstra <john.dykstra1@gmail.com>
To: Vegard Nossum <vegard.nossum@gmail.com>
Cc: Linux Netdev List <netdev@vger.kernel.org>,
	Ingo Molnar <mingo@elte.hu>,
	Pekka Enberg <penberg@cs.helsinki.fi>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: net: uninitialized loopback addr leaks to userspace
Date: Sun, 07 Jun 2009 16:03:27 -0500	[thread overview]
Message-ID: <1244408607.9064.8.camel@Maple> (raw)
In-Reply-To: <19f34abd0905301323k1498ca3fv31b271de65d60afc@mail.gmail.com>

On Sat, 2009-05-30 at 22:23 +0200, Vegard Nossum wrote:
> It seems that loopback's hardware address is never initialized by the
> kernel. So if userspace attempts to read this address before it has
> been set, the kernel will return some uninitialized data (only 6
> bytes, though).

Thank you for the report, Vegard.

I've been unable to reproduce the problem you describe, using
2.6-30-rc8, this test program and a couple of kernel builds for system
load:

------------------------------------------------------------------
#define REPEAT_COUNT 10000

int childTask() {
	struct ifreq ifreq;
	int fd;
	unsigned char allBits;

	fd = socket(AF_INET, SOCK_DGRAM, 0);
	if (fd < 0){
		printf("Error %s from socket()\n", strerror(errno));
		_exit(-1);
	}

	strncpy(ifreq.ifr_name, "lo", sizeof("lo"));
	if (ioctl (fd, SIOCGIFHWADDR, &ifreq) < 0){
		printf("Error %s from ioctl(SIOCGIFHWADDR) for %s.\n", strerror(errno), ifreq.ifr_name);
		_exit(-1);
	}
	
	allBits = ifreq.ifr_hwaddr.sa_data[0] |
			ifreq.ifr_hwaddr.sa_data[1] |
			ifreq.ifr_hwaddr.sa_data[2] |
			ifreq.ifr_hwaddr.sa_data[3] |
			ifreq.ifr_hwaddr.sa_data[4] |
			ifreq.ifr_hwaddr.sa_data[5];

	if (allBits != 0)
		printf("Device %s -> Ethernet %02x:%02x:%02x:%02x:%02x:%02x\n", ifreq.ifr_name,
			(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[0],
			(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[1],
			(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[2],
			(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[3],
			(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[4],
			(int) ((unsigned char *) &ifreq.ifr_hwaddr.sa_data)[5]);
}


int main(int argc, char *argv[]) {
   	void **child_stack;
	int pid, i, status;

	child_stack = (void **) malloc(16384);

	for (i = 0; i < REPEAT_COUNT; i++){

		pid = clone(childTask, child_stack, CLONE_NEWNET, NULL);
		if (pid < 0){
			printf("Error %s from clone()\n", strerror(errno));
			_exit(-1);
		}
		
		pid = waitpid(pid, &status, __WCLONE);
		if (pid < 0){
			printf("Error %s from waitpid()\n", strerror(errno));
			_exit(-1);
		}
	}   
      
	return 0;
}
------------------------------------------------------------------

Looking at the kernel code, it appears that all bytes of struct
net_device, including the L2 address, are initialized to zeros at
interface creation time.

Can you spot a difference between your test procedures and mine that
would enable me to reproduce the problem?

  --  John


  reply	other threads:[~2009-06-07 21:03 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-05-30 20:23 net: uninitialized loopback addr leaks to userspace Vegard Nossum
2009-06-07 21:03 ` John Dykstra [this message]
2009-06-08 10:00   ` Vegard Nossum
2009-06-08 10:44     ` [PATCH net-next-2.6] net: loopback device dev->addr_len fix Eric Dumazet
2009-06-08 12:13       ` [PATCH net-next-2.6] net: dev_addr_init() fix Eric Dumazet
2009-06-08 12:41         ` Jiri Pirko
2009-06-08 13:06         ` Ingo Molnar
2009-06-08 13:49           ` Eric Dumazet
2009-06-09 12:21             ` David Miller
2009-06-07 23:11 ` net: uninitialized loopback addr leaks to userspace Stephen Hemminger
2009-06-08  9:16   ` Vegard Nossum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1244408607.9064.8.camel@Maple \
    --to=john.dykstra1@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=netdev@vger.kernel.org \
    --cc=penberg@cs.helsinki.fi \
    --cc=vegard.nossum@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).