Bug 1119486 - Coverity reports STACK_USE error at qemu-kvm-x86.c:1546
Summary: Coverity reports STACK_USE error at qemu-kvm-x86.c:1546
Keywords:
Status: CLOSED WONTFIX
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: qemu-kvm
Version: 6.6
Hardware: Unspecified
OS: Unspecified
unspecified
unspecified
Target Milestone: rc
: ---
Assignee: Eduardo Habkost
QA Contact: Virtualization Bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2014-07-14 21:29 UTC by Jeff Nelson
Modified: 2014-07-24 19:42 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2014-07-24 19:42:17 UTC


Attachments (Terms of Use)

Description Jeff Nelson 2014-07-14 21:29:59 UTC
Description of problem:
   Coverity reports STACK_USE error at qemu-kvm-x86.c:1546

Version-Release number of selected component (if applicable):
    6.6.0

How reproducible:
    100%

Steps to Reproduce:
1. make -C redhat rh-test-patch             then
2. make -C redhat rh-brew-covscan           then
3. review patch results.

Actual results:
   A Coverity error appears, looking like this:

       Error: STACK_USE: [#def12]
       qemu-kvm-0.12.1.2/qemu-kvm-x86.c:1546: stack_use_local_overflow:
          Local variable "copy" uses 57376 bytes of stack space,
          which exceeds the maximum single use of 10000 bytes.

Expected results:
   No Coverity error.

Additional info:
   The line in question was introduced by commit 3e7e951d way back in 2007. I believe a newer version of Coverity was recently installed, and that is why this error hasn't been reported before.

   The actual line reported by Coverity may be different than 1546. The error occurs in routine kvm_arch_init_vcpu(CPUState *cenv). The code leading up to and including the line with the error looks like:

    int kvm_arch_init_vcpu(CPUState *cenv)
    {
        struct kvm_cpuid_entry2 cpuid_ent[100];
        struct kvm_cpuid_entry2 *c;
    #ifdef KVM_CPUID_SIGNATURE
        struct kvm_cpuid_entry2 *pv_ent;
        uint32_t signature[3];
    #endif
        int cpuid_nent = 0;
--->    CPUState copy;

Comment 2 Eduardo Habkost 2014-07-15 18:54:47 UTC
The 10000 bytes limit seems arbitrary, what's the reason for that limit?

Using 57k of the stack in a single function is not nice, but that's code in the initialization path which runs only once for each VCPU, so I don't see any potential for trouble.

Does anybody have any argument for treating this as a real bug and not closing this BZ as NOTABUG?

Comment 3 Eric Blake 2014-07-15 20:32:38 UTC
(In reply to Eduardo Habkost from comment #2)
> The 10000 bytes limit seems arbitrary, what's the reason for that limit?
> 
> Using 57k of the stack in a single function is not nice, but that's code in
> the initialization path which runs only once for each VCPU, so I don't see
> any potential for trouble.
> 
> Does anybody have any argument for treating this as a real bug and not
> closing this BZ as NOTABUG?

Any function that uses more than 4k of stack risks missing the guard page that the OS uses to auto-grow the stack, which can lead to all sorts of obscure behavior.  It would be nice if upstream qemu could take a leaf from libvirt and be fixed to compile with -Wframe-larger-than=4096.

Comment 4 Eduardo Habkost 2014-07-16 00:34:34 UTC
Reopening.


Note You need to log in before you can comment on or make changes to this bug.