Skip to contentSkip to conversation

nand: fix address overflow

PATCH In review Rabin Vincent 4 participants 5 messages Nov 10, 2015 – Nov 13, 2015

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nand: fix address overflow

The shifts of the address mask and value shift beyond 32 bits when there are 5 address cycles.

---
 hw/block/nand.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nand.c +2 -2
index 61d2cec..a68266f 100644
@@ -522,8 +522,8 @@ void nand_setio(DeviceState *dev, uint32_t value)
 
     if (s->ale) {
         unsigned int shift = s->addrlen * 8;
-        unsigned int mask = ~(0xff << shift);
-        unsigned int v = value << shift;
+        uint64_t mask = ~(0xffull << shift);
+        uint64_t v = (uint64_t)value << shift;
 
         s->addr = (s->addr & mask) | v;
         s->addrlen ++;
Signature · 1 line
1.7.10.4
Reviewed-by on v1 1/1
#1 lore raw
Quoted 14 lines · Rabin Vincent

The shifts of the address mask and value shift beyond 32 bits when there are 5 address cycles.

---
 hw/block/nand.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nand.c +0 -0
index 61d2cec..a68266f 100644

hw/block/nand.c void nand_setio(DeviceState *dev, uint32_t value) · line 529

Quoted 10 lines
hw/block/nand.c +2 -2
@@ -522,8 +522,8 @@ void nand_setio(DeviceState *dev, uint32_t value)
 
     if (s->ale) {
         unsigned int shift = s->addrlen * 8;
-        unsigned int mask = ~(0xff << shift);
-        unsigned int v = value << shift;
+        uint64_t mask = ~(0xffull << shift);
+        uint64_t v = (uint64_t)value << shift;
 
         s->addr = (s->addr & mask) | v;
         s->addrlen ++;
Reviewed-by
#2 lore raw
Quoted 24 lines · Paolo Bonzini
Quoted 21 lines · Rabin Vincent

The shifts of the address mask and value shift beyond 32 bits when there are 5 address cycles.

---
 hw/block/nand.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nand.c +2 -2
index 61d2cec..a68266f 100644
@@ -522,8 +522,8 @@ void nand_setio(DeviceState *dev, uint32_t value)
 
     if (s->ale) {
         unsigned int shift = s->addrlen * 8;
-        unsigned int mask = ~(0xff << shift);
-        unsigned int v = value << shift;
+        uint64_t mask = ~(0xffull << shift);
+        uint64_t v = (uint64_t)value << shift;
 
Quoted 6 lines

hw/block/nand.c void nand_setio(DeviceState *dev, uint32_t value) · line 529

Quoted 3 lines
hw/block/nand.c +0 -0
         s->addr = (s->addr & mask) | v;
         s->addrlen ++;

This is a bugfix right? IIUC This would not have worked for accesses to devices above column address 255 at all. Should this go to stable/2.5?

Regards,
Peter

Quoted 1 line
#3 lore raw
Quoted 29 lines
Quoted 22 lines · Rabin Vincent
Quoted 21 lines

The shifts of the address mask and value shift beyond 32 bits when there are 5 address cycles.

---
 hw/block/nand.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nand.c +2 -2
index 61d2cec..a68266f 100644
@@ -522,8 +522,8 @@ void nand_setio(DeviceState *dev, uint32_t value)
 
     if (s->ale) {
         unsigned int shift = s->addrlen * 8;
-        unsigned int mask = ~(0xff << shift);
-        unsigned int v = value << shift;
+        uint64_t mask = ~(0xffull << shift);
+        uint64_t v = (uint64_t)value << shift;
 
Quoted 6 lines

hw/block/nand.c void nand_setio(DeviceState *dev, uint32_t value) · line 529

Quoted 3 lines
hw/block/nand.c +0 -0
         s->addr = (s->addr & mask) | v;
         s->addrlen ++;
Quoted 5 lines

This is a bugfix right? IIUC This would not have worked for accesses to devices above column address 255 at all. Should this go to stable/2.5?

Yes, it should. Michael, are you planning to send another pull request during hard freeze?

Paolo

#4 lore raw

Am 13.11.2015 um 10:32 hat Paolo Bonzini geschrieben:

Quoted 29 lines
Quoted 29 lines
Quoted 28 lines · Rabin Vincent
Quoted 14 lines

The shifts of the address mask and value shift beyond 32 bits when there are 5 address cycles.

---
 hw/block/nand.c |    4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/block/nand.c +0 -0
index 61d2cec..a68266f 100644

hw/block/nand.c void nand_setio(DeviceState *dev, uint32_t value) · line 529

Quoted 10 lines
hw/block/nand.c +2 -2
@@ -522,8 +522,8 @@ void nand_setio(DeviceState *dev, uint32_t value)
 
     if (s->ale) {
         unsigned int shift = s->addrlen * 8;
-        unsigned int mask = ~(0xff << shift);
-        unsigned int v = value << shift;
+        uint64_t mask = ~(0xffull << shift);
+        uint64_t v = (uint64_t)value << shift;
 
         s->addr = (s->addr & mask) | v;
         s->addrlen ++;
Quoted 8 lines
Quoted 5 lines

This is a bugfix right? IIUC This would not have worked for accesses to devices above column address 255 at all. Should this go to stable/2.5?

Yes, it should. Michael, are you planning to send another pull request during hard freeze?

The block layer catch-all entry in MAINTAINERS says that it's mine, so I'll just take it through my block tree.

Kevin