plugins: fix syscall filter return value type
v2 cover plugins: fix syscall filter return value type
Hi,
The sysret value of the syscall filter callback is declared as uint64_t, but it is semantically signed: the negative range encodes errno. This makes it int64_t, matching the ret parameter of qemu_plugin_vcpu_syscall_ret_cb_t, which already uses int64_t for the same syscall return value.
As discussed on v1, this is not a correctness fix (the filter only sets sysret, so the bit pattern is the same either way); it is a consistency and readability improvement, so that the same syscall return value is typed the same way on the read side and the write side.
I did not bump QEMU_PLUGIN_VERSION, since this only changes the signedness of an existing argument.
v1: https://lore.kernel.org/qemu-devel/[email protected]/
Changes since v1:
- rebased onto current master, where the syscall callbacks now take a userdata argument; the filter signatures were adjusted to keep that while changing only the sysret type. No functional change otherwise.
Thanks for your review.
Ziyang Zhang (1):
plugins: use int64_t for the syscall filter return value
include/plugins/qemu-plugin.h | 2 +- include/qemu/plugin.h | 4 ++-- linux-user/syscall.c | 2 +- plugins/core.c | 2 +- tests/tcg/plugins/setpc.c | 2 +- tests/tcg/plugins/syscall.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
Signature · 1 line
2.34.1
PATCH v2 1/1 plugins: use int64_t for the syscall filter return value
The syscall return value passed back through the syscall filter callback is semantically signed: negative values encode errno codes. Declaring the sysret pointer as uint64_t * is therefore misleading and forces callers to launder the value through an unsigned temporary.
Change the sysret pointer to int64_t * across the public plugin API typedef (qemu_plugin_vcpu_syscall_filter_cb_t), the internal qemu_plugin_vcpu_syscall_filter() prototypes and stub, its implementation in plugins/core.c, the linux-user caller, and the in-tree example plugins.
---
v2: rebased onto current master. The syscall callbacks now take a
userdata argument, so the filter signatures were adjusted to keep that while changing only the sysret type. No functional change.
--- include/plugins/qemu-plugin.h | 2 +- include/qemu/plugin.h | 4 ++-- linux-user/syscall.c | 2 +- plugins/core.c | 2 +- tests/tcg/plugins/setpc.c | 2 +- tests/tcg/plugins/syscall.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
include/plugins/qemu-plugin.h +1 -1
@@ -871,7 +871,7 @@ typedef bool int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7, uint64_t a8, - uint64_t *sysret, + int64_t *sysret, void *userdata);/**
include/qemu/plugin.h +2 -2
@@ -172,7 +172,7 @@ bool qemu_plugin_vcpu_syscall_filter(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7, - uint64_t a8, uint64_t *sysret); + uint64_t a8, int64_t *sysret); void qemu_plugin_vcpu_mem_cb(CPUState *cpu, uint64_t vaddr, uint64_t value_low,
@@ -288,7 +288,7 @@ static inline bool qemu_plugin_vcpu_syscall_filter(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7, - uint64_t a8, uint64_t *sysret) + uint64_t a8, int64_t *sysret) {return false; }
linux-user/syscall.c +1 -1
@@ -14619,7 +14619,7 @@ static bool send_through_syscall_filters(CPUState *cpu, int num, abi_long arg7, abi_long arg8, abi_long *sysret) { - uint64_t sysret64 = 0; + int64_t sysret64 = 0;bool filtered =qemu_plugin_vcpu_syscall_filter (cpu, num, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, &sysret64);
plugins/core.c +1 -1
@@ -573,7 +573,7 @@ bool qemu_plugin_vcpu_syscall_filter(CPUState *cpu, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7, - uint64_t a8, uint64_t *sysret) + uint64_t a8, int64_t *sysret) {struct qemu_plugin_cb *cb, *next;enum qemu_plugin_event ev =QEMU_PLUGIN_EV_VCPU_SYSCALL_FILTER ;
tests/tcg/plugins/setpc.c +1 -1
@@ -27,7 +27,7 @@ static bool vcpu_syscall_filter(unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7, uint64_t a8, - uint64_t *sysret, void *userdata) + int64_t *sysret, void *userdata) { if (num == MAGIC_SYSCALL) { if (a1 == SETPC) {
tests/tcg/plugins/syscall.c +1 -1
@@ -176,7 +176,7 @@ static bool vcpu_syscall_filter(unsigned int vcpu_index, int64_t num, uint64_t a1, uint64_t a2, uint64_t a3, uint64_t a4, uint64_t a5, uint64_t a6, uint64_t a7, uint64_t a8, - uint64_t *sysret, void *userdata) + int64_t *sysret, void *userdata) { /* Special syscall to test the filter functionality. */ if (num == 4096 && a1 == 0x66CCFF) {
Signature · 1 line
2.34.1
Re: [PATCH v2 1/1] plugins: use int64_t for the syscall filter return value
Quoted 16 lines · Ziyang Zhang
The syscall return value passed back through the syscall filter callback is semantically signed: negative values encode errno codes. Declaring the sysret pointer as
uint64_t* is therefore misleading and forces callers to launder the value through an unsigned temporary.Change the sysret pointer to
int64_t* across the public plugin API typedef (qemu_plugin_vcpu_syscall_filter_cb_t), the internalqemu_plugin_vcpu_syscall_filter()prototypes and stub, its implementation inplugins/core.c, the linux-user caller, and the in-tree example plugins.Signed-off-by Ziyang Zhang <[email protected]>---
v2: rebased onto current master. The syscall callbacks now take a
userdata argument, so the filter signatures were adjusted to keep that while changing only the sysret type. No functional change.
Quoted 9 lines
--- include/plugins/qemu-plugin.h | 2 +- include/qemu/plugin.h | 4 ++-- linux-user/syscall.c | 2 +- plugins/core.c | 2 +- tests/tcg/plugins/setpc.c | 2 +- tests/tcg/plugins/syscall.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
Re: [PATCH v2 1/1] plugins: use int64_t for the syscall filter return value
In reply to Ziyang ZhangQuoted 5 lines · Ziyang Zhang
The syscall return value passed back through the syscall filter callback is semantically signed: negative values encode errno codes. Declaring the sysret pointer as
uint64_t* is therefore misleading and forces callers to launder the value through an unsigned temporary.
Quoted 7 lines
Change the sysret pointer to
int64_t* across the public plugin API typedef (qemu_plugin_vcpu_syscall_filter_cb_t), the internalqemu_plugin_vcpu_syscall_filter()prototypes and stub, its implementation inplugins/core.c, the linux-user caller, and the in-tree example plugins.Signed-off-by Ziyang Zhang <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Quoted 28 lines · Ziyang Zhang
Hi,
The sysret value of the syscall filter callback is declared as
uint64_t, but it is semantically signed: the negative range encodes errno. This makes itint64_t, matching the ret parameter ofqemu_plugin_vcpu_syscall_ret_cb_t, which already usesint64_tfor the same syscall return value.As discussed on v1, this is not a correctness fix (the filter only sets sysret, so the bit pattern is the same either way); it is a consistency and readability improvement, so that the same syscall return value is typed the same way on the read side and the write side.
I did not bump
QEMU_PLUGIN_VERSION, since this only changes the signedness of an existing argument.v1: https://lore.kernel.org/qemu-devel/[email protected]/
Changes since v1:
- rebased onto current master, where the syscall callbacks now take a userdata argument; the filter signatures were adjusted to keep that while changing only the sysret type. No functional change otherwise.Thanks for your review.
Ziyang Zhang (1):
plugins: useint64_tfor the syscall filter return value
Quoted 8 lines
include/plugins/qemu-plugin.h | 2 +- include/qemu/plugin.h | 4 ++-- linux-user/syscall.c | 2 +- plugins/core.c | 2 +- tests/tcg/plugins/setpc.c | 2 +- tests/tcg/plugins/syscall.c | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-)
This was merged into master (b83371668192a705b878e909c5ae9c1233cbd5fb). Thank you for your contribution!
Regards,
Pierrick