x86/hvm_event: fix uninitialized struct field usage introduced by c/s f5365e6
PATCH 1/1 x86/hvm_event: fix uninitialized struct field usage introduced by c/s f5365e6
c/s f5365e6: "xen/vm-events: Move parts of monitor_domctl code to common-side", introduced a use without initialization issue. hvm_event_breakpoint calls hvm_event_traps(&req) and if sync is true that ors some bits into req->flags which was never initialised. Reported by Coverity Scan.
Initializes req @ hvm_event_breakpoint entry.
--- xen/arch/x86/hvm/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
xen/arch/x86/hvm/event.c +1 -1
@@ -173,7 +173,7 @@ int hvm_event_breakpoint(unsigned long rip, {struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch; -vm_event_request_t req; +vm_event_request_t req = {};switch ( type ) {
Signature · 1 line
2.5.0
Quoted 18 lines · Corneliu ZUZU
c/s f5365e6: "xen/vm-events: Move parts of
monitor_domctlcode to common-side", introduced a use without initialization issue.hvm_event_breakpointcallshvm_event_traps(&req)and if sync is true that ors some bits intoreq->flagswhich was never initialised. Reported by Coverity Scan.Initializes req @
hvm_event_breakpointentry.Signed-off-by Corneliu ZUZU <[email protected]>--- xen/arch/x86/hvm/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/hvm/event.c +0
-0
xen/arch/x86/hvm/event.c int hvm_event_breakpoint(unsigned long rip, · line 179
Quoted 8 lines
xen/arch/x86/hvm/event.c +1
-1@@ -173,7 +173,7 @@ int hvm_event_breakpoint(unsigned long rip, {struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch; -vm_event_request_t req; +vm_event_request_t req = {};switch ( type ) {
Quoted 3 lines · Razvan Cojocaru
Quoted 1 line · Corneliu ZUZU
c/s f5365e6: "xen/vm-events: Move parts of
monitor_domctlcode to
common-side",
Quoted 2 lines
Quoted 2 lines
introduced a use without initialization issue.
hvm_event_breakpointcallshvm_event_traps(&req)and if sync is true
that
Quoted 10 lines
Quoted 10 lines
ors some bits into
req->flagswhich was never initialised. Reported by Coverity Scan.Initializes req @
hvm_event_breakpointentry.Signed-off-by Corneliu ZUZU <[email protected]>--- xen/arch/x86/hvm/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 10 lines
xen/arch/x86/hvm/event.c int hvm_event_breakpoint(unsigned long rip, · line 176
Quoted 10 lines
xen/arch/x86/hvm/event.c +1
-1@@ -173,7 +173,7 @@ int hvm_event_breakpoint(unsigned long rip, {struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch; -vm_event_request_t req; +vm_event_request_t req = {};
Should this be = { 0 } instead? Also, as I recall the request is not initialized on any of the paths, so we might as well do it for all of them, not just here. It would help avoid the listener erronously using some fields that were not actually initialized as well.
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 21 lines · Tamas K Lengyel
Quoted 3 lines · On Feb 18, 2016 03:46, "Razvan Cojocaru" <[email protected]…
Quoted 1 line · Corneliu ZUZU
c/s f5365e6: "xen/vm-events: Move parts of
monitor_domctlcode tocommon-side",
Quoted 2 lines
Quoted 2 lines
introduced a use without initialization issue.
hvm_event_breakpointcallshvm_event_traps(&req)and if sync is truethat
Quoted 6 lines
Quoted 6 lines
ors some bits into
req->flagswhich was never initialised. Reported by Coverity Scan.Initializes req @
hvm_event_breakpointentry.Signed-off-by Corneliu ZUZU <[email protected]<mailto:[email protected]>>
Quoted 4 lines
Quoted 4 lines
--- xen/arch/x86/hvm/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 15 lines
Quoted 10 lines
xen/arch/x86/hvm/event.c int hvm_event_breakpoint(unsigned long rip, · line 176
Quoted 10 lines
xen/arch/x86/hvm/event.c +1
-1@@ -173,7 +173,7 @@ int hvm_event_breakpoint(unsigned long rip, {struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch; -vm_event_request_t req; +vm_event_request_t req = {};Should this be = { 0 } instead? Also, as I recall the request is not initialized on any of the paths, so we might as well do it for all of them, not just here. It would help avoid the listener erronously using some fields that were not actually initialized as well.
That should achieve the same thing. I first looked up "= {}" in the Xen source code and found:
$ grep -R "= {}"
arch/arm/domain_build.c: struct kernel_info kinfo = {};
arch/x86/time.c: struct vcpu_time_info *u, _u = {};
arch/x86/tboot.c: uint8_t nonce[16] = {};
arch/x86/tboot.c: uint8_t nonce[16] = {};
arch/x86/tboot.c: uint8_t nonce[16] = {};
arch/x86/traps.c: unsigned char insns_before[8] = {}, insns_after[16] = {};
arch/x86/x86_emulate/x86_emulate.c: union vex vex = {};
arch/x86/x86_emulate/x86_emulate.c: struct x86_emulate_stub stub = {};
arch/x86/cpu/mtrr/generic.c:struct mtrr_state mtrr_state = {};
arch/x86/cpu/common.c:const struct cpu_dev *__read_mostly
cpu_devs[X86_VENDOR_NUM] = {};
arch/x86/domain.c: unsigned long total[MASK_EXTR(PGT_type_mask,
PGT_type_mask) + 1] = {};
tools/kconfig/expr.c: union string_value lval = {}, rval = {};
common/grant_table.c: struct gnttab_copy_buf src = {};
common/grant_table.c: struct gnttab_copy_buf dest = {};So I thought that that's the prevailing convention. I've now searched for "= {0}", and I see that that has also been done, so I suppose either way is fine as far as the coding style goes?
$ grep -R "= {0}"
arch/arm/mm.c: lpae_t pte = {0};
arch/arm/mm.c: lpae_t pte = {0};
drivers/char/exynos4210-uart.c:} exynos4210_com = {0};
drivers/char/pl011.c:} pl011_com = {0};
drivers/char/omap-uart.c:} omap_com = {0};
drivers/char/scif-uart.c:} scif_com = {0};
drivers/char/cadence-uart.c:} cuart_com = {0};
tools/kconfig/nconf.gui.c:attributes_t attributes[ATTR_MAX+1] = {0};
crypto/vmac.c: uint64_t in[2] = {0}, out[2];Thanks,
Razvan
Quoted 59 lines · Razvan Cojocaru
Quoted 19 lines · Tamas K Lengyel
Quoted 2 lines · On Feb 18, 2016 03:46, "Razvan Cojocaru" <[email protected]…
Quoted 1 line · Corneliu ZUZU
c/s f5365e6: "xen/vm-events: Move parts of
monitor_domctlcode tocommon-side",
Quoted 2 lines
Quoted 2 lines
introduced a use without initialization issue.
hvm_event_breakpointcallshvm_event_traps(&req)and if sync is truethat
Quoted 6 lines
Quoted 6 lines
ors some bits into
req->flagswhich was never initialised. Reported by Coverity Scan.Initializes req @
hvm_event_breakpointentry.Signed-off-by Corneliu ZUZU <[email protected]<mailto:[email protected]>>
Quoted 4 lines
Quoted 4 lines
--- xen/arch/x86/hvm/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
Quoted 10 lines
xen/arch/x86/hvm/event.c int hvm_event_breakpoint(unsigned long rip, · line 176
Quoted 10 lines
xen/arch/x86/hvm/event.c +1
-1@@ -173,7 +173,7 @@ int hvm_event_breakpoint(unsigned long rip, {struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch; -vm_event_request_t req; +vm_event_request_t req = {};Should this be = { 0 } instead? Also, as I recall the request is not initialized on any of the paths, so we might as well do it for all of them, not just here. It would help avoid the listener erronously using some fields that were not actually initialized as well.
That should achieve the same thing. I first looked up "= {}" in the Xen source code and found:
$ grep -R "= {}" arch/arm/domain_build.c: struct kernel_info kinfo = {}; arch/x86/time.c: struct vcpu_time_info *u, _u = {}; arch/x86/tboot.c: uint8_t nonce[16] = {}; arch/x86/tboot.c: uint8_t nonce[16] = {}; arch/x86/tboot.c: uint8_t nonce[16] = {}; arch/x86/traps.c: unsigned char insns_before[8] = {}, insns_after[16] = {}; arch/x86/x86_emulate/x86_emulate.c: union vex vex = {}; arch/x86/x86_emulate/x86_emulate.c: struct x86_emulate_stub stub = {}; arch/x86/cpu/mtrr/generic.c:struct mtrr_state mtrr_state = {}; arch/x86/cpu/common.c:const struct cpu_dev *__read_mostly cpu_devs[X86_VENDOR_NUM] = {}; arch/x86/domain.c: unsigned long total[MASK_EXTR(PGT_type_mask, PGT_type_mask) + 1] = {}; tools/kconfig/expr.c: union string_value lval = {}, rval = {}; common/grant_table.c: struct gnttab_copy_buf src = {}; common/grant_table.c: struct gnttab_copy_buf dest = {};So I thought that that's the prevailing convention. I've now searched for "= {0}", and I see that that has also been done, so I suppose either way is fine as far as the coding style goes?
Quoted 10 lines
$ grep -R "= {0}"
arch/arm/mm.c: lpae_t pte = {0};
arch/arm/mm.c: lpae_t pte = {0};
drivers/char/exynos4210-uart.c:} exynos4210_com = {0};
drivers/char/pl011.c:} pl011_com = {0};
drivers/char/omap-uart.c:} omap_com = {0};
drivers/char/scif-uart.c:} scif_com = {0};
drivers/char/cadence-uart.c:} cuart_com = {0};
tools/kconfig/nconf.gui.c:attributes_t attributes[ATTR_MAX+1] = {0};
crypto/vmac.c: uint64_t in[2] = {0}, out[2];The two are equivalent as far as C goes. I prefer the former as it is slightly shorter.
~Andrew
Quoted 72 lines · Andrew Cooper
Quoted 37 lines · Razvan Cojocaru
Quoted 19 lines · Tamas K Lengyel
Quoted 2 lines · On Feb 18, 2016 03:46, "Razvan Cojocaru" <[email protected]…
Quoted 1 line · Corneliu ZUZU
c/s f5365e6: "xen/vm-events: Move parts of
monitor_domctlcode tocommon-side",
Quoted 2 lines
Quoted 2 lines
introduced a use without initialization issue.
hvm_event_breakpointcallshvm_event_traps(&req)and if sync is truethat
Quoted 6 lines
Quoted 6 lines
ors some bits into
req->flagswhich was never initialised. Reported by Coverity Scan.Initializes req @
hvm_event_breakpointentry.Signed-off-by Corneliu ZUZU <[email protected]<mailto:[email protected]>>
Quoted 4 lines
Quoted 4 lines
--- xen/arch/x86/hvm/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)Quoted 14 lines
Quoted 10 lines
xen/arch/x86/hvm/event.c int hvm_event_breakpoint(unsigned long rip, · line 176
Quoted 10 lines
xen/arch/x86/hvm/event.c +1
-1@@ -173,7 +173,7 @@ int hvm_event_breakpoint(unsigned long rip, {struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch; -vm_event_request_t req; +vm_event_request_t req = {};Should this be = { 0 } instead? Also, as I recall the request is not initialized on any of the paths, so we might as well do it for all of them, not just here. It would help avoid the listener erronously using some fields that were not actually initialized as well.
That should achieve the same thing. I first looked up "= {}" in the Xen source code and found:
Quoted 7 lines
$ grep -R "= {}" arch/arm/domain_build.c: struct kernel_info kinfo = {}; arch/x86/time.c: struct vcpu_time_info *u, _u = {}; arch/x86/tboot.c: uint8_t nonce[16] = {}; arch/x86/tboot.c: uint8_t nonce[16] = {}; arch/x86/tboot.c: uint8_t nonce[16] = {}; arch/x86/traps.c: unsigned char insns_before[8] = {}, insns_after[16] ={};
Quoted 15 lines
arch/x86/x86_emulate/x86_emulate.c: union vex vex = {};arch/x86/x86_emulate/x86_emulate.c: structx86_emulate_stubstub = {}; arch/x86/cpu/mtrr/generic.c:structmtrr_statemtrr_state= {}; arch/x86/cpu/common.c:const structcpu_dev*__read_mostlycpu_devs[X86_VENDOR_NUM] = {};arch/x86/domain.c: unsigned long total[MASK_EXTR(PGT_type_mask,PGT_type_mask) + 1] = {};tools/kconfig/expr.c: unionstring_valuelval = {}, rval = {};common/grant_table.c: structgnttab_copy_bufsrc = {};common/grant_table.c: structgnttab_copy_bufdest = {};So I thought that that's the prevailing convention. I've now searched for "= {0}", and I see that that has also been done, so I suppose either way is fine as far as the coding style goes?
Quoted 10 lines
$ grep -R "= {0}" arch/arm/mm.c: lpae_t pte = {0}; arch/arm/mm.c: lpae_t pte = {0}; drivers/char/exynos4210-uart.c:} exynos4210_com = {0}; drivers/char/pl011.c:} pl011_com = {0}; drivers/char/omap-uart.c:} omap_com = {0}; drivers/char/scif-uart.c:} scif_com = {0}; drivers/char/cadence-uart.c:} cuart_com = {0}; tools/kconfig/nconf.gui.c:attributes_t attributes[ATTR_MAX+1] = {0}; crypto/vmac.c: uint64_t in[2] = {0}, out[2];
Quoted 2 lines
The two are equivalent as far as C goes. I prefer the former as it is slightly shorter.
OK, as long as they are equivalent I'm fine with either. I always use the {0} syntax, it looks more explicit to me, so just wanted to double-check that it means the same thing.
Thanks,
Tamas
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel
Quoted 7 lines · Corneliu ZUZU
c/s f5365e6: "xen/vm-events: Move parts of
monitor_domctlcode to common-side", introduced a use without initialization issue.hvm_event_breakpointcallshvm_event_traps(&req)and if sync is true that ors some bits intoreq->flagswhich was never initialised. Reported by Coverity Scan.Initializes req @
hvm_event_breakpointentry.
Coverity-ID: 1353192
Quoted 1 line
Signed-off-by Corneliu ZUZU <[email protected]>
Quoted 17 lines
--- xen/arch/x86/hvm/event.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)xen/arch/x86/hvm/event.c +1
-1@@ -173,7 +173,7 @@ int hvm_event_breakpoint(unsigned long rip, {struct vcpu *curr = current;struct arch_domain *ad = &curr->domain->arch; -vm_event_request_t req; +vm_event_request_t req = {};switch ( type ) {