xen/livepatch: Fix secure_payload() in non-debug builds
PATCH 1/1 xen/livepatch: Fix secure_payload() in non-debug builds
The ro_pages + rw_pages + text_pages != payload->pages check is not something which is reasonable to skip at runtime. Rewrite it to not be an ASSERT().
As the code is being shuffled anyway, rework the logic calling arch_livepatch_secure() to reduce its verbosity.
---
CC: Konrad Rzeszutek Wilk <[email protected]>
CC: Ross Lagerwall <[email protected]>
--- xen/common/livepatch.c | 37 ++++++++++++++++--------------------- 1 file changed, 16 insertions(+), 21 deletions(-)
xen/common/livepatch.c +16 -21
@@ -405,32 +405,27 @@ static int move_payload(struct payload *payload, struct livepatch_elf *elf)static int secure_payload (struct payload *payload,struct livepatch_elf *elf) { -int rc =0 ; -unsigned int text_pages, rw_pages, ro_pages; +unsigned int text_pages =PFN_UP (payload->text_size); +unsigned int rw_pages =PFN_UP (payload->rw_size); +unsigned int ro_pages =PFN_UP (payload->ro_size); +int rc; - text_pages =PFN_UP (payload->text_size); +if ( ro_pages + rw_pages + text_pages != payload->pages ) +return -EINVAL ; -if ( text_pages ) - { - rc =arch_livepatch_secure (payload->text_addr, text_pages,LIVEPATCH_VA_RX ); -if ( rc ) -return rc; - } - rw_pages =PFN_UP (payload->rw_size); -if ( rw_pages ) - { - rc =arch_livepatch_secure (payload->rw_addr, rw_pages,LIVEPATCH_VA_RW ); -if ( rc ) -return rc; - } +if ( text_pages && + (rc =arch_livepatch_secure (payload->text_addr, text_pages,LIVEPATCH_VA_RX )) ) +return rc; - ro_pages =PFN_UP (payload->ro_size); -if ( ro_pages ) - rc =arch_livepatch_secure (payload->ro_addr, ro_pages,LIVEPATCH_VA_RO ); +if ( rw_pages && + (rc =arch_livepatch_secure (payload->rw_addr, rw_pages,LIVEPATCH_VA_RW )) ) +return rc; -ASSERT (ro_pages + rw_pages + text_pages == payload->pages); +if ( ro_pages && + (rc =arch_livepatch_secure (payload->ro_addr, ro_pages,LIVEPATCH_VA_RO )) ) +return rc; -return rc; +return 0 ; } static bool section_ok(const struct livepatch_elf *elf,
Signature · 1 line
2.30.2
Quoted 2 lines · Andrew Cooper
The
ro_pages+rw_pages+text_pages!=payload->pagescheck is not something which is reasonable to skip at runtime. Rewrite it to not be anASSERT().
Isn't this merely a sanity check? IOW isn't returning -EINVAL in this case misleading, as to calling "invalid input" what really is an internal error in Xen? But anyway, I guess I'll leave this to the maintainers.
Quoted 2 lines
As the code is being shuffled anyway, rework the logic calling
arch_livepatch_secure()to reduce its verbosity.
By "verbosity", dym lines of code?
Jan
Quoted 7 lines
From: Jan Beulich <[email protected]>
Sent: Monday, April 17, 2023 11:41 AM
To: Andrew Cooper <[email protected]>
Cc: Konrad Rzeszutek Wilk <[email protected]>; Ross Lagerwall <[email protected]>; Xen-devel <[email protected]>
Subject: Re: [PATCH] xen/livepatch: Fixsecure_payload()in non-debug builds
On 17.04.2023 11:58, Andrew Cooper wrote:
Quoted 7 lines
Quoted 2 lines
The
ro_pages+rw_pages+text_pages!=payload->pagescheck is not something which is reasonable to skip at runtime. Rewrite it to not be anASSERT().Isn't this merely a sanity check? IOW isn't returning
-EINVALin this case misleading, as to calling "invalid input" what really is an internal error in Xen? But anyway, I guess I'll leave this to the maintainers.
Yes, it looks like it is just a sanity check of the payload->pages calculation in move_payload(). Since it is not dependent on the payload, I think ASSERT() is correct.
Ross