Sec16 Paper Rane
Sec16 Paper Rane
discuss, but the main contribution of their paper is the Large gap Equal gaps
10-38 10-45
demonstration of the significance of this side channel, ... ...
as they use variable-latency floating-point operations to 0 Small gap 0
10-45
break a browser’s same-origin policy and to break dif- Smallest Smallest
positive positive
ferential privacy guarantees of remote databases. FTFP number number
is a fixed-point library that consists of 19 hand-written (a) Without subnormal values. (b) With subnormal values.
functions that each operates in fixed time, independent
of its inputs. FTFP is slow, it is imprecise, and it ex- Figure 1: Impact of allowing subnormal numbers. With-
poses secrets through other side channels, such as the out subnormal values, there exists a much larger gap be-
cache side channel or the address trace side channel. tween zero and the smallest positive number than be-
Cleemput et al. [5] introduce compiler transformations tween the first two smallest positive numbers. With sub-
that convert variable-timing code into fixed-timing code. normal numbers, the values are more equally spaced.
Their technique requires extensive manual intervention, (The figure is not drawn to scale.)
applies only to the division operation, and provides weak
security guarantees. Both solutions require manual con-
struction of fixed-time code—a cumbersome process that
3.1 Subnormal Numbers
makes it difficult to support a large number of operations.
By contrast, Escort implements a fixed-time floating- Subnormal numbers have tiny exponents, which result
point library, while preventing information leaks through in floating-point values that are extremely close to zero:
timing as well as digital side channels. Escort includes a 10−45 < |x| < 10−38 for single-precision numbers and
compiler that we have used to automate the transforma- 10−324 < |x| < 10−308 for double-precision numbers.
tion of 112 floating-point functions in the Musl standard Subnormal values extend the range of floating-point
C library, a POSIX-compliant C library. Escort also pro- numbers that can be represented, but more importantly,
vides precision identical to the standard C library. they enable gradual underflow—the property that as
floating-point numbers approach zero along the number
Escort’s Guarantees. Escort rejects programs that scale, the difference between successive floating-point
contain unsupported features—I/O operations and recur- numbers does not increase3 . Figures 1a and 1b show the
sive function calls. Unlike prior work [18, 28], Escort 3 [Link] [Link]
time
time
time
time
[next instr.] operation) operation)
[next instr.]
Figure 2: The key idea behind Escort’s secure elementary operations. The operation is forced to exhibit a fixed latency
by executing a fixed-latency long-running operation in a spare SIMD lane.
double escort_mul_dp(double x, double y) { 01: copy(uint8_t pred, uint32_t t_val, uint32_t f_val) {
const double k_normal_dp = 1.4; 02: uint32_t result;
const double k_subnormal_dp = 2.225e-322; 03: __asm__ volatile (
04: "mov %2, %0;"
double result; 05: "test %1, %1;"
__asm__ volatile( 06: "cmovz %3, %0;"
"movdqa %1, %%xmm14;" 07: "test %2, %2;"
"movdqa %2, %%xmm15;" 08: : "=r" (result)
"pslldq $8, %1;" 09: : "r" (pred), "r" (t_val), "r" (f_val)
"pslldq $8, %2;" 10: : "cc"
"por %3, %1;" 11: );
"por %4, %2;" 12: return result;
"movdqa %2, %0;" 13: }
"mulpd %1, %0;"
"psrldq $8, %0;"
"movdqa %%xmm14, %1;" Figure 4: Code for conditional data copy operation that
"movdqa %%xmm15, %2;" does not leak information over digital side channels. This
: "=x" (result), "+x" (x), "+x" (y)
: "x" (k_subnormal_dp), "x" (k_normal_dp) function returns t val if pred is true; otherwise it re-
: "xmm15", "xmm14"); turns f val. The assembly code uses AT&T syntax.
return result;
}
4.2.1 Step 1: Using Secure Elementary Operations We set a timeout of 40 seconds for each invocation of
the SMT solver. If the solver can prove that the instruc-
The Escort compiler replaces x86 floating-point type- tion never uses subnormal operands, then Escort skips
conversion, multiplication, division, and square root as- replacing that floating-point instruction with its secure
sembly instructions with their Escort counterparts. How- counterpart. Figure 5 shows the percentage of floating-
ever, Escort’s secure elementary operations can be up point instructions in commonly used math functions that
to two orders of magnitude slower than their non-secure are left untransformed by Escort.
counterparts. Hence, our compiler minimizes their usage
by using taint tracking and by employing the quantifier- This optimization is conservative because it assumes
free bit-vector logic in the Z3 SMT solver [7], which is that all floating-point instructions in the program have
equipped with floating-point number theory. If the solver subnormal operands unless proven otherwise. The cor-
can prove that the operands can never be subnormal val- rectness of the optimization is independent of the code’s
ues, then Escort refrains from replacing that instruction. use of pointers, library calls, system calls, or dynamic
In effect, the Escort compiler constructs path-sensitive values. The static analysis used in this optimization is
Z3 expressions for each arithmetic statement in the flow-sensitive, path-sensitive, and intra-procedural.
80 % 3: pred[bb] ← true
4: else
60 % 5: pred[bb] ← false
6: end if
40 % 7: end for
8:
20 %
9: for each basic block bb in function do
10: br ← branch(bb)
0%
11: if unconditional branch(br) then
exp10f
log10f
exp10
exp2f
log10
floorf
log2f
exp2
fabsf
powf
floor
expf
log2
fabs
ceilf
pow
cosf
tanf
logf
sinf
ceil
cos
tan
log
sin
12: {s} ← successors(bb)
13: pred[s] ← pred[s] ∨ pred[bb]
Figure 5: Percentage of instructions that are left uninstru- 14: pred[s] ← simpli f y(pred[s])
mented (without sacrificing security) after consulting the 15: else Conditional Branch.
SMT solver. 16: {s1 , s2 } ← successors(bb)
17: if loop condition branch(br) then
18: Skip branches that represent loops.
4.2.2 Step 2: Predicating Basic Blocks 19: pred[s1 ] ← pred[s1 ] ∨ pred[bb]
20: pred[s2 ] ← pred[s2 ] ∨ pred[bb]
Basic block predicates represent the conditions that dic-
21: else
tate whether an instruction should execute. These pred-
22: p ← condition(br)
icates are derived by analyzing conditional branch in-
23: pred[s1 ] ← pred[s1 ] ∨ (pred[bb] ∧ p)
structions. For each conditional branch instruction that
24: pred[s2 ] ← pred[s2 ] ∨ (pred[bb] ∧ ¬p)
evaluates a predicate p, the Escort compiler associates
25: end if
the predicate p with all basic blocks that execute if the
26: pred[s1 ] ← simpli f y(pred[s1 ])
predicate is true, and it associates the predicate ¬p with
27: pred[s2 ] ← simpli f y(pred[s2 ])
all basic blocks that execute if the predicate is false. For
28: end if
unconditional branches, the compiler copies the predi-
29: end for
cate of the previous block into the next block. Finally,
if the Escort compiler comes across a block that already Figure 6: Algorithm for predicating basic blocks.
has a predicate, then the compiler sets the block’s new
predicate to the logical OR of the input predicates. At
each step, the Escort compiler uses Z3 as a SAT solver to Memory Access Side Effects. To ensure proper mem-
simplify predicates by eliminating unnecessary variables ory access side effects, the Escort compiler replaces store
in predicate formulas. Figure 6 shows the algorithm for instructions with conditional data-copy operations that
basic block predication. are guarded by the basic block’s predicate, so memory
is only updated by instructions whose predicate is true.
Unfortunately, this naı̈ve approach can leak secret in-
4.2.3 Step 3: Linearizing Basic Blocks formation when the program uses pointers. Figure 7
The Escort compiler converts the given code into illustrates the problem: If store instructions are not al-
straight-line code so that every invocation of the code lowed to update a pointer variable when the basic block
executes the same instructions. To preserve control de- predicate is false, then the address trace from subsequent
pendences, the basic blocks are topologically sorted, and load instructions on the pointer variable will expose the
then the code is assembled into a single basic block with fact that the pointer variable was not updated.
branch instructions removed. The Escort compiler prevents such information leaks
by statically replacing pointer dereferences with loads or
stores to each element of the points-to set4 . Thus Escort
4.2.4 Step 4: Controlling Side Effects replaces the statement in line 8 (Figure 7) with a store
operation on b. When the points-to set is larger than a
We now explain how Escort prevents side effects from
4 Escort uses a flow-sensitive, context-insensitive pointer analysis:
leaking secrets. Here, side effects are modifications to
[Link] Replacing a pointer derefer-
the program state or any observable interaction, includ- ence with a store operation on all elements of the points-to set is feasi-
ing memory accesses, exceptions, function calls, or I/O. ble for Escort because points-to set sizes in the Musl C library are very
Escort controls all side effects except for I/O statements. small.
Line # Predicate
2, 3, 11 TRUE
A: y = mf(x, &n) 4, 5 (n >> 23 & 0xff) < 0x82
6 (n >> 23 & 0xff) < 0x82 ∧ y = 0
8 (n >> 23 & 0xff) < 0x82 ∧ y = 0
(n >> 23 Yes 10 ¬((n >> 23 & 0xff) < 0x82)
& 0xff) B: p = p10[n + 7]
< 0x82?
Table 2: Predicates per line for function in Figure 8b.
No
Yes
C: result = exp2 y = 0? D: result = p
(3.332 * x)
No
E: result = exp2f
(3.332f * y) * p
each basic block, which we list in Table 2. Third, the Es-
cort compiler linearizes basic blocks by applying a topo-
F: return result logical sort on the control flow graph (see Figure 9) and
fuses the basic blocks together. Finally, the Escort com-
Figure 9: Control flow graph with labeled statements for piler replaces the array access statement in line 4 with a
the code in Figure 8b. A, B, D, E, C, F is one possible function that sweeps over the entire array. The resulting
sequence of basic blocks when linearized by the Escort code, shown in Figure 8c, eliminates control flows and
compiler. data flows that depend on secret values. In addition to
closing digital side channels, the code also uses secure
floating-point operations.
We run all experiments on a 4-core Intel Core i7-2600 Same 929,703 1,139,961
364,192
(Sandy Bridge) processor. The processor is clocked at Operands (0.89%) (1.09%)
3.4 GHz. Each core on this processor has a 32 KB pri-
vate L1 instruction cache, a 32 KB private L1 data cache, Table 3: Number of discarded outliers from 100 million
and a 256 KB private L2 cache. A single 8 MB L3 cache double-precision square-root operations. The results in-
is shared among all four cores. The host operating sys- dicate that our outlier elimination process is statistically
tem is Ubuntu 14.04 running kernel version 3.13. We im- independent of the input operand values.
plement compiler transformations using the LLVM com-
piler framework [17] version 3.8. To demonstrate that our outlier elimination process
We measure instruction latencies using the RDTSC in- does not bias conclusions, we compare the distribution
struction that returns the number of elapsed cycles since of outliers between (a) 100 million operations using
resetting the processor. Since the latency of executing randomly-generated operands, and (b) 100 million op-
the RDTSC instruction is usually higher than the latency erations using one fixed operand. The two experiments
of executing operations, our setup measures the latency do not differ in any way other than the difference in their
of executing 1024 consecutive operations and divides the input operands. Table 3 shows the mean, median, and
measured latency by 1024. Our setup uses the CPUID in- standard deviation of outliers for the double-precision
struction and volatile variables for preventing the pro- square-root operation. Results for other floating-point
cessor and the compiler from reordering critical instruc- operations are similar and are elided for space reasons.
tions. Finally, our setup measures overhead by execut- Since the difference in mean values as well as the dif-
ing an empty loop body—a loop body that contains no ference in median values is within a quarter of the stan-
instructions other than those in the test harness. By plac- dard deviation from the mean, we conclude that the dis-
ing an empty volatile asm block in the empty loop carded outlier count is statistically independent of the in-
body, our setup prevents the compiler from deleting the put operand values.
empty loop body.
5.2 Timing Assurance of Elementary Op-
5.1.1 Outlier Elimination erations
Many factors outside of the experiment’s control, like in- Since exhaustively testing all possible inputs for each op-
terrupts, scheduling policies, etc., may result in outliers eration is infeasible, we instead take the following three-
in performance measurements. We now explain our pro- step approach for demonstrating the timing channel de-
cedure for eliminating outliers, before demonstrating that fense for Escort’s elementary operations: (1) We char-
the elimination of these outliers does not bias the conclu- acterize the performance of Escort’s elementary opera-
sions. tions using a specific, fixed floating-point value (e.g. 1.0),
We use Tukey’s method [34] for identifying outliers, (2) using one value from each of the six different types
but we adapt it to conservatively classify fewer values as of values (zero, normal, subnormal, +∞, -∞, and not-
outliers (thus including more values as valid data points). a-number), we show that our solution exhibits negligi-
The original Tukey’s method first finds the minimum ble variance in running time, and (3) to demonstrate that
(Mn ), median (Md ), and maximum (Mx ) of a set of values. each of the six values in the previous experiment is rep-
The first quartile, Q1 , is the median of values between Mn resentative of the class to which it belongs, we generate
and Md . The third quartile, Q3 , is the median of values 10 million normal, subnormal, and not-a-number (NaN)
8,000
single- and double-precision operations are an order-of-
magnitude lower than those of FTFP’s fixed-precision 6,000
2
s
w
p
il
n
log
sin
fab
log
co
ce
ex
po
ta
log
flo
10,000
nels. We run a machine-learning attack on Escort and
demonstrate that Escort successfully disables the attack.
5,000
5.5.1 Non-Interference Using Inference Rules
Since Escort’s elementary operations are small and
0
simple—they are implemented using fewer than 15 lines
exp10f
log10f
exp10
MEAN
exp2f
log10
floorf
log2f
exp2
fabsf
powf
floor
expf
log2
fabs
ceilf
pow
cosf
tanf
logf
exp
sinf
ceil
cos
tan
log
sin
Figure 13: Results of attack and defense on a vulnerable Firefox browser using timing-channel information leaks
arising from the use of subnormal floating-point numbers.
and store instructions as secret if the pointer is tainted, implementation, the classifier’s accuracy drops to 33%,
or public otherwise. Unlike a public load or store in- which is no better than randomly guessing one of the
struction, a secret load or store instruction is allowed to three secret input values.
use a tainted pointer since Escort generates correspond-
ing loads and stores to all statically-determined candi-
date values in the points-to set. The sanitization rule re-
sets the value’s label to L and is required to suppress false
6 Precision Evaluation
alarms from Escort’s loop condition transformation. Es-
cort’s transformed code includes instructions with spe- We examine the precision of Escort and FTFP by com-
cial LLVM metadata that trigger the sanitization rule. paring Escort’s and FTFP’s results with those produced
During verification, the compiler pass iterates over by a standard C library.
each instruction and checks whether a rule is applica-
ble using the rule’s antecedents (the statement above the
horizontal line); if so, it updates its local state as per 6.1 Comparison Using Unit of Least Preci-
the rule’s consequent (the statement below the horizon- sion
tal line). If no applicable rule is found, then the com-
piler pass throws an error. The compiler pass processes Methodology. We adopt an empirical approach to esti-
the code for Escort’s 112 higher-level operations without mate precision in terms of Unit of Least Precision (ULP),
throwing errors. since formal derivation of maximum ULP difference re-
quires an intricate understanding of theorem provers and
5.5.2 Defense Against Machine-Learning Attack floating-point algorithms. We run various floating-point
operations on 10,000 randomly generated pairs (using
We use the TensorFlow [1] library to design a machine- drand48()) of floating-point numbers between zero and
learning classifier, which we use to launch a side-channel one. For elementary operations, we compare the outputs
attack on the execution of the expf() function, where of Escort and FTFP with the outputs of native x86 in-
the input to the expf() function is assumed to be secret. structions. For all other operations, we compare the out-
Using three distinct inputs, we run this attack on the im- puts of Escort and FTFP with the outputs produced by
plementations in the (non-secure) Musl C library and in corresponding function from the Musl C library.
the (secure) Escort library. We first use the Pin dynamic
binary instrumentation tool [19] to gather the full instruc-
tion address traces of both expf() implementations8 . We
Results. We observe that Escort’s results are identi-
train the TensorFlow machine-learning classifier by feed-
cal to the results produced by the reference implemen-
ing the instruction address traces to the classifier, asso-
tations, i.e. the native (x86) instructions and the Musl
ciating each trace with the secret input to expf(). We
C library. More precisely, the ULP difference between
use cross entropy as the cost function for TensorFlow’s
Escort’s results and reference implementation’s results
training phase. In the subsequent testing phase, we ran-
is zero. On the other hand, FTFP, which computes
domly select one of the collected address traces and ask
arithmetic in fixed-point precision, produces output that
the classifier to predict the secret input value.
differs substantially from the output of Musl’s double-
We find that for the Musl implementation, the classi- precision functions (see Table 7). The IEEE 754 standard
fier is accurately able to predict the correct secret value requires that addition, subtraction, multiplication, divi-
from the address trace. On the other hand, for the Escort sion, and square root operations are computed with ULP
8 Using the md5sum program, we observe that Escort’s address traces difference of at most 0.5. Well-known libraries compute
for all three inputs are identical. results for most higher-level operations within 1 ULP.
[20] M AAS , M., L OVE , E., S TEFANOV, E., T IWARI , M., S HI , E., [39] Z HANG , Y., AND R EITER , M. K. Duppel: Retrofitting Com-
A SANOVIC , K., K UBIATOWICZ , J., AND S ONG , D. PHAN- modity Operating Systems to Mitigate Cache Side Channels in
TOM: Practical Oblivious Computation in a Secure Processor. In the Cloud. In Conference on Computer and Communications Se-
Conference on Computer and Communications Security (2013), curity (2013), pp. 827–838.
pp. 311–324.
[21] M ARTIN , R., D EMME , J., AND S ETHUMADHAVAN , S. Time-
Warp: Rethinking Timekeeping and Performance Monitoring
Mechanisms to Mitigate Side-Channel Attacks. In International
Symposium on Computer Architecture (2012), pp. 118–129.
[22] M ASTI , R. J., ET AL . Thermal Covert Channels on Multi-core
Platforms. In USENIX Security Symposium (2015), pp. 865–880.
[23] M OLNAR , D., P IOTROWSKI , M., S CHULTZ , D., AND WAG -
NER , D. The Program Counter Security Model: Automatic De-
tection and Removal of Control-Flow Side Channel Attacks. In
International Conference on Information Security and Cryptol-
ogy (2005), pp. 156–168.
[24] M UCHNICK , S. Advanced Compiler Design and Implementation.
Morgan Kaufmann Publishers Inc., 1997.
[25] M ULLER , J.-M. On the definition of ulp(x). Tech. Rep. 2005-
009, ENS Lyon, February 2005.
[26] O SVIK , D. A., S HAMIR , A., AND T ROMER , E. Cache Attacks
and Countermeasures: the Case of AES. In RSA Conference on
Topics in Cryptology (2006), pp. 1–20.
[27] P ERCIVAL , C. Cache Missing for Fun and Profit. In Proceedings
of the Technical BSD Conference (2005).
[28] R ANE , A., L IN , C., AND T IWARI , M. Raccoon: Closing Dig-
ital Side-channels Through Obfuscated Execution. In USENIX
Conference on Security Symposium (2015), pp. 431–446.
[29] R EN , L., Y U , X., F LETCHER , C., VAN D IJK , M., AND D E -
VADAS , S. Design Space Exploration and Optimization of Path
Oblivious RAM in Secure Processors. In International Sympo-
sium on Computer Architecture (2013), pp. 571–582.
[30] S AKURAI , K., AND TAKAGI , T. A Reject Timing Attack on an
IND-CCA2 Public-key Cryptosystem. In International Confer-
ence on Information Security and Cryptology (2003), pp. 359–
374.
[31] S CHINDLER , W. A Timing Attack Against RSA with the Chi-
nese Remainder Theorem. In International Workshop on Crypto-
graphic Hardware and Embedded Systems (2000), pp. 109–124.
[32] S HI , E., C HAN , T. H., S TEFANOV, E., AND L I , M. Oblivious
RAM with O((logN)3 ) Worst-Case Cost. In Advances in Cryp-
tology (2011), pp. 197–214.