Skip to contentSkip to conversation

random: Remove SA_SAMPLE_RANDOM from floppy driver

PATCH In review Matt Mackall 17 participants 58 messages May 5, 2006 – May 31, 2006

Subsystems (17)
Network drivers Arm (32-bit) SCSI USB +13 more subsystems
lore
Share & tools
lore
#3 lore raw

PATCH 4/14 random: Change cpqarray to use add_disk_randomness

In reply to Matt Mackall

Change cpqarray to use add_disk_randomness

Disk devices should use add_disk_randomness rather than SA_SAMPLE_RANDOM

drivers/block/cpqarray.c +3 -2
Index: 2.6/drivers/block/cpqarray.c
===================================================================
@@ -408,8 +408,7 @@ static int cpqarray_register_ctlr( int i
 	}
 	hba[i]->access.set_intr_mask(hba[i], 0);
 	if (request_irq(hba[i]->intr, do_ida_intr,
-		SA_INTERRUPT|SA_SHIRQ|SA_SAMPLE_RANDOM,
-		hba[i]->devname, hba[i]))
+		SA_INTERRUPT|SA_SHIRQ, hba[i]->devname, hba[i]))
 	{
 		printk(KERN_ERR "cpqarray: Unable to get irq %d for %s\n",
 				hba[i]->intr, hba[i]->devname);
@@ -1034,6 +1033,8 @@ static inline void complete_command(cmdl
 
 	complete_buffers(cmd->rq->bio, ok);
 
+	add_disk_randomness(cmd->rq->rq_disk);
+
         DBGPX(printk("Done with %p\n", cmd->rq););
 	end_that_request_last(cmd->rq, ok ? 1 : -EIO);
 }
#1 lore raw

PATCH 2/14 random: Remove redundant SA_SAMPLE_RANDOM from NinjaSCSI

In reply to Matt Mackall

Remove redundant SA_SAMPLE_RANDOM from NinjaSCSI

The scsi layer is already calling add_disk_randomness in scsi_end_request.

ps: ninjas rule!

drivers/scsi/nsp32.c +1 -2
Index: 2.6/drivers/scsi/nsp32.c
===================================================================
@@ -2866,8 +2866,7 @@ static int nsp32_detect(struct scsi_host
 	 */
 	nsp32_do_bus_reset(data);
 
-	ret = request_irq(host->irq, do_nsp32_isr,
-			  SA_SHIRQ | SA_SAMPLE_RANDOM, "nsp32", data);
+	ret = request_irq(host->irq, do_nsp32_isr, SA_SHIRQ, "nsp32", data);
 	if (ret < 0) {
 		nsp32_msg(KERN_ERR, "Unable to allocate IRQ for NinjaSCSI32 "
 			  "SCSI PCI controller. Interrupt: %d", host->irq);
drivers/scsi/pcmcia/nsp_cs.c +1 -1
Index: 2.6/drivers/scsi/pcmcia/nsp_cs.c
===================================================================
@@ -1623,7 +1623,7 @@ static int nsp_cs_probe(struct pcmcia_de
 	/* Interrupt handler */
 	link->irq.Handler	 = &nspintr;
 	link->irq.Instance       = info;
-	link->irq.Attributes     |= (SA_SHIRQ | SA_SAMPLE_RANDOM);
+	link->irq.Attributes     |= SA_SHIRQ;
 
 	/* General socket configuration */
 	link->conf.Attributes	 = CONF_ENABLE_IRQ;
#52 lore raw

PATCH 9/14 random: Remove SA_SAMPLE_RANDOM from i2c drivers

In reply to Matt Mackall

Remove SA_SAMPLE_RANDOM from i2c drivers

There's no obvious reason why all interrupts from an i2c bus interface should be considered a good source of the sort of entropy needed by /dev/random.

drivers/i2c/chips/tps65010.c +2 -3
Index: 2.6/drivers/i2c/chips/tps65010.c
===================================================================
@@ -521,8 +521,9 @@ tps65010_probe(struct i2c_adapter *bus, 
 		goto fail1;
 	}
 
+	irqflags = 0;
 #ifdef	CONFIG_ARM
-	irqflags = SA_SAMPLE_RANDOM | SA_TRIGGER_LOW;
+	irqflags |= SA_TRIGGER_LOW;
 	if (machine_is_omap_h2()) {
 		tps->model = TPS65010;
 		omap_cfg_reg(W4_GPIO58);
@@ -544,8 +545,6 @@ tps65010_probe(struct i2c_adapter *bus, 
 
 		// FIXME set up this board's IRQ ...
 	}
-#else
-	irqflags = SA_SAMPLE_RANDOM;
 #endif
 
 	if (tps->irq > 0) {
#48 lore raw

PATCH 8/14 random: Remove SA_SAMPLE_RANDOM from USB gadget drivers

In reply to Matt Mackall

Remove SA_SAMPLE_RANDOM from USB gadget drivers

There's no a priori reason to think that USB device interrupts will contain "entropy" as defined/required by /dev/random. In fact, most operations will be streaming and bandwidth- or CPU-limited. /dev/random needs unpredictable inputs such as human interaction or chaotic physical processes like turbulence manifested in disk seek times.

drivers/usb/gadget/pxa2xx_udc.c +4 -8
Index: 2.6/drivers/usb/gadget/pxa2xx_udc.c
===================================================================
@@ -2525,10 +2525,8 @@ static int __init pxa2xx_udc_probe(struc
 
 #ifdef CONFIG_ARCH_LUBBOCK
 	if (machine_is_lubbock()) {
-		retval = request_irq(LUBBOCK_USB_DISC_IRQ,
-				lubbock_vbus_irq,
-				SA_INTERRUPT | SA_SAMPLE_RANDOM,
-				driver_name, dev);
+		retval = request_irq(LUBBOCK_USB_DISC_IRQ, lubbock_vbus_irq,
+				     SA_INTERRUPT, driver_name, dev);
 		if (retval != 0) {
 			printk(KERN_ERR "%s: can't get irq %i, err %d\n",
 				driver_name, LUBBOCK_USB_DISC_IRQ, retval);
@@ -2536,10 +2534,8 @@ lubbock_fail0:
 			free_irq(IRQ_USB, dev);
 			return -EBUSY;
 		}
-		retval = request_irq(LUBBOCK_USB_IRQ,
-				lubbock_vbus_irq,
-				SA_INTERRUPT | SA_SAMPLE_RANDOM,
-				driver_name, dev);
+		retval = request_irq(LUBBOCK_USB_IRQ, lubbock_vbus_irq,
+				     SA_INTERRUPT, driver_name, dev);
 		if (retval != 0) {
 			printk(KERN_ERR "%s: can't get irq %i, err %d\n",
 				driver_name, LUBBOCK_USB_IRQ, retval);
drivers/usb/gadget/omap_udc.c +2 -2
Index: 2.6/drivers/usb/gadget/omap_udc.c
===================================================================
@@ -2819,7 +2819,7 @@ bad_on_1710:
 
 	/* USB general purpose IRQ:  ep0, state changes, dma, etc */
 	status = request_irq(pdev->resource[1].start, omap_udc_irq,
-			SA_SAMPLE_RANDOM, driver_name, udc);
+			     0, driver_name, udc);
 	if (status != 0) {
 		ERR( "can't get irq %ld, err %d\n",
 			pdev->resource[1].start, status);
@@ -2828,7 +2828,7 @@ bad_on_1710:
 
 	/* USB "non-iso" IRQ (PIO for all but ep0) */
 	status = request_irq(pdev->resource[2].start, omap_udc_pio_irq,
-			SA_SAMPLE_RANDOM, "omap_udc pio", udc);
+			     0, "omap_udc pio", udc);
 	if (status != 0) {
 		ERR( "can't get irq %ld, err %d\n",
 			pdev->resource[2].start, status);
drivers/usb/gadget/goku_udc.c +2 -3
Index: 2.6/drivers/usb/gadget/goku_udc.c
===================================================================
@@ -1924,8 +1924,7 @@ static int goku_probe(struct pci_dev *pd
 	/* init to known state, then setup irqs */
 	udc_reset(dev);
 	udc_reinit (dev);
-	if (request_irq(pdev->irq, goku_irq, SA_SHIRQ/*|SA_SAMPLE_RANDOM*/,
-			driver_name, dev) != 0) {
+	if (request_irq(pdev->irq, goku_irq, SA_SHIRQ, driver_name, dev)) {
 		DBG(dev, "request interrupt %s failed\n", bufp);
 		retval = -EBUSY;
 		goto done;
@@ -1945,7 +1944,7 @@ static int goku_probe(struct pci_dev *pd
 
 	return 0;
 
-done:
+ done:
 	if (dev)
 		goku_remove (pdev);
 	return retval;
#53 lore raw

PATCH 10/14 random: Remove bogus SA_SAMPLE_RANDOM from mpc52xx serial driver

In reply to Matt Mackall

Remove bogus SA_SAMPLE_RANDOM from mpc52xx serial driver

Serial lines are not a good a priori source of entropy.

drivers/serial/mpc52xx_uart.c +1 -1
Index: 2.6/drivers/serial/mpc52xx_uart.c
===================================================================
@@ -191,7 +191,7 @@ mpc52xx_uart_startup(struct uart_port *p
 
 	/* Request IRQ */
 	ret = request_irq(port->irq, mpc52xx_uart_int,
-		SA_INTERRUPT | SA_SAMPLE_RANDOM, "mpc52xx_psc_uart", port);
+		SA_INTERRUPT, "mpc52xx_psc_uart", port);
 	if (ret)
 		return ret;
 
#4 lore raw

PATCH 5/14 random: Remove bogus SA_SAMPLE_RANDOM from at91 compact flash driver

In reply to Matt Mackall

Remove bogus SA_SAMPLE_RANDOM from at91 compact flash driver

Flash doesn't possess the same unpredictable performance characteristics as traditional media.

drivers/pcmcia/at91_cf.c +1 -2
Index: 2.6/drivers/pcmcia/at91_cf.c
===================================================================
@@ -267,8 +267,7 @@ static int __init at91_cf_probe(struct d
 	);
 
 	/* must be a GPIO; ergo must trigger on both edges */
-	status = request_irq(board->det_pin, at91_cf_irq,
-			SA_SAMPLE_RANDOM, driver_name, cf);
+	status = request_irq(board->det_pin, at91_cf_irq, 0, driver_name, cf);
 	if (status < 0)
 		goto fail0;
 
drivers/mmc/at91_mci.c +1 -1
Index: 2.6/drivers/mmc/at91_mci.c
===================================================================
@@ -889,7 +889,7 @@ static int at91_mci_probe(struct platfor
 	 */
 	if (host->board->det_pin) {
 		ret = request_irq(host->board->det_pin, at91_mmc_det_irq,
-				SA_SAMPLE_RANDOM, DRIVER_NAME, host);
+				  0, DRIVER_NAME, host);
 		if (ret)
 			DBG("couldn't allocate MMC detect irq\n");
 	}
#5 lore raw

PATCH 6/14 random: Remove redundant SA_SAMPLE_RANDOM from touchscreen drivers

In reply to Matt Mackall

Remove redundant SA_SAMPLE_RANDOM from touchscreen drivers

The core input layer is already calling add_input_randomness.

drivers/input/touchscreen/ads7846.c +1 -2
Index: 2.6/drivers/input/touchscreen/ads7846.c
===================================================================
@@ -770,8 +770,7 @@ static int __devinit ads7846_probe(struc
 
 	ts->last_msg = m;
 
-	if (request_irq(spi->irq, ads7846_irq,
-			SA_SAMPLE_RANDOM | SA_TRIGGER_FALLING,
+	if (request_irq(spi->irq, ads7846_irq, SA_TRIGGER_FALLING,
 			spi->dev.bus_id, ts)) {
 		dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
 		err = -EBUSY;
drivers/input/touchscreen/h3600_ts_input.c +2 -4
Index: 2.6/drivers/input/touchscreen/h3600_ts_input.c
===================================================================
@@ -399,16 +399,14 @@ static int h3600ts_connect(struct serio 
 	set_GPIO_IRQ_edge(GPIO_BITSY_NPOWER_BUTTON, GPIO_RISING_EDGE);
 
 	if (request_irq(IRQ_GPIO_BITSY_ACTION_BUTTON, action_button_handler,
-			SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
-			"h3600_action", &ts->dev)) {
+			SA_SHIRQ | SA_INTERRUPT, "h3600_action", &ts->dev)) {
 		printk(KERN_ERR "h3600ts.c: Could not allocate Action Button IRQ!\n");
 		err = -EBUSY;
 		goto fail2;
 	}
 
 	if (request_irq(IRQ_GPIO_BITSY_NPOWER_BUTTON, npower_button_handler,
-			SA_SHIRQ | SA_INTERRUPT | SA_SAMPLE_RANDOM,
-			"h3600_suspend", &ts->dev)) {
+			SA_SHIRQ | SA_INTERRUPT, "h3600_suspend", &ts->dev)) {
 		printk(KERN_ERR "h3600ts.c: Could not allocate Power Button IRQ!\n");
 		err = -EBUSY;
 		goto fail3;
#6 lore raw

PATCH 7/14 random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall

Remove SA_SAMPLE_RANDOM from network drivers

/dev/random wants entropy sources to be both unpredictable and unobservable. Network devices are neither as they may be directly observed and controlled by an attacker. Thus SA_SAMPLE_RANDOM is not appropriate.

drivers/net/3c523.c +1 -2
Index: 2.6/drivers/net/3c523.c
===================================================================
@@ -289,8 +289,7 @@ static int elmc_open(struct net_device *
 
 	elmc_id_attn586();	/* disable interrupts */
 
-	ret = request_irq(dev->irq, &elmc_interrupt, SA_SHIRQ | SA_SAMPLE_RANDOM,
-			  dev->name, dev);
+	ret = request_irq(dev->irq, &elmc_interrupt, SA_SHIRQ, dev->name, dev);
 	if (ret) {
 		printk(KERN_ERR "%s: couldn't get irq %d\n", dev->name, dev->irq);
 		elmc_id_reset586();
drivers/net/3c527.c +1 -1
Index: 2.6/drivers/net/3c527.c
===================================================================
@@ -435,7 +435,7 @@ static int __init mc32_probe1(struct net
 	 *	Grab the IRQ
 	 */
 
-	err = request_irq(dev->irq, &mc32_interrupt, SA_SHIRQ | SA_SAMPLE_RANDOM, DRV_NAME, dev);
+	err = request_irq(dev->irq, &mc32_interrupt, SA_SHIRQ, DRV_NAME, dev);
 	if (err) {
 		release_region(dev->base_addr, MC32_IO_EXTENT);
 		printk(KERN_ERR "%s: unable to get IRQ %d.\n", DRV_NAME, dev->irq);
drivers/net/ibmlana.c +2 -1
Index: 2.6/drivers/net/ibmlana.c
===================================================================
@@ -782,7 +782,8 @@ static int ibmlana_open(struct net_devic
 
 	/* register resources - only necessary for IRQ */
 
-	result = request_irq(priv->realirq, irq_handler, SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
+	result = request_irq(priv->realirq, irq_handler,
+			     SA_SHIRQ, dev->name, dev);
 	if (result != 0) {
 		printk(KERN_ERR "%s: failed to register irq %d\n", dev->name, dev->irq);
 		return result;
drivers/net/ixgb/ixgb_main.c +1 -2
Index: 2.6/drivers/net/ixgb/ixgb_main.c
===================================================================
@@ -258,8 +258,7 @@ ixgb_up(struct ixgb_adapter *adapter)
 
 #endif
 	if((err = request_irq(adapter->pdev->irq, &ixgb_intr,
-				  SA_SHIRQ | SA_SAMPLE_RANDOM,
-				  netdev->name, netdev)))
+			      SA_SHIRQ, netdev->name, netdev)))
 		return err;
 
 	/* disable interrupts and get the hardware into a known state */
drivers/net/mv643xx_eth.c +1 -1
Index: 2.6/drivers/net/mv643xx_eth.c
===================================================================
@@ -778,7 +778,7 @@ static int mv643xx_eth_open(struct net_d
 	int err;
 
 	err = request_irq(dev->irq, mv643xx_eth_int_handler,
-			SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
+			SA_SHIRQ, dev->name, dev);
 	if (err) {
 		printk(KERN_ERR "Can not assign IRQ number to MV643XX_eth%d\n",
 								port_num);
drivers/net/sk_mca.c +1 -1
Index: 2.6/drivers/net/sk_mca.c
===================================================================
@@ -824,7 +824,7 @@ static int skmca_open(struct net_device 
 	/* register resources - only necessary for IRQ */
 	result =
 	    request_irq(priv->realirq, irq_handler,
-			SA_SHIRQ | SA_SAMPLE_RANDOM, "sk_mca", dev);
+			SA_SHIRQ, "sk_mca", dev);
 	if (result != 0) {
 		printk("%s: failed to register irq %d\n", dev->name,
 		       dev->irq);
drivers/net/tg3.c +3 -3
Index: 2.6/drivers/net/tg3.c
===================================================================
@@ -6602,12 +6602,12 @@ static int tg3_request_irq(struct tg3 *t
 		fn = tg3_msi;
 		if (tp->tg3_flags2 & TG3_FLG2_1SHOT_MSI)
 			fn = tg3_msi_1shot;
-		flags = SA_SAMPLE_RANDOM;
+		flags = 0;
 	} else {
 		fn = tg3_interrupt;
 		if (tp->tg3_flags & TG3_FLAG_TAGGED_STATUS)
 			fn = tg3_interrupt_tagged;
-		flags = SA_SHIRQ | SA_SAMPLE_RANDOM;
+		flags = SA_SHIRQ;
 	}
 	return (request_irq(tp->pdev->irq, fn, flags, dev->name, dev));
 }
@@ -6626,7 +6626,7 @@ static int tg3_test_interrupt(struct tg3
 	free_irq(tp->pdev->irq, dev);
 
 	err = request_irq(tp->pdev->irq, tg3_test_isr,
-			  SA_SHIRQ | SA_SAMPLE_RANDOM, dev->name, dev);
+			  SA_SHIRQ, dev->name, dev);
 	if (err)
 		return err;
 
drivers/net/cris/eth_v10.c +1 -1
Index: 2.6/drivers/net/cris/eth_v10.c
===================================================================
@@ -672,7 +672,7 @@ e100_open(struct net_device *dev)
 	/* allocate the irq corresponding to the receiving DMA */
 
 	if (request_irq(NETWORK_DMA_RX_IRQ_NBR, e100rxtx_interrupt,
-			SA_SAMPLE_RANDOM, cardname, (void *)dev)) {
+			0, cardname, dev)) {
 		goto grace_exit0;
 	}
 
drivers/net/e1000/e1000_main.c +1 -2
Index: 2.6/drivers/net/e1000/e1000_main.c
===================================================================
@@ -463,8 +463,7 @@ e1000_up(struct e1000_adapter *adapter)
 	}
 #endif
 	if ((err = request_irq(adapter->pdev->irq, &e1000_intr,
-		              SA_SHIRQ | SA_SAMPLE_RANDOM,
-		              netdev->name, netdev))) {
+			       SA_SHIRQ, netdev->name, netdev))) {
 		DPRINTK(PROBE, ERR,
 		    "Unable to allocate interrupt Error: %d\n", err);
 		return err;
#2 lore raw

PATCH 3/14 random: Make CCISS use add_disk_randomness

In reply to Matt Mackall

Make CCISS use add_disk_randomness

Disk devices should use the add_disk_randomness API rather than SA_SAMPLE_RANDOM.

drivers/block/cciss.c +2 -2
Index: 2.6/drivers/block/cciss.c
===================================================================
@@ -1221,6 +1221,7 @@ static void cciss_softirq_done(struct re
 	printk("Done with %p\n", rq);
 #endif /* CCISS_DEBUG */
 
+	add_disk_randomness(rq->rq_disk);
 	spin_lock_irqsave(&h->lock, flags);
 	end_that_request_last(rq, rq->errors);
 	cmd_free(h, cmd,1);
@@ -3152,8 +3153,7 @@ static int __devinit cciss_init_one(stru
 	/* make sure the board interrupts are off */
 	hba[i]->access.set_intr_mask(hba[i], CCISS_INTR_OFF);
 	if( request_irq(hba[i]->intr[SIMPLE_MODE_INT], do_cciss_intr,
-		SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM, 
-			hba[i]->devname, hba[i])) {
+		SA_INTERRUPT | SA_SHIRQ, hba[i]->devname, hba[i])) {
 		printk(KERN_ERR "cciss: Unable to get irq %d for %s\n",
 			hba[i]->intr[SIMPLE_MODE_INT], hba[i]->devname);
 		goto clean2;
#0 lore raw

PATCH 1/14 random: Remove SA_SAMPLE_RANDOM from floppy driver

Remove SA_SAMPLE_RANDOM from floppy driver

The floppy driver is already calling add_disk_randomness as it should, so this was redundant.

include/asm-alpha/floppy.h +2 -3
Index: 2.6/include/asm-alpha/floppy.h
===================================================================
@@ -26,9 +26,8 @@
 #define fd_enable_irq()         enable_irq(FLOPPY_IRQ)
 #define fd_disable_irq()        disable_irq(FLOPPY_IRQ)
 #define fd_cacheflush(addr,size) /* nothing */
-#define fd_request_irq()        request_irq(FLOPPY_IRQ, floppy_interrupt, \
-					    SA_INTERRUPT|SA_SAMPLE_RANDOM, \
-				            "floppy", NULL)
+#define fd_request_irq()        request_irq(FLOPPY_IRQ, floppy_interrupt,\
+					    SA_INTERRUPT, "floppy", NULL)
 #define fd_free_irq()           free_irq(FLOPPY_IRQ, NULL);
 
 #ifdef CONFIG_PCI
include/asm-arm/floppy.h +1 -1
Index: 2.6/include/asm-arm/floppy.h
===================================================================
@@ -25,7 +25,7 @@
 
 #define fd_inb(port)		inb((port))
 #define fd_request_irq()	request_irq(IRQ_FLOPPYDISK,floppy_interrupt,\
-					SA_INTERRUPT|SA_SAMPLE_RANDOM,"floppy",NULL)
+					    SA_INTERRUPT,"floppy",NULL)
 #define fd_free_irq()		free_irq(IRQ_FLOPPYDISK,NULL)
 #define fd_disable_irq()	disable_irq(IRQ_FLOPPYDISK)
 #define fd_enable_irq()		enable_irq(IRQ_FLOPPYDISK)
include/asm-arm26/floppy.h +1 -1
Index: 2.6/include/asm-arm26/floppy.h
===================================================================
@@ -22,7 +22,7 @@
 
 #define fd_inb(port)		inb((port))
 #define fd_request_irq()	request_irq(IRQ_FLOPPYDISK,floppy_interrupt,\
-					SA_INTERRUPT|SA_SAMPLE_RANDOM,"floppy",NULL)
+					SA_INTERRUPT,"floppy",NULL)
 #define fd_free_irq()		free_irq(IRQ_FLOPPYDISK,NULL)
 #define fd_disable_irq()	disable_irq(IRQ_FLOPPYDISK)
 #define fd_enable_irq()		enable_irq(IRQ_FLOPPYDISK)
include/asm-i386/floppy.h +2 -3
Index: 2.6/include/asm-i386/floppy.h
===================================================================
@@ -147,9 +147,8 @@ static int fd_request_irq(void)
 		return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
 						   "floppy", NULL);
 	else
-		return request_irq(FLOPPY_IRQ, floppy_interrupt,
-						   SA_INTERRUPT|SA_SAMPLE_RANDOM,
-						   "floppy", NULL);	
+		return request_irq(FLOPPY_IRQ, floppy_interrupt, SA_INTERRUPT,
+				   "floppy", NULL);
 
 }
 
include/asm-mips/mach-generic/floppy.h +1 -1
Index: 2.6/include/asm-mips/mach-generic/floppy.h
===================================================================
@@ -98,7 +98,7 @@ static inline void fd_disable_irq(void)
 static inline int fd_request_irq(void)
 {
 	return request_irq(FLOPPY_IRQ, floppy_interrupt,
-	                   SA_INTERRUPT | SA_SAMPLE_RANDOM, "floppy", NULL);
+	                   SA_INTERRUPT, "floppy", NULL);
 }
 
 static inline void fd_free_irq(void)
include/asm-mips/mach-jazz/floppy.h +1 -1
Index: 2.6/include/asm-mips/mach-jazz/floppy.h
===================================================================
@@ -90,7 +90,7 @@ static inline void fd_disable_irq(void)
 static inline int fd_request_irq(void)
 {
 	return request_irq(FLOPPY_IRQ, floppy_interrupt,
-	                   SA_INTERRUPT | SA_SAMPLE_RANDOM, "floppy", NULL);
+	                   SA_INTERRUPT, "floppy", NULL);
 }
 
 static inline void fd_free_irq(void)
include/asm-parisc/floppy.h +2 -4
Index: 2.6/include/asm-parisc/floppy.h
===================================================================
@@ -159,10 +159,8 @@ static int fd_request_irq(void)
 		return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
 						   "floppy", NULL);
 	else
-		return request_irq(FLOPPY_IRQ, floppy_interrupt,
-						   SA_INTERRUPT|SA_SAMPLE_RANDOM,
-						   "floppy", NULL);	
-
+		return request_irq(FLOPPY_IRQ, floppy_interrupt, SA_INTERRUPT,
+				   "floppy", NULL);
 }
 
 static unsigned long dma_mem_alloc(unsigned long size)
include/asm-powerpc/floppy.h +1 -2
Index: 2.6/include/asm-powerpc/floppy.h
===================================================================
@@ -28,8 +28,7 @@
 #define fd_disable_irq()        disable_irq(FLOPPY_IRQ)
 #define fd_cacheflush(addr,size) /* nothing */
 #define fd_request_irq()        request_irq(FLOPPY_IRQ, floppy_interrupt, \
-					    SA_INTERRUPT|SA_SAMPLE_RANDOM, \
-				            "floppy", NULL)
+					    SA_INTERRUPT, "floppy", NULL)
 #define fd_free_irq()           free_irq(FLOPPY_IRQ, NULL);
 
 #ifdef CONFIG_PCI
include/asm-ppc/floppy.h +2 -4
Index: 2.6/include/asm-ppc/floppy.h
===================================================================
@@ -99,10 +99,8 @@ static int fd_request_irq(void)
 		return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
 						   "floppy", NULL);
 	else
-		return request_irq(FLOPPY_IRQ, floppy_interrupt,
-						   SA_INTERRUPT|SA_SAMPLE_RANDOM,
-						   "floppy", NULL);
-
+		return request_irq(FLOPPY_IRQ, floppy_interrupt, SA_INTERRUPT,
+				   "floppy", NULL);
 }
 
 static int vdma_dma_setup(char *addr, unsigned long size, int mode, int io)
include/asm-sh/floppy.h +3 -4
Index: 2.6/include/asm-sh/floppy.h
===================================================================
@@ -147,11 +147,10 @@ static int fd_request_irq(void)
 {
 	if(can_use_virtual_dma)
 		return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
-						   "floppy", NULL);
+				   "floppy", NULL);
 	else
-		return request_irq(FLOPPY_IRQ, floppy_interrupt,
-						   SA_INTERRUPT|SA_SAMPLE_RANDOM,
-						   "floppy", NULL);	
+		return request_irq(FLOPPY_IRQ, floppy_interrupt, SA_INTERRUPT,
+				   "floppy", NULL);
 
 }
 
include/asm-x86_64/floppy.h +2 -4
Index: 2.6/include/asm-x86_64/floppy.h
===================================================================
@@ -147,10 +147,8 @@ static int fd_request_irq(void)
 		return request_irq(FLOPPY_IRQ, floppy_hardint,SA_INTERRUPT,
 						   "floppy", NULL);
 	else
-		return request_irq(FLOPPY_IRQ, floppy_interrupt,
-						   SA_INTERRUPT|SA_SAMPLE_RANDOM,
-						   "floppy", NULL);	
-
+		return request_irq(FLOPPY_IRQ, floppy_interrupt, SA_INTERRUPT,
+				   "floppy", NULL);
 }
 
 static unsigned long dma_mem_alloc(unsigned long size)
#57 lore raw

PATCH 14/14 random: Remove add_interrupt_randomness

Remove add_interrupt_randomness

This patch removes add_interrupt_randomness, which was only used by IRQ handlers that used to set SA_SAMPLE_RANDOM.

drivers/char/random.c +2 -36
Index: 2.6/drivers/char/random.c
===================================================================
@@ -127,18 +127,12 @@
  *
  * 	void add_input_randomness(unsigned int type, unsigned int code,
  *                                unsigned int value);
- * 	void add_interrupt_randomness(int irq);
+ *      void add_disk_randomness(struct gendisk *disk);
  *
  * add_input_randomness() uses the input layer interrupt timing, as well as
  * the event type information from the hardware.
  *
- * add_interrupt_randomness() uses the inter-interrupt timing as random
- * inputs to the entropy pool.  Note that not all interrupts are good
- * sources of randomness!  For example, the timer interrupts is not a
- * good choice, because the periodicity of the interrupts is too
- * regular, and hence predictable to an attacker.  Disk interrupts are
- * a better measure, since the timing of the disk interrupts are more
- * unpredictable.
+ * add_disk_randomness() does the same for disk devices.
  *
  * All of these routines try to estimate how many bits of randomness a
  * particular randomness source.  They do this by keeping track of the
@@ -557,7 +551,6 @@ struct timer_rand_state {
 };
 
 static struct timer_rand_state input_timer_state;
-static struct timer_rand_state *irq_timer_state[NR_IRQS];
 
 /*
  * This function adds entropy to the entropy "pool" by using timing
@@ -647,15 +640,6 @@ void add_input_randomness(unsigned int t
 			     (type << 4) ^ code ^ (code >> 4) ^ value);
 }
 
-void add_interrupt_randomness(int irq)
-{
-	if (irq >= NR_IRQS || irq_timer_state[irq] == 0)
-		return;
-
-	DEBUG_ENT("irq event %d\n", irq);
-	add_timer_randomness(irq_timer_state[irq], 0x100 + irq);
-}
-
 void add_disk_randomness(struct gendisk *disk)
 {
 	if (!disk || !disk->random)
@@ -901,24 +885,6 @@ static int __init rand_initialize(void)
 }
 module_init(rand_initialize);
 
-void rand_initialize_irq(int irq)
-{
-	struct timer_rand_state *state;
-
-	if (irq >= NR_IRQS || irq_timer_state[irq])
-		return;
-
-	/*
-	 * If kmalloc returns null, we just won't use that entropy
-	 * source.
-	 */
-	state = kmalloc(sizeof(struct timer_rand_state), GFP_KERNEL);
-	if (state) {
-		memset(state, 0, sizeof(struct timer_rand_state));
-		irq_timer_state[irq] = state;
-	}
-}
-
 void rand_initialize_disk(struct gendisk *disk)
 {
 	struct timer_rand_state *state;
include/linux/random.h +0 -4
Index: 2.6/include/linux/random.h
===================================================================
@@ -42,12 +42,8 @@ struct rand_pool_info {
 
 #ifdef __KERNEL__
 
-extern void rand_initialize_irq(int irq);
-
 extern void add_input_randomness(unsigned int type, unsigned int code,
 				 unsigned int value);
-extern void add_interrupt_randomness(int irq);
-
 extern void get_random_bytes(void *buf, int nbytes);
 void generate_random_uuid(unsigned char uuid_out[16]);
 
#54 lore raw

PATCH 11/14 random: Remove UML usage of SA_SAMPLE_RANDOM

In reply to Matt Mackall

Remove UML usage of SA_SAMPLE_RANDOM

UML can't know that its input sources are unpredictable or unobservable and should not assume or pretend that they are. It should instead gather entropy from the host's /dev/random.

arch/um/drivers/line.c +2 -3
Index: 2.6/arch/um/drivers/line.c
===================================================================
@@ -406,7 +406,7 @@ static irqreturn_t line_write_interrupt(
 int line_setup_irq(int fd, int input, int output, struct line *line, void *data)
 {
 	struct line_driver *driver = line->driver;
-	int err = 0, flags = SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM;
+	int err = 0, flags = SA_INTERRUPT | SA_SHIRQ;
 
 	if (input)
 		err = um_request_irq(driver->read_irq, fd, IRQ_READ,
@@ -767,8 +767,7 @@ void register_winch_irq(int fd, int tty_
 	spin_unlock(&winch_handler_lock);
 
 	if(um_request_irq(WINCH_IRQ, fd, IRQ_READ, winch_interrupt,
-			  SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
-			  "winch", winch) < 0)
+			  SA_INTERRUPT | SA_SHIRQ, "winch", winch) < 0)
 		printk("register_winch_irq - failed to register IRQ\n");
 }
 
arch/um/drivers/mconsole_kern.c +1 -2
Index: 2.6/arch/um/drivers/mconsole_kern.c
===================================================================
@@ -779,8 +779,7 @@ static int mconsole_init(void)
 	register_reboot_notifier(&reboot_notifier);
 
 	err = um_request_irq(MCONSOLE_IRQ, sock, IRQ_READ, mconsole_interrupt,
-			     SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM,
-			     "mconsole", (void *)sock);
+			     SA_INTERRUPT | SA_SHIRQ, "mconsole", sock);
 	if (err){
 		printk("Failed to get IRQ for management console\n");
 		return(1);
arch/um/drivers/port_kern.c +4 -6
Index: 2.6/arch/um/drivers/port_kern.c
===================================================================
@@ -104,9 +104,8 @@ static int port_accept(struct port_list 
 		  .telnetd_pid 	= pid,
 		  .port 	= port });
 
-	if(um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt, 
-			  SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM, 
-			  "telnetd", conn)){
+	if(um_request_irq(TELNETD_IRQ, socket[0], IRQ_READ, pipe_interrupt,
+			  SA_INTERRUPT | SA_SHIRQ, "telnetd", conn)){
 		printk(KERN_ERR "port_accept : failed to get IRQ for "
 		       "telnetd\n");
 		goto out_free;
@@ -185,9 +184,8 @@ void *port_data(int port_num)
 		       port_num, -fd);
 		goto out_free;
 	}
-	if(um_request_irq(ACCEPT_IRQ, fd, IRQ_READ, port_interrupt, 
-			  SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM, "port",
-			  port)){
+	if(um_request_irq(ACCEPT_IRQ, fd, IRQ_READ, port_interrupt,
+			  SA_INTERRUPT | SA_SHIRQ, "port", port)){
 		printk(KERN_ERR "Failed to get IRQ for port %d\n", port_num);
 		goto out_close;
 	}
arch/um/drivers/xterm_kern.c +2 -3
Index: 2.6/arch/um/drivers/xterm_kern.c
===================================================================
@@ -53,9 +53,8 @@ int xterm_fd(int socket, int *pid_out)
 		  .new_fd 	= -1 });
 	init_completion(&data->ready);
 
-	err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt, 
-			     SA_INTERRUPT | SA_SHIRQ | SA_SAMPLE_RANDOM, 
-			     "xterm", data);
+	err = um_request_irq(XTERM_IRQ, socket, IRQ_READ, xterm_interrupt,
+			     SA_INTERRUPT | SA_SHIRQ, "xterm", data);
 	if (err){
 		printk(KERN_ERR "xterm_fd : failed to get IRQ for xterm, "
 		       "err = %d\n",  err);
arch/um/kernel/irq.c +1 -2
Index: 2.6/arch/um/kernel/irq.c
===================================================================
@@ -474,8 +474,7 @@ int init_aio_irq(int irq, char *name, ir
 	}
 
 	err = um_request_irq(irq, fds[0], IRQ_READ, handler,
-			     SA_INTERRUPT | SA_SAMPLE_RANDOM, name,
-			     (void *) (long) fds[0]);
+			     SA_INTERRUPT, name, (void *) (long) fds[0]);
 	if (err) {
 		printk("init_aio_irq - : um_request_irq failed, err = %d\n",
 		       err);
arch/um/kernel/sigio_kern.c +1 -2
Index: 2.6/arch/um/kernel/sigio_kern.c
===================================================================
@@ -31,8 +31,7 @@ int write_sigio_irq(int fd)
 	int err;
 
 	err = um_request_irq(SIGIO_WRITE_IRQ, fd, IRQ_READ, sigio_interrupt,
-			     SA_INTERRUPT | SA_SAMPLE_RANDOM, "write sigio",
-			     NULL);
+			     SA_INTERRUPT, "write sigio", NULL);
 	if(err){
 		printk("write_sigio_irq : um_request_irq failed, err = %d\n",
 		       err);
#55 lore raw

PATCH 12/14 random: Remove not very useful SA_SAMPLE_RANDOM from lubbock

In reply to Matt Mackall

Remove not very useful SA_SAMPLE_RANDOM from lubbock

arch/arm/mach-pxa/lubbock.c +1 -1
Index: 2.6/arch/arm/mach-pxa/lubbock.c
===================================================================
@@ -342,7 +342,7 @@ static int lubbock_mci_init(struct devic
 	init_timer(&mmc_timer);
 	mmc_timer.data = (unsigned long) data;
 	return request_irq(LUBBOCK_SD_IRQ, lubbock_detect_int,
-			SA_SAMPLE_RANDOM, "lubbock-sd-detect", data);
+			0, "lubbock-sd-detect", data);
 }
 
 static int lubbock_mci_get_ro(struct device *dev)
#56 lore raw

PATCH 13/14 random: Remove SA_SAMPLE_RANDOM from IRQ fastpath

In reply to Matt Mackall

Remove SA_SAMPLE_RANDOM

This removes the SA_SAMPLE_RANDOM interface which was not used with sufficient paranoia and introduced an extra branch test into all IRQ handling.

arch/arm/kernel/irq.c +0 -14
Index: 2.6/arch/arm/kernel/irq.c
===================================================================
@@ -361,9 +361,6 @@ __do_irq(unsigned int irq, struct irqact
 		action = action->next;
 	} while (action);
 
-	if (status & SA_SAMPLE_RANDOM)
-		add_interrupt_randomness(irq);
-
 	spin_lock_irq(&irq_controller_lock);
 
 	return retval;
@@ -670,17 +667,6 @@ int setup_irq(unsigned int irq, struct i
 	 * so we have to be careful not to interfere with a
 	 * running system.
 	 */
-	if (new->flags & SA_SAMPLE_RANDOM) {
-		/*
-		 * This function might sleep, we want to call it first,
-		 * outside of the atomic block.
-		 * Yes, this might clear the entropy pool if the wrong
-		 * driver is attempted to be loaded, without actually
-		 * installing a new handler, but is this really a problem,
-		 * only the sysadmin is able to do this.
-		 */
-	        rand_initialize_irq(irq);
-	}
 
 	/*
 	 * The following block of code has to be executed atomically
arch/arm26/kernel/irq.c +0 -17
Index: 2.6/arch/arm26/kernel/irq.c
===================================================================
@@ -202,9 +202,6 @@ __do_irq(unsigned int irq, struct irqact
 		action = action->next;
 	} while (action);
 
-	if (status & SA_SAMPLE_RANDOM)
-		add_interrupt_randomness(irq);
-
 	spin_lock_irq(&irq_controller_lock);
 }
 
@@ -452,17 +449,6 @@ int setup_irq(unsigned int irq, struct i
 	 * so we have to be careful not to interfere with a
 	 * running system.
 	 */
-	if (new->flags & SA_SAMPLE_RANDOM) {
-		/*
-		 * This function might sleep, we want to call it first,
-		 * outside of the atomic block.
-		 * Yes, this might clear the entropy pool if the wrong
-		 * driver is attempted to be loaded, without actually
-		 * installing a new handler, but is this really a problem,
-		 * only the sysadmin is able to do this.
-		 */
-	        rand_initialize_irq(irq);
-	}
 
 	/*
 	 * The following block of code has to be executed atomically
@@ -530,9 +516,6 @@ int setup_irq(unsigned int irq, struct i
  *	SA_SHIRQ		Interrupt is shared
  *
  *	SA_INTERRUPT		Disable local interrupts while processing
- *
- *	SA_SAMPLE_RANDOM	The interrupt can be used for entropy
- *
  */
 
 //FIXME - handler used to return void - whats the significance of the change?
arch/frv/kernel/irq-routing.c +0 -2
Index: 2.6/arch/frv/kernel/irq-routing.c
===================================================================
@@ -90,8 +90,6 @@ void distribute_irqs(struct irq_group *g
 				action = action->next;
 			} while (action);
 
-			if (status & SA_SAMPLE_RANDOM)
-				add_interrupt_randomness(irq);
 			local_irq_disable();
 		}
 	}
arch/frv/kernel/irq.c +0 -14
Index: 2.6/arch/frv/kernel/irq.c
===================================================================
@@ -345,9 +345,6 @@ asmlinkage void do_NMI(void)
  *	SA_SHIRQ		Interrupt is shared
  *
  *	SA_INTERRUPT		Disable local interrupts while processing
- *
- *	SA_SAMPLE_RANDOM	The interrupt can be used for entropy
- *
  */
 
 int request_irq(unsigned int irq,
@@ -577,17 +574,6 @@ int setup_irq(unsigned int irq, struct i
 	 * so we have to be careful not to interfere with a
 	 * running system.
 	 */
-	if (new->flags & SA_SAMPLE_RANDOM) {
-		/*
-		 * This function might sleep, we want to call it first,
-		 * outside of the atomic block.
-		 * Yes, this might clear the entropy pool if the wrong
-		 * driver is attempted to be loaded, without actually
-		 * installing a new handler, but is this really a problem,
-		 * only the sysadmin is able to do this.
-		 */
-		rand_initialize_irq(irq);
-	}
 
 	/* must juggle the interrupt processing stuff with interrupts disabled */
 	spin_lock_irqsave(&level->lock, flags);
arch/h8300/kernel/ints.c +0 -5
Index: 2.6/arch/h8300/kernel/ints.c
===================================================================
@@ -158,9 +158,6 @@ int request_irq(unsigned int irq, 
 	irq_handle->devname = devname;
 	irq_list[irq] = irq_handle;
 
-	if (irq_handle->flags & SA_SAMPLE_RANDOM)
-		rand_initialize_irq(irq);
-
 	enable_irq(irq);
 	return 0;
 }
@@ -222,8 +219,6 @@ asmlinkage void process_int(int irq, str
 		if (irq_list[irq]) {
 			irq_list[irq]->handler(irq, irq_list[irq]->dev_id, fp);
 			irq_list[irq]->count++;
-			if (irq_list[irq]->flags & SA_SAMPLE_RANDOM)
-				add_interrupt_randomness(irq);
 		}
 	} else {
 		BUG();
arch/h8300/platform/h8s/ints.c +1 -5
Index: 2.6/arch/h8300/platform/h8s/ints.c
===================================================================
@@ -192,9 +192,7 @@ int request_irq(unsigned int irq,
 	irq_handle->dev_id  = dev_id;
 	irq_handle->devname = devname;
 	irq_list[irq] = irq_handle;
-	if (irq_handle->flags & SA_SAMPLE_RANDOM)
-		rand_initialize_irq(irq);
-	
+
 	/* enable interrupt */
 	/* compatible i386  */
 	if (irq >= EXT_IRQ0 && irq <= EXT_IRQ15)
@@ -270,8 +268,6 @@ asmlinkage void process_int(unsigned lon
 		if (irq_list[vec]) {
 			irq_list[vec]->handler(vec, irq_list[vec]->dev_id, fp);
 			irq_list[vec]->count++;
-			if (irq_list[vec]->flags & SA_SAMPLE_RANDOM)
-				add_interrupt_randomness(vec);
 		}
 	} else {
 		BUG();
arch/sparc64/kernel/irq.c +0 -18
Index: 2.6/arch/sparc64/kernel/irq.c
===================================================================
@@ -437,20 +437,6 @@ int request_irq(unsigned int irq, irqret
 	if (unlikely(!bucket->irq_info))
 		return -ENODEV;
 
-	if ((bucket != &pil0_dummy_bucket) && (irqflags & SA_SAMPLE_RANDOM)) {
-		/*
-	 	 * This function might sleep, we want to call it first,
-	 	 * outside of the atomic block. In SA_STATIC_ALLOC case,
-		 * random driver's kmalloc will fail, but it is safe.
-		 * If already initialized, random driver will not reinit.
-	 	 * Yes, this might clear the entropy pool if the wrong
-	 	 * driver is attempted to be loaded, without actually
-	 	 * installing a new handler, but is this really a problem,
-	 	 * only the sysadmin is able to do this.
-	 	 */
-		rand_initialize_irq(irq);
-	}
-
 	spin_lock_irqsave(&irq_action_lock, flags);
 
 	if (check_irq_sharing(bucket->pil, irqflags)) {
@@ -673,10 +659,6 @@ static void process_bucket(int irq, stru
 		} else {
 			upa_writel(ICLR_IDLE, bp->iclr);
 		}
-
-		/* Test and add entropy */
-		if (random & SA_SAMPLE_RANDOM)
-			add_interrupt_randomness(irq);
 	}
 out:
 	bp->flags &= ~IBF_INPROGRESS;
include/asm-mips/signal.h +0 -1
Index: 2.6/include/asm-mips/signal.h
===================================================================
@@ -107,7 +107,6 @@ typedef unsigned long old_sigset_t;		/* 
  * SA_INTERRUPT is also used by the irq handling routines.
  * SA_SHIRQ flag is for shared interrupt support on PCI and EISA.
  */
-#define SA_SAMPLE_RANDOM	SA_RESTART
 
 #ifdef CONFIG_TRAD_SIGNALS
 #define sig_uses_siginfo(ka)	((ka)->sa.sa_flags & SA_SIGINFO)
include/asm-xtensa/signal.h +0 -1
Index: 2.6/include/asm-xtensa/signal.h
===================================================================
@@ -118,7 +118,6 @@ typedef struct {
  * SA_INTERRUPT is also used by the irq handling routines.
  * SA_SHIRQ is for shared interrupt support on PCI and EISA.
  */
-#define SA_SAMPLE_RANDOM	SA_RESTART
 #define SA_SHIRQ		0x04000000
 #define SA_PROBEIRQ		0x08000000
 #endif
include/linux/signal.h +0 -1
Index: 2.6/include/linux/signal.h
===================================================================
@@ -16,7 +16,6 @@
  * SA_SHIRQ is for shared interrupt support on PCI and EISA.
  * SA_PROBEIRQ is set by callers when they expect sharing mismatches to occur
  */
-#define SA_SAMPLE_RANDOM	SA_RESTART
 #define SA_SHIRQ		0x04000000
 #define SA_PROBEIRQ		0x08000000
 
kernel/irq/handle.c +0 -2
Index: 2.6/kernel/irq/handle.c
===================================================================
@@ -92,8 +92,6 @@ fastcall int handle_IRQ_event(unsigned i
 		action = action->next;
 	} while (action);
 
-	if (status & SA_SAMPLE_RANDOM)
-		add_interrupt_randomness(irq);
 	local_irq_disable();
 
 	return retval;
kernel/irq/manage.c +0 -12
Index: 2.6/kernel/irq/manage.c
===================================================================
@@ -185,17 +185,6 @@ int setup_irq(unsigned int irq, struct i
 	 * so we have to be careful not to interfere with a
 	 * running system.
 	 */
-	if (new->flags & SA_SAMPLE_RANDOM) {
-		/*
-		 * This function might sleep, we want to call it first,
-		 * outside of the atomic block.
-		 * Yes, this might clear the entropy pool if the wrong
-		 * driver is attempted to be loaded, without actually
-		 * installing a new handler, but is this really a problem,
-		 * only the sysadmin is able to do this.
-		 */
-		rand_initialize_irq(irq);
-	}
 
 	/*
 	 * The following block of code has to be executed atomically
@@ -364,7 +353,6 @@ EXPORT_SYMBOL(free_irq);
  *
  *	SA_SHIRQ		Interrupt is shared
  *	SA_INTERRUPT		Disable local interrupts while processing
- *	SA_SAMPLE_RANDOM	The interrupt can be used for entropy
  *
  */
 int request_irq(unsigned int irq,
#7 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 3 lines · Matt Mackall

Remove SA_SAMPLE_RANDOM from network drivers

/dev/random wants entropy sources to be both unpredictable and unobservable. Network devices are neither as they may be directly observed and controlled by an attacker. Thus SA_SAMPLE_RANDOM is not appropriate.

I thought I saw an analysis somewhere of why it was actually OK to include randomness from network devices (or even basically any interrupt source that isn't periodic on a fundamental hardware level). It had something to do with investigating interrupt arrival time from real-time network traffic; they hooked a logic analyzer of sorts up to the physical ethernet cable itself and to the system bus of the destination computer (and wrote software that recorded a TSC timestamp of every interrupt). Essentially the interaction between the occasional ethernet retransmission, variable internal network card latencies and queues, variable CPU-dependent interrupt latencies, critical sections in the OS, etc, plus the high-resolution nature of the TSC used for a seed value made it a chaotic system and basically cryptographically impossible to predict the interrupt data. It's possible that the analysis I saw was later proven incorrect; but I'd be interested if you've seen some paper or research on the topic that I haven't, I'd be interested in references.

Cheers,
Kyle Moffett

#8 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 8 lines · Kyle Moffett
Quoted 6 lines · Matt Mackall

Remove SA_SAMPLE_RANDOM from network drivers

/dev/random wants entropy sources to be both unpredictable and unobservable. Network devices are neither as they may be directly observed and controlled by an attacker. Thus SA_SAMPLE_RANDOM is not appropriate.

Quoted 16 lines

I thought I saw an analysis somewhere of why it was actually OK to include randomness from network devices (or even basically any interrupt source that isn't periodic on a fundamental hardware level). It had something to do with investigating interrupt arrival time from real-time network traffic; they hooked a logic analyzer of sorts up to the physical ethernet cable itself and to the system bus of the destination computer (and wrote software that recorded a TSC timestamp of every interrupt). Essentially the interaction between the occasional ethernet retransmission, variable internal network card latencies and queues, variable CPU-dependent interrupt latencies, critical sections in the OS, etc, plus the high-resolution nature of the TSC used for a seed value made it a chaotic system and basically cryptographically impossible to predict the interrupt data. It's possible that the analysis I saw was later proven incorrect; but I'd be interested if you've seen some paper or research on the topic that I haven't, I'd be interested in references.

I haven't seen such an analysis, scholarly or otherwise and my bias here is to lean towards the paranoid.

Assuming a machine with no TSC and an otherwise quiescent ethernet (hackers burning the midnight oil), I think most of the hard-to-analyze bits above get pretty transparent.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
maintainer
#9 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 6 lines · Matt Mackall

I haven't seen such an analysis, scholarly or otherwise and my bias here is to lean towards the paranoid.

Assuming a machine with no TSC and an otherwise quiescent ethernet (hackers burning the midnight oil), I think most of the hard-to-analyze bits above get pretty transparent.

As always, whether or not the packet arrival times could be guessable and/or controlled by an attacker really depends on your threat model. For someone who has an ethernet monitor attached directly to the segment right next to your computer, it's very likely that they would be successful in guessing the inputs into the entropy pool. However, an attacker with physical access to your machine could probably do all sorts of other things, such as install a keyboard sniffer, etc.

For a remote attacker, life gets much more difficult. Each switch, router, and bridge effectively has a queue into which packets must flow through, and that is _not_ known to a remote attacker. This is especially true today, when most people don't even use repeaters, but rather switches/bridges, which effectly make each ethernet connection to each host its own separate collision domain (indeed that term doesn't even apply for modern high-speed ethernets).

I've always thought the right answer is that whether or not network packet arrival times should be used as entropy input should be configurable, since depending on the environment, it might or might not be safe, and for some hosts (particularly diskless servers), the network might be the only source of entropy available to them.

- Ted

#10 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 24 lines · On Fri, 5 May 2006 15:11:27 -0400 Theodore Tso <[email protected]> wrote:
Quoted 6 lines · Matt Mackall

I haven't seen such an analysis, scholarly or otherwise and my bias here is to lean towards the paranoid.

Assuming a machine with no TSC and an otherwise quiescent ethernet (hackers burning the midnight oil), I think most of the hard-to-analyze bits above get pretty transparent.

As always, whether or not the packet arrival times could be guessable and/or controlled by an attacker really depends on your threat model. For someone who has an ethernet monitor attached directly to the segment right next to your computer, it's very likely that they would be successful in guessing the inputs into the entropy pool. However, an attacker with physical access to your machine could probably do all sorts of other things, such as install a keyboard sniffer, etc.

For a remote attacker, life gets much more difficult. Each switch, router, and bridge effectively has a queue into which packets must flow through, and that is _not_ known to a remote attacker. This is especially true today, when most people don't even use repeaters, but rather switches/bridges, which effectly make each ethernet connection to each host its own separate collision domain (indeed that term doesn't even apply for modern high-speed ethernets).

Quoted 7 lines

I've always thought the right answer is that whether or not network packet arrival times should be used as entropy input should be configurable, since depending on the environment, it might or might not be safe, and for some hosts (particularly diskless servers), the network might be the only source of entropy available to them.

- Ted

An added problem is that many of the high speed interfaces have interrupt mitigation. The chip will hold off the interrupt for a short time to try and aggregate multiple packets. This has the effect of synchronizing the interrupt, and reduces the entropy, especially under load. NAPI also eliminates much of the entropy in network drivers. So the quality of the entropy also depends on the chipset. Most of the older, dumber hardware probably has better entropy but worse performance.

#11 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Theodore Tso
Quoted 24 lines · Theodore Tso
Quoted 6 lines · Matt Mackall

I haven't seen such an analysis, scholarly or otherwise and my bias here is to lean towards the paranoid.

Assuming a machine with no TSC and an otherwise quiescent ethernet (hackers burning the midnight oil), I think most of the hard-to-analyze bits above get pretty transparent.

As always, whether or not the packet arrival times could be guessable and/or controlled by an attacker really depends on your threat model. For someone who has an ethernet monitor attached directly to the segment right next to your computer, it's very likely that they would be successful in guessing the inputs into the entropy pool. However, an attacker with physical access to your machine could probably do all sorts of other things, such as install a keyboard sniffer, etc.

For a remote attacker, life gets much more difficult. Each switch, router, and bridge effectively has a queue into which packets must flow through, and that is _not_ known to a remote attacker. This is especially true today, when most people don't even use repeaters, but rather switches/bridges, which effectly make each ethernet connection to each host its own separate collision domain (indeed that term doesn't even apply for modern high-speed ethernets).

Quoted 5 lines

I've always thought the right answer is that whether or not network packet arrival times should be used as entropy input should be configurable, since depending on the environment, it might or might not be safe, and for some hosts (particularly diskless servers), the network might be the only source of entropy available to them.

Nonetheless, the current SA_SAMPLE_RANDOM scheme should go. A) it's in the IRQ fast path B) most of its users are bogus which strongly indicates it's a bad API.

Instead (if we want network entropy) we should add an add_network_randomness call in some central location in the network stack (probably right next to netpoll's RX hooks) and probably have it compiled out by default.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
maintainer
#41 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall

From: Matt Mackall <[email protected]>
Date: Fri, 05 May 2006 11:42:35 -0500

Quoted 8 lines

Remove SA_SAMPLE_RANDOM from network drivers

/dev/random wants entropy sources to be both unpredictable and unobservable. Network devices are neither as they may be directly observed and controlled by an attacker. Thus SA_SAMPLE_RANDOM is not appropriate.

Besides the other issues discussed, what you are doing is essentially making a headless machine with a quiet disk have next to zero entropy available.

I don't think we can seriously consider this patch, as I've seen real users run into this lack of entropy issue.

If you want to do a generic thing in the networking to create entropy, fine, but it must be on by default or else people in the above situation (and there are many) will have an unusable /dev/random and friends.

#42 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 10 lines · David S. Miller

From: Matt Mackall <[email protected]>
Date: Fri, 05 May 2006 11:42:35 -0500

Quoted 7 lines

Remove SA_SAMPLE_RANDOM from network drivers

/dev/random wants entropy sources to be both unpredictable and unobservable. Network devices are neither as they may be directly observed and controlled by an attacker. Thus SA_SAMPLE_RANDOM is not appropriate.

Quoted 8 lines
Quoted 1 line

Besides the other issues discussed, what you are doing is essentially making a headless machine with a quiet disk have next to zero entropy available.

I don't think we can seriously consider this patch, as I've seen real users run into this lack of entropy issue.

And my claim is they don't actually have any entropy. If they want to continue fooling themselves, they can copy the device node for /dev/urandom to /dev/random.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
maintainer
#43 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

From: Matt Mackall <[email protected]>
Date: Fri, 5 May 2006 18:03:24 -0500

Quoted 3 lines

And my claim is they don't actually have any entropy. If they want to continue fooling themselves, they can copy the device node for /dev/urandom to /dev/random.

Prove it and convince us.

The burdon of proof is on your shoulders, since you're the one who wants to just rip it out without any satisfactory replacement.

#49 lore raw

Re: [PATCH 8/14] random: Remove SA_SAMPLE_RANDOM from USB gadget drivers

In reply to Matt Mackall
Quoted 8 lines · Matt Mackall

Remove SA_SAMPLE_RANDOM from USB gadget drivers

There's no a priori reason to think that USB device interrupts will contain "entropy" as defined/required by /dev/random. In fact, most operations will be streaming and bandwidth- or CPU-limited. /dev/random needs unpredictable inputs such as human interaction or chaotic physical processes like turbulence manifested in disk seek times.

You may remove SA_SAMPLE_RANDOM from disk interrupts on the same grounds, because flash-based "IDE" drives have no seek. Indeed, with careful choice of components, setup, and placement of sniffing equipment you may construct a case where you can predict interrupt times.

But it's too artificial to matter in real life.

Come on, let's get real. A few low bits of TSC are random enough (for just about any interrupt source).

Attackers will probably look for easier ways to hack your crypto than predicting /dev/random.
--
vda

maintainer
#12 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 8 lines · Matt Mackall

Nonetheless, the current SA_SAMPLE_RANDOM scheme should go. A) it's in the IRQ fast path B) most of its users are bogus which strongly indicates it's a bad API.

Instead (if we want network entropy) we should add an add_network_randomness call in some central location in the network stack (probably right next to netpoll's RX hooks) and probably have it compiled out by default.

I disagree. It really wants to be a run-time controllable thing, and probably on a per-interface/per-device driver basis, since it should be up to the system administrator who is deploying the box, not the developer or distribution compiling the kernel, to make that determination.

Also, the entropy sampling *really* wants to be done in the hard IRQ handling path, not some place higher in the stack since the scheduler would smooth out the unpredictable timing information. Moving it into the interrupt routines is in fact a problem for CONFIG_PREEMPT_RT, since the device driver's interrupt handlers become a schedulable entity, since the IRQ handling is moved into a separate kernel thread. So I would much prefer to see the entropy sampling stay in its current location, since people using real-time deserve real randomness too. (In fact, some of them may have a **much** stronger need for it. :-)

As far as your reasons that you've given, (A) I find it hard to believe a single conditional jump is really going to be measurable, and (B) sure, fix the bad users, but the downside of screwing up SA_SAMPLE_RANDOM is fairly limited; it only messes up the entropy estimator, and in practice most users are using /dev/urandom anyway. The random driver's algorithms are designed so that /dev/random can be world writable, and an attacker can write arbitrary data, include all zero's, without degrading the entropy in the pool.(*) Hence, while a bad user of SA_SAMPLE_RANDOM should be fixed, it is hardly a catastrophic failure.

- Ted

(*)So if User A writes data which he knows into /dev/random, it doesn't help User A guess what /dev/random or /dev/urandom might produce next --- and if User B doesn't know what User A has written into the pool, User B's job just got harder. So if User's B, C, and D all do the same thing, the net result is that effective unpredictability of the random pool has increased for everyone.)

#44 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to David S. Miller
Quoted 8 lines
Quoted 5 lines

Remove SA_SAMPLE_RANDOM from network drivers
/dev/random wants entropy sources to be both unpredictable and unobservable. Network devices are neither as they may be directly observed and controlled by an attacker. Thus SA_SAMPLE_RANDOM is not appropriate.

Besides the other issues discussed, what you are doing is essentially making a headless machine with a quiet disk have next to zero entropy available.

Consider adding a cheap soundcard to the system and run 'audio-entropyd': www.vanheusden.com/aed

Folkert van Heusden

Signature · 3 lines
www.biglumber.com <- site where one can exchange PGP key signatures 
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
#45 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 2 lines · Folkert van Heusden

Consider adding a cheap soundcard to the system and run 'audio-entropyd': www.vanheusden.com/aed

Can't get much cheaper than the crap that comes on every motherboard these days ;-)

Also aren't temp sensors (on the disk or mobo) a good entropy source?

Lee

#13 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Theodore Tso
Quoted 10 lines · Theodore Tso
Quoted 8 lines · Matt Mackall

Nonetheless, the current SA_SAMPLE_RANDOM scheme should go. A) it's in the IRQ fast path B) most of its users are bogus which strongly indicates it's a bad API.

Instead (if we want network entropy) we should add an add_network_randomness call in some central location in the network stack (probably right next to netpoll's RX hooks) and probably have it compiled out by default.

Quoted 5 lines

I disagree. It really wants to be a run-time controllable thing, and probably on a per-interface/per-device driver basis, since it should be up to the system administrator who is deploying the box, not the developer or distribution compiling the kernel, to make that determination.

Ok, I can agree with that. The interface would have to be extended to pass more than just IRQ number to do anything vaguely intelligent in random.c.

Quoted 6 lines

Also, the entropy sampling *really* wants to be done in the hard IRQ handling path, not some place higher in the stack since the scheduler would smooth out the unpredictable timing information. Moving it into the interrupt routines is in fact a problem for CONFIG_PREEMPT_RT, since the device driver's interrupt handlers become a schedulable entity, since the IRQ handling is moved into a separate kernel thread.

Yes, PREEMPT_RT definitely does break my proposal. Sigh.

Quoted 3 lines

So I would much prefer to see the entropy sampling stay in its current location, since people using real-time deserve real randomness too. (In fact, some of them may have a **much** stronger need for it. :-)

This is the point that bothers me. It's one thing to optimistically mix network samples (or any other convenient source) into the entropy pool. I'm all for that. The more, the better.

But let's take a step back from network devices and look at entropy accounting in the abstract for a moment. The whole point of /dev/random vs /dev/urandom is: entropy(output) < entropy(input) so that even if the hash function is broken, we can't guess the internal pool state and we still have some security. Consider these cases:

Case 1:
Hash function not broken: /dev/random and /dev/urandom are equally secure, but /dev/random blocks at inconvenient moments. One should thus really use /dev/urandom for everything unless one suspects that an attacker is able to observe and record enough /dev/urandom output that they'll be able to make use of it should the following happen (aka forward security):

Case 2:
Hash function broken, entropy accounting is conservative: /dev/urandom is breakable when entropy runs low because it's revealing more internal entropy than it's collecting and an attacker can eventually collect enough information to guess the internal state. Fortunately /dev/random stays secure but blocks.

Case 3:
Hash function broken, entropy accounting is over-optimistic:
/dev/urandom and /dev/random are both equally insecure because both are revealing more internal entropy than they're collecting. So you should just use /dev/urandom because at least it doesn't block.

Putting aside all the practical issue of what exactly is entropy and what decent entropy sources are, we should be able to agree on this much. And this basically says that if you do your entropy accounting badly, you throw the baby out with the bathwater.

Now I'll throw out a proposed definition of entropy for our purposes:
the amount of information in a sample that's both unpredictable and unobservable. If something is partially observable or predictable, we must take the minimum of the two.

Our current entropy estimator assumes its sources are unobservable and are at least largely unpredictable. This is arguably not the case, but that's a separate discussion. Let's assume for the sake of argument that our entropy estimator gets it right.

But network traffic should be _assumed_ to be observable to some degree. Everything else in network security makes the assumption that traffic is completely snoopable. By contrast, we assume people can't see us type our passwords[1]. So while our entropy estimator assumes observability == 0, for the network case, 0 < observability <= 1. And if it's greater than what our entropy estimator assumes, our entropy estimates are now too optimistic and /dev/random security degrades to that of /dev/urandom.

Yes, this is all strictly theoretical. But the usefulness of /dev/random is exactly as theoretical. So if you use /dev/random for it's theoretical advantages (and why else would you?), this defeats that.

On the other hand, another approach to this is probably to just be much more paranoid about our entropy estimates and take a factor of 10 or so off of all of them (and do our accounting in fixed point). Thoughts?

[1] though hearing someone type a password is actually enough

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#14 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 7 lines · Matt Mackall
Quoted 3 lines

So I would much prefer to see the entropy sampling stay in its current location, since people using real-time deserve real randomness too. (In fact, some of them may have a **much** stronger need for it. :-)

This is the point that bothers me. It's one thing to optimistically mix network samples (or any other convenient source) into the entropy pool. I'm all for that. The more, the better.

Isnt it possible to use timestamps on the received packages. So you get the indeterministic timing from interrupt context and can process it in a less hot path. Also the timestamps are helpfull for other stuff, also.

Gruss
Bernd

maintainer
#15 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 10 lines · Matt Mackall

Case 3:
Hash function broken, entropy accounting is over-optimistic:
/dev/urandom and /dev/random are both equally insecure because both are revealing more internal entropy than they're collecting. So you should just use /dev/urandom because at least it doesn't block.

Putting aside all the practical issue of what exactly is entropy and what decent entropy sources are, we should be able to agree on this much. And this basically says that if you do your entropy accounting badly, you throw the baby out with the bathwater.

Agreed, but I'd an additional point of nuance; this assumes that the attacker (call him Boris for the sake of argument) can actually gain access to enough /dev/random or /dev/urandom outputs, and be knowledgable about all other calls to /dev/random and exactly when they happen (since entropy extractions cause the TSC to be mixed into the pool) so Boris can can actually determine the contents of the pool. Note that simply "breaking" a cryptographic hash, in the sense of finding two input values that collide to the same output value, does not mean that the hash has been sufficiently analyzed that it would be possible to accomplish this feat. And given that it took 80,000 CPU hours to determine find this collision, and the complexity of the attack was 2**51, it seems highly likely that with a poolsize of 4096 bits, that it would take a huge amount of /dev/random extractions, complete with the exact TSC timestamp when the extractions were happening, such that an attacker would be able to have enough information to break the pool.

Does this mean we should __depend__ on this? No, we should always do the best job that we can. But it's also fair to say that even if the hash function is "broken", that the results are not automatically going to be catastrophic. If the attacker can't get their hands on enough of an output stream from /dev/random, then it's not likely to do much. For an attacker who only has network access, this could be quite difficult.

Quoted 8 lines

But network traffic should be _assumed_ to be observable to some degree. Everything else in network security makes the assumption that traffic is completely snoopable. By contrast, we assume people can't see us type our passwords[1]. So while our entropy estimator assumes observability == 0, for the network case, 0 < observability <= 1. And if it's greater than what our entropy estimator assumes, our entropy estimates are now too optimistic and /dev/random security degrades to that of /dev/urandom.

The timing of network arrivals is observable to *some* degree. Of course, so is the timing from block I/O interrupts. The question is whether or not it is predictable enough at the finest resolution. For block device interrupts, there has been papers showing that air currents inside the spinning media is chaotic enough that it can actually influence the timing at which interrupts are returned --- at least for systems a decade ago. To be honest, it would probably be a useful and worthwhile masters thesis for a grad student to revisit the problem using modern disk drive technologies, controllers, and interconnects to see if this is still a valid assumption.

For network traffic, again, it depends on your threat model. For an attacker stationed in Fort Mead, Maryland, with over a dozen router and ethernet switches between them and the target system, there are enough packet queues and buffers that any hope of observing packet interarrival times is almost certainly hopeless. As I've said, if an attacker has direct physical access to the ethernet segment between your host and the switch, then while the attacker is busy installing a keyboard switcher and possibly doing a black bag job on your hard disk to install monitoring software directly in the OS software, yes, the FBI agent could probably install something on the ethernet between your host and the switch that could precisely measure packet arrival times very accurately. Is that something the system administrator should care about? Maybe, maybe not.

That's why I think it should be configurable. If you don't have a real hardware number generator, maybe blocking would be preferable to not having good entropy. But in other circumstances, what people need is the best possible randomness they can get, and their security is not enhanced by simply taking it away from them altogether. That makes about as much sense as GNOME making its applications "easier to use" by removing functionality (to quote Linus).

Quoted 4 lines

Yes, this is all strictly theoretical. But the usefulness of /dev/random is exactly as theoretical. So if you use /dev/random for it's theoretical advantages (and why else would you?), this defeats that.

This becomes a philosophical arugment. Yes, we should strive for as much theoretical perfection as possible. But at the same time, we need to live in the real world, and adding network entropy which can defeat the bored high school student in Russia using some black hat toolkit they downloaded of the internet is useful --- even if it can't defeat the NSA/FBI agent who can perform a black bag job and place a monitoring device on your internal ethernet segment.

- Ted

#50 lore raw

Re: [PATCH 8/14] random: Remove SA_SAMPLE_RANDOM from USB gadget drivers

In reply to Denis Vlasenko
Quoted 2 lines · Denis Vlasenko
Quoted 1 line · Matt Mackall

Remove SA_SAMPLE_RANDOM from USB gadget drivers

It's conventional to post USB patches to linux-usb-devel, or at least to CC that list.

Quoted 6 lines
Quoted 6 lines

There's no a priori reason to think that USB device interrupts will contain "entropy" as defined/required by /dev/random. In fact, most operations will be streaming and bandwidth- or CPU-limited. /dev/random needs unpredictable inputs such as human interaction or chaotic physical processes like turbulence manifested in disk seek times.

And that'd be why you removed that SAMPLE_RANDOM from the Lubbock VBUS irqs ... which come from users connecting (by hand!) a USB cable. :)

You shouldn't add spaces before labels, or change indents from pure-tab to tabs-plus-four-spaces.

Admittedly OMAP _now_ has access to the FIPS-certified hardware RNG, so for that platform it's hard to justify needing other entropy sources. But on the other hand, DMA completion IRQs aren't exactly predictable either, and it doesn't necessarily hurt to salt a high entropy pool with some less-high entropy inputs.

Quoted 5 lines

Come on, let's get real. A few low bits of TSC are random enough (for just about any interrupt source).

Attackers will probably look for easier ways to hack your crypto than predicting /dev/random.

I'm not sure I'd go that far. But I'd agree that this particular patch should not be merged.

Reasonable people could have arguments about the quality of a given entropy source ... and the SA_SAMPLE_RANDOM mechanism has no way to indicate that quality, thereby wrongly implying that all interrupts have the same entropy contribution. A few Kbytes/second is very different from a few bits per hour.

But I disagree with the blanket assertion that only high quality crypto-ready RNG sources should ever be provided ... and that lower quality sources are useless. Sure it helps if attackers need extra hours to make the attack, but extra minutes help too.

- Dave

#51 lore raw

Re: [PATCH 8/14] random: Remove SA_SAMPLE_RANDOM from USB gadget drivers

Quoted 15 lines · David Brownell
Quoted 2 lines · Denis Vlasenko
Quoted 1 line · Matt Mackall

Remove SA_SAMPLE_RANDOM from USB gadget drivers

It's conventional to post USB patches to linux-usb-devel, or at least to CC that list.

Quoted 6 lines
Quoted 6 lines

There's no a priori reason to think that USB device interrupts will contain "entropy" as defined/required by /dev/random. In fact, most operations will be streaming and bandwidth- or CPU-limited. /dev/random needs unpredictable inputs such as human interaction or chaotic physical processes like turbulence manifested in disk seek times.

Quoted 2 lines

And that'd be why you removed that SAMPLE_RANDOM from the Lubbock VBUS irqs ... which come from users connecting (by hand!) a USB cable. :)

Really I removed it because I want SAMPLE_RANDOM to go away and most of the users were either pretty trivial (the Lubbock case), wrong (a bunch of block devices, etc), or suspect (network, i2c).

Quoted 2 lines

You shouldn't add spaces before labels, or change indents from pure-tab to tabs-plus-four-spaces.

Show me where I did that, please.

Quoted 5 lines

Admittedly OMAP _now_ has access to the FIPS-certified hardware RNG, so for that platform it's hard to justify needing other entropy sources. But on the other hand, DMA completion IRQs aren't exactly predictable either, and it doesn't necessarily hurt to salt a high entropy pool with some less-high entropy inputs.

The sampling is fine. It's the _accounting_ that's at issue.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#16 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Theodore Tso
Quoted 12 lines · Theodore Tso
Quoted 10 lines · Matt Mackall

Case 3:
Hash function broken, entropy accounting is over-optimistic:
/dev/urandom and /dev/random are both equally insecure because both are revealing more internal entropy than they're collecting. So you should just use /dev/urandom because at least it doesn't block.

Putting aside all the practical issue of what exactly is entropy and what decent entropy sources are, we should be able to agree on this much. And this basically says that if you do your entropy accounting badly, you throw the baby out with the bathwater.

Quoted 7 lines

Agreed, but I'd an additional point of nuance; this assumes that the attacker (call him Boris for the sake of argument) can actually gain access to enough /dev/random or /dev/urandom outputs, and be knowledgable about all other calls to /dev/random and exactly when they happen (since entropy extractions cause the TSC to be mixed into the pool) so Boris can can actually determine the contents of the pool.

Yes, that's assumed. Because otherwise /dev/urandom would be sufficient in all cases.

Quoted 4 lines

Note that simply "breaking" a cryptographic hash, in the sense of finding two input values that collide to the same output value, does not mean that the hash has been sufficiently analyzed that it would be possible to accomplish this feat.

I'm not talking about any existing attacks, I'm talking about what would theoretically be possible were a first preimage attack on our hash to become practical.

Quoted 7 lines

Does this mean we should __depend__ on this? No, we should always do the best job that we can. But it's also fair to say that even if the hash function is "broken", that the results are not automatically going to be catastrophic. If the attacker can't get their hands on enough of an output stream from /dev/random, then it's not likely to do much. For an attacker who only has network access, this could be quite difficult.

All agreed. But that applies equally to /dev/urandom. The only thing that distinguishes the two is entropy accounting and entropy accounting only makes a difference if it's conservative.

I am _not_ arguing that any of this is practical. I'm arguing that it's completely beside the point.

Quoted 11 lines
Quoted 8 lines

But network traffic should be _assumed_ to be observable to some degree. Everything else in network security makes the assumption that traffic is completely snoopable. By contrast, we assume people can't see us type our passwords[1]. So while our entropy estimator assumes observability == 0, for the network case, 0 < observability <= 1. And if it's greater than what our entropy estimator assumes, our entropy estimates are now too optimistic and /dev/random security degrades to that of /dev/urandom.

The timing of network arrivals is observable to *some* degree. Of course, so is the timing from block I/O interrupts.

That's a whole 'nother topic we can tackle separately.

Quoted 1 line

For network traffic, again, it depends on your threat model.

Here's a threat model: I remotely break into your LAN and 0wn insecure Windows box X that's one switch jump away from the web server Y that processes your credit card transactions. I use standard techniques to kick the switch into broadcast mode so I can see all its traffic or maybe I break into the switch itself and temporarily isolate Y from the rest of the world so that only X can talk to it. I'm still in Russia, but I might as well be in the same room.

Quoted 7 lines

That's why I think it should be configurable. If you don't have a real hardware number generator, maybe blocking would be preferable to not having good entropy. But in other circumstances, what people need is the best possible randomness they can get, and their security is not enhanced by simply taking it away from them altogether. That makes about as much sense as GNOME making its applications "easier to use" by removing functionality (to quote Linus).

Again, I think it's perfectly reasonable to sample from all sorts of sources. All my issues are about the entropy accounting.

Quoted 5 lines
Quoted 4 lines

Yes, this is all strictly theoretical. But the usefulness of /dev/random is exactly as theoretical. So if you use /dev/random for it's theoretical advantages (and why else would you?), this defeats that.

Quoted 7 lines

This becomes a philosophical arugment. Yes, we should strive for as much theoretical perfection as possible. But at the same time, we need to live in the real world, and adding network entropy which can defeat the bored high school student in Russia using some black hat toolkit they downloaded of the internet is useful --- even if it can't defeat the NSA/FBI agent who can perform a black bag job and place a monitoring device on your internal ethernet segment.

No thoughts on scaling back our entropy estimates?

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
maintainer
#24 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall

From: Matt Mackall <[email protected]>
Date: Sat, 6 May 2006 11:48:08 -0500

Quoted 2 lines

But network traffic should be _assumed_ to be observable to some degree.

But, and this is a huge but and the one that matters, nothing between the network packet arriving and the interrupt being delivered is observable outside of the machine.

The PHY of the network card has some tiny delays internal to how it decodes the coding sequence on the wire and passes it on to the MAC.

The MAC and the bus frontend have all sorts of timing and delays wrt. making sure the necessary RX descriptor is fetched and if a free packet buffer is available, DMA'ing the packet into memory.

If the chip has hw interrupt mitigation enabled, these add other delays and almost across the board these interrupt mitigation timers are relatively imprecise. If the first packet that starts the time hits half-way between two clock ticks, the mitigation fire will be a half clock off.

There are propagation delays for the interrupt to get to the cpu. Every implementation is there, but the delays are there and highly variable. In many cases, it's the time to send a cacheline over the main system bus to the target cpu (MSI, or sparc64 style PCI controllers which turn traditional INTX signals into 64-byte interrupt packets targeted at specific cpus).

Then there is the trap entry delay, and perhaps the cpu has interrupts disabled while holding a spinlock or whatever. Then there are all the cache misses and instruction execution delays just to get into the interrupt handler.

None of this is observable or predictable outside of the machine. So the arguments about the SA_SAMPLE_RANDOM samples being risky in the networking drivers is bogus.

Please put together a test case that proves that /dev/random can be predicted just by being on the wire sniffing packets going into the machine. Then you will have my full support.

Everything shown so far is theoretical swiss cheese.

maintainer
#17 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall

From: Matt Mackall <[email protected]>
Date: Sat, 6 May 2006 15:33:04 -0500

Quoted 10 lines · Theodore Tso
Quoted 1 line

For network traffic, again, it depends on your threat model.

Here's a threat model: I remotely break into your LAN and 0wn insecure Windows box X that's one switch jump away from the web server Y that processes your credit card transactions. I use standard techniques to kick the switch into broadcast mode so I can see all its traffic or maybe I break into the switch itself and temporarily isolate Y from the rest of the world so that only X can talk to it. I'm still in Russia, but I might as well be in the same room.

Doesn't matter.

You cannot measure any of the delays happening between network packet being seen on the wire to interrupt handler actually executing.

There is so much variable jitter and it depends on so many minute details at both the hardware and software level, that you can't guess this stuff. What's the load on the box? How many clock cycles does it take for an interrupt to propagate to the cpu, how many clock cycles from interrupt reception until the cpu executes the interrupt handler, how are the hw interrupt mitigation facilities programmed and how do their timers work, what is the wire to PHY delay, what is the PHY to MAC delay, how many cycles does it take for the FIFO to DMA the packet into main memory, what is the delay from DMA'ing the packet to main memory and the indication of the interrupt condition. etc. etc. etc.

You can't know any of that.

Please put together a real reproducable attack that others can run too and would validate justify SA_SAMPLE_RANDOM from networking drivers. It's all swiss cheese theory until you do this. And we should not be making kernel changes merely due to swiss cheese theory.

maintainer
#18 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 3 lines · Matt Mackall

I'm not talking about any existing attacks, I'm talking about what would theoretically be possible were a first preimage attack on our hash to become practical.

Note that even the first preimage attack on a hash (none of which have been demonstrated for MD-5, SHA-0, SHA-1, or reduced-round or otherwise weakened versions of the same, as far as I know), would be sufficient by itself to guarantee that the attacker would be able to determine the contents of the entropy pool from the output stream. A preimage attack merely states that the attacker can find a _single_ input which hashes to a particular output value of the crypto checksum. Because we are hashing the entire pool to produce each chunk of output, by the pigeonhole principle and the observed statistical random distribution properties of the hash, there are a very large number of potential pool values that could result in that particular hash (we are compressing 4096 bits down to 80 bits).

So a successful cryptographic attack would have to combine a successful preimage attack of the cryptographic hash core with additional refinements so that the preimage attack technique can produce *multiple" (in fact, probably all possible) preimages, and correlate that with the pool mixing function to successful rule out preimages based on the successive outputs from the algorithm (assuming that the attacker can determine the exact TSC timestamp when the extraction happened, since that's mixed into the pool as part of the extraction process).

The point is that we are using a *very* conservative design, unlike Yarrow which used a minimally-sized entropy pool and which would be far more vulnerable to the discovery of a preimage attack on the hash.

Quoted 3 lines

All agreed. But that applies equally to /dev/urandom. The only thing that distinguishes the two is entropy accounting and entropy accounting only makes a difference if it's conservative.

OK, but in that case, in order to make /dev/urandom as secure as possible (which is what most programs would use anyway for things like session keys, etc.), we shouldn't be throwing away the entropy from network interrupts, but rather always collecting the input and merely changing how much entropy credits to assign to various interrupts.

After all, the only application where /dev/random is really justified is for key generation of long-term public/private keypairs, and in those cases you almost always have a keyboard attached since the security requirements are such that you probably don't want ot be doing it remotely anyway.

My philosophy on the entropy accounting is that it isn't necessarily accurate; sometimes it over-estimates entropy, and sometimes it under-estimates entropy. The main thing it does is to make it significantly harder for an attacker to gather a huge number of data points to use for carrying out a theoretical cryptographic attack. It provides additional security, but it isn't necessarily perfect (nothing in this world is).

Quoted 7 lines

Here's a threat model: I remotely break into your LAN and 0wn insecure Windows box X that's one switch jump away from the web server Y that processes your credit card transactions. I use standard techniques to kick the switch into broadcast mode so I can see all its traffic or maybe I break into the switch itself and temporarily isolate Y from the rest of the world so that only X can talk to it. I'm still in Russia, but I might as well be in the same room.

I could ask questions about why the insecure Windows box is on the same network as the box processing the credit card transactions, or how the attacker is familiar with the network topology, or knows the clock frequencies of your CPU(s) and when your box was last rebooted so it can make guesses about the TSC values that will be hashed in --- or know which CPU (for SMP boxes) an interrupt will be processed on since on current Intel/AMD boxes the TSC is not synchronized. But even if the attacker knows all of this, the attacker still doesn't know the current starting point of the pool.

Quoted 2 lines

Again, I think it's perfectly reasonable to sample from all sorts of sources. All my issues are about the entropy accounting.

But in that case your patch which removes the call to add_entropy() is probably not the right thing, yes? Maybe making the amount of entropy which is credited for each device interrupt ought to be configurable, sure. But we should be collecting the interrupt-arrival times regardless of how much we bump the entropy accounting.

- Ted

#25 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to David S. Miller
Quoted 9 lines · David S. Miller

From: Matt Mackall <[email protected]>
Date: Sat, 6 May 2006 11:48:08 -0500

Quoted 2 lines

But network traffic should be _assumed_ to be observable to some degree.

Please put together a test case that proves that /dev/random can be predicted just by being on the wire sniffing packets going into the machine. Then you will have my full support.

Sure.

First, since the existence of /dev/random's entropy accounting scheme is predicated on the assumption that we can break the hash function at will, I'll replace SHA1 with, oh, say, CRC-16. This'll be illustrative until someone has a nice preimage attack against SHA1.

Then I'll run my test on one of the various arches where HZ=~100 and we don't have a TSC. Like Sparc?

/* XXX Maybe do something better at some point... -DaveM */ typedef unsigned long cycles_t;
#define get_cycles() (0)

Now all the inputs are easily predictable from anywhere with <10ms ping, with the occassional need to guess between a pair of timer ticks. And since I can calculate preimages of CRC-16, I can now deduce the state of the pool if I can watch some subset of its output, say https session keys I request. And then I can start guessing future outputs and breaking into other people's https sessions.

The point of /dev/random is to -survive- SHA1 being broken by never giving out more secrets than we take in. That doesn't work if we give it observable inputs and claim they're not observable, which is what you're doing by setting SA_SAMPLE_RANDOM.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#19 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Theodore Tso
Quoted 5 lines · Theodore Tso
Quoted 2 lines

Again, I think it's perfectly reasonable to sample from all sorts of sources. All my issues are about the entropy accounting.

But in that case your patch which removes the call to add_entropy() is probably not the right thing, yes?

Note the emphatic "again", because I conceded that in my very first response to you.

The question is, what is the right thing? Not what we have now.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
maintainer
#26 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall

From: Matt Mackall <[email protected]>
Date: Sat, 6 May 2006 23:59:20 -0500

Quoted 4 lines

First, since the existence of /dev/random's entropy accounting scheme is predicated on the assumption that we can break the hash function at will, I'll replace SHA1 with, oh, say, CRC-16. This'll be illustrative until someone has a nice preimage attack against SHA1.

I don't understand why you're changing one of the preconditions in order to "prove" that what we have now can be broken. This is more swiss cheese theory.

We use SHA1 right now, so you have to use SHA1 in your reproducable attack. Since there is no preimage attack for SHA1 you can't prove that it can be done.

Quoted 6 lines

Then I'll run my test on one of the various arches where HZ=~100 and we don't have a TSC. Like Sparc?

/* XXX Maybe do something better at some point... -DaveM */ typedef unsigned long cycles_t;
#define get_cycles() (0)

You're really stretching things here, using a platform that is basically in almost no usage at all. Sure if you use a silly example, almost anything is possible. CRC-16 and sparc 32-bit, give me a break.

And the remote person has to know that the machine is a 32-bit sparc box, good luck with that. And this is yet another variable amongst all of the highly variable and unpredictable delays between packet visibility on the wire and the actual interrupt being serviced, which you have not addressed at all.

You haven't addressed the real case that matters, the ones on platforms that have a TSC that works and with SHA1.

Until you prove that can be broken, you are simply still spewing more of your incredible swiss cheese theory. Don't give me any crap about an almost entirely abandoned architecture that doesn't implement TSC, and using algorithms other than SHA1. The real code uses SHA1, so that's what you have to prove can be broken.

You're just circling around the real issues and trying to be "right" and this is what I dislike so much about theoretical people. They show you what can be done theoretically, yet never in practice with what we really have now.

#46 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Lee Revell
Quoted 5 lines
Quoted 2 lines

Consider adding a cheap soundcard to the system and run 'audio-entropyd': www.vanheusden.com/aed

Can't get much cheaper than the crap that comes on every motherboard these days ;-)
Also aren't temp sensors (on the disk or mobo) a good entropy source?

Not sure about that. If I look at
http://keetweej.vanheusden.com/draw_temp.php?limit=86400 it looks like that at least the cpu sensor gets only updated every x seconds.

Folkert van Heusden

Signature · 3 lines
Feeling generous? -> http://www.vanheusden.com/wishlist.php
----------------------------------------------------------------------
Phone: +31-6-41278122, PGP-key: 1F28D8AE, www.vanheusden.com
#28 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 17 lines

Sure.

First, since the existence of /dev/random's entropy accounting scheme is predicated on the assumption that we can break the hash function at will, I'll replace SHA1 with, oh, say, CRC-16. This'll be illustrative until someone has a nice preimage attack against SHA1.

Then I'll run my test on one of the various arches where HZ=~100 and we don't have a TSC. Like Sparc?

Now all the inputs are easily predictable from anywhere with <10ms ping, with the occassional need to guess between a pair of timer ticks. And since I can calculate preimages of CRC-16, I can now deduce the state of the pool if I can watch some subset of its output, say https session keys I request. And then I can start guessing future outputs and breaking into other people's https sessions.

Quoted 2 lines

The point of /dev/random is to -survive- SHA1 being broken by never giving out more secrets than we take in.

OK, here goes...

1 - by eliminating feeding enthopy from network cards you are eliminating all sources of enthropy for _lots_ of people (think headless servers, embedded systems - even though there can be other sources of enthropy there) Unfortunatelly, bad enthropy is still better than no enthropy (just think - no ssh / https, etc, etc)

2 - some platforms have much better enthropy sources than ethernet (or user input), just think hardware rngs, or even the sound card rng thing mentioned above

3 - as people said, your example (CRC-16 on specific platfoms) is (IMHO) an exxageration. Of course, /dev/random should try and protect us from whatever protocol being broken. That being said, this protection should be 'realistic'. In theory most things are broken if we have enough equipment and computing power.

My conclusion, I have no problem removing SA_SAMPLE_RANDOM *IN SPECIFIC CASES* (meaning, this should be user configurable). In a secure environment / platform has rng, it could be turned off, and in a headless server / embedded system / it could be left on.

Of course, that's just MHO...

Thiago

#29 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 17 lines · Thiago Galesi
Quoted 17 lines

Sure.

First, since the existence of /dev/random's entropy accounting scheme is predicated on the assumption that we can break the hash function at will, I'll replace SHA1 with, oh, say, CRC-16. This'll be illustrative until someone has a nice preimage attack against SHA1.

Then I'll run my test on one of the various arches where HZ=~100 and we don't have a TSC. Like Sparc?

Now all the inputs are easily predictable from anywhere with <10ms ping, with the occassional need to guess between a pair of timer ticks. And since I can calculate preimages of CRC-16, I can now deduce the state of the pool if I can watch some subset of its output, say https session keys I request. And then I can start guessing future outputs and breaking into other people's https sessions.

Quoted 6 lines
Quoted 2 lines

The point of /dev/random is to -survive- SHA1 being broken by never giving out more secrets than we take in.

OK, here goes...

1 - by eliminating feeding enthopy from network cards you are

Keep up, folks, I dropped that position in the very first round of replies.

Quoted 3 lines

2 - some platforms have much better enthropy sources than ethernet (or user input), just think hardware rngs, or even the sound card rng thing mentioned above

Point?

Quoted 2 lines

3 - as people said, your example (CRC-16 on specific platfoms) is (IMHO) an exxageration.

Yes, CRC-16 was a rhetorical device. MD4 would not have been. HZ=100 is not an exaggeration. Odds are pretty good you have such a Linux box in the form of a router or such already. This completely invalidates all the arguments about the hardware making the timing too unpredictable as it does so on a timescale of microseconds or less.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#27 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to David S. Miller
Quoted 4 lines · David S. Miller

You're just circling around the real issues and trying to be "right" and this is what I dislike so much about theoretical people. They show you what can be done theoretically, yet never in practice with what we really have now.

What you're missing is this:

/dev/random's entropy counting scheme sole reason to exist is to defend against theoretical future attacks against its cryptographic primitives. Thus _any_ discussion of its correctness must perforce be theoretical.

By substituting CRC-16 for SHA1, I've simply brought the future attack we're concerned about to today.

As I said at the beginning of this thread, I'm perfectly happy to continue taking samples from network devices. My concerns are entirely with how we account their entropy, which is strictly in the realm of theory to start with.

I will instead change the entropy estimator to be more conservative and to note the presence of high resolution clocks so that we can feed it garbage more safely.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#47 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Folkert van Heusden
Quoted 9 lines · Folkert van Heusden
Quoted 5 lines
Quoted 2 lines

Consider adding a cheap soundcard to the system and run 'audio-entropyd': www.vanheusden.com/aed

Can't get much cheaper than the crap that comes on every motherboard these days ;-)
Also aren't temp sensors (on the disk or mobo) a good entropy source?

Not sure about that. If I look at
http://keetweej.vanheusden.com/draw_temp.php?limit=86400 it looks like that at least the cpu sensor gets only updated every x seconds.

Yeah, heat sensors are not terribly useful. Thermal insulation acts as a very aggressive low pass filter on whatever noise might exist in the input.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#30 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 11 lines
Quoted 4 lines

OK, here goes...

1 - by eliminating feeding enthopy from network cards you are

Keep up, folks, I dropped that position in the very first round of replies.

As I said at the beginning of this thread, I'm perfectly happy to continue taking samples from network devices. My concerns are entirely with how we account their entropy, which is strictly in the realm of theory to start with.

ok, now I get it...

Quoted 6 lines
Quoted 4 lines

2 - some platforms have much better enthropy sources than ethernet (or user input), just think hardware rngs, or even the sound card rng thing mentioned above

Point?

Point is, sometimes you have plenty of enthropy available and sometimes you only have the network card (and maybe an HD). Two different situations, in one of them we can accept (it's even beter) not acquiring enthropy from the network card completely.

Quoted 6 lines
Quoted 3 lines

3 - as people said, your example (CRC-16 on specific platfoms) is (IMHO) an exxageration.

Yes, CRC-16 was a rhetorical device. MD4 would not have been. HZ=100 is not an exaggeration.

Agreed

Odds are pretty good you have such a Linux box

Quoted 3 lines

in the form of a router or such already. This completely invalidates all the arguments about the hardware making the timing too unpredictable as it does so on a timescale of microseconds or less.

Yes, that situation is pretty common.

Here is my point: I don't think the kernel shoud "try very hard" to fix "lack of good enthropy sources". Yes, you've presented situations where someone (ultimately) could guess what is being read from /dev/random.

In practice, though, it should ultimatelly fall upon the end-user/developer to have a system with good enough (for him/her) enthropy sources. If he is happy with lots of "bad enthropy" so be it. Hovever, if he wants / needs to be sure that /dev/random is not predictable, (IMHO) he can always plug a hardware RNG and only read from that (hence what I said about configuring who are your enthropy sources).

maintainer
#31 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 1 line · Matt Mackall

Yes, CRC-16 was a rhetorical device. MD4 would not have been.

MD4 is succeptible to a 2nd pre-image attack, yes. This means that given a specific message and its MD4 checksum, you can find another message which will have the same MD4 checksum. But that doesn't help you at all if you only have the MD4 checksum. And even the 2nd pre-image attack still requires O(2**40) operations. That's within the reach of modern CPU's yes, but that simply gives you a *second* pre-image that has the same MD4 checksum as original message.

In order to crack the entropy pool, you need a large number of outputs from /dev/random, and be able to find a large number of pre-images very rapidly. This is the main reason why I believe the entropy accounting is still useful. Even if the entropy accounting is off by several orders of magnitude, it is still useful, since the attacks that we're talking about will very likely require a huge number of data points. For example, the most powerful cryptoanalytic attack against DES still requires 2**43 plaintext/ciphertext pairs.

But in answer to your question, what should we do, my suggestion would be to sample all interrupts, and calculate the estimated entropy credits as we to day, but scaled by an amount that can range from 0 to 100%. This amount can be configured by system administrators, and will have intelligent defaults for each device driver to the amount of entropy should be credited for a particular device. If we care, we can set the default percentage scalaing factor for platforms with no TSC reguster and HZ=100 to be zero. But for most normal/modern platforms, I would argue the default scaling factor should be 100%.

The bottom line is this is much ado about nothing. As I have said, most programs use /dev/urandom, not /dev/random; the only really appropriate use of /dev/random is to generate long-term public/private keypairs, or perhaps to seed some other cryptographic random number generator (like /dev/urandom).

- Ted

#32 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 4 lines · Theodore Tso

But in answer to your question, what should we do, my suggestion would be to sample all interrupts, and calculate the estimated entropy credits as we to day, but scaled by an amount that can range from 0 to 100%.

I actually posted a patch to add a sysctl to do exactly that a few years ago.

Quoted 2 lines

But for most normal/modern platforms, I would argue the default scaling factor should be 100%.

And I would argue it should be no more than 50%. Just because I've seen so many would-have-thought-they-were-impossible attacks pan out.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#33 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall

Hi!

Quoted 6 lines

Then I'll run my test on one of the various arches where HZ=~100 and we don't have a TSC. Like Sparc?

/* XXX Maybe do something better at some point... -DaveM */ typedef unsigned long cycles_t;
#define get_cycles() (0)

Seems like sparc32 is broken :-(, and probably broken terminally... there are very little randomness sources that can handle 10msec sampling period :-(.

Maybe we should disable /dev/random on sparc32?

Signature · 1 line
Thanks for all the (sleeping) penguins.
maintainer
#34 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

From: Pavel Machek <[email protected]>
Date: Mon, 8 May 2006 06:26:05 +0000

Quoted 7 lines
Quoted 6 lines

Then I'll run my test on one of the various arches where HZ=~100 and we don't have a TSC. Like Sparc?

/* XXX Maybe do something better at some point... -DaveM */ typedef unsigned long cycles_t;
#define get_cycles() (0)

Quoted 5 lines

Seems like sparc32 is broken :-(, and probably broken terminally... there are very little randomness sources that can handle 10msec sampling period :-(.

Maybe we should disable /dev/random on sparc32?

What do other platforms without a TSC do?

#35 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 10 lines · David S. Miller

From: Pavel Machek <[email protected]>
Date: Mon, 8 May 2006 06:26:05 +0000

Quoted 7 lines
Quoted 6 lines

Then I'll run my test on one of the various arches where HZ=~100 and we don't have a TSC. Like Sparc?

/* XXX Maybe do something better at some point... -DaveM */ typedef unsigned long cycles_t;
#define get_cycles() (0)

Quoted 7 lines
Quoted 5 lines

Seems like sparc32 is broken :-(, and probably broken terminally... there are very little randomness sources that can handle 10msec sampling period :-(.

Maybe we should disable /dev/random on sparc32?

What do other platforms without a TSC do?

Using get_cycles() for /dev/random is new as of 2.6. Before that, we were directly calling rdtsc on x86 alone. 10msec resolution is fine for plenty of sources.

Quoted 1 line

From a brief glance, the following don't have a useful get_cycles:

v850, sh, sh64, h8300, m32r, arm, arm26, cris, frv, um, m68k, xtensa, sparc

And several others like mips (and x86) have one on only some hardware.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#36 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Hi!

Quoted 5 lines
Quoted 1 line

What do other platforms without a TSC do?

Using get_cycles() for /dev/random is new as of 2.6. Before that, we were directly calling rdtsc on x86 alone. 10msec resolution is fine for plenty of sources.

For what devices are timestamps still 'random/unobservable' in 10msec range?

Maybe keyboard... but no, keyboard has autorepeat and can be observed remotely with 10msec accuracy in many cases. (telnet to bbs?)

Disk requests take less than 10msec.

It is trivial to measure packets with 10msec accuracy.

Mouse will generate many events within 10msec when user actually uses it.

...so, what devices are still random with 10msec sampling?

Signature · 1 line
Thanks for all the (sleeping) penguins.
#37 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 8 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 1 line

What do other platforms without a TSC do?

Using get_cycles() for /dev/random is new as of 2.6. Before that, we were directly calling rdtsc on x86 alone. 10msec resolution is fine for plenty of sources.

Quoted 5 lines

For what devices are timestamps still 'random/unobservable' in 10msec range?

Maybe keyboard... but no, keyboard has autorepeat and can be observed remotely with 10msec accuracy in many cases. (telnet to bbs?)

Please go look at the code.

Signature · 1 line
Mathematics is the supreme nostalgia of our time.
#20 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Theodore Tso

On Sat, May 06, 2006 at 21:22:00 -0400, Theodore Tso wrote:
...

Quoted 5 lines

I could ask questions about why the insecure Windows box is on the same network as the box processing the credit card transactions, or how the attacker is familiar with the network topology, or knows the clock frequencies of your CPU(s) and when your box was last rebooted so it can make guesses about the TSC values that will be hashed in ---

Currently init_std_data plays only with do_gettimeofday and system_utsname. Why not also feed get_cycles(), jiffies, pointer to init_std_data function or something to add_entropy_words?

For example, I notice that syncookie_secret is initialized very early in the boot, and it's never written to again.
If system clock is +-1 s accurate at boot and kernel is from some common distro, I wonder how secure syncookie_secret is.

And if I read correctly, get_random_int() keeps producing the same output during the same jiffy, if CONFIG_X86_HAS_TSC is undef? Why not create a new function for get_random_int() (instead of just calling secure_ip_id())
which includes 64bit-counter, pid and jiffies in the hash given to half_md4_transform?

Also, I believe add_input_randomness needs fixing.
I noticed that when using e.g. evdev in Xorg, one mouse movement or button press causes eight events, and all of them are fed to add_timer_randomness. There maybe 7 out of 8 of the events get 1 bit of entropy added because they happen on the same jiffy.

I have been playing with Fortuna patch (JLC's patch with dozens of fixes by me), and from looking at debug outputs, it seems that last input "event" is marked by
(type == 0) && (code == 0) && (value == 0) ...

So I am doing this way:
keep on jhash'ing type, code, value in add_input_randomness till they're all-zeros,
then give the resulting u32 to add_timer_randomness. jhash value can be static variable and you can ignore the fact you are "mixing" different events from different sources into the hash.

Now when I press and release ANY key (or e.g. click mouse button), I get exactly two calls to add_timer_randomness, which each add 3-11 bits of entropy. I think this is how it should work. At least 3 bits doesn't sound too overestimated ;-O

And for disk events, maybe limit to at max a couple of calls to add_timer_randomness per jiffy?
Maybe also limit similarly in add_input_randomness? (For disk events I also add disk_stat_read(disk, sectors[0]/[1])
as entropy)

For add_interrupt_randomness, if there anything what could be added as entropy, besides irq and time?

http://safari.iki.fi/fortuna-random-2.6.16.14-safari.patch.bz2
Warning: enabling debug might produce sensitive data into log files and/or console.
/proc/sys/kernel/random/debug specifies which debugs to produce (valid values 0-63 , OR 1, 2, 4, 8, 16, 32 together).
If link does not seem to work, I am either rebooting a
a newer Fortuna version or my system blew up or I have dropped your packets with netfilter.

What about adding entropy from data received from network? For example, with netfilter module, pass every Nth checksum from a packet (for example, from DNS replies) to add_entropy_words() ?

Quoted 4 lines

or know which CPU (for SMP boxes) an interrupt will be processed on since on current Intel/AMD boxes the TSC is not synchronized. But even if the attacker knows all of this, the attacker still doesn't know the current starting point of the pool.

...

#38 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Matt Mackall
Quoted 9 lines · Matt Mackall
Quoted 8 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 1 line

What do other platforms without a TSC do?

Using get_cycles() for /dev/random is new as of 2.6. Before that, we were directly calling rdtsc on x86 alone. 10msec resolution is fine for plenty of sources.

Quoted 7 lines
Quoted 5 lines

For what devices are timestamps still 'random/unobservable' in 10msec range?

Maybe keyboard... but no, keyboard has autorepeat and can be observed remotely with 10msec accuracy in many cases. (telnet to bbs?)

Please go look at the code.

Ok, so perhaps it got autorepeat right. Still you claimed "plenty" of usable sources, and keyboard is remotely observable. Please show me "plenty".
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#39 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Pavel Machek
Quoted 14 lines · Pavel Machek

Hi!

Quoted 5 lines
Quoted 1 line

What do other platforms without a TSC do?

Using get_cycles() for /dev/random is new as of 2.6. Before that, we were directly calling rdtsc on x86 alone. 10msec resolution is fine for plenty of sources.

For what devices are timestamps still 'random/unobservable' in 10msec range?

Maybe keyboard... but no, keyboard has autorepeat and can be observed remotely with 10msec accuracy in many cases. (telnet to bbs?)

Quoted 8 lines

Disk requests take less than 10msec.

It is trivial to measure packets with 10msec accuracy.

Mouse will generate many events within 10msec when user actually uses it.

...so, what devices are still random with 10msec sampling?

There may be no devices with randomness in 10msec ...

... but how about the *count* of events during 10msec?

Keyboard presses may be observable from outside, but disk accesses, network interrupts, mouse moves etc. .... especially if the (outside) accesses have to be correlated to the (internal) timer interrupt.

Get the count of events in 10msec, take the lowest bit. In 1.28 seconds you'll get your 128bit key.

Or, to be conservative, take only the XOR of 8 consecutive bits ... then you'll have to wait 10 seconds, but will be a bit more secure.

Such a mechanism could even be used on machines with TSC ... just do an (non-locked) increment of some counter, reset it on every jiffie, and take a bit of entropy.

How about that?

Regards,

Phil

#40 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Theodore Tso
Quoted 5 lines · Theodore Tso

I've always thought the right answer is that whether or not network packet arrival times should be used as entropy input should be configurable, since depending on the environment, it might or might not be safe, and for some hosts (particularly diskless servers), the network might be the only source of entropy available to them.

The trully concerned should simply use true random number generators. Like a zenner diodes noise. For everybody else... most if not all of what /dev/random does, just simply
isn't worth the trouble at all. Thus the less of it the better.
BTW. Did somebody notice that the whole disc seek time dance around /dev/random does, is quite idiotic for deterministic flash drives? It will screw yours "randomness" silently...

#21 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

In reply to Theodore Tso
Quoted 8 lines · Theodore Tso

Agreed, but I'd an additional point of nuance; this assumes that the attacker (call him Boris for the sake of argument) can actually gain access to enough /dev/random or /dev/urandom outputs, and be knowledgable about all other calls to /dev/random and exactly when they happen (since entropy extractions cause the TSC to be mixed into the pool) so Boris can can actually determine the contents of the pool. Note that simply "breaking" a cryptographic hash, in the sense of finding two input values that collide to the same output value,

Quoted 8 lines

does not mean that the hash has been sufficiently analyzed that it would be possible to accomplish this feat. And given that it took 80,000 CPU hours to determine find this collision, and the complexity of the attack was 2**51, it seems highly likely that with a poolsize of 4096 bits, that it would take a huge amount of /dev/random extractions, complete with the exact TSC timestamp when the extractions were happening, such that an attacker would be able to have enough information to break the pool.

Anytime you start to make unquantified assumptions in the context of /dev/random the issue turns up that this whole thing is not worth the trouble because much simpler approaches will be sufficient enough to acomplish what it does. On the other hand you can't provide any actual full analysis of it's behaviour - which is just *not acceptable* for anybody trully concerned. And this in conjunction makes the WHOLE idea behind it questionable.

maintainer
#22 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 7 lines · Marcin Dalecki

Anytime you start to make unquantified assumptions in the context of / dev/random the issue turns up that this whole thing is not worth the trouble because much simpler approaches will be sufficient enough to acomplish what it does. On the other hand you can't provide any actual full analysis of it's behaviour - which is just *not acceptable* for anybody trully concerned. And this in conjunction makes the WHOLE idea behind it questionable.

Nobody can provide any kind of full analysis about whether or not SHA-2 or AES is secure, either. Does that we mean we just give up and go home? No, we do the best job we can, with the best information we have. Sometimes that means we have to make assumptions, but the entire construction of AES and SHA-2 is based on similar assumptions, too.

Academics who make "full analysis" generally use as axioms things like "assume MD5 is secure" or "assume SHA-1 is secure", which are really fancy assumptions. If we had used a "simpler approaches" based such axioms we might have been in trouble. So I think some of the analysis and designs choices that I made in /dev/random is most definitely worth the trouble.

Regards,

- Ted

#23 lore raw

Re: [PATCH 7/14] random: Remove SA_SAMPLE_RANDOM from network drivers

Quoted 23 lines · Theodore Tso
Quoted 7 lines · Marcin Dalecki

Anytime you start to make unquantified assumptions in the context of / dev/random the issue turns up that this whole thing is not worth the trouble because much simpler approaches will be sufficient enough to acomplish what it does. On the other hand you can't provide any actual full analysis of it's behaviour - which is just *not acceptable* for anybody trully concerned. And this in conjunction makes the WHOLE idea behind it questionable.

Nobody can provide any kind of full analysis about whether or not SHA-2 or AES is secure, either. Does that we mean we just give up and go home? No, we do the best job we can, with the best information we have. Sometimes that means we have to make assumptions, but the entire construction of AES and SHA-2 is based on similar assumptions, too.

Academics who make "full analysis" generally use as axioms things like "assume MD5 is secure" or "assume SHA-1 is secure", which are really fancy assumptions. If we had used a "simpler approaches" based such axioms we might have been in trouble. So I think some of the analysis and designs choices that I made in /dev/random is most definitely worth the trouble.

Quoted 3 lines

Regards,

- Ted

As usual I agree with you, for lack of a really good random source it's worth doing the best possible job with what's available. Would be nice to have a cheap USB bit babbler, tho.

Signature · 5 lines
Bill Davidsen <[email protected]>
  Obscure bug of 2004: BASH BUFFER OVERFLOW - if bash is being run by a
normal user and is setuid root, with the "vi" line edit mode selected,
and the character set is "big5," an off-by-one errors occurs during
wildcard (glob) expansion.