1 00:00:00,000 --> 00:00:04,040 All right, everyone, thank you very much for joining us. 2 00:00:04,300 --> 00:00:14,680 Our next talk is SDLC Nightmares, Defeating Secure Code Review, GPT Hallucination with Julo and April. 3 00:00:16,200 --> 00:00:17,040 Hello 4 00:00:24,550 --> 00:00:36,510 , my name is Julo and I just graduated from the Pennsylvania State University last year and now I'm working as a security engineer in industry. 5 00:00:36,530 --> 00:00:42,610 And my research interest is focused on applying deep learning in cybersecurity. 6 00:00:44,330 --> 00:00:51,350 And I'm April, Carnegie Mellon University graduate and currently a security engineer as well. 7 00:00:51,550 --> 00:00:57,930 A fun fact about me is I learned and applied my InfoSec knowledge during writing science fictions. 8 00:00:59,030 --> 00:01:01,830 Okay, let's get started. 9 00:01:01,830 --> 00:01:12,370 As most of us might have noticed, nowadays, large language models have been playing an increasingly important role in our daily work and lives. 10 00:01:12,370 --> 00:01:22,690 Today we'll discuss how LLMs can be applied to security code analysis and evaluate their reliability in understanding program logic. 11 00:01:24,550 --> 00:01:26,730 Overview of our talk today. 12 00:01:26,730 --> 00:01:35,250 First, we'll introduce LLMs and their strengths in SDLC, then we'll uncover their limitations through an experiment. 13 00:01:35,250 --> 00:01:42,170 Based on our findings, we'll further discuss the root causes and their other related issues. 14 00:01:42,170 --> 00:01:48,770 Finally, we'll summarize key takeaways on how to better utilize LLMs in our work. 15 00:01:51,140 --> 00:01:55,040 So, first of all, what is a large language model? 16 00:01:55,040 --> 00:02:06,400 Basically, LLM is advanced machine learning models that understand and generate human-like text by learning from fast data sets. 17 00:02:06,400 --> 00:02:15,040 They use deep learning, especially transformer architectures, to predict the most probable word in a sentence. 18 00:02:15,040 --> 00:02:25,940 For example, in this figure, it estimates a 91% probability that the word blue follows the phrase, the color of the sky is. 19 00:02:25,940 --> 00:02:38,040 LLMs generate coherent and contextually appropriate text, enabling tasks like answering questions, translation, and our topic today, code analysis. 20 00:02:38,880 --> 00:02:42,840 Now, let's talk about SDLC. 21 00:02:42,840 --> 00:02:51,100 A typical software development lifecycle involves various stages where LLMs can significantly assist. 22 00:02:51,100 --> 00:03:08,700 By understanding semantics and recognizing patterns, LLMs can comprehend natural language and analyze code, performing tasks like code generation, test case creation, and also documentation. 23 00:03:08,700 --> 00:03:22,720 From a security perspective, they also help with threat modeling and identifying vulnerabilities, ultimately boosting the efficiency and quality throughout the SDLC. 24 00:03:23,180 --> 00:03:26,860 However, LLMs can make mistakes. 25 00:03:26,860 --> 00:03:29,640 Here are two famous examples. 26 00:03:29,640 --> 00:03:36,620 When Google introduced their chatbot bot, it made a factual error during its very first demo. 27 00:03:36,620 --> 00:03:50,040 Another instance involved ChatGPT, which confidently asserted that 9.11 is greater than 9.9, a mistake even an elementary student would recognize. 28 00:03:50,100 --> 00:03:56,460 These errors stem from the tendency to state incorrect information as facts. 29 00:03:56,460 --> 00:04:04,400 LLMs often hallucinate, like what I do every time before sleeping or conceiving a science fiction story. 30 00:04:04,400 --> 00:04:12,720 They tend to make up information because they are essentially autocomplete systems based on probability rather than facts. 31 00:04:13,280 --> 00:04:18,600 Now, let's see their performance in code analysis. 32 00:04:18,960 --> 00:04:26,360 Before diving into the experiment, let's first take a closer look at the code itself. 33 00:04:26,360 --> 00:04:35,560 Technically, source code is a sequence of tokens consisting of three types, keywords, operators, and user-defined names. 34 00:04:35,940 --> 00:04:47,480 Keywords and operators are defined by the specification of each programming language, and they control the actual logic flow of the program execution. 35 00:04:47,480 --> 00:04:51,020 So we categorize them as logical features. 36 00:04:51,100 --> 00:05:02,900 Meanwhile, user-defined names, annotations, and comments, which don't influence the program's flow once it's compiled, are categorized as literal features. 37 00:05:03,780 --> 00:05:13,300 So our goal for the experiment is to determine what types of features in the code LLMs can actually learn and process. 38 00:05:13,300 --> 00:05:26,660 We'll mask the literal features by replacing the changeable names that don't affect the program flow, and then use the LLM to perform code analysis tasks on this modified code. 39 00:05:26,660 --> 00:05:37,960 By evaluating the performance, we'll assess whether the LLM can effectively process the logical features when literal features are absent or even misleading. 40 00:05:38,940 --> 00:05:44,660 To conceal the literal features, we'll adopt three kinds of anonymization. 41 00:05:44,660 --> 00:05:49,800 So here is an example of the bubble sort function in Java. 42 00:05:49,800 --> 00:05:53,400 And the first anonymization is for function name. 43 00:05:53,400 --> 00:05:59,180 So here we can replace the bubble sort string with our customized string. 44 00:05:59,180 --> 00:06:02,620 And the second one is for variable names. 45 00:06:02,620 --> 00:06:09,120 Two examples here is the begin and end, which we can replace with our strings. 46 00:06:09,120 --> 00:06:12,920 And the last one is the method invocation name. 47 00:06:12,920 --> 00:06:23,600 Here we have a function pret as one of the arguments for the bubble sort function, so we can replace the invocation name with our customized string. 48 00:06:24,760 --> 00:06:33,280 Meanwhile, to understand how literal features affect LLM comprehension, we also use two name replacement strategies. 49 00:06:33,280 --> 00:06:48,600 The first one is just replacing it with some randomly generated string, while the second one is shuffling the names with other meaningful names from the code, making it more misleading for users. 50 00:06:48,700 --> 00:06:49,700 For readers. 51 00:06:49,700 --> 00:06:50,860 Sorry. 52 00:06:51,240 --> 00:06:59,980 So, after the literal features are concealed, the LLM performs two main tasks related to code analysis. 53 00:06:59,980 --> 00:07:14,760 The first one is code clone detection, which identifies and measures the similarity between different code fragments to see if they generate the same result when given the same input. 54 00:07:15,140 --> 00:07:30,880 The second one is code search, where it tries to retrieve the code fragment from a larger code corpus that closely matches a developer's intent, which is expressed in natural language as the input. 55 00:07:31,960 --> 00:07:35,300 So, here are the results we got. 56 00:07:35,300 --> 00:07:44,560 It shows that anonymizing names significantly decreases model performance, especially when we replace all three kinds of names. 57 00:07:44,840 --> 00:08:01,820 In the code search task, we also notice that anonymizing master definition name causes more degradation than anonymizing master invocation name, indicating a stronger correlation between the master definition name and their purpose. 58 00:08:01,820 --> 00:08:13,980 As for different languages, anonymizing a single attribute affects Python more, but changing all naming attributes impacts Java the most. 59 00:08:13,980 --> 00:08:24,200 Probably because the verbosity and the structure in Java code that can mitigate partial anonymization are fully disrupted. 60 00:08:25,880 --> 00:08:42,920 Compared to the code clone detection task, the performance degradation is more pronounced in code search task, since well-defined variable and method names are crucial for relating the code snippet to its descriptive purpose. 61 00:08:43,640 --> 00:08:57,360 So, overall, the results clearly show that while logical features are what matters for a program to execute, what LLMs processed are mostly the literal features from the code. 62 00:08:57,360 --> 00:08:59,740 Now I'll hand it over to Dr. 63 00:08:59,740 --> 00:09:03,740 Zhilong to discuss the reasons and possible solutions. 64 00:09:04,320 --> 00:09:05,280 Okay. 65 00:09:08,500 --> 00:09:14,360 So, let's discuss some root cause for the misleading names and comments in the code. 66 00:09:14,360 --> 00:09:22,820 Basically, we just observed three types of the root cause for these misleading names and comments. 67 00:09:22,820 --> 00:09:29,380 And they are malicious code committers and outdated comments and bad coding practice. 68 00:09:33,320 --> 00:09:44,120 Malicious code contributors can contribute some malicious code to the open source projects, and to avoid being detected by the code reviewers. 69 00:09:44,120 --> 00:09:53,080 And they usually can change the naming to some misleading names to avoid being detected by the code reviewer. 70 00:09:56,610 --> 00:10:09,430 Secondly, in software development, programs often frequently update their code to fix some bugs or add some new features. 71 00:10:09,450 --> 00:10:15,770 Well, the comments corresponding to the code may not be updated in time. 72 00:10:15,870 --> 00:10:27,410 In this example, partial code was removed during a new commit, and, however, the corresponding comment was not removed accordingly. 73 00:10:29,030 --> 00:10:38,570 Comments that are not updated can cause inconsistency with the code, and we call them outdated comments. 74 00:10:38,570 --> 00:10:44,470 Outdated comments can mislead the light learning model during code analysis. 75 00:10:47,280 --> 00:11:03,420 Also, in bad coding practice, confusing variable names and misleading variable names could be given by even a benign programmer and developer, which can mislead the code reviewer, too. 76 00:11:06,800 --> 00:11:16,060 So, next, we are going to cover some other issues when using the light learning model to do the code analysis. 77 00:11:20,400 --> 00:11:26,780 Besides the aforementioned limitations, we also observe two limitations. 78 00:11:26,780 --> 00:11:37,160 The first one is lack of context, and the second one is diverse performance on different program language. 79 00:11:37,160 --> 00:11:39,240 We will show the detail. 80 00:11:46,080 --> 00:11:50,900 Most light learning models can only handle a sequence of a limited length. 81 00:11:50,900 --> 00:12:06,700 For example, GPT-3 can handle a sequence with 2,048 tokens at most, and GPT-4 can handle 32,000 tokens at most. 82 00:12:07,160 --> 00:12:19,280 However, the code for even small projects can have thousands lines of code, and each line of code contains usually more than 10 tokens. 83 00:12:19,980 --> 00:12:28,660 Therefore, the light learning model cannot consume all the code at once, which will lead to a lack of context issue. 84 00:12:29,840 --> 00:12:32,220 Let's show this figure. 85 00:12:32,520 --> 00:12:47,540 We have a big project here showing this figure, and let's consider the context of the light learning model through this blue box. 86 00:12:47,540 --> 00:12:56,920 And when we use the light learning model to analyze this whole project, we need to analyze a part of them individually. 87 00:13:04,800 --> 00:13:19,360 So, based on our observation, in most cases, the light learning model is used to analyze each function individually, and it cannot have a big picture of the whole project. 88 00:13:19,360 --> 00:13:27,980 So, we actually have written an ARX preprint to dive into this problem. 89 00:13:27,980 --> 00:13:32,680 We also proposed some solutions to solve this problem. 90 00:13:32,680 --> 00:13:39,980 And for people who are interested in the details can read this ARX preprint. 91 00:13:44,290 --> 00:13:52,890 Also, we observed that the light learning model has a diverse performance across different program languages. 92 00:13:52,890 --> 00:13:59,010 And different light learning models also have different strengths across different program languages. 93 00:13:59,010 --> 00:14:09,750 And we did a quick experiment to evaluate the light learning model's ability to infer the program logic on two program languages. 94 00:14:10,250 --> 00:14:13,610 And the result is shown in the table here. 95 00:14:15,060 --> 00:14:24,550 We can observe that the GPT 3.5 has shown the best results on PHP and Go. 96 00:14:24,550 --> 00:14:31,550 However, Gemini can show the best results on PHP and Python. 97 00:14:38,240 --> 00:14:38,760 Okay. 98 00:14:38,760 --> 00:14:47,480 So, next, we will discuss how to avoid this issue in using light learning model for code analysis. 99 00:14:50,180 --> 00:14:53,760 So, we start from some ad hoc solutions. 100 00:14:53,880 --> 00:15:04,600 And if the code is committed by the trusted developer, we should expect them to improve the quality of the name convention. 101 00:15:04,740 --> 00:15:21,940 And if the code is committed by some untrusted developer, and we should pay special attention in case the light learning model is fooled by the malicious code committer, which can easily be achieved based on experiments. 102 00:15:22,140 --> 00:15:36,840 And for example, we could deploy some naming logic in constancy detection and use it to detect the inconsistency before we perform the code review. 103 00:15:40,680 --> 00:15:52,780 However, to really solve this problem, we believe that we need to change the model a little bit to specifically for the code analysis. 104 00:15:52,780 --> 00:16:01,100 And the current popular pre-training task for the light learning model, as far as we know, is the mask token prediction. 105 00:16:01,900 --> 00:16:07,160 In mask token prediction task, it masks off some tokens in the sequence. 106 00:16:07,420 --> 00:16:20,740 Here, if I take this as example, and it masks off some of that tokens from its sequence and uses neural network to predict this token. 107 00:16:20,740 --> 00:16:26,220 And this is how current light learning model is trained, as far as we know. 108 00:16:26,240 --> 00:16:37,120 And the mask token prediction task mainly focuses on the literal feature when applied to the source code analysis. 109 00:16:37,140 --> 00:16:47,100 But if we apply this model to the neural language NLP, it's okay, because it does not have too much of the logic features. 110 00:16:47,100 --> 00:16:50,200 But for the source code, we have a lot of the logic features. 111 00:16:50,200 --> 00:17:17,500 So, to really solve this problem, we think that we need to add some more pre-training tasks to train a new large program language model, which we should add some logic feature prediction tasks so that it can better capture the logic feature, not the literal feature. 112 00:17:17,500 --> 00:17:29,160 Because, as we show, relying too much on the literal feature will result in some issues as we have demonstrated in the experiments. 113 00:17:33,820 --> 00:17:45,200 So, for the audience who are interested in the details of this talk, you can refer to this ARX preprint for more details. 114 00:17:45,540 --> 00:17:49,480 And here is our contact information. 115 00:17:49,580 --> 00:17:51,960 And that's all of our talk.