Package: initscripts
Version: 2.86.ds1-61
Severity: normal
Tags: patch

We should correctly calculate the size of the random.seed to be written.

Note that /proc/sys/kernel/random/poolsize reports the number of bits,
not bytes, so a conversion factor is needed.

This is #2 in a group of 5 patches for init.d/urandom.

-- System Information:
Debian Release: 5.0.5
  APT prefers stable
  APT policy: (500, 'stable')
Architecture: i386 (i586)

Kernel: Linux 2.6.26.5 (PREEMPT)
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)
Shell: /bin/sh linked to /bin/bash
>From 45e354973831aa3e50d230f98b25853660a42f39 Mon Sep 17 00:00:00 2001
From: John Denker <j...@av8n.com>
Date: Sat, 11 Sep 2010 09:22:36 -0700
Subject: [PATCH 2/5] Calculate POOLBYTES correctly. Note that /proc/sys/kernel/random/poolsize reports the number of bits, not bytes, so a conversion factor is needed.

---
 urandom |   13 ++++++++-----
 1 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/urandom b/urandom
index 1007147..5172e7f 100755
--- a/urandom
+++ b/urandom
@@ -14,8 +14,11 @@
 
 PATH=/sbin:/usr/sbin:/bin:/usr/bin
 SAVEDFILE=/var/lib/urandom/random-seed
-POOLSIZE=512
-[ -f /proc/sys/kernel/random/poolsize ] && POOLSIZE="$(cat /proc/sys/kernel/random/poolsize)"
+if ! POOLBYTES=$((
+  ($(cat /proc/sys/kernel/random/poolsize 2>/dev/null) + 7) / 8
+)) ; then
+  POOLBYTES=512
+fi
 . /lib/init/vars.sh
 
 . /lib/lsb/init-functions
@@ -31,7 +34,7 @@ do_status () {
 case "$1" in
   start|"")
 	[ "$VERBOSE" = no ] || log_action_begin_msg "Initializing random number generator"
-	# Load and then save $POOLSIZE bytes,
+	# Load and then save $POOLBYTES bytes,
 	# which is the size of the entropy pool
 	if [ -f "$SAVEDFILE" ]
 	then
@@ -40,7 +43,7 @@ case "$1" in
 	rm -f $SAVEDFILE
 	# Hm, why is the saved pool re-created at boot? [pere 2009-09-03]
 	umask 077
-	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
+	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLBYTES count=1 >/dev/null 2>&1
 	ES=$?
 	umask 022
 	[ "$VERBOSE" = no ] || log_action_end_msg $ES
@@ -50,7 +53,7 @@ case "$1" in
 	# see documentation in linux/drivers/char/random.c
 	[ "$VERBOSE" = no ] || log_action_begin_msg "Saving random seed"
 	umask 077
-	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLSIZE count=1 >/dev/null 2>&1
+	dd if=/dev/urandom of=$SAVEDFILE bs=$POOLBYTES count=1 >/dev/null 2>&1
 	ES=$?
 	[ "$VERBOSE" = no ] || log_action_end_msg $ES
 	;;
-- 
1.7.0.4

Reply via email to