Skip to contentSkip to conversation

linux-users/syscall: make do_ioctl_rt safer

PATCH In review Alex Bennée 2 participants 2 messages Nov 8, 2018

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-users/syscall: make do_ioctl_rt safer

host_rt_dev_ptr is set while looping through a control structure. The compiler can not know that all structures passed to do_ioctl_rt will trigger the if clause so rightly complains with an --enable-sanitizers build. To keep the compiler happy we default the host_rt_dev_ptr and check it has been set before attempting to follow it.

---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +2 -2
index 810a58b704..3a942f1f4a 100644
@@ -4669,7 +4669,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
     int target_size;
     void *argptr;
     abi_ulong *target_rt_dev_ptr;
-    unsigned long *host_rt_dev_ptr;
+    unsigned long *host_rt_dev_ptr = NULL;
     abi_long ret;
     int i;
 
@@ -4715,7 +4715,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
     unlock_user(argptr, arg, 0);
 
     ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp));
-    if (*host_rt_dev_ptr != 0) {
+    if (host_rt_dev_ptr && *host_rt_dev_ptr != 0) {
         unlock_user((void *)*host_rt_dev_ptr,
                     *target_rt_dev_ptr, 0);
     }
Signature · 1 line
2.17.1
#1 lore raw
Quoted 26 lines · Alex Bennée

host_rt_dev_ptr is set while looping through a control structure. The compiler can not know that all structures passed to do_ioctl_rt will trigger the if clause so rightly complains with an --enable-sanitizers build. To keep the compiler happy we default the host_rt_dev_ptr and check it has been set before attempting to follow it.

---
 linux-user/syscall.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
linux-user/syscall.c +1 -1
index 810a58b704..3a942f1f4a 100644
@@ -4669,7 +4669,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
     int target_size;
     void *argptr;
     abi_ulong *target_rt_dev_ptr;
-    unsigned long *host_rt_dev_ptr;
+    unsigned long *host_rt_dev_ptr = NULL;
     abi_long ret;
     int i;
 

linux-user/syscall.c static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp, · line 4718

Quoted 5 lines
linux-user/syscall.c +1 -1
@@ -4715,7 +4715,7 @@ static abi_long do_ioctl_rt(const IOCTLEntry *ie, uint8_t *buf_temp,
     unlock_user(argptr, arg, 0);
 
     ret = get_errno(safe_ioctl(fd, ie->host_cmd, buf_temp));
-    if (*host_rt_dev_ptr != 0) {
+    if (host_rt_dev_ptr && *host_rt_dev_ptr != 0) {

As host_rt_dev_ptr should be set in every case, I think an "assert(host_rt_dev_ptr != NULL)" would be more meaningful.

Thanks,
Laurent