Reporting Issues
Bug 3324 - MpInitLib: SEV-ES stacks share page with code and other data
Summary: MpInitLib: SEV-ES stacks share page with code and other data
Status: RESOLVED FIXED
Alias: None
Product: EDK2
Classification: Unclassified
Component: Code (show other bugs)
Version: Current
Hardware: All All
: Lowest normal
Assignee: thomas.lendacky
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-04-12 10:29 UTC by Marvin Häuser
Modified: 2021-05-29 07:38 UTC (History)
11 users (show)

See Also:
EDK II Code First industry standard specifications: ---
Branch URL:
Release(s) the issue is observed: EDK II Master
The OS the target platform is running: ---
Package: UefiCpuPkg
Release(s) the issues must be fixed: EDK II Master
Tianocore documents:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Marvin Häuser 2021-04-12 10:29:11 UTC
The SEV-ES stacks may share page with code and other data. This does not only risk the other data to be overwritten by stack overflows, it also prevents stack guarding and NX stack.

[1] https://github.com/tianocore/edk2/blob/2072c22a0d63c780b0cc6377f6d4ffb116ad6144/UefiCpuPkg/Library/MpInitLib/MpLib.c#L1171-L1179

[2] https://github.com/tianocore/edk2/blob/2072c22a0d63c780b0cc6377f6d4ffb116ad6144/UefiCpuPkg/Library/MpInitLib/MpLib.c#L1212
Comment 1 John Mathews 2021-05-05 14:29:37 UTC
Thomas Lendacky, 
I added you to CC list, to bring this BZ to your attention. Please review.
Comment 2 thomas.lendacky 2021-05-06 11:37:35 UTC
Would a separate allocation, that is page aligned/page sized, resolve the concern? In other words, for example during PEI:

- Have the reset vector code and data be at 9F000 for 0x1000

- Have the SEV-ES AP reset stacks be at 9E000 for 0x1000 (variable based on vCPU count) below the reset vector code and data
Comment 3 Marvin Häuser 2021-05-06 12:42:52 UTC
Thank you for your reply, Thomas. That will definitely improve the situation, but I am wondering whether it would not make sense to go a step further and separate the individual AP stacks, so that guarding pages can be placed on each's top and bottom. To not waste too much space, I guess they can remain contiguous (as in the top guard page of one stack doubles as the bottom guard page of another), but that'd need explicit support then (as guard pages are otherwise automatically inserted by DxeCore according to the PCD policy per page allocation).

I don't think I can comment on the reset vector situation as I lack information on data content and page protection on entry. I trust your judgement. :)
Comment 4 thomas.lendacky 2021-05-06 13:11:03 UTC
(In reply to Marvin Häuser from comment #3)
> Thank you for your reply, Thomas. That will definitely improve the
> situation, but I am wondering whether it would not make sense to go a step
> further and separate the individual AP stacks, so that guarding pages can be
> placed on each's top and bottom. To not waste too much space, I guess they
> can remain contiguous (as in the top guard page of one stack doubles as the
> bottom guard page of another), but that'd need explicit support then (as
> guard pages are otherwise automatically inserted by DxeCore according to the
> PCD policy per page allocation).

IIUC, that would be two pages per AP + one initial top page? If that is the case, I don't think we can do that because we have a limited number of pages available below 1MB. For example, when I boot a VM today, the current range below 1MB in PEI is 0 - 0xA0000, which is only 160 pages. It would impose a much stricter limit on the number of vCPUs that can be specified.

> 
> I don't think I can comment on the reset vector situation as I lack
> information on data content and page protection on entry. I trust your
> judgement. :)
Comment 5 Marvin Häuser 2021-05-06 13:47:16 UTC
Oh, the stacks must be below 1 MB too? That's unfortunate. :( Thank you!
Comment 7 Laszlo Ersek 2021-05-13 06:24:42 UTC
Hi Tom,

(In reply to thomas.lendacky from comment #6)
> v1:
>   https://edk2.groups.io/g/devel/message/75033
>  
> https://listman.redhat.com/archives/edk2-devel-archive/2021-May/msg00349.html
>   msgid:
> <1162d1f4fe09048aaafba6f6ea3046bebd34fc2b.1620766224.git.thomas.lendacky@amd.
> com>

this BZ has been filed as a Security Issue.

Personally, I disagree that this is a security issue (it doesn't seem exploitable). I would rather call it an "armoring feature request".

*However*, even though that's my personal opinion, as long as the BZ *is* filed as a (non-public) security issue, we should consider it embargoed, and we should neither discuss it publicly, nor post patches for it to the list. I'd support opening this ticket up to the public, but until / unless that happens, we shouldn't just post patches to the list, before an embargo date is set, and the set date elapses.

https://github.com/tianocore/tianocore.github.io/wiki/Reporting-Security-Issues

While bugzilla is *by far* not the perfect tool for patch reviews, for the time being we attach security patches to BZ tickets, for review. So all the discussions around the symptoms, impact, CVSS score, embargo date, fixes, reviews etc happen in the ticket, for a security issue. Once the embargo ends, the ticket is opened up and the latest patches from the BZ are reposted to the edk2-devel mailing list, a bit of time is given to the community for a final round of review, and then the patches are merged upstream.

Regarding the current patch review -- personally I'd like to defer that to Marvin (primarily) and the UefiCpuPkg maintainers (secondarily).
Comment 8 Marvin Häuser 2021-05-13 06:31:09 UTC
Hey Laszlo,

Sorry, I'm actually not sure why I filed this as security issue. I filed I think 17 tickets that day, so maybe I simply got it mixed up. :) Of course you can decide on whether to open it, but if it is fine for me to do it as the reporter, I absolutely will.

Hey Thomas,

Thank you a lot for the patch. Sorry, but it will take me a bit to get to it. First glance is good and definitely addresses the issue.
Comment 9 Laszlo Ersek 2021-05-13 06:31:58 UTC
I should also mention that the infosec group has a monthly phone (maybe video?) meeting where they go through the security BZ backlog, and that's when eligible BZs get opened up, based on the live discussion and the prior comments in the tickets. I usually don't dial in to the meeting, but seek to keep a close eye on tickets, and to state quickly (usually, although not always, with the help of Red Hat ProdSec) whether a ticket should be embargoed, and if so, for how long, in our opinion.

This one, I don't see as directly exploitable. It may be a gap in a generic protection mechanism, yes. So personally I don't mind that the patch was posted, but it did not conform to the process, as far as I can tell.

Best I can offer is some regression testing (in non-SEV guests), once we figure out where the patch should be discussed, going forward.

(Unfortunately I don't have a SEV-ES environment set up yet, for regression-testing in a SEV-ES guest.)
Comment 10 Laszlo Ersek 2021-05-13 06:35:59 UTC
(In reply to Marvin Häuser from comment #8)
> Hey Laszlo,
> 
> Sorry, I'm actually not sure why I filed this as security issue. I filed I
> think 17 tickets that day, so maybe I simply got it mixed up. :) Of course
> you can decide on whether to open it, but if it is fine for me to do it as
> the reporter, I absolutely will.

I think it never hurts to file a BZ as a Security Issue at first if the reporter has any concerns about the potential exploitability of the problem -- people can always discuss on the BZ and then decide to open it up. Looks like you had no such concerns however, when filing this ticket.

Tom, can you please comment? Do you agree as well that we shouldn't treat this as a security issue? If that's the case, then I'd propose that Marvin do open up the ticket. Thanks!
Comment 11 thomas.lendacky 2021-05-13 09:16:55 UTC
(In reply to Laszlo Ersek from comment #10)
> 
> Tom, can you please comment? Do you agree as well that we shouldn't treat
> this as a security issue? If that's the case, then I'd propose that Marvin
> do open up the ticket. Thanks!

Yes, I agree, I don't see this as a security issue.

And my bad on posting patches. Since there wasn't a paper or method of exploitation mentioned I didn't think there was any kind of embargo period.

For my education, would all patch review for a security issue be done within the bugzilla or is there a special mailing list or ... ?
Comment 12 Laszlo Ersek 2021-05-13 10:25:58 UTC
Hi Tom,

Personally, I would strongly prefer to use the existent <infosec@edk2.groups.io> mailing list for security patch review, but many other project participants disagreed, saying that such a mailing list is not confidential enough.

So we've been stuck with security patch reviews through bugzilla attachments, for a while. There isn't any more recent guidance that I could cite here.

Thanks!
Comment 14 Laszlo Ersek 2021-05-29 07:38:29 UTC
Merged in commit dbc22a178546 via <https://github.com/tianocore/edk2/pull/1674>.