2019-02-16 08:23:15

by Sultan Alsawaf

[permalink] [raw]
Subject: [PATCH] random: fix inconsistent spinlock usage

All users of the struct entropy_store spinlock use the irqsave spinlock variant.
Spinlock users of the same lock should use be consistent in their use of a
certain spinlock primitive, which makes add_interrupt_randomness()'s spinlock
usage incorrect.

Fix the inconsistency by converting add_interrupt_randomness()'s spinlocks to
use the irqsave primitive.

Signed-off-by: Sultan Alsawaf <[email protected]>
---
drivers/char/random.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/char/random.c b/drivers/char/random.c
index 38c6d1af6..1365017a7 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1239,6 +1239,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
__u64 ip;
unsigned long seed;
int credit = 0;
+ unsigned long flags;

if (cycles == 0)
cycles = get_reg(fast_pool, regs);
@@ -1269,7 +1270,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
return;

r = &input_pool;
- if (!spin_trylock(&r->lock))
+ if (!spin_trylock_irqsave(&r->lock, flags))
return;

fast_pool->last = now;
@@ -1285,7 +1286,7 @@ void add_interrupt_randomness(int irq, int irq_flags)
__mix_pool_bytes(r, &seed, sizeof(seed));
credit = 1;
}
- spin_unlock(&r->lock);
+ spin_unlock_irqrestore(&r->lock, flags);

fast_pool->count = 0;

--
2.20.1


2019-02-17 07:00:45

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCH] random: fix inconsistent spinlock usage

On Fri, Feb 15, 2019 at 02:03:06PM -0800, Sultan Alsawaf wrote:
> All users of the struct entropy_store spinlock use the irqsave spinlock variant.
> Spinlock users of the same lock should use be consistent in their use of a
> certain spinlock primitive, which makes add_interrupt_randomness()'s spinlock
> usage incorrect.
>
> Fix the inconsistency by converting add_interrupt_randomness()'s spinlocks to
> use the irqsave primitive.
>
> Signed-off-by: Sultan Alsawaf <[email protected]>

This isn't a problem; interrupts are off by definition when
add_interrupt_randomness() is called so there's no point using the
irqsave version.

Also, please note that your patches are whitespace damaged, so they
can't be applied directly. You may want to look into how you are
sending your patches.

Regards,

- Ted