[all-commits] [llvm/llvm-project] 102b41: [CMSE] Clear padding bits of struct/unions/fp16 pa...
Momchil Velikov via All-commits
all-commits at lists.llvm.org
Tue Apr 28 09:06:34 PDT 2020
Branch: refs/heads/master
Home: https://github.com/llvm/llvm-project
Commit: 102b4105e3fd568ed2c758ed7e6fd266a819d6db
https://github.com/llvm/llvm-project/commit/102b4105e3fd568ed2c758ed7e6fd266a819d6db
Author: Momchil Velikov <momchil.velikov at arm.com>
Date: 2020-04-28 (Tue, 28 Apr 2020)
Changed paths:
M clang/include/clang/AST/Decl.h
M clang/include/clang/Basic/DiagnosticSemaKinds.td
M clang/lib/AST/Decl.cpp
M clang/lib/CodeGen/CGCall.cpp
M clang/lib/CodeGen/CodeGenFunction.h
M clang/lib/Sema/SemaDeclAttr.cpp
M clang/lib/Sema/SemaExpr.cpp
M clang/lib/Sema/SemaStmt.cpp
A clang/test/CodeGen/cmse-clear-arg.c
A clang/test/CodeGen/cmse-clear-fp16.c
A clang/test/CodeGen/cmse-clear-return.c
A clang/test/Sema/arm-cmse-no-diag.c
M clang/test/Sema/arm-cmse.c
Log Message:
-----------
[CMSE] Clear padding bits of struct/unions/fp16 passed by value
When passing a value of a struct/union type from secure to non-secure
state (that is returning from a CMSE entry function or passing an
argument to CMSE-non-secure call), there is a potential sensitive
information leak via the padding bits in the structure. It is not
possible in the general case to ensure those bits are cleared by using
Standard C/C++.
This patch makes the compiler emit code to clear such padding
bits. Since type information is lost in LLVM IR, the code generation
is done by Clang.
For each interesting record type, we build a bitmask, in which all the
bits, corresponding to user declared members, are set. Values of
record types are returned by coercing them to an integer. After the
coercion, the coerced value is masked (with bitwise AND) and then
returned by the function. In a similar manner, values of record types
are passed as arguments by coercing them to an array of integers, and
the coerced values themselves are masked.
For union types, we effectively clear only bits, which aren't part of
any member, since we don't know which is the currently active one.
The compiler will issue a warning, whenever a union is passed to
non-secure state.
Values of half-precision floating-point types are passed in the least
significant bits of a 32-bit register (GPR or FPR) with the most
significant bits unspecified. Since this is also a potential leak of
sensitive information, this patch also clears those unspecified bits.
Differential Revision: https://reviews.llvm.org/D76369
More information about the All-commits
mailing list