Repository navigation
Expand file tree
/
Copy pathsyntax.tex
More file actions
1425 lines (1340 loc) · 64.3 KB
/
Copy pathsyntax.tex
File metadata and controls
1425 lines (1340 loc) · 64.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
\chapter{Hoare-Style Verification}\label{ch:syntax}
While the methodology presented in the previous chapter
for verifying \gls{memuse} works well, it is not ideal.
The need to manually formulate regions
and the amount of work required for developing invariants
reduces potential scalability.
In order to deal with those downsides,
this \lcnamecref{ch:syntax} introduces the concept of \glspl[prereset]{fmuc}
generated by untrusted, informal tools.
\Glspl{fmuc} consist of two main components:
theorems on \gls{memuse} and \emph{proof ingredients}.%
\index{proof!ingredient}
The proof ingredients are assumptions on memory layout,
control flow information, and invariants
generated to reduce the amount of work required from end users.
Certificate generation is presented in \cref{se:fmuc_gen},
while the process of verification in \gls{isabelle} is documented in \cref{se:fmuc_ver}.
A full example of \gls{fmuc} usage can then be found in \cref{se:syntax_example}.
That example could theoretically overwrite
its own return address due to its pointer arguments, causing \gls{cfi} issues.
The associated \gls{fmuc} provides preconditions to prevent such cases
along with a formal proof of return address preservation under those conditions.
Following the example in \cref{se:xen} is an in-depth case study
on \gls{xen} hypervisor \autocite{chisnall2008definitive}.
In total, \glspl{fmuc} were generated and proofs discharged in \gls{isabelle}
for 251 \glslink{xen}{Xen} functions.
\begin{comment}
My primary contributions to the certificate generation and verification approach%
\index{certificate}
presented in this chapter include the Hoare rules developed
for \gls{memuse} as well as the \gls{vcg} used to apply those rules
to \gls{scf} in \gls{isabelle} (\cref{se:fmuc_ver}).
I also greatly expanded the code for full translation of the \glspl{fmuc} into the \gls{isabelle}[/HOL] language and helped adapt the \gls{scf} into a form suitable for verification in \gls{isabelle} (\cref{isabelle_scf}).
Additionally, I contributed to invariant generation (\cref{sse:inv_gen})
and performed much of the verification work for our large case study,
presented in \cref{se:xen}.
\end{comment}
\section{\Glsfmtshort{fmuc} Generation}\label{se:fmuc_gen}
\begin{figure*}
\centering
\begin{tikzpicture}[gnode/.style={draw, rounded corners, text centered}]
\graph[grow right=2.88815cm]{
Assembly[gnode] ->[dashed]
"Control\\Flow\\Graph"[gnode,align=center] ->["\ref{sse:cfg_extract}"]
"Syntactic\\Control\\Flow"[gnode,align=center] ->["\ref{sse:syntax_symb}"]
"Memory\\Regions\\and\\\glsxtrshortpl{mrr}"[gnode,align=center]
->["\ref{sse:inv_gen}"]
Invariants[gnode] ->[dashed] Certificate[gnode];
};
\end{tikzpicture}
\caption{Overview of \glsfmtshort{fmuc} generation}\label{fig:overview}
\end{figure*}
\Glspl{fmuc} require the assembly code of a program as input.
That source assembly could be obtained from a binary using a disassembler, such as \texttt{objdump},
IDA \autocite{ida}, Ghidra's decompiler \autocite{ghidra}, or Capstone \autocite{capstone}.
If source code is available, it could be generated directly by a compiler instead.
Each function specified for verification receives \pgls{fmuc};
those that are not included in the verification effort,%
\index{verification!effort}
including system calls and functions from dynamic libraries,
can be treated as black boxes,
the usage of which is described in \cref{sse:fmuc_comp}.
The general procedure for generating \glspl{fmuc}, laid out in \cref{fig:overview},
can be broken up into three main parts.
The first part involves control flow extraction from the supplied assembly
using \pgls{cfg} analysis similar to angr's CFGFast%
\index{angr!CFGFast}
\autocite{shoshitaishvili2016state},
ultimately producing \pgls{scf} (the details of which are presented
in \cref{sse:cfg_extract}).
Afterwards, per-basic block symbolic execution
is utilized to generate the set of memory regions
read and written by the function in question.
This was detailed in \cref{ch:symbolic_execution}.
To eliminate duplicates and produce \glspl{mrr}
showing which regions overlap or are enclosed or separate,
the region sets are then fed to the \gls{smt} solver \gls{z3} \autocite{de2008z3}.
Symbolic execution is also used in the process of generating
the pre- and postconditions for each basic block,
elaborated on in \cref{sse:inv_gen}.
With the exception of \gls{mrr} generation,
none of the steps in this procedure are included in the \gls{tcb}.
The process of verifying the generated \gls{fmuc} (see \cref{se:fmuc_ver})
will fail if there are issues in control flow extraction,
\gls{scf} generation, informal symbolic execution, or invariant generation.
\Gls{mrr} generation is an exception
because the \glspl{mrr} are formulated as assumptions,
and thus inconsistent \glspl{mrr} will result in vacuous proofs.
This is why the methodology relies on \gls{z3} for \gls{mrr} generation;
using a known-reliable tool greatly reduces the possibility of issues.
\subsection{Control Flow Extraction}\label{sse:cfg_extract}
%As described in \cref{se:hoare},
%in
In order to apply \pgls{vcg} that utilizes Hoare rules to verify a Hoare triple,
there must be some syntactic structure to apply those rules to.
This chapter uses a syntactic representation of control flow called \gls{scf}
in part for that purpose.
\Gls{scf} expresses assembly programs as a combination of basic blocks,
branches, loops, and function calls.
The following grammar provides a description of \gls{scf}
produced by the extraction code.
Each basic block is represented by the polymorphic type~$\beta$,
while branching conditions are represented using the polymorphic type~$\Phi$.
\begin{bnf}
\bnfprod*{scf}{
\bnfpn{scf}\bnfsp\bnfts{;}\bnfsp\bnfpn{scf}
\bnfor\bnfts{Block}\bnfsp\bnftd{$\beta$}
\bnfor\bnfts{Skip}
\bnfor\bnfts{Continue}
\bnfor\bnfts{Break}\bnfsp\bnfpn{br}
} \\
\bnfmore{
\bnfor\bnfts{If}\bnfsp\bnftd{$\Phi$}
\bnfsp\bnfts{Then}\bnfsp\bnfpn{scf}
\bnfsp\bnfts{Else}\bnfsp\bnfpn{scf}
\bnfsp\bnfts{Fi}
\bnfor\bnfts{Loop}\bnfsp\bnfpn{scf}\bnfsp\bnfts{Pool}\bnfsp\bnfpn{res}
} \\
\bnfprod{br}{
\bnftd{ID}\bnfor\bnfes
} \\
\bnfprod{res}{
\bnfts{Resume}\bnfsp\bnfts{\{(}\bnftd{ID}\bnfts{,}
\bnfpn{scf}\bnfts{),}\bnfsk\bnfts{\}}
\bnfor\bnfes
}
\end{bnf}
Loops in this formulation have no exit condition;%
\index{loop}
instead, they rely on having one or more internal \texttt{Break} statements,%
\index{loop!break}
which may have an identifier to indicate how the loop was exited, for termination.
\texttt{Continue}s function the same as in C,%
\index{loop!continue}
causing loop execution to skip to the next iteration.
For loops that have multiple exit points,
\texttt{Resume} statements provide different code to execute
based on which exit was taken as indicated by the \texttt{Break} identifier.
Notably, the above data structure does not explicitly contain
control flow statements such as \lstinline|goto| or \lstinline|throw|/\lstinline|catch|.
Unconditional jumps like \lstinline|goto|s make code harder to reason about
in a structured way and can be modeled by the existing syntactic constructs,
while structured \gls{eh} as used in \gls{cpp} is generally provided
by external function calls.%
\index{exception handling!function}
%(\cref{se:structured_exceptions}).
\begin{example}[\Glsfmtshort{scf} extraction]
\Cref{fig:ex_cf} provides an example of \gls{scf} extracted from \pgls{cfg}.
The \gls{cfg} in \cref{fig:ex_cf_cfg} can be seen to have two branching conditions
that do not involve loops, one from $\ABB~0$ with condition~$f_0$
and one from $\ABB~7$ with condition~$f_7$.
This leads to if statements with those conditions
being added to the \gls{scf} in \cref{fig:ex_cf_scf} after their respective blocks.
The one loop present has two exit points.
If condition~$f_1$ is false after execution of $\ABB~1$,
the loop will exit to $\ABB~4$, while $\ABB~2$ will exit to $\ABB~3$ if~$f_2$ is false.
This leads to the $\ABreak$ statements present in the extracted \gls{scf}
in their respective conditional statements
annotated with the IDs for their associated exit blocks.
Those two exit points also result in the generation of a $\AWhileResume$ clause
indicating where those $\ABreak$s exit to.
\begin{figure*}
\hspace*\fill
\subcaptionbox{Example \glsfmtshort{cfg}\label{fig:ex_cf_cfg}}{
\begin{tikzpicture}[->, node distance=0.75cm]
\node[draw=none] (0) {0};
\node[draw=none] (1) [below=of 0] {1};
\node[draw=none] (2) [below=of 1]{2};
\node[draw=none] (3) [below=of 2]{3};
\node[draw=none] (4) [left=of 3, xshift=0.5cm, yshift=0.5cm]{4};
\node[draw=none] (5) [below=of 3]{5};
\node[draw=none] (6) [below=of 5, xshift=0.5cm, yshift=0.5cm]{6};
\node[draw=none] (7) [right=of 1]{7};
\node[draw=none] (8) [right=of 3, xshift=0.5cm, yshift=0.5cm]{8};
\node[draw=none] (9) [right=of 5]{9};
\path (0) edge node[left]{$f_0$} (1);
\draw[rounded corners=2mm] (0) -|
node[above, xshift=0.4cm, yshift=-0.9cm]{$\neg f_0$} (7);
\path (1) edge [bend left] node[right]{$f_1$} (2);
\draw[rounded corners=2mm] (1) -| node[left, yshift=-1.3cm]{$\neg f_1$} (4);
\path (2) edge [bend left] node[left, xshift=0.1cm]{$f_2$} (1);
\path (2) edge node[right]{$\neg f_2$} (3);
\path (3) edge node[right]{} (5);
\draw[rounded corners=2mm] (4) |- (5);
\path (5) edge node[right]{} (6);
\draw[rounded corners=2mm] (7) -| node[right, yshift=-1.3cm]{$\neg f_7$} (8);
\path (7) edge node[left, yshift=-1cm]{$f_7$} (9);
\draw[rounded corners=2mm] (8) |- (9);
\path (9) edge node[right]{} (6);
\end{tikzpicture}
}
\hfill
\subcaptionbox{Syntactic Control Flow\label{fig:ex_cf_scf}}{
\(\begin{array}{l}
\ABB~0\ASeq* \\
\AIf~f_0~\AThen \\
\ind{4ex}\AWhile \\
\ind{8ex}\ABB~1\ASeq* \\
\ind{8ex}\AIf~f_1~\AThen \\
\ind{12ex}\ABB~2\ASeq* \\
\ind{12ex}\AIf~f_2~\AThen~\AContinue~\AElse~\ABreak~2~\AFi \\
\ind{8ex}\AElse \\
\ind{12ex}\ABreak~1 \\
\ind{8ex}\AFi \\
\ind{4ex}\AOd~\AWhileResume~\{(2,\ABB~3),(1,\ABB~4)\}\ASeq* \\
\ind{4ex}\ABB~5 \\
\AElse \\
\ind{4ex}\ABB~7\ASeq* \\
\ind{4ex}\AIf~f_7~\AThen~\ASkip~\AElse~\ABB~8~\AFi\ASeq* \\
\ind{4ex}\ABB~9 \\
\AFi\ASeq* \\
\ABB~6
\end{array}\)
}
\hspace*\fill
\caption{Example of control flow extraction}\label{fig:ex_cf}
\end{figure*}
\end{example}
\subsubsection{Restrictions}
There two important restrictions on the current control flow extraction approach,
the more severe of which is the lack of support for indirect branching.
The \gls{cfg} analysis done by the current extraction algorithm
is not strong enough to handle indirect branching at the moment.
In some cases, the set of possible branches can be determined based on the
local function context, but the result of an indirect branch is often based off of input arguments, as well. Even if the result set
might be determinable with static analysis, it would have to be interprocedural,
and branch destinations based on external input cannot be determined.
Finally, as the if-then-else statement provides the sole form of
branching control flow, the algorithm is not optimal
due to the duplication of blocks to fit less structured control flow
into a more structured model. In the worst case,
it can result in \gls{scf} explosion, described below.
\subsubsection{\Glsfmtshort{scf} Explosion}\label{sse:scf_explode}
As stated, the algorithm is not optimal in terms of generated \gls{scf} size
due to the possibility of certain basic blocks being duplicated.
There are two situations where such basic block duplication occurs,
one less common than the other.
The less common situation is when loop having multiple entry points,
which can occur in situations that involve less-structured control flow,
such as \pgls{c} program that jumps into a loop using \texttt{goto}.
Such situations are relatively uncommon, even in optimized code.
If it does happen, the entire loop must be duplicated.
The more common situation, by contrast, involves complex conditional branching
that can occur even without loops.
\begin{example}[\Glsfmtshort{scf} explosion]
\Cref{fig:ex_nonopt} shows a small example of branching control flow
that results in $\ABB~3$ being duplicated.
That block could itself be an even more complicated subgraph,
possibly leading to exponential code duplication.
\begin{figure*}
\hspace*\fill
\subcaptionbox{\Glsfmtshort{cfg}}{
\begin{tikzpicture}[->, node distance=0.75cm]
\node[draw=none] (0) {0};
\node[draw=none] (1) [right=of 0] {1};
\node[draw=none] (2) [right=of 1] {2};
\node[draw=none] (3) [right=of 2] {3};
\node[draw=none] (4) [right=of 3] {4};
\path (0) edge node[below]{$f_0$} (1);
\path (0) edge [bend left] node[above]{$\neg f_0$} (4);
\path (1) edge node[above]{$f_1$} (2);
\path (1) edge [bend right] node[below]{$\neg f_1$} (3);
\path (2) edge node[above]{$f_2$} (3);
\path (2) edge [bend right] node[below]{$\neg f_2$} (4);
\path (3) edge (4);
\end{tikzpicture}
}
\hfill
\subcaptionbox{\Glsfmtshort{scf}}{
\(\begin{array}{l}
\ABB~0; \\
\AIf~f_0~\AThen~\ABB~1; \\
\ind{4ex}\AIf~f_1~\AThen~\ABB~2; \\
\ind{8ex}\AIf~f_2~\AThen~\ABB~3 \\
\ind{8ex}\AElse~\ASkip~\AFi \\
\ind{4ex}\AElse~\ABB~3~\AFi \\
\AElse~\ASkip~\AFi; \\
\ABB~4
\end{array}\)
}
\hspace*\fill
\caption{Example of code duplication}\label{fig:ex_nonopt}
\end{figure*}
\end{example}
\subsection{Symbolic Execution for Generation}\label{sse:syntax_symb}
In \cref{sse:cfg_extract}, the semantics of assembly were expressed%
\index{semantics!assembly}
in terms of control flow between basic blocks.
This section now covers the symbolic execution of those individual blocks.
The Haskell symbolic execution engine
takes as input a data structure of type $\scf(B,E_F)$,
which is formulated over basic blocks,
and produces $\scf(\powerset(\gls{assign}),\gls{esp})$,
which is formulated over sets of assignments.
It keeps track of all used memory regions,
both the actual regions used by instructions as well as merged regions,
in order to supply those regions as part of an \gls{fmuc}.
\subsubsection{Generating Memory Region Relations}
Because symbolic execution uses symbolic state,
the relations of enclosure, separation, and overlap,
defined in \cref{memory_aliasing}, must be determined for symbolic expressions.
Unfortunately, there is no single solution, no one decision procedure,
that can determine these properties for all symbolic expressions automatically.
As an example of the potential issues that can occur,
take the completely symbolic regions $r_0=\region{a_0}{s_0}$
and $r_1=\region{a_1}{s_1}$.
Without additional information, we cannot determine any relations for these regions.
If they are \emph{possibly} different then they must be treated as different regions,
while if they \emph{necessarily} overlap
then they must be treated as a single merged region.
To deal with such symbolic issues,
the three aforementioned relations of enclosure, separation, and overlap
are formulated as \gls{smt} problems.
The \gls{smt} formulations are negations
of the equations presented in \cref{def:sep,def:enc};
the result states the property holds if the resultant problem is \emph{unsatisfiable}.
These \gls{smt} problems can be solved by \gls{z3} \autocite{de2008z3}
for a wide range of expressions over bitvectors
using the \inlineisabelle{QF_UFBV} logic \autocite{smtlib:bitvector-logic,smtlib:bitvector-theory}.
\Gls{z3} is also used in this work for determining the sign of two values
in the region merge algorithm, originally presented in \cref{def:merge}.
Additionally, reads of overlapping regions may require merging
and separation analysis as described in \cref{memory_aliasing},
so they also rely on \gls{z3}.
The result of evaluating the above \gls{smt} problems
over all pairs of memory regions for a basic block, each region being given a unique ID,
is two sets with element type $\gls{nat}\times\gls{nat}$, $\var{enc}$ and $\var{ovl}$.
Every element $(i_0,i_1)$ in $\var{enc}$ indicates that the region with ID~$i_0$
is enclosed by the region with ID~$i_1$.
Every element $(i_0,i_1)$ in $\var{ovl}$ indicates that the two regions with those IDs
overlap.
Those two sets are the \glspl{mrr} for the block,
and using them as assumptions allows for efficient execution of the rewrite rules
in \cref{memory_rewrite}.
\subsection{Invariant Generation}\label{sse:inv_gen}
Invariants, formalized as sets of assignments of the aforementioned type~\gls{assign},
\index{invariant}
are generated by starting from a precondition for the entry point of the function
and \emph{propagating} it throughout.%
\index{invariant!propagation}
The initial precondition of the function as a whole is generated
by including initial symbolic values for all registers that are read
before they are written as well as all used memory regions
that are not enclosed in another.
The concrete initial value of the instruction pointer, \rip,
must also be included,
and the (symbolic) address to return to after function completion
must be indicated as stored on the stack.
In Haskell, the conditions in question are represented as sets of assignments.
\begin{example}[Initial invariant]
To reuse \cref{ex:simple}, its initial precondition would be:
\begin{equation}
\phi=\{\mathrip\coloneqq\mathtt{a0},
\mathrsp\coloneqq\rspo,
\region{\mathrsp-8}{8}\coloneqq v_0,
\region{\mathrsp}{8}\coloneqq\retaddr\}.
\end{equation}%
\nomenclature{$\phi$}{Denotes a generated invariant}
\end{example}
Propagation requires performing \emph{substitution},%
\index{invariant!substitution}
which is defined over assignments, state parts, and expressions,
all with respect to invariant~$\phi$.
\begin{subequations}
\begin{align}
\subst(\phi,\var{sp}\coloneqq v) &= \subst(\phi,\var{sp})\coloneqq\subst(\phi,v)\\
\subst(\phi,\var{sp}) &= \text{if }\exists v\cdot(\var{sp},v)\in\phi
\text{ then }v\text{ else }\var{sp} \\
\subst(\phi,e_0\bop e_1) &= \text{if }\exists v\cdot(e_0\bop e_1,v)\in\phi
\text{ then }v\text{ else }\subst(\phi,e_0)\bop\subst(\phi,e_1) \\
\text{unary ops} &= \dotso \notag \\
\text{ternary ops} &= \dotso \notag
\end{align}
\end{subequations}%
\nomenclature[operator]{$\bop$}{Denotes an arbitrary binary operator}
\Cref{algo:prop} performs invariant propagation.
Each block is modified by applying all applicable substitutions
with respect to~$\phi$.
Invariant~$\phi$ is then modified based off of the semantics of the block.%
\index{semantics}
Treating~$\alpha$ as the set of assignments in the block,
$\phi$ is modified by taking the subset of substitutions
where the substitutees are overwritten by~$\alpha$
and combining them with the subset of substitutions
that were completely unmodified by any assignment in~$\alpha$:
\begin{equation}
\post(\phi,\alpha)\footnote{%
This is a different $\post$ from that used to identify \gls{cfg} block children.
}\equiv\{(v,e)\mid(v\coloneqq e\in\alpha\land(v,\_)\in\phi)
\lor((v,e)\in\phi\land(v,e)\text{ is unmodified by }\alpha)\}.
\end{equation}
\begin{example}[Invariant propagation]
Once again consider \cref{ex:simple}.
Propagation of the initial precondition through the single basic block
produces the following postcondition:
\begin{equation}
\begin{split}
\phi=\{\mathrip &\coloneqq\retaddr, \\
\mathrsp &\coloneqq\rspo+8, \\
\region{\rspo-8}8 &\coloneqq\mathtt{0xAABBCCDD}\concat
\takebits{31,16}v_0\concat\mathtt{0xEEFF}, \\
\region{\rspo}8 &\coloneqq\retaddr\}.
\end{split}
\end{equation}
\end{example}
\begin{algorithm}
\caption{Invariant propagation}\label{algo:prop}
\begin{algorithmic}
\Require{Input is of type $\scf(\powerset(\gls{assign}),\gls{esp})$}
% only \glsentryshort works for some reason
\Ensure{Output is a tuple of possibly-updated~$\phi$
and \glsentryshort{scf} updated with current~$\phi$:
$\gls{assign}\times\scf(\powerset(\gls{assign}),\gls{esp})$}
\Function{prop}{$\phi,\ABB~\alpha$}
\State $\phi'\gets\post(\phi,\subst(\phi,\alpha))$
\State\Return $(\phi',\ABB~(\alpha\text{ annotated with }\phi))$
\EndFunction
\Function{prop}{$\phi,\alpha_0\ASeq \alpha_1$}
\State $(\phi',\alpha_0')\gets\Call{prop}{\phi,\alpha_0}$
\State $(\phi'',\alpha_1')\gets\Call{prop}{\phi',\alpha_1}$
\State\Return $(\phi'',\alpha_0'\ASeq \alpha_1')$
\EndFunction
\Function{prop}{$\phi,\AIf~f~\AThen~\alpha_0~\AElse~\alpha_1~\AFi$}
\State $(\phi_0,\alpha'_0)\gets\Call{prop}{\phi,\alpha_0}$
\State $(\phi_1,\alpha'_1)\gets\Call{prop}{\phi,\alpha_1}$
\State $\phi'\gets\phi_0\cap\phi_1$
\State\Return $(\phi',\AIf~\subst(\phi,f)~\AThen~
\alpha'_0~\AElse~\alpha'_1~\AFi)$
\EndFunction
\Function{prop}{$\phi,\AWhile~\alpha~\AOd$}
\State $(\phi',\alpha')\gets\Call{prop}{\phi,\alpha}$
\If{$\phi\subseteq\phi'$}%
\nomenclature[operator]{$\subseteq$}{Indicates subset relation}
\State\Return $(\phi,\AWhile~\alpha'~\AOd)$
\Else
\State\Return $\Call{prop}{\phi\cap\phi',\AWhile~\alpha~\AOd}$
\EndIf
\EndFunction
\Function{prop}{$\phi,\AWhileResume~\var{resumes}$}
\ForAll{$\alpha_i\in\var{resumes}$}
\State $(\phi'_i,\alpha'_i)\gets\Call{prop}{\phi,\alpha_i}$
\EndFor
\State $\phi''\gets\bigcap\phi'$
\State\Return $(\phi'',\AWhileResume~\Call{zip}{i,\alpha'})$
\EndFunction
\Function{prop}{$\phi,\alpha$}\Comment{Default case}
\State\Return $(\phi,\alpha)$
\EndFunction
\end{algorithmic}
\end{algorithm}
Invariant propagation is straightforward for sequencing and if statements,
with sequencing simply chaining invariant propagation
and if statements producing an invariant that is the common result
of propagating the initial invariant down both branches.
In contrast, a loop with body~$\alpha$ requires continual propagation
until the invariant~$\phi$ stabilizes, possibly by becoming~$\varnothing$.%
\nomenclature{$\varnothing$}{The empty set}
This stabilization is identified
by checking if~$\phi$ is a subset of its propagated self.
If it is, then \gls{prop} returns the propagated~$\phi$
and a new loop with the propagated body.
Otherwise,
the original loop is propagated again with the intersection of~$\phi$
and its propagated self.
This process effectively computes the loop invariant
as the greatest subset of the initial invariant
that is preserved by execution of the loop body.
For loops that have multiple exits,
each exit's resume is propagated with the invariant at the point of exit evaluation.
In a similar fashion to the process for if statements,
the invariants that result from individual resume propagation
are intersected to produce a singular invariant for all resumes,
which is then returned along with all of the propagated resumes.
\section{\Glsfmtshort{fmuc} Verification}\label{se:fmuc_ver}
This section presents verification of \pgls{fmuc} as shown in \cref{fig:verify},
one of the primary contributions for this chapter as mentioned in its preamble.
Both the \gls{fmuc} and the original assembly are loaded into \gls{isabelle}[/HOL],
where the \gls{memuse} theorem is then proven using the proof ingredients
provided by the \gls{fmuc}.
By this method, which requires a step function
that models the semantics of the assembly instructions
and a process to apply it repeatedly,
the \gls{fmuc}['s] \gls{memuse} Hoare triple can be verified.
\begin{figure*}
\centering
\begin{tikzpicture}[->, every node/.style={
draw,
rounded corners,
text width=3cm,
text centered,
minimum height=1.5cm
}]
\node (a) {\gls{isabelle}[/HOL]};
\node[above left=of a] (b) {Assembly};
\node[below left=of a] (c) {Certificate};
\node[right=1.5cm of a] (d) {OK/unproven};
\draw (b) -- (a.north west);
\draw (c) -- (a.south west);
\draw (a) -- (d);
\end{tikzpicture}
\caption{Overview of \glsfmtshort{fmuc} verification}\label{fig:verify}
\end{figure*}
% \glsentryname doesn't handle post-insertion so no point in using it here
\subsection{Syntactic Control Flow in \texorpdfstring{\gls{isabelle}[/HOL]}{Isabelle/HOL}}\label{isabelle_scf}
As described previously, \gls{scf} is a representation of the control flow of a function
in terms of syntactic structures such as basic blocks,
loops, and if-then-else statements.
While very similar to the \gls{scf} used when generating \glspl{fmuc},
there are some modifications that must be made when the generated \glspl{scf}
are to be loaded into \gls{isabelle}[/HOL].
These modifications are required due to subtle differences in the semantics
of the generating tool versus the verifying tool,
and are required to properly support the Hoare rules
described in \cref{scf_hoare} below.
In the \gls{isabelle}[/HOL] representation,
there are no \texttt{Break}s or \texttt{Continue}s;
any occurrences of such statements are translated to \texttt{Skip}.
This does mean that programs that cannot be easily transformed
such that that translation does not modify the overall semantics
are not easily handled in this framework.
However, none of functions encountered in the case study presented in \cref{se:xen}
had that issue, so it does not appear to be a significant drawback.
Additionally, loops in the \gls{isabelle}[/HOL] \gls{scf} syntax do rely on a explicit exit condition.
This condition is simply the precondition of the entry block of the loop
as generated using the methodology in \cref{sse:inv_gen}.
Another important difference is that basic blocks in \gls{isabelle} take the form $\ABB~\Block*{n}{a}{i}$,
where~$n$ indicates the number of instructions in the block,~$a$ is the address
of the last instruction in the block, and~$i$ is an ID
that uniquely identifies the block in the current \gls{scf}.
This style is used to assist with the symbolic execution methodology described in
\cref{sse:syntax_ver_symb}.
Finally, to properly handle function calls in the \gls{isabelle}[/HOL] syntax,
the analyzed \glspl{cfg} are preprocessed prior to performing extraction
in order to isolate \inlineasm{call} instructions into their own basic blocks.
% Freek did the preprocessing but I did all the rest.
These single-instruction blocks are then translated into \texttt{Call}~$f$ entries
in the \gls{isabelle}[/HOL] \gls{scf}, where~$f$ is the textual label of the function called.
This allows for proper matching with the Hoare rules presented below.
\subsection{Symbolic Execution for Verification}\label{sse:syntax_ver_symb}
\Cref{cfg_symb_exec} previously presented a formal symbolic execution engine
based on the machine model described in \cref{se:machine_model}.
It provides a function \gls{run} that describes the symbolic execution of
blocks in a control flow graph.
The formal function for block-level symbolic execution presented in this chapter,%
\index{symbolic!execution}
by contrast, is a \emph{transition relation}%
\index{transition relation} formulated as
\begin{equation*}
\execblock:\gls{nat}\times W\times\gls{nat}\times S\times S\rightarrow\gls{bool}.
\end{equation*}
Its inputs are the number of instructions left to execute in the block,
the address of the last instruction in the block, the block's ID,
the current state~$\sigma$, and an ending state~$\sigma'$.
Its result is true if and only if execution
starting from the current instruction in state~$\sigma$
and running to the ending address can produce state~$\sigma'$.
The other arguments are used to ensure termination and block matching.
Undefined behavior, such as null-pointer dereferencing,
is modeled by relating the state in which it occurs to any successor state
supplied with it.
The internal step function has type $\gls{step}:A\times\gls{nat}\times S\rightarrow S$,
with its first argument being an instruction, its second being the size of the instruction,
and its third being the current state.
The function returns the state after instruction execution,
incrementing \rip\ by the supplied size
if it was not changed by a control flow instruction instead.
% TODO: provide the detail of the $\exec$ function if time permits
The $\execblock$ function is used internally by another transition relation,
this one for the symbolic execution of entire \glspl{scf}:
$\exec:\var{SCF}\times S\times S\rightarrow\mathbb{B}$.
That function recurses through \pgls{scf}
and checks $\execblock$ on every block it finds,
performing the necessary state transformations to deal with the semantics of
the individual \gls{scf} components encountered.
Any loops encountered are dealt with using \pgls{lfp} construction.
This means that, if there are any infinite loops present,
the function will have no related successor states.
The only matching state would be $\infloop$.
Strictly speaking, $\exec$ is not actually executed when used in \gls{fmuc} proofs;
it exists to allow proving the correctness
of the Hoare rules shown below in \cref{scf_hoare}.
Unlike the symbolic execution for generation,
this symbolic execution methodology is implemented fully in \gls{isabelle}[/HOL],
meaning that every rewrite rule has been formally proven correct.
\subsection{Per-Block Verification}\label{sse:per-block}
The verification methodology presented here occurs
by first verifying the functionality of each basic block in the corresponding function.
This is done for each block by proving the lemma shown below,
using the $\exec$ function from the previous section.
To do this, however, a formal notion of \emph{\gls{memuse}}
with respect to state changes is required.
\begin{definition}[Memory usage with respect to state changes]\label{def:mem_preserve}
The set of memory regions~$M'$ characterizes \gls{memuse} with respect to
the change from some state~$\sigma$ to some other state~$\sigma'$
if and only if every byte outside of the regions in~$M'$ is the same in both states.
The addresses of those bytes are represented by the variable~$a$.
This is formally expressed as:
\begin{equation}
\usage(M',\sigma,\sigma')\equiv\forall a\cdot(\forall r\in M'\cdot\region{a}1\gls{separate}r)
\longrightarrow\readmemS{\sigma}a{1}=\readmemS{\sigma'}a{1}.
\end{equation}
\end{definition}
Using \cref{def:mem_preserve}, each block gets a lemma of the form
\begin{equation}
P(\sigma)\longrightarrow\execblock(n,a,i,\sigma,\sigma')\land
Q(\sigma')\land\usage(M(\sigma),\sigma,\sigma').\label{eq:block_lemma}
\end{equation}
Note that~$M$ is a state-dependent function.
Every generated version of \cref{eq:block_lemma} is discharged
with an \gls{isabelle}[/HOL] proof method written in Eisbach \autocite{matichuk2016eisbach},
\gls{isabelle}'s proof automation language.
For each block, the method takes the block-related proof ingredients
from the \gls{fmuc} and runs symbolic execution
to prove the postcondition and thus establish \gls{memuse} for the block.
The open variables $P$, $Q$, $n$, $a$, $i$, and $M$ are all provided by the \gls{fmuc}.
No user interaction is required outside of cases where semantics
for specific instructions are unavailable or the \gls{isabelle} libraries in use
do not have the right simplification lemmas for automatic reasoning.
Those cases are rare and become rarer as more relevant lemmas are developed,
so for basic blocks, the proof is essentially automated.
\subsection{Function Body Verification}
While symbolic execution works well to establish \gls{memuse} on the level of basic blocks,
the goal of this verification effort is to formally establish \gls{memuse}
on the function level. This section describes that process,
which occurs after the individual blocks have had their semantics and \gls{memuse} derived
and relies on \gls{hoare-logic}. % (described in \cref{se:hoare}).
\subsubsection{Hoare Rules}\label{scf_hoare}
The Hoare triple formulation used for this work, $\htriple*{P}f{Q}M$,
resembles traditional Hoare triples a bit more than the version from \cref{ch:cfg},%
\index{Hoare!triple}
as rather than a halting condition
it takes a syntactic representation of the program, an \gls{scf}.
Unlike traditional Hoare triples, however,
it also explicitly contains the set of memory regions,~$M$,
that contain the areas of memory read and written by the program the \gls{scf} encodes.
Syntactic structure is required because \gls{hoare-logic} is a Hoare-style approach.
\begin{definition}[Hoare triple for \glsfmtshort{scf}]\label{def:preserve}
\begin{equation}
\htriple*{P}f{Q}{M}\equiv
\forall\sigma~\sigma'\cdot P(\sigma)\land\exec(f,\sigma,\sigma')\longrightarrow
Q(\sigma')\land\usage(M,\sigma,\sigma')
\end{equation}
\end{definition}
The above definition states the following:
if precondition~$P$ holds on the initial state~$\sigma$
and~$\sigma'$ would be the result of symbolically executing the \gls{scf}~$f$,
postcondition~$Q$ will hold on the produced state
and any values stored in the regions of memory outside set~$M$ remain unchanged.
While \cref{def:preserve} focuses on the regions written to,
the regions read must also be included as symbolic execution
relies on those regions being included.
Without them, proofs that require symbolically executing
the related instructions will not complete.
\begin{figure*}
\centering
\subcaptionbox{Introduction rule\label{fig:intro-rule}}{
\AxiomC{$\begin{multlined}
\forall\sigma~\sigma'\cdot P(\sigma)\longrightarrow \\
\execblock(n,a,i,\sigma,\sigma')\land{} \\
Q(\sigma')\land\usage(M(\sigma),\sigma,\sigma')
\end{multlined}$}
\AxiomC{$M'=\{r\mid\exists\sigma\cdot P(\sigma)\land r\in M(\sigma)\}$}
\BinaryInfC{$\htriple*{P}{\ABB~\Block*{n}{a}{i}}{Q}{M'}$}
\DisplayProof
}
\subcaptionbox{Sequence rule}{
\AxiomC{$\htriple*{P}f{Q}{M_1}$}
\AxiomC{$\htriple*{Q}g{R}{M_2}$}
\AxiomC{$M=M_1\cup M_2$}
\TrinaryInfC{$\htriple*{P}{f\ASeq g}{R}{M}$}
\DisplayProof
}
\subcaptionbox{Conditional rule}{
\AxiomC{$\htriple*{P\land B}f{Q_1}{M_1}$}
\AxiomC{$\htriple*{P\land\neg B}g{Q_2}{M_2}$}
\AxiomC{$Q_1\lor Q_2\longrightarrow Q$}
\AxiomC{$M=M_1\cup M_2$}
\QuaternaryInfC{$\htriple*{P}{\AIf~B~\AThen~f~\AElse~g~\AFi}{Q}{M}$}
\DisplayProof
}
\subcaptionbox{While rule\label{fig:hoare-loop}}{
\AxiomC{$\htriple*{I\land B}f{I'}{M}$}
\AxiomC{$I'\longrightarrow I$}
\AxiomC{$I\land\neg b\longrightarrow Q$}
\TrinaryInfC{$\htriple*{I}{\texttt{While}~B\texttt{ DO }f\texttt{ OD}}{Q}{M}$}
\DisplayProof
}
\hfill
\subcaptionbox{Skip rule}{
\AxiomC{$M=\varnothing$}
\AxiomC{$P\longrightarrow Q$}
\BinaryInfC{$\htriple*{P}\ASkip{Q}{M}$}
\DisplayProof
}\hspace*\fill
\subcaptionbox{Resume rule}{
\AxiomC{$\forall {0\leq j\leq n}\cdot\htriple*{P}{a_j}{Q_j}{M_j}$}
\AxiomC{$(\bigvee_{0\leq j\leq n} Q_j)\longrightarrow Q$}
\AxiomC{$M = \bigcup_{0\leq j\leq n}M_j$}%
\nomenclature[operator]{$\bigcup$}{Repeated union over a sequence or set of sets, akin to sum/product notation}
\TrinaryInfC{$\htriple*{P}{\AWhileResume\{(i_0,a_0),\dotsc,(i_n, a_n)\}}{Q}{M}$}
\DisplayProof
}
\hspace*\fill
\subcaptionbox{Precondition weakening\label{fig:hoare-weaken}}{
\AxiomC{$P\longrightarrow P'$}
\AxiomC{$\htriple{P'}b{Q}{M}$}
\BinaryInfC{$\htriple{P}b{Q}{M}$}
\DisplayProof
}
\hfill
\subcaptionbox{Postcondition strengthening}{
\AxiomC{$Q'\longrightarrow Q$}
\AxiomC{$\htriple*{P}b{Q'}{M}$}
\BinaryInfC{$\htriple*{P}b{Q}{M}$}
\DisplayProof
}\hspace*\fill
\caption{Hoare rules for \gls{memuse}}\label{fig:rules}
\end{figure*}
\subsubsection{The Introduction Rule}
This rule, depicted in \cref{fig:intro-rule},
is the rule that ties the per-block verification to the function-body verification.
The first assumption requires the symbolic execution method be run
from a universally quantified initial symbolic state~$\sigma$ that satisfies the precondition.
As long as any resulting state~$\sigma'$ satisfies the postcondition~$Q$,
the set of memory regions~$M$ generated for the block should be correct.
The second assumption is required because of an important subtlety:
the regions generated in the~\gls{fmuc} are state dependent.
As previously stated,
the~$M$ for a block is actually a function based on the block's initial state:
its regions depend on the values stored in memory.
However, it makes no sense to express the regions used by individual blocks
within a larger function in terms of their own individual initial state alone.
It would be unsound for regions that depend on values calculated
in the middle of the function to be expressed solely in terms of the initial state.
As such,
the Hoare triples are defined over a state-independent set of memory regions,~$M'$.
That set is obtained for each block
by taking the generated state-dependent set of memory regions
and applying that set to any state that satisfies the current invariant.
\subsubsection{The Other Rules}
While the introduction rule for basic blocks
is the ultimate target of our Hoare rule application process,
the rest of the rules are required to decompose the syntax above the level of blocks.
The remainder of \cref{fig:rules} describes those additional rules.
The Sequence, Conditional, and Resume rules are straightforward:
their ultimate memory region sets are the unions of the region sets of their constituents.
Note that the sequence rule is sound only because the memory predicates
are independent of state as discussed in \cref{sse:per-block}.
The while rule is based on a loop invariant,~$I$.
If the \gls{memuse} of one iteration of loop body~$f$
is constrained to set of memory regions~$M$,
then so is the \gls{memuse} of every other iteration.
This may sound counterintuitive,
so consider a simple C-like loop that starts from $i=0$ and iterates while $i<10$.
The body of this example loop contains single-byte array assignment operations
along the lines of $a[i]=v$.
Verification of the loop requires the loop invariant $I(\sigma)=i(\sigma)<10$.
The \gls{fmuc} of the loop body will have, as a state-dependent set of memory regions, $M(\sigma)=\{\region{a+i(\sigma)}1\}$, which is a single region of one byte.
If the \gls{hoare-logic} introduction rule were to be applied to the block
that is the body of the loop, the result would be as follows:
\begin{subequations}
\begin{align}
M' &= \{r\mid\exists\sigma\cdot I(\sigma)\land r\in M(\sigma)\} \\
&= \{r\mid\exists\sigma\cdot i(\sigma)<10\land r=\region{a+i(\sigma)}1\} \\
&= \{\region{a'}1\mid a\leq a'\le a+10\}
\end{align}
\end{subequations}
The set~$M'$ contains the regions of memory used by the entire loop,
not just one iteration.
This is because the introduction rule applies the state-dependent set of memory regions
to any state that satisfies the invariant.
Thus, the strength of the generated invariants directly influences
the tightness of the overapproximation of \gls{memuse}
and of \gls{memuse} as a whole.
A weaker invariant, such as $i<20$, would result in a larger set of memory regions
by relaxing the constraints on symbolic addresses and,
for other situations, symbolic region sizes.
\begin{lstlisting}[
gobble=2,
float=*,
language=Isabelle,
caption=VCG step method,
label=lst:vcg_step
]
method vcg_step =
((rule htriples)+, rule blocks)+,
(simp add: pred_logic Ps Qs)?, |\label{step_simp}|
(((auto simp: eq_def)[])+)? |\label{step_auto}|
\end{lstlisting}
\begin{lstlisting}[
gobble=2,
float=*,
language=Isabelle,
caption=Main VCG method,
label=lst:vcg
]
method vcg uses scf =
subst scf,
vcg_step+
\end{lstlisting}
\subsubsection{Verification Condition Generation}\label{sse:vcg}
The \gls{vcg} presented here is a set of Eisbach proof methods,
the entry point of which is shown in \cref{lst:vcg}.
It is designed to automatically apply the proper \gls{hoare-logic} rules
as much as possible via the \inlineisabelle{vcg_step} method in \cref{lst:vcg_step},
driven by the formal \gls{scf} provided by the \gls{fmuc}.
Internally, \inlineisabelle{vcg_step} repeatedly applies one of the Hoare rules
from \cref{fig:rules} (excluding the While, strengthening, and weakening rules)
to the current state of the \gls{scf} until no more rules can be applied.
At that point, it assumes that the introduction rule has been applied,
resulting in a block goal being generated, and attempts to discharge that goal
using one of the lemmas generated for \cref{sse:per-block}.
This process is repeated until no more of the restricted set of rules can be applied
or the last rule application resulted in a non-block goal.
At that point, \cref{step_simp} cleans up any preconditions and postconditions
in the current goal.
The last step, \cref{step_auto}, then tries to eliminate as many goals as it can,
one at a time, with \gls{isabelle}'s basic \inlineisabelle{auto} method.
If there are no loops present in the \gls{scf} under consideration,
this method will complete the proof without any need for user interaction.
\begin{lstlisting}[
gobble=2,
float=*,
language=Isabelle,
caption=Alternate step method for $\AWhileResume$ clauses,
label=lst:vcg_cases
]
method vcg_step' =
(rule htriples)+,
simp,
((rule htriples)+, rule blocks)+,
(simp add: pred_logic Ps Qs)?,
(((auto simp: eq_def)[])+)?
\end{lstlisting}
\begin{lstlisting}[
gobble=2,
float=*,
language=Isabelle,
caption=VCG method for loops,
label=lst:vcg_while,
escapechar=*
]
method vcg_while for P :: state_pred =
((rule htriples)+)?,
rule HTriple_weaken[where P=P], *\label{step_weaken}*
simp add: pred_logic Ps Qs,
rule HTriple_while,
vcg_step+,
(simp add: pred_logic Ps Qs)+,
(
(vcg_step' | vcg_step)+,
(simp+)?
)?
\end{lstlisting}
In the case where loops are present,
the \gls{vcg} provides an alternate \inlineisabelle{vcg_while} method,
shown in \cref{lst:vcg_while}
that relies on the loop rule presented in \cref{fig:hoare-loop}.
That loop rule is structured such that
the majority of work required to support the loops
is identifying the preconditions of their exit blocks
and then supplying their disjunction to \inlineisabelle{vcg_while}.
This method relies on application of the weakening rule
presented in \cref{fig:hoare-weaken} on \cref{step_weaken}
to show that the postcondition of the block before entry implies the loop invariant.
The method \inlineisabelle{vcg_step'}, used within \inlineisabelle{vcg_while},
is provided for those cases where a loop has multiple exit points.
A $\AWhileResume$ statement will be present in such cases,
and the process of rule application and simplification must occur
in a slightly different order. On occasion, there will also be a loop that has a single
exit point but gets a $\AWhileResume$ statement anyway
due to how the control flow extraction algorithm is set up.
The process of dealing with such statements is roughly the same, however.
After application of \inlineisabelle{vcg_while},
nested loops and those with multiple exit points may require
additional applications of condition simplifying or plain \inlineisabelle{simp} usage
around further applications of \inlineisabelle{vcg_step}.
Nothing beyond that should be necessary.
Without exception, each of the proofs we produced
could be finished using standard, off-the-shelf \gls{isabelle}[/HOL] methods,
though finishing them was not always an automatic process.
The part that is usually the most involved,
defining the invariants (as seen in the previous chapter)
is taken care of by the \gls{fmuc} generation.
This leaves dealing with loops, particularly ones with multiple exit points,
as the biggest challenge for most situations.
\subsection{Composition}\label{sse:fmuc_comp}
In order to achieve a scalable verification methodology,
it must support some form of compositionality.
Consider the body of an already-verified function~$f$
with the following Hoare triple:
\begin{equation*}
\htriple*{P_f}f{Q_f}{M_f}.
\end{equation*}
In order to reuse that function's proof in a compositional fashion,%
\index{function!composition}
it is treated as a black box.%
\index{function!black box}
Now consider the assembly of a function~$g$ that calls~$f$:
\begin{lstlisting}[style=x64, gobble=2, numbers=none]
a0: push rbp
a1: call f
a2: pop rbp
a3: ret
\end{lstlisting}
$P$ and~$Q$ are the pre- and postconditions just before executing \inlineasm{call}
and just after it returns.
$P$ contains the equality $\readmem{\rspo^g-8}{8}=\rbpo^g$,
expressing that~$g$ has pushed the frame pointer \rbp%
\index{frame!pointer}
into its own local stack frame.%
\index{stack!frame}
The ultimate postcondition of~$g$
expresses that the callee-saved register \rbp\ is properly restored:%
\index{register!callee-saved}
$\mathrbp=\rbpo^g$.
That operation is indeed performed by \inlineasm{pop rbp}.
In order to prove proper restoration of \rbp,
a proof that function~$f$ did not overwrite any byte in the region%
\index{memory!region}
$\region{\rspo^g-8}{8}$ is required.
The proof must also show that~$f$ does not overwrite region $\region{\rspo^g}{8}$,
which stores the address~$g$ returns to.
That proof would be specific to this particular instance of calling~$f$.
Of course,~$g$ may not be the only function that calls~$f$.
It may even be called multiple times by the same function.
Every call has specific requirements on which memory regions must be preserved,
based on the calling context.
Thus, to be able to verify function~$f$ once
but reuse its proof for each call,
the proof must at least contain an overapproximation
of the memory written to by function~$f$.
This is exactly what \emph{separation
logic} \autocite{o2001local,reynolds2002separation,krebbers2017essence}%
\index{separation logic}
requires.
As described in \cref{sse:composition},
separation logic provides a \emph{frame rule} for compositional reasoning.%
\index{separation logic!frame rule}