Skip to contentSkip to conversation

linux-user: Fix payload size logic in host_to_target_cmsg()

PATCH In review Peter Maydell 2 participants 2 messages May 18, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: Fix payload size logic in host_to_target_cmsg()

Coverity points out that there's a missing break in the switch in host_to_target_cmsg() where we update tgt_len for cmsg_level/cmsg_type combinations which require a different length for host and target (CID 1385425). To avoid duplicating the default case (target length same as host) in both switches, set that before the switch so that only the cases which want to override it need any code.

This fixes a bug where we would have used the wrong length for SOL_SOCKET/SO_TIMESTAMP messages where the target and host have differently sized 'struct timeval' (ie one is 32 bit and the other is 64 bit).

---
 linux-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/syscall.c +2 -1
index af8603f1b7..88d166cdff 100644
@@ -1825,6 +1825,7 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         /* Payload types which need a different size of payload on
          * the target must adjust tgt_len here.
          */
+        tgt_len = len;
         switch (cmsg->cmsg_level) {
         case SOL_SOCKET:
             switch (cmsg->cmsg_type) {
@@ -1834,8 +1835,8 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
             default:
                 break;
             }
+            break;
         default:
-            tgt_len = len;
             break;
         }
 
Signature · 1 line
2.17.0
Reviewed-by on v1 1/1
#1 lore raw

Le 18/05/2018 à 20:47, Peter Maydell a écrit :

Quoted 32 lines

Coverity points out that there's a missing break in the switch in host_to_target_cmsg() where we update tgt_len for cmsg_level/cmsg_type combinations which require a different length for host and target (CID 1385425). To avoid duplicating the default case (target length same as host) in both switches, set that before the switch so that only the cases which want to override it need any code.

This fixes a bug where we would have used the wrong length for SOL_SOCKET/SO_TIMESTAMP messages where the target and host have differently sized 'struct timeval' (ie one is 32 bit and the other is 64 bit).

---
 linux-user/syscall.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
linux-user/syscall.c +1 -0
index af8603f1b7..88d166cdff 100644
@@ -1825,6 +1825,7 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
         /* Payload types which need a different size of payload on
          * the target must adjust tgt_len here.
          */
+        tgt_len = len;
         switch (cmsg->cmsg_level) {
         case SOL_SOCKET:
             switch (cmsg->cmsg_type) {

linux-user/syscall.c static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh, · line 1842

Quoted 9 lines
linux-user/syscall.c +1 -1
@@ -1834,8 +1835,8 @@ static inline abi_long host_to_target_cmsg(struct target_msghdr *target_msgh,
             default:
                 break;
             }
+            break;
         default:
-            tgt_len = len;
             break;
         }