[00:00.000 --> 00:07.520] All right, everyone, thank you very much for joining us. Our next talk is SDLC Nightmares, [00:07.520 --> 00:14.680] Defeating Secure Code Review, GPT Hallucination with Julo and April. [00:16.200 --> 00:31.710] Hello, my name is Julo and I just graduated from the Pennsylvania State University last [00:31.710 --> 00:39.430] year and now I'm working as a security engineer in industry. And my research interest is focused [00:39.430 --> 00:42.610] on applying deep learning in cybersecurity. [00:44.330 --> 00:50.070] And I'm April, Carnegie Mellon University graduate and currently a security engineer [00:50.070 --> 00:56.590] as well. A fun fact about me is I learned and applied my InfoSec knowledge during writing [00:56.590 --> 00:57.930] science fictions. [00:59.030 --> 01:06.470] Okay, let's get started. As most of us might have noticed, nowadays, large language models [01:06.470 --> 01:13.170] have been playing an increasingly important role in our daily work and lives. Today we'll [01:13.170 --> 01:19.730] discuss how LLMs can be applied to security code analysis and evaluate their reliability [01:19.730 --> 01:22.690] in understanding program logic. [01:24.550 --> 01:31.910] Overview of our talk today. First, we'll introduce LLMs and their strengths in SDLC, then we'll [01:31.910 --> 01:37.750] uncover their limitations through an experiment. Based on our findings, we'll further discuss [01:37.750 --> 01:45.050] the root causes and their other related issues. Finally, we'll summarize key takeaways on [01:45.050 --> 01:48.770] how to better utilize LLMs in our work. [01:51.140 --> 01:58.460] So, first of all, what is a large language model? Basically, LLM is advanced machine [01:58.460 --> 02:05.440] learning models that understand and generate human-like text by learning from fast data [02:05.440 --> 02:13.280] sets. They use deep learning, especially transformer architectures, to predict the most probable [02:13.280 --> 02:20.480] word in a sentence. For example, in this figure, it estimates a 91% probability that [02:20.480 --> 02:28.240] the word blue follows the phrase, the color of the sky is. LLMs generate coherent and [02:28.240 --> 02:35.200] contextually appropriate text, enabling tasks like answering questions, translation, and [02:35.200 --> 02:38.040] our topic today, code analysis. [02:38.880 --> 02:47.300] Now, let's talk about SDLC. A typical software development lifecycle involves various stages [02:47.300 --> 02:56.140] where LLMs can significantly assist. By understanding semantics and recognizing patterns, LLMs [02:56.140 --> 03:04.780] can comprehend natural language and analyze code, performing tasks like code generation, [03:04.780 --> 03:11.900] test case creation, and also documentation. From a security perspective, they also help [03:11.900 --> 03:19.780] with threat modeling and identifying vulnerabilities, ultimately boosting the efficiency and quality [03:20.460 --> 03:29.900] throughout the SDLC. However, LLMs can make mistakes. Here are two famous examples. When [03:29.900 --> 03:36.620] Google introduced their chatbot bot, it made a factual error during its very first demo. [03:36.620 --> 03:46.320] Another instance involved ChatGPT, which confidently asserted that 9.11 is greater than 9.9, a [03:46.320 --> 03:53.880] mistake even an elementary student would recognize. These errors stem from the tendency to state [03:53.880 --> 04:00.880] incorrect information as facts. LLMs often hallucinate, like what I do every time before [04:00.880 --> 04:07.020] sleeping or conceiving a science fiction story. They tend to make up information because they [04:07.020 --> 04:14.720] are essentially autocomplete systems based on probability rather than facts. Now, let's [04:14.720 --> 04:23.240] see their performance in code analysis. Before diving into the experiment, let's first take [04:23.300 --> 04:30.240] a closer look at the code itself. Technically, source code is a sequence of tokens consisting [04:30.240 --> 04:38.480] of three types, keywords, operators, and user-defined names. Keywords and operators are defined [04:38.480 --> 04:45.580] by the specification of each programming language, and they control the actual logic flow of [04:45.580 --> 04:52.700] the program execution. So we categorize them as logical features. Meanwhile, user-defined [04:52.700 --> 04:59.820] names, annotations, and comments, which don't influence the program's flow once it's compiled, [04:59.820 --> 05:07.900] are categorized as literal features. So our goal for the experiment is to determine what [05:07.900 --> 05:14.700] types of features in the code LLMs can actually learn and process. We'll mask the literal [05:14.700 --> 05:20.400] features by replacing the changeable names that don't affect the program flow, and then [05:20.400 --> 05:29.080] use the LLM to perform code analysis tasks on this modified code. By evaluating the performance, [05:29.080 --> 05:34.860] we'll assess whether the LLM can effectively process the logical features when literal [05:34.860 --> 05:42.260] features are absent or even misleading. To conceal the literal features, we'll adopt [05:42.260 --> 05:48.840] three kinds of anonymization. So here is an example of the bubble sort function in [05:48.840 --> 05:56.400] Java. And the first anonymization is for function name. So here we can replace the bubble sort [05:56.400 --> 06:03.340] string with our customized string. And the second one is for variable names. Two examples [06:03.340 --> 06:11.060] here is the begin and end, which we can replace with our strings. And the last one is the [06:11.060 --> 06:17.520] method invocation name. Here we have a function pret as one of the arguments for the bubble [06:17.520 --> 06:25.880] sort function, so we can replace the invocation name with our customized string. Meanwhile, [06:25.880 --> 06:32.060] to understand how literal features affect LLM comprehension, we also use two name replacement [06:32.060 --> 06:39.080] strategies. The first one is just replacing it with some randomly generated string, while [06:39.080 --> 06:45.440] the second one is shuffling the names with other meaningful names from the code, making [06:45.440 --> 06:53.680] it more misleading for users. For readers. Sorry. So, after the literal features are [06:53.680 --> 07:01.340] concealed, the LLM performs two main tasks related to code analysis. The first one is [07:01.340 --> 07:07.420] code clone detection, which identifies and measures the similarity between different [07:07.420 --> 07:15.860] code fragments to see if they generate the same result when given the same input. The [07:15.860 --> 07:21.920] second one is code search, where it tries to retrieve the code fragment from a larger [07:21.920 --> 07:28.880] code corpus that closely matches a developer's intent, which is expressed in natural language [07:28.880 --> 07:38.340] as the input. So, here are the results we got. It shows that anonymizing names significantly [07:38.340 --> 07:45.620] decreases model performance, especially when we replace all three kinds of names. In the [07:45.620 --> 07:52.140] code search task, we also notice that anonymizing master definition name causes more degradation [07:52.140 --> 07:58.860] than anonymizing master invocation name, indicating a stronger correlation between the master [07:58.860 --> 08:06.460] definition name and their purpose. As for different languages, anonymizing a single [08:06.460 --> 08:13.980] attribute affects Python more, but changing all naming attributes impacts Java the most. [08:13.980 --> 08:20.900] Probably because the verbosity and the structure in Java code that can mitigate partial [08:20.900 --> 08:30.920] anonymization are fully disrupted. Compared to the code clone detection task, the performance [08:30.920 --> 08:37.140] degradation is more pronounced in code search task, since well-defined variable and method [08:37.140 --> 08:45.060] names are crucial for relating the code snippet to its descriptive purpose. So, overall, the [08:45.060 --> 08:52.340] results clearly show that while logical features are what matters for a program to execute, [08:52.580 --> 08:58.780] what LLMs processed are mostly the literal features from the code. Now I'll hand it over [08:58.780 --> 09:03.740] to Dr. Zhilong to discuss the reasons and possible solutions. [09:04.320 --> 09:14.360] Okay. So, let's discuss some root cause for the misleading names and comments in the code. [09:14.360 --> 09:21.420] Basically, we just observed three types of the root cause for these misleading names [09:21.420 --> 09:27.880] and comments. And they are malicious code committers and outdated comments and bad coding [09:27.880 --> 09:38.420] practice. Malicious code contributors can contribute some malicious code to the open [09:38.420 --> 09:45.640] source projects, and to avoid being detected by the code reviewers. And they usually can [09:45.640 --> 09:53.080] change the naming to some misleading names to avoid being detected by the code reviewer. [09:56.610 --> 10:05.450] Secondly, in software development, programs often frequently update their code to fix [10:06.130 --> 10:12.530] some bugs or add some new features. Well, the comments corresponding to the code may [10:12.530 --> 10:21.810] not be updated in time. In this example, partial code was removed during a new commit, [10:21.810 --> 10:27.410] and, however, the corresponding comment was not removed accordingly. [10:29.030 --> 10:38.570] Comments that are not updated can cause inconsistency with the code, and we call them outdated comments. [10:38.570 --> 10:44.470] Outdated comments can mislead the light learning model during code analysis. [10:47.280 --> 10:54.740] Also, in bad coding practice, confusing variable names and misleading variable names could [10:54.740 --> 11:03.420] be given by even a benign programmer and developer, which can mislead the code reviewer, too. [11:06.800 --> 11:14.080] So, next, we are going to cover some other issues when using the light learning model [11:14.080 --> 11:26.780] to do the code analysis. Besides the aforementioned limitations, we also observe two limitations. [11:26.780 --> 11:35.680] The first one is lack of context, and the second one is diverse performance on different [11:35.680 --> 11:48.520] program language. We will show the detail. Most light learning models can only handle [11:48.760 --> 11:59.400] a sequence of a limited length. For example, GPT-3 can handle a sequence with 2,048 tokens [11:59.400 --> 12:10.080] at most, and GPT-4 can handle 32,000 tokens at most. However, the code for even small [12:10.080 --> 12:17.320] projects can have thousands lines of code, and each line of code contains usually more [12:17.320 --> 12:24.580] than 10 tokens. Therefore, the light learning model cannot consume all the code at once, [12:24.580 --> 12:34.480] which will lead to a lack of context issue. Let's show this figure. We have a big project [12:34.480 --> 12:41.710] here showing this figure, and let's consider the context of the light learning model through [12:42.240 --> 12:53.680] this blue box. And when we use the light learning model to analyze this whole project, we need [12:53.680 --> 13:10.420] to analyze a part of them individually. So, based on our observation, in most cases, the [13:10.420 --> 13:16.620] light learning model is used to analyze each function individually, and it cannot have [13:16.780 --> 13:26.820] a big picture of the whole project. So, we actually have written an ARX preprint to dive [13:26.820 --> 13:34.360] into this problem. We also proposed some solutions to solve this problem. And for people who [13:34.360 --> 13:47.130] are interested in the details can read this ARX preprint. Also, we observed that the light [13:47.130 --> 13:53.450] learning model has a diverse performance across different program languages. And different [13:53.450 --> 13:59.010] light learning models also have different strengths across different program languages. [13:59.010 --> 14:05.210] And we did a quick experiment to evaluate the light learning model's ability to infer [14:05.210 --> 14:13.610] the program logic on two program languages. And the result is shown in the table here. [14:15.060 --> 14:26.150] We can observe that the GPT 3.5 has shown the best results on PHP and Go. However, Gemini [14:26.150 --> 14:42.820] can show the best results on PHP and Python. Okay. So, next, we will discuss how to avoid [14:42.820 --> 14:52.460] this issue in using light learning model for code analysis. So, we start from some ad hoc [14:52.460 --> 15:01.140] solutions. And if the code is committed by the trusted developer, we should expect them [15:01.140 --> 15:08.200] to improve the quality of the name convention. And if the code is committed by some untrusted [15:08.200 --> 15:14.920] developer, and we should pay special attention in case the light learning model is fooled [15:14.920 --> 15:22.260] by the malicious code committer, which can easily be achieved based on experiments. And [15:22.260 --> 15:31.120] for example, we could deploy some naming logic in constancy detection and use it to detect [15:31.120 --> 15:43.780] the inconsistency before we perform the code review. However, to really solve this problem, [15:43.780 --> 15:51.520] we believe that we need to change the model a little bit to specifically for the code [15:51.520 --> 15:57.640] analysis. And the current popular pre-training task for the light learning model, as far [15:57.640 --> 16:04.920] as we know, is the mask token prediction. In mask token prediction task, it masks off [16:04.920 --> 16:11.920] some tokens in the sequence. Here, if I take this as example, and it masks off some of [16:11.920 --> 16:21.280] that tokens from its sequence and uses neural network to predict this token. And this is [16:21.280 --> 16:28.260] how current light learning model is trained, as far as we know. And the mask token prediction [16:28.260 --> 16:37.120] task mainly focuses on the literal feature when applied to the source code analysis. [16:37.140 --> 16:45.400] But if we apply this model to the neural language NLP, it's okay, because it does not have too [16:45.400 --> 16:50.200] much of the logic features. But for the source code, we have a lot of the logic features. [16:50.200 --> 16:59.600] So, to really solve this problem, we think that we need to add some more pre-training [16:59.600 --> 17:10.900] tasks to train a new large program language model, which we should add some logic feature [17:10.900 --> 17:17.500] prediction tasks so that it can better capture the logic feature, not the literal feature. [17:17.500 --> 17:25.500] Because, as we show, relying too much on the literal feature will result in some issues [17:26.020 --> 17:37.540] as we have demonstrated in the experiments. So, for the audience who are interested in [17:37.540 --> 17:46.560] the details of this talk, you can refer to this ARX preprint for more details. And here [17:46.560 --> 17:51.960] is our contact information. And that's all of our talk.