Skip to contentSkip to conversation

hw/ivshmem.c don't check for negative values on unsigned data types

PATCH Applied [email protected] 4 participants 7 messages Aug 30, 2010 – Sep 4, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/ivshmem.c don't check for negative values on unsigned data types

From: Jes Sorensen <[email protected]>

There is no need to check for dest < 0 or vector >= 0 as both are uint16_t.

This should fix problems with broken build with aggressive compiler flags. Reported by Xudong Hao <[email protected]>

---
 hw/ivshmem.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/ivshmem.c +2 -2
index bbb5cba..afebbc3 100644
@@ -199,13 +199,13 @@ static void ivshmem_io_writel(void *opaque, target_phys_addr_t addr,
 
         case DOORBELL:
             /* check that dest VM ID is reasonable */
-            if ((dest < 0) || (dest > s->max_peer)) {
+            if (dest > s->max_peer) {
                 IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest);
                 break;
             }
 
             /* check doorbell range */
-            if ((vector >= 0) && (vector < s->peers[dest].nb_eventfds)) {
+            if (vector < s->peers[dest].nb_eventfds) {
                 IVSHMEM_DPRINTF("Writing %" PRId64 " to VM %d on vector %d\n",
                                                     write_one, dest, vector);
                 if (write(s->peers[dest].eventfds[vector],
Signature · 1 line
1.7.2.2
#1 lore raw
Quoted 33 lines · [email protected] wrote:

From: Jes Sorensen <[email protected]>

There is no need to check for dest < 0 or vector >= 0 as both are uint16_t.

This should fix problems with broken build with aggressive compiler flags. Reported by Xudong Hao <[email protected]>

---
 hw/ivshmem.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/ivshmem.c +1 -2
index bbb5cba..afebbc3 100644
@@ -199,13 +199,13 @@ static void ivshmem_io_writel(void *opaque,
 target_phys_addr_t addr, 
 
         case DOORBELL:
             /* check that dest VM ID is reasonable */
-            if ((dest < 0) || (dest > s->max_peer)) {
+            if (dest > s->max_peer) {
                 IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n",
                 dest); break;
             }
 
             /* check doorbell range */
-            if ((vector >= 0) && (vector <

s->peers[dest].nb_eventfds)) { + if (vector <
s->peers[dest].nb_eventfds) {

Quoted 3 lines

IVSHMEM_DPRINTF("Writing %" PRId64 " to VM %d on
vector %d\n", write_one, dest, vector); if (write(s->peers[dest].eventfds[vector],

This patch works for me.

Thanks,
Xudong

#2 lore raw
In reply to [email protected]
Quoted 33 lines · Xudong
Quoted 32 lines · [email protected] wrote:

From: Jes Sorensen <[email protected]>

There is no need to check for dest < 0 or vector >= 0 as both are uint16_t.

This should fix problems with broken build with aggressive compiler flags. Reported by Xudong Hao <[email protected]>

 hw/ivshmem.c |    4 ++--
 1 files changed, 2 insertions(+), 2 deletions(-)
hw/ivshmem.c +1 -2
index bbb5cba..afebbc3 100644
@@ -199,13 +199,13 @@ static void ivshmem_io_writel(void *opaque,
 target_phys_addr_t addr, 
 
         case DOORBELL:
             /* check that dest VM ID is reasonable */
-            if ((dest < 0) || (dest > s->max_peer)) {
+            if (dest > s->max_peer) {
                 IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n",
                 dest); break;
             }
 
             /* check doorbell range */
-            if ((vector >= 0) && (vector <

s->peers[dest].nb_eventfds)) { + if (vector <

                 s->peers[dest].nb_eventfds) {
Quoted 6 lines
Quoted 3 lines

IVSHMEM_DPRINTF("Writing %" PRId64 " to VM %d on
vector %d\n", write_one, dest, vector); if (write(s->peers[dest].eventfds[vector],

This patch works for me.

Jes, correct result is this patch works for me on x86_64 system. However, in i386 system, there is another bug:

...

  CC    x86_64-softmmu/ivshmem.o
  CC    x86_64-softmmu/fpu/softfloat-native.o
  CC    x86_64-softmmu/op_helper.o

cc1: warnings being treated as errors
/home/build/gitrepo/qemu/hw/ivshmem.c: In function 'check_shm_size. /home/build/gitrepo/qemu/hw/ivshmem.c:357: warning: format '%ld' expects type 'long int', but argt 5 has type '__off64_t make[1]: *** [ivshmem.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [subdir-x86_64-softmmu] Error 2

Thanks,
Xudong

#3 lore raw
Quoted 43 lines · Xudong
Quoted 33 lines · Xudong
Quoted 32 lines · [email protected] wrote:

From: Jes Sorensen <[email protected]>

There is no need to check for dest < 0 or vector >= 0 as both are uint16_t.

This should fix problems with broken build with aggressive compiler flags. Reported by Xudong Hao <[email protected]>

 hw/ivshmem.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
hw/ivshmem.c +0 -0
index bbb5cba..afebbc3 100644
@@ -199,13 +199,13 @@ static void ivshmem_io_writel(void *opaque,
 target_phys_addr_t addr,
 

         case DOORBELL:
             /* check that dest VM ID is reasonable */
-            if ((dest < 0) || (dest > s->max_peer)) {
+            if (dest > s->max_peer) { IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest); break;
             }

             /* check doorbell range */
-            if ((vector >= 0) && (vector < s->peers[dest].nb_eventfds)) { +            if (vector < s->peers[dest].nb_eventfds) {

Quoted 6 lines
Quoted 3 lines

                 IVSHMEM_DPRINTF("Writing %" PRId64 " to VM %d on vector %d\n", write_one, dest, vector); if (write(s->peers[dest].eventfds[vector],

This patch works for me.

Jes, correct result is this patch works for me on x86_64 system. However, in i386 system, there is another bug:

Quoted 10 lines

...
 CC    x86_64-softmmu/ivshmem.o
 CC    x86_64-softmmu/fpu/softfloat-native.o
 CC    x86_64-softmmu/op_helper.o
cc1: warnings being treated as errors
/home/build/gitrepo/qemu/hw/ivshmem.c: In function 'check_shm_size. /home/build/gitrepo/qemu/hw/ivshmem.c:357: warning: format '%ld' expects type 'long int', but argt 5 has type '__off64_t make[1]: *** [ivshmem.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [subdir-x86_64-softmmu] Error 2

Hmm, that was causing problems on 32-bit systems, not 64-bit. Is this with gcc 4.1.2? Please the try the following patch from Avi that should add the necessary cast.

http://www.mail-archive.com/[email protected]/msg40715.html

Cam

#4 lore raw
Quoted 55 lines · Cam Macdonell
Quoted 43 lines · Xudong
Quoted 33 lines · Xudong
Quoted 32 lines · [email protected] wrote:

From: Jes Sorensen <[email protected]>

There is no need to check for dest < 0 or vector >= 0 as both are uint16_t.

This should fix problems with broken build with aggressive compiler flags. Reported by Xudong Hao <[email protected]>

 hw/ivshmem.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
hw/ivshmem.c +0 -0
index bbb5cba..afebbc3 100644
@@ -199,13 +199,13 @@ static void ivshmem_io_writel(void *opaque,
 target_phys_addr_t addr,
 

         case DOORBELL:
             /* check that dest VM ID is reasonable */
-            if ((dest < 0) || (dest > s->max_peer)) {
+            if (dest > s->max_peer) { IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest); break;
             }

             /* check doorbell range */
-            if ((vector >= 0) && (vector < s->peers[dest].nb_eventfds)) { +            if (vector < s->peers[dest].nb_eventfds) {

Quoted 6 lines
Quoted 3 lines

                 IVSHMEM_DPRINTF("Writing %" PRId64 " to VM %d on vector %d\n", write_one, dest, vector); if (write(s->peers[dest].eventfds[vector],

This patch works for me.

Jes, correct result is this patch works for me on x86_64 system. However, in i386 system, there is another bug:

Quoted 10 lines

...
 CC    x86_64-softmmu/ivshmem.o
 CC    x86_64-softmmu/fpu/softfloat-native.o
 CC    x86_64-softmmu/op_helper.o
cc1: warnings being treated as errors
/home/build/gitrepo/qemu/hw/ivshmem.c: In function 'check_shm_size. /home/build/gitrepo/qemu/hw/ivshmem.c:357: warning: format '%ld' expects type 'long int', but argt 5 has type '__off64_t make[1]: *** [ivshmem.o] Error 1
make[1]: *** Waiting for unfinished jobs....
make: *** [subdir-x86_64-softmmu] Error 2

Quoted 2 lines

Hmm, that was causing problems on 32-bit systems, not 64-bit.  Is this with gcc 4.1.2?

Oh sorry, I read too fast, you did say it was on 32-bit. Avi's patch will do the trick.

Cam

Acked-by on v1 1/1
#5 lore raw
In reply to [email protected]
Quoted 27 lines · On Mon, Aug 30, 2010 at 4:31 AM, <[email protected]> wrote:

From: Jes Sorensen <[email protected]>

There is no need to check for dest < 0 or vector >= 0 as both are uint16_t.

This should fix problems with broken build with aggressive compiler flags. Reported by Xudong Hao <[email protected]>

---
 hw/ivshmem.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
hw/ivshmem.c +0 -0
index bbb5cba..afebbc3 100644
@@ -199,13 +199,13 @@ static void ivshmem_io_writel(void *opaque, target_phys_addr_t addr,
 

        case DOORBELL:
            /* check that dest VM ID is reasonable */
-            if ((dest < 0) || (dest > s->max_peer)) {
+            if (dest > s->max_peer) { IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest); break;
            }

Quoted 10 lines

            /* check doorbell range */
-            if ((vector >= 0) && (vector < s->peers[dest].nb_eventfds)) {
+            if (vector < s->peers[dest].nb_eventfds) { IVSHMEM_DPRINTF("Writing %" PRId64 " to VM %d on vector %d\n", write_one, dest, vector); if (write(s->peers[dest].eventfds[vector],
--
1.7.2.2

I sent a patch yesterday that addressed it, but it is probably better to remove the tests that switched to signed 16-bit ints.

Anthony, please apply this one.

Cam

Applied
#6 lore raw
In reply to [email protected]

Thanks, applied.

Quoted 38 lines · On Mon, Aug 30, 2010 at 10:31 AM, <[email protected]> wrote:

From: Jes Sorensen <[email protected]>

There is no need to check for dest < 0 or vector >= 0 as both are uint16_t.

This should fix problems with broken build with aggressive compiler flags. Reported by Xudong Hao <[email protected]>

---
 hw/ivshmem.c |    4 ++--

 1 files changed, 2 insertions(+), 2 deletions(-)
hw/ivshmem.c +0 -0
index bbb5cba..afebbc3 100644
@@ -199,13 +199,13 @@ static void ivshmem_io_writel(void *opaque, target_phys_addr_t addr,
 

        case DOORBELL:
            /* check that dest VM ID is reasonable */
-            if ((dest < 0) || (dest > s->max_peer)) {
+            if (dest > s->max_peer) { IVSHMEM_DPRINTF("Invalid destination VM ID (%d)\n", dest); break;
            }

            /* check doorbell range */
-            if ((vector >= 0) && (vector < s->peers[dest].nb_eventfds)) {
+            if (vector < s->peers[dest].nb_eventfds) { IVSHMEM_DPRINTF("Writing %" PRId64 " to VM %d on vector %d\n", write_one, dest, vector); if (write(s->peers[dest].eventfds[vector],
--
1.7.2.2