Xen Security Advisory 55 - Multiple vulnerabilities in libelf PV kernel handling
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
A message that is not in the archive (sent off-list or not yet received): [email protected]
Chuck Anderson writes ("Re: Xen Security Advisory 55 - Multiple vulnerabilities> >> * 907abe4 2013-06-07 | libxc: check blob size before proceeding...
Quoted 14 lines
Quoted 7 lines
Quoted 7 lines
(quoted diff) +3
-0@@ -278,6 +278,10 @@ size_t xc_dom_check_gzip(xc_interface *xch, void *blob, siz + if ( ziplen < 6 ) + /* too small */ + return 0;Quoted 6 lines
Quoted 2 lines
Add #define for
MIN_ZIPLENand include a comment on why it is 6. Then:
+ if (MIN_ZIPLEN< 6 )The code below uses simple integers. Your proposal would separate the definition of the limit to be applied from the code which is to be protected, so I think it's better the way it is.
Quoted 4 lines
I think it is better to use good programming practices with new code even if existing code doesn't. In any case I think a comment saying why 6 is used would be a good. That way a reviewer knows what your assumptions are and can evaluate if it is an appropriate value.
I'll add a comment.
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
**********
* 1448048 2013-06-07 | libxc: range checks in
xc_dom_p2m_hostand... OKThanks. Should I take this as a formal Reviewed-by and put your name on the patch ?
Yes. For all "OK", please add:
Reviewed-by Chuck Anderson <[email protected]>
Excellent, thanks.
Quoted 28 lines
Quoted 28 lines
Quoted 20 lines
**********
* e80dd92 2013-06-07 | libxc: Add range checking to
xc_dom_binloader(quoted diff) +2
-1@@ -123,9 +123,12 @@ static struct xen_bin_image_table *find_table(struct xc_dom probe_ptr = dom->kernel_blob; probe_end = dom->kernel_blob + dom->kernel_size - sizeof(*table); - if ( (void*)probe_end > (dom->kernel_blob + 8192) ) + if ( dom->kernel_size >= 8192 && + (void*)probe_end > (dom->kernel_blob + 8192) ) probe_end = dom->kernel_blob + 8192;
probe_endiskernel_blob+dom->kernel_size- metadata table size You could simplify the code and make it clearer by changing:(quoted diff) +2
-0+ if ( dom->kernel_size >= 8192 && + (void*)probe_end > (dom->kernel_blob + 8192) ) probe_end = dom->kernel_blob + 8192;Quoted 4 lines
to:
+ if (
dom->kernel_size> (8192 -sizeof(*table)) )probe_end = dom->kernel_blob + 8192;Perhaps, but I think it's probably better to make a smaller change here. If we were to change it I think the change would be this:
Quoted 7 lines
Quoted 5 lines
-
probe_end=dom->kernel_blob+dom->kernel_size-sizeof(*table);
+ if (dom->kernel_size> (8192 -sizeof(*table)) )probe_end = dom->kernel_blob + 8192; else+
probe_end=dom->kernel_blob+dom->kernel_size-sizeof(*table);Yep, that works.
I think at this stage of the development of the series, I would prefer not to change it though. Thanks for your comment though.
Quoted 1 line
Quoted 1 line
Quoted 1 line
* 8dfa66a 2013-06-07 | libxc: Fix range checking in
xc_dom_pfn_to_ptr...
...
Quoted 10 lines
Quoted 10 lines
Quoted 9 lines
Replace the last 6 instructions with:
(quoted diff) +3
-0+ ptr = xc_dom_pfn_to_ptr_retcount(dom, page, 0, &safe_region_count); + if ( ptr != NULL ) + *safe_region_out = (safe_region_count <<
XC_DOM_PAGE_SHIFT(dom)) - offs
et;(quoted diff) +3
-0+ else + *safe_region_out = 0; + return ptr;
Quoted 8 lines
Quoted 1 line
I'm not sure why ?
- I'm assuming "if ( ptr != NULL )" is the expected path. Handling it first prevents the likely branch mis-prediction. Not a big deal but good to do if practical as is the case here.
- "
*safe_region_out= 0" will be overwritten in the expected code path so do it only when needed.
I don't think this is such a hot path that we should be thinking about these kinds of optimisations here. Setting *safe_region_out=0 at the start is a simple guard against any error exit paths, even though at the moment there is only one such.
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
if ( pfn > dom->total_pages || /* multiple checks to avoidoverflows */
Isn't pfn zero-based? If so, the test should be:
if ( pfn >= dom->total_pages || /* multiple checks to avoidoverflows */
Quoted 8 lines
Quoted 5 lines
Quoted 2 lines
I believe there are similar off-by-one errors in existing code if pfn is zero-based.
If count is nonzero then this will be caught by the third inequality. This code isn't touched by my patch series.
I was reviewing just the changes in the patch but that chunk of existing code caught my eye.
I see.
Quoted 2 lines
Normally a pfn is zero-based. If you have N pfns they would be numbered 0, 1, ..., N-1.
Yes. However as I say if count is nonzero this works correctly I think.
If count is zero then we are in the other case where we look up an existing block, which has different length checks. It says:
if ( pfn >= phys->first + phys->count )
continue;which will mean that pfn must be < phys->first + phys->count ie it must be strictly within the block.
So this code is currently fine.
Thanks,
Ian.