Subject: Re: rpc xid randomness
To: None <fvdl@netbsd.org>
From: Jun-ichiro itojun Hagino <itojun@itojun.org>
List: tech-userlevel
Date: 09/09/2003 06:37:28
--NextPart-20030909063624-2189100
Content-Type: Text/Plain; charset=us-ascii

> On Mon, Sep 08, 2003 at 07:50:58PM +0900, Jun-ichiro itojun Hagino wrote:
> > 	to summarize,
> > 	- the currently-committed code is not good.  it is not resistant to
> > 	  number reuse/duplication.
> > 	- sequential number with time.tv_sec initialization is resistant to
> > 	  number reuse/duplication, if we don't set date(1).
> > 	- niels' generator is resistant to number reuse/duplcation, and probably
> > 	  there's no chance for duplication on reboot (due to the use of random
> > 	  number as initialization)
> I just want to see some kind of benchmark, like lat_rpc from lmbench.
> Or maybe just spray(8).
> If it doesn't introduce too much overhead, it's fine with me.

	with 65536 iteration:

itojun[starfruit:/tmp] ./a.out 
begin: 1063056924.00613695

end: 1063056925.00897448
diff: 1.00283753

	machine spec and source code is attached.

itojun

--NextPart-20030909063624-2189100
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="1"

NetBSD 1.6Z (STARFRUIT) #436: Mon Sep  8 15:42:50 JST 2003
	itojun@starfruit.itojun.org:/home/itojun/NetBSD/src/sys/arch/i386/compile/STARFRUIT
total memory = 1022 MB
avail memory = 941 MB
using 6144 buffers containing 52476 KB of memory
BIOS32 rev. 0 found at 0xfd780
mainbus0 (root)
cpu0 at mainbus0: (uniprocessor)
cpu0: Intel Pentium M (Banias) (686-class), 1398.89 MHz, id 0x695
cpu0: features a7e9f9bf<FPU,VME,DE,PSE,TSC,MSR,MCE,CX8,SEP,MTRR>
cpu0: features a7e9f9bf<PGE,MCA,CMOV,PAT,CFLUSH,DS,ACPI,MMX>
cpu0: features a7e9f9bf<FXSR,SSE,SSE2,TM,SBF>
pci0 at mainbus0 bus 0: configuration mode 1
pci0: i/o space, memory space enabled, rd/line, rd/mult, wr/inv ok
pchb0 at pci0 dev 0 function 0
pchb0: Intel 82855PM MCH Host Controller (rev. 0x03)
agp0 at pchb0: aperture at 0xd0000000, size 0x10000000
ppb0 at pci0 dev 1 function 0: Intel 82855PM Host-to-AGP Bridge (rev. 0x03)
pci1 at ppb0 bus 1
pci1: i/o space, memory space enabled
vga1 at pci1 dev 0 function 0: ATI Technologies Radeon Mobility M6 LY (AGP) (rev. 0x00)
wsdisplay0 at vga1 kbdmux 1: console (80x25, vt100 emulation)
wsmux1: connecting to wsdisplay0
uhci0 at pci0 dev 29 function 0: Intel 82801DB/DBM USB UHCI Controller #1 (rev. 0x01)
uhci0: interrupting at irq 11
usb0 at uhci0: USB revision 1.0
uhub0 at usb0
uhub0: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub0: 2 ports with 2 removable, self powered
uhci1 at pci0 dev 29 function 1: Intel 82801DB/DBM USB UHCI Controller #2 (rev. 0x01)
uhci1: interrupting at irq 11
usb1 at uhci1: USB revision 1.0
uhub1 at usb1
uhub1: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub1: 2 ports with 2 removable, self powered
uhci2 at pci0 dev 29 function 2: Intel 82801DB/DBM USB UHCI Controller #3 (rev. 0x01)
uhci2: interrupting at irq 11
usb2 at uhci2: USB revision 1.0
uhub2 at usb2
uhub2: Intel UHCI root hub, class 9/0, rev 1.00/1.00, addr 1
uhub2: 2 ports with 2 removable, self powered
Intel 82801DB/DBM USB EHCI Controller (USB serial bus, interface 0x20, revision 0x01) at pci0 dev 29 function 7 not configured
ppb1 at pci0 dev 30 function 0: Intel 82801BAM Hub-to-PCI Bridge (rev. 0x81)
pci2 at ppb1 bus 2
pci2: i/o space, memory space enabled
cbb0 at pci2 dev 0 function 0: Ricoh 5C476 PCI-CardBus bridge (rev. 0xaa)
cbb1 at pci2 dev 0 function 1: Ricoh 5C476 PCI-CardBus bridge (rev. 0xaa)
fwohci0 at pci2 dev 0 function 2: Ricoh 5C552 PCI-CardBus bridge/Firewire (rev. 0x02)
fwohci0: interrupting at irq 11
fwohci0: OHCI 1.0, 00:06:1b:03:10:00:b0:49, 400Mb/s, 2048 max_rec, 4 ir_ctx, 4 it_ctx
wm0 at pci2 dev 1 function 0: Intel i82540EP 1000BASE-T Ethernet, rev. 3
wm0: interrupting at irq 11
wm0: Ethernet address 00:09:6b:fa:6f:49
makphy0 at wm0 phy 1: Marvell 88E1011 Gigabit PHY, rev. 4
makphy0: 10baseT, 10baseT-FDX, 100baseTX, 100baseTX-FDX, 1000baseT, 1000baseT-FDX, auto
cbb2 at pci2 dev 2 function 0: Texas Instruments PCI1410 PCI-CardBus Bridge (rev. 0x01)
cbb0: interrupting at irq 11
cardslot0 at cbb0 slot 0 flags 0
cardbus0 at cardslot0: bus 3 device 0
pcmcia0 at cardslot0
cbb1: interrupting at irq 11
cardslot1 at cbb1 slot 1 flags 0
cardbus1 at cardslot1: bus 6 device 0
pcmcia1 at cardslot1
cbb2: interrupting at irq 11
cardslot2 at cbb2 slot 2 flags 0
cardbus2 at cardslot2: bus 9 device 0
pcmcia2 at cardslot2
pcib0 at pci0 dev 31 function 0
pcib0: Intel 82801DB ISA Bridge (rev. 0x01)
pciide0 at pci0 dev 31 function 1: Intel 82801DBM IDE Controller (ICH4-M) (rev. 0x01)
pciide0: bus-master DMA support present
pciide0: primary channel wired to compatibility mode
wd0 at pciide0 channel 0 drive 0: <IC25N040ATCS04-0>
wd0: drive supports 16-sector PIO transfers, LBA addressing
wd0: 35124 MB, 71363 cyl, 16 head, 63 sec, 512 bytes/sect x 71934020 sectors
wd0: 32-bit data port
wd0: drive supports PIO mode 4, DMA mode 2, Ultra-DMA mode 5 (Ultra/100)
pciide0: primary channel interrupting at irq 14
wd0(pciide0:0:0): using PIO mode 4, Ultra-DMA mode 5 (Ultra/100) (using DMA data transfers)
pciide0: secondary channel wired to compatibility mode
pciide0: disabling secondary channel (no drives)
Intel 82801DB/DBM SMBus Controller (SMBus serial bus, revision 0x01) at pci0 dev 31 function 3 not configured
auich0 at pci0 dev 31 function 5: i82801DB (ICH4) AC-97 Audio
auich0: interrupting at irq 11
auich0: 20 bit precision support
auich0: ac97: Analog Devices AD1981B codec; headphone, 20 bit DAC, no 3D stereo
auich0: ac97: ext id 601<AC97_22,AMAP,VRA>
audio0 at auich0: full duplex, mmap, independent
Intel 82801DB/DBM AC97 Modem Controller (modem communications, revision 0x01) at pci0 dev 31 function 6 not configured
isa0 at pcib0
com0 at isa0 port 0x3f8-0x3ff irq 4: ns16550a, working fifo
com1 at isa0 port 0x2f8-0x2ff irq 3: ns16550a, working fifo
pckbc0 at isa0 port 0x60-0x64
pckbd0 at pckbc0 (kbd slot)
pckbc0: using irq 1 for kbd slot
wskbd0 at pckbd0: console keyboard, using wsdisplay0
pms0 at pckbc0 (aux slot)
pckbc0: using irq 12 for aux slot
wsmouse0 at pms0 mux 0
lpt2 at isa0 port 0x3bc-0x3bf irq : polled
pcppi0 at isa0 port 0x61
midi0 at pcppi0: PC speaker
sysbeep0 at pcppi0
isapnp0 at isa0 port 0x279: ISA Plug 'n Play device support
npx0 at isa0 port 0xf0-0xff: using exception 16
fdc0 at isa0 port 0x3f0-0x3f7 irq 6 drq 2
isapnp0: no ISA Plug 'n Play devices found
apm0 at mainbus0: Power Management spec V1.2
apm0: battery life expectancy: 100%
apm0: A/C state: on
apm0: battery charge state: high
auich0: measured ac97 link rate at 48008 Hz, will use 48000 Hz
Kernelized RAIDframe activated
IPsec: Initialized Security Association Processing.
fw0 at fwohci0: 00:06:1b:03:10:00:b0:49:0a:02:ff:ff:f0:01:00:00
wi0 at pcmcia2 function 0: Dell, TrueMobile 1150 Series PC Card, Version 01.01
wi0: 802.11 address 00:02:2d:6c:db:f6
wi0: using Lucent Embedded WaveLAN/IEEE
wi0: Lucent Firmware: Station (8.10.1)
wi0: supported rates: 1Mbps 2Mbps 5.5Mbps 11Mbps
boot device: wd0
root on wd0a dumps on wd0b
root file system type: ffs
wsdisplay0: screen 1 added (80x25, vt100 emulation)
wsdisplay0: screen 2 added (80x25, vt100 emulation)
wsdisplay0: screen 3 added (80x25, vt100 emulation)
wsdisplay0: screen 4 added (80x25, vt100 emulation)
Cisco Systems, Wireless LAN Adapter, M^? (manufacturer 0x0, product 0x0) Aironet Wireless Communications product 0xa505 (miscellaneous network) at cardbus0 dev 0 function 0 not configured
sa_switch(6507.16 flag 900004): Not enough stacks.
set{u,g}id pid 8103 (netstat) was invoked by uid 1001 ppid 6646 (MozillaFirebird-) with fd 0 closed
com3 at pcmcia1 function 0: serial device
com3: ns16550a, working fifo

--NextPart-20030909063624-2189100
Content-Type: Text/Plain; charset=us-ascii
Content-Disposition: attachment; filename="hoge.c"

#include <sys/time.h>
#include <stdio.h>

int
main()
{
	int i;
	struct timeval tv1, tv2, tv;;

	gettimeofday(&tv1, NULL);
	fprintf(stderr, "begin: %ld.%08ld\n", tv1.tv_sec, tv1.tv_usec);
	for (i = 0; i < 65536; i++) {
		__rpc_getxid();
	}
	printf("\n");
	gettimeofday(&tv2, NULL);
	fprintf(stderr, "end: %ld.%08ld\n", tv2.tv_sec, tv2.tv_usec);

	tv.tv_sec = tv2.tv_sec - tv1.tv_sec;
	tv.tv_usec = tv2.tv_usec - tv1.tv_usec;
	if (tv.tv_usec < 0) {
		tv.tv_sec--;
		tv.tv_usec += 1000000;
	}
	fprintf(stderr, "diff: %ld.%08ld\n", tv.tv_sec, tv.tv_usec);
}

--NextPart-20030909063624-2189100--