RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1555108 - AES isn't clearing the key information in it's context when finished.
Summary: AES isn't clearing the key information in it's context when finished.
Keywords:
Status: CLOSED CURRENTRELEASE
Alias: None
Product: Red Hat Enterprise Linux 7
Classification: Red Hat
Component: nss-softokn
Version: 7.0
Hardware: Unspecified
OS: Unspecified
high
high
Target Milestone: rc
: 7.5
Assignee: nss-nspr-maint
QA Contact: BaseOS QE Security Team
URL:
Whiteboard:
Depends On:
Blocks: 1472750 1556910
TreeView+ depends on / blocked
 
Reported: 2018-03-14 00:28 UTC by Bob Relyea
Modified: 2018-10-30 20:06 UTC (History)
9 users (show)

Fixed In Version:
Doc Type: If docs needed, set a value
Doc Text:
Clone Of:
: 1556910 (view as bug list)
Environment:
Last Closed: 2018-10-30 15:44:53 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)
Patch to zero the context (which key information) when finished with them. (1.35 KB, patch)
2018-03-14 00:42 UTC, Bob Relyea
no flags Details | Diff


Links
System ID Private Priority Status Summary Last Updated
Mozilla Foundation 1445511 0 None None None 2018-03-14 00:28:04 UTC

Description Bob Relyea 2018-03-14 00:28:05 UTC
AES doesn't clear out the context data before it frees it in two places:

AES_ContextDestroy in rijndael.c
intel_AES_GCM_DestroyContext in intel-gcm-wrap.c

Comment 2 Bob Relyea 2018-03-14 00:42:56 UTC
Created attachment 1407755 [details]
Patch to zero the context (which key information) when finished with them.

Comment 4 Kai Engert (:kaie) (inactive account) 2018-03-14 11:09:55 UTC
 void
 AES_DestroyContext(AESContext *cx, PRBool freeit)
 {
+    void *mem = cx->mem;
     if (cx->worker_cx && cx->destroy) {
         (*cx->destroy)(cx->worker_cx, PR_TRUE);
         cx->worker_cx = NULL;
         cx->destroy = NULL;
     }
+    PORT_Memset(cx, 0, sizeof(AESContext));
     if (freeit) {
-        PORT_Free(cx->mem);
+        PORT_Free(mem);
     }
 }


The code seems correct, and I agree it clears the context structures.

But I have two suggestions/questions:

Q1: The code doesn't clear the contents of cx->mem. Should it? But that would require to know the size of that block. Is it known?

Q2: The helper variable "mem" seems unnecessary. Why not simply place the memset call as the very last line in this function?

Comment 7 Bob Relyea 2018-03-14 18:52:58 UTC
I explained this to kai verbally, but it's worth documenting.

cx is contained in mem:

    mem->  +---------+
           |         |
           .         .
           .         .
           .         .
           |         |
    cx->   +---------+
           |         |
           |         |
           .         .
           .         .
           | cx->mem |
           .         .
           .         .
           |         |
end of cx  +---------+
           |         |
           .         .
           .         .
           |         |
end of mem +---------+

This is done for memory alignment purposes. So space is allocated sizeof(cx) + sizeof(alignment) and assigned to mem. cx is set to the aligned pointer within mem, and cx->mem is set to mem. cx is used as the active context (the extra space in mem is not touched. This was all added by mozilla in the last year to speed up AES performance.

So the order in the patch is important.
1. We need to save mem before we clear the cx (because cx->mem would be cleared and we can't reference it later).
2. We have to clear the cx before we free mem, (because cx is embedded in the mem block and freeing mem frees cx)
3. Finally with mem saved and cx cleared we can safely free mem.


Note You need to log in before you can comment on or make changes to this bug.