Patch-Based 1-Day Out-of-Bounds Vulnerabilities Detection Tool for Downstream Binaries

: In the past decades, due to the popularity of cloning open-source software, 1-day vulnerabilities are prevalent among cyber-physical devices. Detection tools for 1-day vulnerabilities effectively protect users who fail to adopt 1-day vulnerability patches in time. However, manufacturers can non-standardly build the binaries from customized source codes to multiple architectures. The code variants in the downstream binaries decrease the accuracy of 1-day vulnerability detections, especially when signatures of out-of-bounds vulnerabilities contain incomplete information of vulnerabilities and patches. Motivated by the above observations, in this paper, we propose P1OVD, an effective patch-based 1-day out-of-bounds vulnerability detection tool for downstream binaries. P1OVD ﬁrst generates signatures containing patch information and vulnerability root cause information. Then, P1OVD uses an accurate and robust matching algorithm to scan target binaries. We have evaluated P1OVD on 104 different versions of 30 out-of-bounds vulnerable functions and 620 target binaries in six different compilation environments. The results show that P1OVD achieved an accuracy of 83.06%. Compared to the widely used patch-level vulnerability detection tool ReDeBug, P1OVD ignores 4.07 unnecessary lines on average. The experiments on the x86_64 platform and the O0 optimization show that P1OVD increases the accuracy of the state-of-the-art tool, BinXray, by 8.74%. Besides, it can analyze a single binary in 4 s after a 20-s ofﬂine signature extraction on average.

However, manufacturers usually non-standardly build binaries from customized source codes for multiple target architectures.Such code variants decrease the accuracy of 1-day vulnerability detection, especially out-of-bounds vulnerabilities.Moreover, the inaccuracy can lead to safety risks or extra manual efforts for security analysis.Due to the prevalence of 1-day out-of-bounds vulnerabilities, in this paper, we propose P1OVD, a 1-day out-of-bounds vulnerability detection tool, which has higher accuracy when code variants appear in the downstream binaries.
Code variants are common and diverse.Research shows that among 6027 counterparts of 285 Android Kernel functions, over 72% of them contain codes that are different from their mainstream versions [19].On the one hand, the code variants that are caused by target architectures or optimization levels can be large.Although they heavily change the instructions, function basic blocks, and function CFGs (control flow graph), they hardly change function logics.On the other hand, code variants can be caused by patching vulnerabilities or unexpectedly introducing new vulnerable modules.So these code variants are critical but small.These two kinds of code variants can appear at the same time, causing two challenges.
The first challenge is that out-of-bounds vulnerability signatures can easily neglect small but important code variants.Function-level 1-day vulnerability detection tools such as Asm2Vec [16] generate vulnerability signatures from the whole vulnerable functions [4][5][6][7][8][9][10][11][12][13][14][15][16].Due to their extremely large scope, they fail to capture the precise context of vulnerabilities.At the same time, patch-level 1-day vulnerability detection tools such as ReDeBug [3] and BinXray [17] generate vulnerability signatures only from patches and their signatures contain incomplete vulnerability information [3,17,18].As a result, when the small code variants influence the vulnerability root causes, the existing tools give false predictions.
The second challenge is that large code variants can decrease the accuracy of the matching methods that depend on AST (abstract syntax tree) shaped out-of-bounds patch signature.Moreover, many existing works have difficulties in balancing the accuracy and robustness.The strict operand-based matching [20] is accurate but sensitive to unimportant code variants, while the graph-similarity-based algorithms [8,9,13,19] improve the robustness but sacrifice accuracy.
To solve the above two challenges, we propose a patch-based 1-day out-of-bounds vulnerability detection tool named P1OVD, which can automatically find 1-day out-ofbounds vulnerabilities in the downstream binaries.It first analyzes patches and outputs source signatures, which solves the first challenge.Then the signature generator maps the source signatures to binary signatures.Finally, the matching engine scans the target binary with the binary signatures.Moreover, when P1OVD matches patch signatures, it uses the novel matching algorithm to solve the second challenge.To evaluate the efficiency and effectiveness, we test P1OVD based on a dataset containing 620 binaries, which are compiled under six compilation environments from 104 different versions of 30 out-ofbounds vulnerable functions.The result shows that P1OVD has a total accuracy of 83.06% and achieves an 8.74% higher accuracythan the state-of-the-art tool BinXray.Besides, it can analyze a single binary in 4 s after a 20-s offline signature extraction on average.We summarize our contributions as follows: • We design an out-of-bounds vulnerability signature that mainly contains patch information and vulnerability information.

•
We propose a matching algorithm that can accurately and robustly find the patch signatures in downstream binaries.

•
We propose a patch-based out-of-bounds vulnerability detection method, P1OVD.P1OVD can accurately locate 1-day out-of-bounds vulnerabilities in downstream binaries even if code variants exist.We evaluate its performance on 620 binaries of 30 real-world patches in Linux Kernel [21].
The rest of this paper is organized as follows.We first summarize the challenges in Section 2. Then we describe the design of P1OVD in Section 3 and evaluate P1OVD in Section 4. Next, we review related work in Section 5. Finally, we give the conclusion in Section 6.

Motivation
The open-source software can be built with customized codes and non-standard building configurations to meet the needs of downstream manufacturers [19], causing code variants.We believe that there are two main challenges caused by code variants: vulnerability signature (Section 2.1) and patch signature matching (Section 2.2).

Vulnerability Signature
The first challenge is that the code variants can significantly affect the vulnerability detection results but can be hard to detect if the vulnerability signatures do not contain enough patch information and vulnerability information.Version differences are parts of the results of the third-party code customization and cause existing works to have high false rates in out-of-bounds vulnerability detection.We take the function init_desc of the Linux Kernel as a motivation example to figure out the severe impacts of code variants.Figure 1 shows three different versions of function init_desc.Red codes are the earliest version, at that time, the vulnerable statement hash_algo_name[hash_algo] had not existed.Then a commit removed the red codes and introduced green codes, where the out-of-bounds vulnerability is located.The parameter hash_algo is possibly tainted and can read the array hash_algo_name out of the buffer bound.The blue codes are added by the patch, they restrict the parameter hash_algo, and relieve the panic.These three versions challenge the state-of-the-art tools because their signatures miss either patch information or vulnerability information.As Figure 2 shows, function-level vulnerability detection tools [4][5][6][7][8][9][10][11][12][13][14][15] take the whole 53-line function into concern and fail to capture the precise context of vulnerabilities.As a result, they think the functions that are similar to known vulnerable functions are vulnerable.Due to the small differences between these three versions, they think the three versions are all vulnerable, which results in high false positives.As Figure 2 shows, some patch-level vulnerability detection tools [3,17], mistakenly think the patch disappearances are the vulnerabilities and fail to include vulnerability information into their signatures.So they focus on the blue codes rather than the green codes.As a result, the red version is labeled vulnerable even if it has no vulnerable operation at all.By considering both vulnerabilities and patches, MVP [18] outperforms vulnerability detection tools.Further, researchers manually evaluate MVP's failures by comparing signatures with vulnerability root causes in case studies.Although MVP can successfully identify all three versions, its vulnerable line searching algorithm introduces a few vulnerabilityirrelevant codes, e.g., the function call of ERR_PTR, which can be replaced by customized error handlings and harm the binary-level signatures.

Patch Signature Matching
As the solution of the first challenge, the binary-level patch information is AST-shaped.However, code variants caused by optimization levels or target architectures can influence the structures of ASTs, which is the second challenge.As Figure 3 shows, the patch checks inputs at 0x401955 (x86_64) and 0x17e4 (aarch64  There are two kinds of matching algorithms.However, neither of them can balance accuracy and robustness.First, Fiber [20] performs a strict operand-based matching, while assuming that the same semantic can result in the same ASTs with few changes on the address-related immediate numbers.However, as Figure 3 shows, the [arg + 6] <= 6 in x86_64 can be transformed into the ![arg + 6] > 6 in aarch64.A strict matching can falsely think the patch signatures generated on the x86_64 platform are different from the patch signatures generated on the aarch64 platform.Second, Pewny et al. [8,9], Feng et al. [13] and Jiang et al. [19] match ASTs with an inaccurate graph-similarity-based structural matching to improve the robustness.However, as Figure 3 shows, the patch only changes 8 to sizeof(cmd->msg), while the latter is an immediate number 6.These tools cannot distinguish the unpatched versions from the patch versions because the patch does not cause any structural difference.

Design of P1OVD
In this section, we first introduce the architecture of our tool (Section 3.1), and then we will introduce the three main parts of P1OVD in detail, including patch analysis (Section 3.2), signature generator (Section 3.3), and matching engine (Section 3.4).The first challenge (Section 2.1) is solved in patch analysis, and the second challenge (Section 2.2) is solved in equation matching (Section 3.4.2).

System Architecture
Figure 4 shows that the P1OVD has four inputs, including unpatched sources, patched sources, reference binaries that are compiled from patched sources, and target binaries waiting to be checked.Since a large number of function-level binary similarity tools are currently available, e.g., Asm2Vec [16], we can obtain the address of the possibly vulnerable function in the target binary by finding out the function most similar to the vulnerable function, without requiring a symbol table.P1OVD has three parts: patch analysis, signature generator, and matching engine.Patch analysis is designed for generating source signatures from the patched sources and unpatched sources.The generated source signatures are accurate and robust enough to overcome the first challenge.Then the signature generator maps the source signatures to binary signatures while keeping their accuracy and robustness.Patch analysis and signature generator are combined to generate binary-level signatures for out-of-bounds vulnerabilities.Finally, the matching engine searches vulnerabilities in the unknown target binaries according to the binary signatures.Especially, the novel patch signature matching algorithm matches the patch signatures accurately and robustly, while solving the second challenge.

Patch Analysis
In this step, we generate the signatures to represent vulnerabilities.As mentioned in Section 2.1, important code variants can be ignored when the vulnerability signatures incompletely contain vulnerability information or patch information.Inspired by the fact that both patch information and vulnerability information can increase the signature accuracy and root causes are widely used to evaluate vulnerability signatures [18], we define that out-of-bounds vulnerability signatures should mainly contain patch information and out-of-bounds vulnerability root cause information.
To obtain vulnerability root causes accurately, P1OVD utilizes a patch analysis tool, SID [22].Patch analysis tools aim at removing the gap between patches and vulnerabilities.Especially, SID outperforms the statical approaches at the accurate out-of-bounds root causes locating.SID defines that the root cause of out-of-bounds vulnerabilities is memory access without proper bound checks.A branching statement, either an if statement or a loop statement that exists in the patch is regarded as a bound check.They are what out-ofbounds patches try to add or correct.Memory access always includes directly indexing arrays by subscripts or calling certain functions to access memory indirectly, which is the root cause of out-of-bounds vulnerabilities.P1OVD locates the memory access and the bound checks according to SID's security rules.
After obtaining patch information and vulnerability root cause information, P1OVD constructs a local PDG (program dependency graph), which is a subgraph of the function PDG starts at bound check and ends at memory access, linking a series of branching statements that are positioned between memory access and bound.The topology of such a local PDG reflects the relationship between patches and vulnerabilities.Compared to local CFG [20], this local PDG is more robust to code variants because compilation environments e.g., optimization levels can significantly change the CFG structures.
Example 1.As Figure 3 shows, the if statement at line 7 is added by patch.So it is a bound check and is the start of local PDG.The variable i is used to index cmd->msg[i] at line 18.So line 18 is the memory access and is the end of local PDG.Finally, line 14 where the variable i compares with cmd->msg_len, which is important because the dissatisfaction of the bound check can make the function skip line 14 and exit directly.So line 14 is included in the local PDG and is the successor of the bound check and the predecessor of the memory access.In conclusion, we extract only three lines as a signature.With little unnecessary information and complete patch information, as well as vulnerability information, this signature can overcome code variants.

Binary Signature Generator
Although the generated signatures are accurate, they are at the source level.Thus, in this step, we map the source signatures to the binary signatures by reference binaries, which are manually generated by compiling the patched sources with the O0 optimization level to x86_64 architecture while reserving the debugging information.P1OVD keeps the binary signatures in the form of local PDGs and only maps each node of the local PDGs from source-level to binary-level because the local PDGs remain the same even if the compilation environments change.
Theoretically, all instructions that correspond to the local PDG statement nodes can be part of the binary signature.However, Zhang et al. [20] announced that only a subset of instructions i.e., root instructions actually summarize the statement key behaviors, and the unnecessary instructions in the signatures can lead to mismatches.Hence, in this step, P1OVD accurately locates root instructions and uses the semantic information of root instruction to represent the statements.

Root Instructions Locating
Due to the significant difference between binary and C source codes, a statement that originally contains multiple instructions may even be divided into multiple basic blocks, during the compilation procedure.For example, an if statement with a logical operation, e.g., && or ||, will be separated into two multiple basic blocks.Hence, for each statement in the local PDG, P1OVD locates the root instructions accurately by taking line numbers, data dependency, variable names, and statement types into concern.
P1OVD first narrows the scope of possible root instructions by selecting the instructions corresponding to statement lines.This can be done with the help of debugging information from reference binaries.
Next, P1OVD narrows the scope of possible root instructions again by variable-based data dependency analysis because variables represent the behavior of the statement in most cases.For example, the vulnerable statement cmd->msg[i] contains two important variables cmd and i and they are combined to generate an out-of-bounds vulnerability.The variable names can be easily obtained by parsing source codes.However, when variables are parameters of operator sizeof they can be turned into a constant and disappear from binaries due to the preprocessing.For example, sizeof(cmd->msg)) corresponds to the immediate number six in the binary.So P1OVD excludes all variables that are only used in the operator sizeof.After extracting variable names, P1OVD uses debugging information to map variable names to rbp related addresses on the stack because without optimization, the GCC compiler stores each local variable on the stack.Since each extracted variables are part of the original statements, the root instructions should data-depend on all extracted variables.Thus, P1OVD performs a data dependency analysis to exclude irrelevant instructions.We define an instruction data-depends on a certain variable if it directly uses the rbp related address or uses the result of another instruction that is data-dependent on the variable.
Finally, one statement can have multiple behaviors at the same time, while some of them are less important.For example, line 18 reads the memory and calls a function.But only reading the memory can cause the exception.Thus, P1OVD locates the root instructions that represent the key behaviors of the statements among the selected candidates.Bound checks and extra branching statements control the values of the program counters.Thus, they are compiled into PSW (program status word) writing instructions and branching instructions.Generally, they are positioned at the end of the basic blocks.We require the root instructions of bound checks are branching instructions because they reserve the important comparison operator information since out-of-bounds patches can only correct the comparison operators.But we require the root instructions of extra branching statements are PSW writing instructions.As mentioned in Section 4.2.3, the results of branching instructions can be simplified.Further, extra branching statements do not need comparison operator information.Finally, there are two kinds of memory access, including function calling and array indexing and they trigger exceptions through load or store instructions in the current functions or the callees.Hence, such behaviors are stored in the function call instructions and load or store instructions.In conclusion, Table 1 shows the type of root instruction we required.

Symbolic Execution
In this section, P1OVD generates sufficient information for root instructions so that they can represent the vulnerabilities and patches.Researchers [8,9,13,19,20] have demonstrated that symbolic execution results i.e., ASTs can robustly represent the operands of instructions.Thus, P1OVD symbolically executes the reference functions from their entries and extracts ASTs forass root instructions.Besides, as Table 1 shows Example 2. As Figure 5 shows.The root cause contains two variables, named cmd and i. P1OVD maps the line to instructions first.Then among these instructions, P1OVD finds that i which is located at rbp-0x20 is used at 0x409b4, while cmd is used at 0x409b8.Since the memory operation at 0x409ba uses both variables to read the memory, P1OVD thinks it is a root instruction.Moreover, by symbolic execution we generate mem_read(arg) etc. to represent the access expression it read.Similarly other nodes of local PDG can be mapped to binary-level.

Matching Engine
The matching engine can judge if an unknown binary is vulnerable or not by using the binary signatures generated from reference binaries.For one binary it has four kinds of output: not vulnerable, patched, vulnerable, unable to judge.Before actually starting to match the vulnerabilities, we use the code similarity to find out the functions that may contain the vulnerabilities in the binaries and use symbolic execution to extract all ASTs of the target functions.Then we start the vulnerability matching.
We find access expressions and PSW write arguments by structural matching and find branching conditions by equation matching.Because the structural matching is faster than the equation matching but dissatisfies the high accuracy required by branching conditions.Finally, we verify the control dependencies using local PDGs.

Structural Matching
Structural matching finds operations with similar semantics to out-of-bounds access expressions or PSW write arguments in the target binaries by calculating the graph similarity of two ASTs.Empirically, we have found that ASTs with the same semantics may have subtle differences when extracted from binary functions of different compilation environments.For example, both a+((b+1)«1) and a+2+(b«1) can be found in binaries when statement a[b+1] appears in the source code.Therefore, we do not require the ASTs to be structurally identical but structurally similar.Thus, the edit-distance-based graph similarity can better reflect the similarity of ASTs and we compare the graph similarity with a predefined threshold to determine whether two ASTs are similar.

Equation Matching
The main task of equation matching is to find a branching condition the same as the patched bound check.However, as mentioned in Section 2.2, both structural matching and strict matching cannot overcome the second challenge.
Fiber [20] matches the same kind of nodes, e.g., immediate numbers with different algorithms according to their positions in the ASTs.Thus, we infer that different parts of branching conditions should be matched according to different precisions.We define a subtree in the AST as a data object if its root node is a memory read operation or it only contains one node that is a function return value or a parameter.Additionally, a data object should not be a subtree of another data object.After extracting data objects, remain the boolean expressions.Empirically, we learn that under different compilation environments, data objects have similar structures, while boolean expressions preserve fixed semantics.So P1OVD matches them according to their structures and semantics correspondingly.
After extracting data objects by traversing the branching conditions, P1OVD uses the structural matching presented in Section 3.4.1 to generate data object pairs, one from the target branching condition and one from the reference branching condition.The matched data object pairs in two ASTs are replaced with the same symbol.In the case that two matched data objects have different sizes, e.g., one is 64-bits long, and the other is 32-bits, P1OVD defines a symbol in the shorter size and replaces two ASTs with this symbol.To satisfy the length requirement of the longer tree, P1OVD pads zero to the left of the defined symbol.P1OVD replaces the data objects to ensure the two bool expressions have identical symbol sets and can be used for solving.
Next, we accurately solve [23] the boolean expressions.Since the boolean expressions are semantically identical, only equal or opposite boolean expressions are matched.In other words, given two boolean expressions Expr 1 and Expr 2 , they are considered matched if only one of Expr 1 = Expr 2 or Expr 1 =! Expr 2 can be solved.Example 3. As Figure 6 shows, to match the [arg + 6] <= 6 and ![arg + 6] > 6, P1OVD first extracts data objects from them.The extracted data objects are both [arg + 6] and they are structurally similar obviously.So P1OVD replaces them with a single symbol x in their original AST.Then P1OVD checks the solving possibility of conditions (x 6) =! (x > 6) and (x 6) =!! (x > 6).Results show x = 0 satisfies the first constrain and the second constrain will never be satisfied, thus P1OVD finds that the two branching conditions are equal.So, in conclusion, the two ASTs represent the same branching condition.At the same time, both strict matching and graph-similarity-based matching cannot distinguish such changes in ASTs.

Similar Data Objects
Equal/Opposite Boolean Expressions

Verify Control Dependency
In this step, P1OVD matches the local PDG topologies by verifying the edge i.e. control dependency of their nodes.This step is to ensure that the bound checks actually control the memory access.Since even if both bound checks and memory access appear in the same function, vulnerabilities can still appear.For example, in Linux Kernel commit 1fa2337, the patch only moves the check of d->msg_len forward to secure the d->msg[i] used in function printk.P1OVD can infer statement A controls statement B from two cases:

•
A is a loop statement.The loop structure is often reordered by optimization, and P1OVD requires every trace that passes the B twice or more to contain an A between every neighbor B.

•
A is an if statement.Since the if statement may be in a loop, P1OVD requires each trace that reaches the B from the function entry to pass A.

Evaluation
We have developed P1OVD with 1200 lines of python code on top of open source libraries Angr [24], joern [25], and pyelftool [26].P1OVD supports aarch64, x86_64, and x86_32 target architectures as well as, O0 and O2 optimization levels.In this section, we first evaluate P1OVD in terms of accuracy (Section 4.2) and efficiency (Section 4.3), and then we compare P1OVD with other tools in terms of the overall performance (Section 4.4) and the effectiveness of signature generation (Section 4.5), and AST matching (Section 4.6).

Datasets
We evaluate our tool based on Linux Kernel because not only is Linux Kernel widely used [27], but also the out-of-bounds vulnerabilities in the Linux Kernel are widely analyzed [22].Our tool has four inputs, including unpatched source code, patched source code, patched binary, and target binary.Thus, we collect three datasets.

Source Codes
Source codes include the patched and unpatched source codes.To ensure that the patch analysis can successfully operate, we use 30 out-of-bounds patches listed in the appendix of SID [22] while two of them are patches of CVE-2017-18379 and CVE-2019-15926.We exclude some patches that are too old that cannot be successfully compiled.

Reference Binaries
The reference binaries are obtained by compiling the patched source code.Still, most of the out-of-bounds vulnerabilities are located in the Linux Kernel optional modules, which are difficult to trigger by the default compilation options.We manually adjust the compilation options for each out-of-bounds patch to satisfy the constraints and apply GCC to compile the patched source codes while reserving the debugging information.

Target Binaries
The target binaries are used to prove that the P1OVD can fight against binaries built with non-standard configurations from customized codes on multiple architectures.To obtain target binaries, we compile source code into 620 different binaries.The collected binaries vary from three aspects, including versions, optimization levels, and target architectures.
We think the first way to customize source codes is to compile the source codes of different versions.When we refer to versions, we do not mean the software release version e.g., "Linux-5.0-y"because a newer software release version does not change the vulnerable function sometimes.We define a new version according to the vulnerable functions.For a vulnerable function, we regard all commits that change this function as versions and divide these versions into three categories, including not vulnerable versions, vulnerable versions, and patched versions.A function had no vulnerability at first and we think the functions in these versions are not vulnerable.And then, at a notable point, the vulnerable memory access began to appear in the function.We think these functions are vulnerable.After the vulnerability was discovered, the repository maintainer corrected the bound check using a patch.We consider these functions are patched.Totally, we obtain 104 different versions from Linux Kernel "master" branch and we classify these versions manually.Second, optimization levels are usually customized and O0 and O2 are the most commonly used optimization.Moreover, the reference binaries are generated based on O0.Thus, we evaluate P1OVD on O0 and O2 optimization levels.Finally, different manufacturers can build sources for different target architectures.We also evaluate P1OVD on three architectures including x86_64, x86_32, and aarch64.The x86_32 uses 32-bit addresses while aarch64 and x86_64 use 64-bit addresses while aarch64 has an instruction set different from x86_64 and x86_32.After obtaining 620 binaries, we generate ground truths for them according to their versions because the changes of compilation environments do not affect the vulnerability detection results.

Accuracy
We evaluate the P1OVD based on the multiclass classification problem.Only the outputs of P1OVD that correctly predict both vulnerability and patch are considered correct.We use precision, recall, F-1 score, and accuracy to measure the accuracy of P1OVD.The four evaluation metrics are defined in Equation (1).P1OVD first generates signatures based on O0 optimization and x86_64 architecture and then scans the target binaries with the signatures.
Table 2 shows the accuracy of P1OVD.Each row represents the compilation environments, and each column stands for the evaluation metrics of three version categories.P1OVD obtains an accuracy of 83.06%.And we manually analyzed the false predict cases and summarized the following four reasons, while the first three are common challenges for symbolic execution-based tools.

Function Inline
Function inline contributes most of the false rates.A function with an inline tag may not be inline during the compilation procedure.It is influenced by many factors e.g., the optimization level, and target architecture.For example, function nvmet_fc_getqueueid called by the function nvmet_fc_find_target_queue is inlined when compiled with aarch64 and O0.However, function nvmet_fc_getqueueid is not inlined when compiled with x86_64 and O0.Whether the callee is inline affects the extracted signature through symbolic execution and function inline is also the key reason why P1OVD has worse performance on aarch64 architecture or O2 optimization level, compared to x86_64 and O0.

Conditional Execution Instructions
Conditional execution instructions are instructions that select whether to perform operations based on the PSW, e.g., CSEL.When multiple conditional branches occur continuously, aarch64 optimizes the efficiency by replacing branch instructions with conditional execution instructions since branch instructions slow the assembly.Function qxl_clientcap_ioctl in commit 62c8ba7 compares qdev->pdev->revision with 4 and byte with 58 continuously, and only one branch instruction to deal with the exception for them.Since we used the AST of branching conditions for boundary check, the inability to find the correct branching conditions in the binary led to false positives.

Simplified Expression
P1OVD will output a false result when a patch changes the loop bound.For example commit 43622021d2e2b changes operator <= to < in the statement for(j=0; j<HID_MAX_IDS; j++).Every time the executor compares the j and HID_MAX_IDS, the value of j is a constant.As a result, Angr will automatically optimize a boolean expression containing only constants to True or False.This prevents us from extracting branching conditions correctly and this is the key reason why the signature cannot ensure all predictions are correct on x86_64 and O0.

Structure Dissimilar
Function hid_register_report in commit 43622021d, indexes an array through report_enum->report_id_hash[id] while report_enum is calculated by device->report_enum+type.However, all the structs have pointer members, which means that when the system address lengths change the sizes of structs change.Although the difference between the two integers is small, optimizing codes by replacing multiplication with an arithmetical left shift is often used in the addressing process, resulting in structural differences.As a result, x86_32 has the worst performance.We believe that graph embedding is a feasible solution to this type of problem.

Performance
Experimented on intel-i7-8700 and 12GB RAM, Table 3 records the time consumption of P1OVD from three aspects of patch analysis, signature generator, and matching engine.Patch analysis and signature generator are used to extract binary signatures offline.We calculate the average time used to generate a signature for one patch.The matching engine is used to determine whether a target binary is vulnerable or not.To solve the situation that different vulnerable functions have different numbers of versions and better reflect the time consumption, we first calculate the average time used for finding a certain vulnerability in various binaries, then we calculate the overall average vulnerabilities finding times.

Accuracy Comparison with Vulnerability Detection Tools
In this section,we evaluate the accuracy of P1OVD by comparing it with the stateof-the-art vulnerability detection tools.We choose BinXray [17] and Asm2Vec [16] as references because they are both open-sourced and BinXray and Asm2Vec are the state-ofthe-art patch-level and function-level vulnerability detection tools.We compare P1OVD, Asm2Vec, and BinXray from four aspects, including precision, recall, F-1 score, and accuracy.For one function, Binxray only has two kinds of outputs vulnerable or patched.So we require P1OVD to predict if the functions are vulnerable or not.Thus, we relabel the patched binaries as not vulnerable binaries.At the same time, Asm2Vec ranks the possibly vulnerable functions.So we think the function in the unknown target binary that has the highest similarity to the vulnerable function in the reference binary is vulnerable.
Table 4 shows the results of the comparison.Asm2Vec, a function-level tool, cannot distinguish three versions well and consider them are all vulnerable, which result in high false positive.Meanwhile, BinXray assumes that vulnerabilities exist when patches disappear.However, bound checks and memory access can both disappear because of code customization.When BinXray cannot detect the patches, it mistakenly believes that the vulnerabilities exist.P1OVD achieves the highest precisions due to its vulnerability signature containing both vulnerability root cause information and patch information.However, P1OVD cannot ensure that all binaries predicted safe are accurately safe.When the patch changes the loop boundary, the simplified expressions described in Section 4.2.3 can cause the results of symbolic execution to contain too little information and P1OVD cannot distinguish the patched version from the unpatched version.However, Binxray uses the patch codes in the binaries as signatures, which works well when the target binary and reference binary are under the same compilation environment.

Effectiveness of Vulnerability Signatures
In this step, we evaluate the effectiveness of our vulnerability signatures by comparing the source signatures of P1OVD with ReDeBug [3] based on the source dataset.Because ReDeBug is a widely used open-source source-level unpatched buggy code detection tool.As Table 5 shows, compared to ReDeBug, P1OVD extracts fewer lines but our signatures contain more vulnerability root cause information and patch information, which means P1OVD can generate more accurate vulnerability signatures.This is because ReDeBug only pays attention to the lines close to the patches.On the contrary, P1OVD focuses more on the statements that control the function security (vulnerability root cause information and patch information), by which P1OVD overcomes the first challenge (Section 2.1).For example, ReDebug always includes the error handling of bound checks because they are added by patches.Meanwhile, P1OVD thinks they are widely customized [19] and excludes them from signatures.In this section, we evaluate the effectiveness of our two-step AST matching algorithm by comparing it with the graph-similarity-based AST matching algorithm, because the graph-similarity-based AST matching algorithm is the most widely used AST matching algorithm among vulnerability detection tools [8,9,13] and is used to enhance the robustness of Fiber [20].To compare with it, we generate a new version of P1OVD by replacing our two-step equation matching component with the graph similarity matching.Table 4 shows that the modified P1OVD has more false positives, which demonstrates that the two-step AST matching algorithm can address the second challenge (Section 2.2).This is because the graph-similarity-based matching can only distinguish action-related nodes and conditionrelated nodes [13] and cannot distinguish the in-node changes.Moreover, when only operands are different, the graph-similarity-based matching algorithm remains unaware.The two-step matching algorithm splits the AST into two parts.If such changes happen in the data objects, P1OVD ignores them.On the contrary, if boolean expression semantics are changed, P1OVD is warned by the solver.

Limitation
P1OVD analyzes the out-of-bounds patches based on security rules of SID [22], which leads to one limitation.Although SID outperforms patch analysis tools, it can neither analyze the patches that involve multiple functions nor understand out-of-bounds patches that do not correct bound checks e.g., extending the array size.Thus, P1OVD cannot successfully detect all out-of-bounds vulnerabilities.To address this problem, we are considering replacing SID with other dynamic patch analysis tools e.g., PatchScope [28].
Further, memory access is a common root cause of many kinds of memory-centric vulnerabilities, e.g., use after free and correcting missing or wrong checks before the memory access can also be the key behavior of security patches.We can polish bound checks to generalize the vulnerabilities that P1OVD can detect.
Finally, the performance of P1OVD in 32-bit architecture is not as good as in 64bit architecture.This is mainly due to the structural changes related to address length (Section 4.2.4).Thus, we try to calculate the similarity scores of two ASTs with a more robust algorithm.Many works [16,29] train neural networks to calculate the graph similarity of CFG or PDG and we think these approaches can be adapted to AST similarity calculation.

Related Work
This article is closely related to four branches of study, function-level 1-day vulnerability detection, patch-level 1-day vulnerability detection, patch presence test, and patch analysis.In the following four sections, we give a brief review of the works that lead to our own.

Function-Level 1-Day Vulnerability Detection
At present, many studies focus on detecting vulnerabilities in source files and binary files by judging whether the target function is similar to the vulnerable function.Usually, function-level 1-day vulnerability detection tools extract features from reference sources or binaries and match them with special algorithms.
Early algorithm using normalized source codes [7], ASTs [5], PDG [4,6], etc. to comprehensively represent the whole source vulnerable function.However, they cannot detect the 1-day vulnerabilities in binaries, due to the lack of binary semantic information.
DiscovRE [10] tries to solve this problem by extracting numerical features from the basic blocks and CFG structural features.Introduced by Genius [12], neural networks use vectors to better represent the function feature, e.g., numerical and structural information [14,15], assembly codes [16].Some tools use tree-liked formulas to represent basic blocks [8], function IO behaviors [9], or even the high-level function semantic information [13].These function-level 1-day vulnerability detection tools take the whole vulnerable functions as the vulnerability signatures and their extremely large scope of function-level signatures cause the first challenge (Section 2.1).When small code variants involve patches or vulnerability root causes, the function-level signatures bring much useless information and cannot give correct predictions.

Patch-Level 1-Day Vulnerability Detection
During the last decade, researchers use patches to improve the function-level 1day vulnerability detection, which is called patch-level vulnerability detection.Early tools [3,17,30,31] believe the missing patch-added codes are the root causes of vulnerabilities.By using normalized and tokenized patches [3], patch sensitive matching algorithms [30], LSTM-embedded code vectors [31], patch modified traces [17], they enhance the patch searching rather than vulnerability searching.
Li et al. [32] think the patch-removed code is vulnerable and using concolic testing to verify the clone of vulnerable code.MVP first [18] announced that the patch and the corresponding vulnerability have different information and it thinks the deleted codes are vulnerable and the added codes are patches.So it uses CPG (code property graphs) to slice vulnerability-related codes as vulnerability signatures and patch-related codes as patch signatures.Further, researchers manually evaluate MVP's failures by comparing signatures with vulnerability root causes in case studies.Although the signatures containing both patch information and vulnerability information improve source-level 1-day vulnerability detection, they contain too much unnecessary information for binary-level vulnerability detection, which leads to the first challenge (Section 2.1).

Patch Presence Test
The concept of patch presence tests is first proposed by Zhang et al. [20].Its main purpose is to accurately confirm whether a binary contains a particular patch or not, while we try to find vulnerabilities rather than patches.Other patch presence tests improve the Fiber [20] in terms of the diversifying source program languages [33] and robustness [19], or polish it with other dynamic tools [34].
Vulnerabilities detections need high accuracy and robustness, which is similar to patch present tests.So, we have a deep look into the Fiber and Pidff [19].They both locate basic blocks corresponding to the patches in the patched binaries.Later, by symbolic execution, they extract the AST-shaped results of these basic blocks as signatures.However, they match their signatures with different methods.While Fiber proposes a strict operand-based patch matching algorithm with little relaxations (inter-changeable operators, addressrelated immediate numbers), PDiff proposed a robust but less accurate graph similaritybased matching algorithm.Unfortunately, neither of them can accurately and robustly match branching conditions in downstream binaries, which leads to the second challenge (Section 2.2).In Section 3.4.2we benefit from both and propose a novel two-step matching algorithm.

Patch Analysis
Patch analyses are used to understand how security patches fix the vulnerabilities.At first, Corley et al. [35] links between bugs and patches while requiring an issue tracking system.Later, Spain [36] proposed binary-level patch patterns to detect unexplored vulnerabilities but limited by lacking high-level semantic information, it cannot fully understand out-of-bounds patches.SID [22] outperforms other statical tools at the accurate out-ofbounds root causes locating, by utilizing symbolic execution.PatchScop [28] dynamically analyzes the patches and gets the highest accuracy although it requires POCs (Proof of Concepts).In this work, we use the state-of-the-art statical tool, SID to locate the root causes of out-of-bounds vulnerabilities.

Conclusions
In this work, we have had a deep look into the 1-day vulnerability detection and identified two challenges introduced by code variants, including vulnerability signature and patch signature matching.To solve the two challenges, we have proposed P1OVD, an accurate detection method for 1-day out-of-bounds vulnerabilities in downstream binaries using patches.P1OVD analyzes the patch to get accurate vulnerability signature, generates binary signatures using debugging information and symbolic execution, and accurately matches the signatures, especially branching condition.Experiments have demonstrated that P1OVD can generate accurate and robust vulnerability signatures and match the signatures accurately.Addressing the above two challenges allows P1OVD to resist interference from code customization, non-standard building configurations, and to detect 1-day out-of-bounds vulnerabilities on multiple architectures more accurately than existing tools.

Figure 2 .
Figure 2. Function-level tools and patch-level tools.
, since the operands of different root instructions are different, P1OVD generates different ASTs for them.The extracted ASTs can represent the vulnerabilities and patches.For example, P1OVD extracts [arg + 6] <= 6 and ![arg + 6] <= 6 for statement cmd->msg_len>sizeof(cmd->msg).The cmd is function argument and AST uses arg to represent it.Then it load the member msg _len with offset six corresponding to [arg + 6].Finally, it is compared to the constant number six and forks the basic block, as ASTs indicate.In conclusion, all statements in the source local PDGs are replaced with ASTs.

Figure 5 .
Figure 5. Locating instructions by mapping line to instructions and variable name to stack.

Table 1 .
Mapping source statement to binary AST.

Table 2 .
Vulnerability Detection Accuracy Test.

Table 3 .
Vulnerability Detection Performance Test.