virt/coco/sev-guest: Remove err in handle_guest_request
PATCH v2 1/1 virt/coco/sev-guest: Remove err in handle_guest_request
The err variable may not be set in the call to snp_issue_guest_request, yet it is unconditionally written back to fw_err if fw_err is non-null. This is undefined behavior, and currently returns uninitialized kernel stack memory to user space.
The fw_err argument is better to just pass through to snp_issue_guest_request, so we do that.
--- drivers/virt/coco/sev-guest/sev-guest.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
drivers/virt/coco/sev-guest/sev-guest.c +1 -4
@@ -305,7 +305,6 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in u8 type, void *req_buf, size_t req_sz, void *resp_buf, u32 resp_sz, __u64 *fw_err) { - unsigned long err; u64 seqno;int rc;
@@ -322,9 +321,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, inreturn rc;/* Call firmware to process the request */ - rc =snp_issue_guest_request (exit_code, &snp_dev->input, &err); -if (fw_err) - *fw_err = err; + rc =snp_issue_guest_request (exit_code, &snp_dev->input, fw_err);if (rc)return rc;
Signature · 1 line
2.38.0.413.g74048e4d9e-goog
Quoted 8 lines · Dionna Glaze
The err variable may not be set in the call to
snp_issue_guest_request, yet it is unconditionally written back tofw_erriffw_erris non-null. This is undefined behavior, and currently returns uninitialized kernel stack memory to user space.The
fw_errargument is better to just pass through tosnp_issue_guest_request, so we do that.
Quoted 8 lines
Cc Tom Lendacky <[email protected]>Cc Paolo Bonzini <[email protected]>Cc Joerg Roedel <[email protected]>Cc Peter Gonda <[email protected]>Cc Thomas Gleixner <[email protected]>Cc Dave Hansen <[email protected]>Signed-off-by Dionna Glaze <[email protected]>
You should include a Fixes: tag.
With that,
Also, you may want to base your other series [1] on this one, since you'll likely get conflicts if this is applied first.
[1] https://lore.kernel.org/lkml/[email protected]/
Thanks,
Tom
Quoted 27 lines
--- drivers/virt/coco/sev-guest/sev-guest.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)drivers/virt/coco/sev-guest/sev-guest.c +1
-4@@ -305,7 +305,6 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, in u8 type, void *req_buf, size_t req_sz, void *resp_buf, u32 resp_sz, __u64 *fw_err) { - unsigned long err; u64 seqno;int rc;@@ -322,9 +321,7 @@ static int handle_guest_request(struct snp_guest_dev *snp_dev, u64 exit_code, inreturn rc;/* Call firmware to process the request */ - rc =snp_issue_guest_request (exit_code, &snp_dev->input, &err); -if (fw_err) - *fw_err = err; + rc =snp_issue_guest_request (exit_code, &snp_dev->input, fw_err);if (rc)return rc;
Quoted 11 lines
You should include a Fixes: tag.
With that,
Reviewed-by Tom Lendacky <[email protected]>Also, you may want to base your other series [1] on this one, since you'll likely get conflicts if this is applied first.
Let's call this a wash and I'll roll this into that other series then. By passing through fw_err directly, I get an unsigned long vs unsigned long long type error (in this v2, mea culpa). So I'll put the rename and re-typing in the x86 patch before this one.
Signature · 1 line
-Dionna Glaze, PhD (she/her)