Skip to content

Commit b08054f

Browse files
committed
Reduce NS16550 address space size to one page
..rather than unbounded, as it used to be. This led to the rather surprising issue #1600, where a part of the address space assumed to be vacant would allow a subset of accesses.
1 parent 3a53c80 commit b08054f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

riscv/ns16550.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <sstream>
33
#include "devices.h"
44
#include "processor.h"
5+
#include "mmu.h"
56
#include "term.h"
67
#include "sim.h"
78
#include "dts.h"
@@ -170,6 +171,9 @@ bool ns16550_t::load(reg_t addr, size_t len, uint8_t* bytes)
170171
if (reg_io_width != len) {
171172
return false;
172173
}
174+
if (addr + len > PGSIZE) {
175+
return false;
176+
}
173177
addr >>= reg_shift;
174178
addr &= 7;
175179

@@ -230,6 +234,9 @@ bool ns16550_t::store(reg_t addr, size_t len, const uint8_t* bytes)
230234
if (reg_io_width != len) {
231235
return false;
232236
}
237+
if (addr + len > PGSIZE) {
238+
return false;
239+
}
233240
addr >>= reg_shift;
234241
addr &= 7;
235242
val = bytes[0];

0 commit comments

Comments
 (0)