Skip to contentSkip to conversation

linux-user: properly check flags in openat2

PATCH In review Andreas Schwab 2 participants 2 messages Feb 10

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 linux-user: properly check flags in openat2

target_to_host_bitmask truncates the bitmask to int. Check that the upper half of the flags do not have any bits set.

---
 linux-user/syscall.c | 4 ++++
 1 file changed, 4 insertions(+)
linux-user/syscall.c +4 -0
index 8469b81878..667aea6a03 100644
@@ -8822,6 +8822,10 @@ static int do_openat2(CPUArchState *cpu_env, abi_long dirfd,
         }
         return ret;
     }
+    if (tswap64(how.flags) >> 32) {
+        return -TARGET_EINVAL;
+    }
+
     pathname = lock_user_string(guest_pathname);
     if (!pathname) {
         return -TARGET_EFAULT;
Signature · 7 lines
2.53.0


-- 
Andreas Schwab, SUSE Labs, [email protected]
GPG Key fingerprint = 0196 BAD8 1CE9 1970 F4BE  1748 E4D4 88E3 0EEA B9D7
"And now for something completely different."
Reviewed-by on v1 1/1
#1 lore raw
Quoted 13 lines · Andreas Schwab

target_to_host_bitmask truncates the bitmask to int. Check that the upper half of the flags do not have any bits set.

---
  linux-user/syscall.c | 4 ++++
  1 file changed, 4 insertions(+)
linux-user/syscall.c +0 -0
index 8469b81878..667aea6a03 100644

linux-user/syscall.c static int do_openat2(CPUArchState *cpu_env, abi_long dirfd, · line 8827

Quoted 6 lines
linux-user/syscall.c +3 -0
@@ -8822,6 +8822,10 @@ static int do_openat2(CPUArchState *cpu_env, abi_long dirfd,
          }
          return ret;
      }
+    if (tswap64(how.flags) >> 32) {
+        return -TARGET_EINVAL;
+    }

Seems a little hackish. Basically target_to_host_bitmask() could be extended to handle 64bit values too.
But as long as all values which we test fits into 32-bits, I think this is a valid patch.

Helge

Quoted 4 lines
linux-user/syscall.c +1 -0
+
      pathname = lock_user_string(guest_pathname);
      if (!pathname) {
          return -TARGET_EFAULT;