Skip to content

Commit 43d5d30

Browse files
Ingo MolnarLinus Torvalds
authored andcommitted
[PATCH] random driver preempt robustness
A certain codepath in the random driver relied on vt_ioctl() being under the BKL and implicitly disabling preemption. The code wasn't buggy upstream but it's slighly unrobust so I think we want the fix upstream too, independently of the remove-bkl patch. Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
1 parent 644f674 commit 43d5d30

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

drivers/char/random.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -807,10 +807,11 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
807807
long delta, delta2, delta3;
808808
int entropy = 0;
809809

810+
preempt_disable();
810811
/* if over the trickle threshold, use only 1 in 4096 samples */
811812
if ( random_state->entropy_count > trickle_thresh &&
812813
(__get_cpu_var(trickle_count)++ & 0xfff))
813-
return;
814+
goto out;
814815

815816
/*
816817
* Use get_cycles() if implemented, otherwise fall back to
@@ -861,6 +862,8 @@ static void add_timer_randomness(struct timer_rand_state *state, unsigned num)
861862
entropy = int_ln_12bits(delta);
862863
}
863864
batch_entropy_store(num, time, entropy);
865+
out:
866+
preempt_enable();
864867
}
865868

866869
void add_keyboard_randomness(unsigned char scancode)

0 commit comments

Comments
 (0)