Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.kernel > #1633401 > unrolled thread
| Started by | Michael Schmitz <schmitzmic@gmail.com> |
|---|---|
| First post | 2017-04-30 09:50 +0200 |
| Last post | 2017-05-24 23:50 +0200 |
| Articles | 3 — 3 participants |
Back to article view | Back to linux.kernel
[RFC] fix race in drivers/char/random.c:get_reg() Michael Schmitz <schmitzmic@gmail.com> - 2017-04-30 09:50 +0200
Re: [RFC] fix race in drivers/char/random.c:get_reg() Geert Uytterhoeven <geert@linux-m68k.org> - 2017-05-12 09:20 +0200
Re: [RFC] fix race in drivers/char/random.c:get_reg() Theodore Ts'o <tytso@mit.edu> - 2017-05-24 23:50 +0200
| From | Michael Schmitz <schmitzmic@gmail.com> |
|---|---|
| Date | 2017-04-30 09:50 +0200 |
| Subject | [RFC] fix race in drivers/char/random.c:get_reg() |
| Message-ID | <tBRMd-qh-3@gated-at.bofh.it> |
get_reg() can be reentered on architectures with prioritized interrupts
(m68k in this case), causing f->reg_index to be incremented after the
range check. Out of bounds memory access past the pt_regs struct results.
This will go mostly undetected unless access is beyond end of memory.
Prevent the race by disabling interrupts in get_reg().
Tested on m68k (Atari Falcon, and ARAnyM emulator).
Kudos to Geert Uytterhoeven for helping to trace this race.
Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
---
drivers/char/random.c | 6 +++++-
1 files changed, 5 insertions(+), 1 deletions(-)
diff --git a/drivers/char/random.c b/drivers/char/random.c
index 1ef2640..7d1799b 100644
--- a/drivers/char/random.c
+++ b/drivers/char/random.c
@@ -1115,12 +1115,16 @@ static void add_interrupt_bench(cycles_t start)
static __u32 get_reg(struct fast_pool *f, struct pt_regs *regs)
{
__u32 *ptr = (__u32 *) regs;
+ unsigned long flags;
if (regs == NULL)
return 0;
+ local_irq_save(flags);
if (f->reg_idx >= sizeof(struct pt_regs) / sizeof(__u32))
f->reg_idx = 0;
- return *(ptr + f->reg_idx++);
+ ptr += f->reg_idx++;
+ local_irq_restore(flags);
+ return *ptr;
}
void add_interrupt_randomness(int irq, int irq_flags)
--
1.7.0.4
[toc] | [next] | [standalone]
| From | Geert Uytterhoeven <geert@linux-m68k.org> |
|---|---|
| Date | 2017-05-12 09:20 +0200 |
| Message-ID | <tGd1M-Y4-13@gated-at.bofh.it> |
| In reply to | #1633401 |
On Sun, Apr 30, 2017 at 9:49 AM, Michael Schmitz <schmitzmic@gmail.com> wrote:
> get_reg() can be reentered on architectures with prioritized interrupts
> (m68k in this case), causing f->reg_index to be incremented after the
> range check. Out of bounds memory access past the pt_regs struct results.
> This will go mostly undetected unless access is beyond end of memory.
>
> Prevent the race by disabling interrupts in get_reg().
>
> Tested on m68k (Atari Falcon, and ARAnyM emulator).
>
> Kudos to Geert Uytterhoeven for helping to trace this race.
>
> Signed-off-by: Michael Schmitz <schmitzmic@gmail.com>
No comments from anyone?
Perhaps this wasn't clear, but (a) an access beyond end of memory crashes
the system, and (b) this is reproducible on Atari systems.
Thanks!
Gr{oetje,eeting}s,
Geert
--
Geert Uytterhoeven -- There's lots of Linux beyond ia32 -- geert@linux-m68k.org
In personal conversations with technical people, I call myself a hacker. But
when I'm talking to journalists I just say "programmer" or something like that.
-- Linus Torvalds
[toc] | [prev] | [next] | [standalone]
| From | Theodore Ts'o <tytso@mit.edu> |
|---|---|
| Date | 2017-05-24 23:50 +0200 |
| Message-ID | <tKMkj-7HS-39@gated-at.bofh.it> |
| In reply to | #1633401 |
On Sun, Apr 30, 2017 at 07:49:21PM +1200, Michael Schmitz wrote: > get_reg() can be reentered on architectures with prioritized interrupts > (m68k in this case), causing f->reg_index to be incremented after the > range check. Out of bounds memory access past the pt_regs struct results. > This will go mostly undetected unless access is beyond end of memory. > > Prevent the race by disabling interrupts in get_reg(). > > Tested on m68k (Atari Falcon, and ARAnyM emulator). > > Kudos to Geert Uytterhoeven for helping to trace this race. > > Signed-off-by: Michael Schmitz <schmitzmic@gmail.com> Thanks, applied. It will go to Linus shortly. - Ted
[toc] | [prev] | [standalone]
Back to top | Article view | linux.kernel
csiph-web