x86/badpage: Fix badpage->order overflow
PATCH 1/1 x86/badpage: Fix badpage->order overflow
For order 32 or more, the shift will truncate. Spotted by Coverity.
---
CC: Jan Beulich <[email protected]>
CC: Wei Liu <[email protected]>
--- xen/common/page_alloc.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/common/page_alloc.c +2 -2
@@ -334,7 +334,7 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe)for ( i =0 ; i < array_size; i++ ) {bootmem_region_zap (badpage->mfn, - badpage->mfn + (1U << badpage->order)); + badpage->mfn + (1UL << badpage->order)); badpage++; } }
@@ -347,7 +347,7 @@ void __init init_boot_pages(paddr_t ps, paddr_t pe)for ( i =0 ; i < array_size; i++ ) {bootmem_region_zap (badpage->mfn, - badpage->mfn + (1U << badpage->order)); + badpage->mfn + (1UL << badpage->order)); badpage++; } }
Signature · 7 lines
2.1.4 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 3 lines · Andrew Cooper
For order 32 or more, the shift will truncate. Spotted by Coverity.
Signed-off-by Andrew Cooper <[email protected]>
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 09.11.18 at 15:42, <[email protected]> wrote:
For order 32 or more, the shift will truncate. Spotted by Coverity.
I find this pretty absurd. What about order 64 or more? Are you suggesting you expect 16Tb or larger bad page ranges?
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>
Anyway, as I don't mind the adjustment
But I'm sure you're aware we have many more examples of 1U (or even plain 1) getting shifted by an order value.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 11 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 09.11.18 at 15:42, <[email protected]> wrote:
For order 32 or more, the shift will truncate. Spotted by Coverity.
I find this pretty absurd. What about order 64 or more? Are you suggesting you expect 16Tb or larger bad page ranges?
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>Anyway, as I don't mind the adjustment
Acked-by Jan Beulich <[email protected]>But I'm sure you're aware we have many more examples of 1U (or even plain 1) getting shifted by an order value.
There is nothing absurd here.
The complaint is that there are two parts of a single calculation at different widths, where C's integer promotion rules results in code which reads correctly, but behaves incorrectly.
If badpage->mfn was uint32_t, there would be no complaint, because all parts of the expression would be evaluated at the same width. This complaint is only because you've got a 32bit shift, and a 64bit addition.
As for likelihood, I really hope we don't need mark a 16Tb range as bad, but given the ability to express this, would you really notice that the result was subtly wrong?
~Andrew
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel
Quoted 20 lines
Quoted 1 line
Quoted 1 line · On 12.11.18 at 20:01, <[email protected]> wrote:
Quoted 11 lines · Jan Beulich
Quoted 2 lines
Quoted 1 line
Quoted 1 line · On 09.11.18 at 15:42, <[email protected]> wrote:
For order 32 or more, the shift will truncate. Spotted by Coverity.
I find this pretty absurd. What about order 64 or more? Are you suggesting you expect 16Tb or larger bad page ranges?
Quoted 1 line
Signed-off-by Andrew Cooper <[email protected]>Anyway, as I don't mind the adjustment
Acked-by Jan Beulich <[email protected]>But I'm sure you're aware we have many more examples of 1U (or even plain 1) getting shifted by an order value.
There is nothing absurd here.
The complaint is that there are two parts of a single calculation at different widths, where C's integer promotion rules results in code which reads correctly, but behaves incorrectly.
Quoted 7 lines
If
badpage->mfnwasuint32_t, there would be no complaint, because all parts of the expression would be evaluated at the same width. This complaint is only because you've got a 32bit shift, and a 64bit addition.As for likelihood, I really hope we don't need mark a 16Tb range as bad, but given the ability to express this, would you really notice that the result was subtly wrong?
I think so, yes. It doesn't matter much here, but the change results in a pointless extra REX.W prefix. Adding a 32-bit value to a 64-bit one is not per se a bug after all. It is (I believe) impossible for a tool to tell apart legitimate and problematic cases.
Jan
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xenproject.org/mailman/listinfo/xen-devel