linux-user: properly check flags in openat2
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.
Signed-off-by Andreas Schwab <[email protected]>
--- linux-user/syscall.c | 4 ++++ 1 file changed, 4 insertions(+)
linux-user/syscall.c +4 -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 ; + } + 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."
Quoted 13 lines · Andreas Schwab
target_to_host_bitmasktruncates the bitmask to int. Check that the upper half of the flags do not have any bits set.Signed-off-by Andreas Schwab <[email protected]>--- linux-user/syscall.c | 4 ++++ 1 file changed, 4 insertions(+)linux-user/syscall.c +0
-0
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.
Reviewed-by Helge Deller <[email protected]>
Helge
Quoted 4 lines
linux-user/syscall.c +1
-0+ pathname =lock_user_string (guest_pathname);if (!pathname) {return -TARGET_EFAULT ;