hvm.c: Prevent gcc uninitialised var warning
PATCH 1/1 hvm.c: Prevent gcc uninitialised var warning
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 reports:
----------------------------------------------------------------------hvm.c: In function `hvm_create_ioreq_server':
hvm.c:487:18: error: `bufioreq_pfn' may be used uninitialised in this function [-Werror=uninitialized]
hvm.c:718:30: note: `bufioreq_pfn' was declared here
----------------------------------------------------------------------
My code analysis says that gcc is wrong, but initilize the variable to prevent the gcc warning.
---
Here is the patch for:
In-Reply-To: <A3CD31A5D207064088A18AC2AF7B5DC6C27A1E9F@MIA20725MBX891B.apps.tmrk.corp>
References: <9AAE0902D5BC7E449B7C8E4E778ABCD0258434BF@AMSPEX01CL01.citrite.net>
<[email protected]> <A3CD31A5D207064088A18AC2AF7B5DC6C27A1E9F@MIA20725MBX891B.apps.tmrk.corp>
Subject: Re: [Xen-devel] Compliling Xen 4.5.0 Fails with error:
=?UTF-8?Q?=E2=80=98bufioreq=5Fpfn=E2=80=99?= may be used uninitialised in this function [-Werror=uninitialized]
xen/arch/x86/hvm/hvm.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
xen/arch/x86/hvm/hvm.c +2 -1
@@ -733,7 +733,8 @@ static int hvm_ioreq_server_map_pages(struct hvm_ioreq_server *s, bool_t is_default, bool_t handle_bufioreq) {struct domain *d = s->domain; -unsigned long ioreq_pfn, bufioreq_pfn; +unsigned long ioreq_pfn; +unsigned long bufioreq_pfn = ~0UL ;/* gcc uninitialised var warning */ int rc;if ( is_default )
Signature · 1 line
1.8.4
Quoted 8 lines · Don Slutz
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 reports:
----------------------------------------------------------------------hvm.c: In function `hvm_create_ioreq_server':
hvm.c:487:18: error: `bufioreq_pfn' may be used uninitialised in this function [-Werror=uninitialized]
hvm.c:718:30: note: `bufioreq_pfn' was declared here
----------------------------------------------------------------------
Quoted 5 lines
My code analysis says that gcc is wrong, but initilize the variable to prevent the gcc warning.
Reported-by Ian Murray <[email protected]>Signed-off-by Don Slutz <[email protected]>
GCC is correct and there is path through this function where bufioreq_pfn is used while uninitialised (non-debug build, is_default = 1, handle_bufioreq = 0).
As an aside, the compiler is in a very easy position to spot this. The error means that GCC has positively identified a basic block which does use bufioreq_pfn before it has been initialised.
I observe that the patch has been committed, but it merely hides the problem and doesn't fix it; hvm_free_ioreq_gmfn(d, bufioreq_pfn) will still clobber arbitrary memory.
No combination of parameters should be able to cause UB like this. In this case, the error handling is incredibly fragile. All the unmapping should be based on information in s->{,buf}ioreq which is set upon successful map, rather than the booleans indicating whether the function should have set up the mappings. This allows all the fail$N labels to collapse into a single, more simple, exit path.
~Andrew
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 25.03.15 at 16:02, <[email protected]> wrote:
Quoted 4 lines · Don Slutz
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 reports:
----------------------------------------------------------------------hvm.c: In function `hvm_create_ioreq_server':
hvm.c:487:18: error: `bufioreq_pfn' may be used uninitialised in thisfunction
Quoted 7 lines
[-Werror=uninitialized]
hvm.c:718:30: note: `bufioreq_pfn' was declared here
----------------------------------------------------------------------My code analysis says that gcc is wrong, but initilize the variable to prevent the gcc warning.
Quoted 6 lines
Quoted 2 lines
Reported-by Ian Murray <[email protected]>Signed-off-by Don Slutz <[email protected]>GCC is correct and there is path through this function where
bufioreq_pfnis used while uninitialised (non-debug build,is_default= 1,handle_bufioreq= 0).
I'm not seeing it: When is_default is set, bufioreq_pfn gets initialized in the first if()'s body.
Quoted 7 lines
As an aside, the compiler is in a very easy position to spot this. The error means that GCC has positively identified a basic block which does use
bufioreq_pfnbefore it has been initialised.I observe that the patch has been committed, but it merely hides the problem and doesn't fix it;
hvm_free_ioreq_gmfn(d, bufioreq_pfn)will still clobber arbitrary memory.
I committed the patch based on me not being able to find a path where the variable would actually be used uninitialized (and it is known that various gcc versions have varying levels of problems with correctly identifying such issues). If indeed there is a path that I'm not seeing, then I'd indeed favor reverting and putting in a proper, backportable fix.
Jan
Quoted 14 lines · Jan Beulich
Quoted 14 lines
Quoted 1 line
Quoted 1 line · On 25.03.15 at 16:02, <[email protected]> wrote:
Quoted 4 lines · Don Slutz
gcc (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3 reports:
----------------------------------------------------------------------hvm.c: In function `hvm_create_ioreq_server':
hvm.c:487:18: error: `bufioreq_pfn' may be used uninitialised in thisfunction
Quoted 7 lines
[-Werror=uninitialized]
hvm.c:718:30: note: `bufioreq_pfn' was declared here
----------------------------------------------------------------------My code analysis says that gcc is wrong, but initilize the variable to prevent the gcc warning.
Quoted 7 lines
Quoted 6 lines
Quoted 2 lines
Reported-by Ian Murray <[email protected]>Signed-off-by Don Slutz <[email protected]>GCC is correct and there is path through this function where
bufioreq_pfnis used while uninitialised (non-debug build,is_default= 1,handle_bufioreq= 0).
Looks like you are talking about the ASSERT(handle_bufioreq). But that does not leave bufioreq_pfn uninitialised.
Currently you cannot get here in that state. The only way to have is_default=1 is:
rc = hvm_create_ioreq_server(d, domid, 1, 1, NULL);
Which should prevent "handle_bufioreq == 0"
Quoted 7 lines
I'm not seeing it: When
is_defaultis set,bufioreq_pfngets initialized in the first if()'s body.Quoted 4 lines
As an aside, the compiler is in a very easy position to spot this. The error means that GCC has positively identified a basic block which does use
bufioreq_pfnbefore it has been initialised.
If the compiler is right, how come the messages says:
may be used
which to me says that it's determination is not 100%
Quoted 4 lines
Quoted 3 lines
I observe that the patch has been committed, but it merely hides the problem and doesn't fix it;
hvm_free_ioreq_gmfn(d, bufioreq_pfn)will still clobber arbitrary memory.
hvm_free_ioreq_gmfn() does have issues. And since it is possible to call it with
d->arch.hvm_domain.params[HVM_PARAM_BUFIOREQ_PFN]
which can be anything.
Quoted 7 lines
I committed the patch based on me not being able to find a path where the variable would actually be used uninitialized (and it is known that various gcc versions have varying levels of problems with correctly identifying such issues). If indeed there is a path that I'm not seeing, then I'd indeed favor reverting and putting in a proper, backportable fix.
I still cannot find a path where this fails. However I can provide a patch that does 2 things:
1) Change the "ASSERT(handle_bufioreq)" to "BUG_ON(handle_bufioreq);" (not sure it is required).
2) Add checking to hvm_free_ioreq_gmfn() to prevent memory clobber since it's arg may come from an HVM_PARAM.
-Don Slutz
Quoted 2 lines
Jan
Quoted 8 lines
Quoted 1 line
Quoted 1 line · On 25.03.15 at 21:03, <[email protected]> wrote:
Quoted 5 lines · Jan Beulich
Quoted 5 lines
Quoted 1 line
Quoted 1 line · On 25.03.15 at 16:02, <[email protected]> wrote:
As an aside, the compiler is in a very easy position to spot this. The error means that GCC has positively identified a basic block which does use
bufioreq_pfnbefore it has been initialised.
Quoted 5 lines
If the compiler is right, how come the messages says:
may be used
which to me says that it's determination is not 100%
No, that's a wrong interpretation of the wording - it instead means that there is at least one path where the variable gets initialized, and at least one where that's not provably the case. As opposed to a variable being used uninitialized no matter what path leads to the use site.
Jan
----- Original Message -----
Quoted 21 lines
From: Jan Beulich <[email protected]>
To: Don Slutz <[email protected]>
Cc: Ian Murray <[email protected]>; Andrew Cooper <[email protected]>; Keir Fraser <[email protected]>; Ian Campbell <[email protected]>; [email protected]
Sent: Thursday, 26 March 2015, 7:48
Subject: Re: [Xen-devel] [PATCH 1/1]hvm.c: Prevent gcc uninitialised var warningQuoted 3 lines
Quoted 1 line
Quoted 1 line · On 25.03.15 at 21:03, <[email protected]> wrote:
Quoted 1 line · Jan Beulich
Quoted 1 line
Quoted 1 line
Quoted 1 line
On 25.03.15 at 16:02, <[email protected]>
Quoted 1 line · wrote:
Quoted 1 line
Quoted 1 line
As an aside, the compiler is in a very easy position to spot this.
The
Quoted 1 line
Quoted 1 line
Quoted 1 line
error means that GCC has positively identified a basic block which
does
Quoted 7 lines
Quoted 2 lines
Quoted 2 lines
use
bufioreq_pfnbefore it has been initialised.If the compiler is right, how come the messages says:
may be used
Quoted 9 lines
Quoted 1 line
which to me says that it's determination is not 100%
No, that's a wrong interpretation of the wording - it instead means that there is at least one path where the variable gets initialized, and at least one where that's not provably the case. As opposed to a variable being used uninitialized no matter what path leads to the use site.
FWIW, I upgraded one of the boxes with the issue to Ubuntu 14.04.2 and gcc no longer complained.
# gcc --version gcc-4.8.real (Ubuntu 4.8.2-19ubuntu1) 4.8.2
Quoted 9 lines
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
http://lists.xen.org/xen-devel