1 00:00:00,000 --> 00:00:06,640 So we have a pre-recorded video, pre-recording from the speakers, and we're going to get started right now. 2 00:00:07,140 --> 00:00:07,900 Thanks. 3 00:00:30,000 --> 00:00:36,500 I completed this work together with my colleague Lishuang Song, and we were really looking forward to presenting in person. 4 00:00:36,500 --> 00:00:42,480 But unfortunately, due to visa application issue, we are unable to attend the event on site. 5 00:00:42,480 --> 00:00:45,300 And we sincerely apologize for this. 6 00:00:45,300 --> 00:00:51,060 And as a result, we have to share our presentations through a pre-recorded video instead. 7 00:00:51,060 --> 00:00:54,560 And if you have any questions, please feel free to contact us. 8 00:00:55,140 --> 00:00:57,020 So here, this is the agenda. 9 00:00:57,020 --> 00:00:59,040 So first is the introduction section. 10 00:00:59,040 --> 00:01:07,480 And after that, we will share where the story begins, and then I will analyze how it only works, and introduce the TorchScript engine. 11 00:01:07,480 --> 00:01:13,260 And finally, I will share the impact of this vulnerability, and share some defense recommendations and summary. 12 00:01:13,660 --> 00:01:15,380 So first, introduction. 13 00:01:15,920 --> 00:01:24,340 And PyTorch is a machine learning framework based on Torch Machine Learning Library, and it was developed by Facebook, and now it is an open source project. 14 00:01:24,340 --> 00:01:27,760 And it is very easy to use and has some really great features. 15 00:01:28,480 --> 00:01:37,440 And PyTorch is widely used in the field of deep learning research, natural language processing, or Corning LP, and computer vision. 16 00:01:37,900 --> 00:01:46,720 And to be honest, in the field of machine learning, there are many, many popular frameworks, and well-known projects like TensorFlow and Keras. 17 00:01:47,040 --> 00:01:55,560 But however, according to the paper with Kodo website, and you can see that PyTorch has undoubtedly been the most popular machine learning framework. 18 00:01:55,560 --> 00:02:01,640 If someone can find some bugs in such a famous AI framework, and that will be a really cool thing. 19 00:02:02,000 --> 00:02:05,720 And next comes the second part, where it all began. 20 00:02:06,240 --> 00:02:11,550 And in the early days, PyTorch used Pico to load and save models for convenience. 21 00:02:11,980 --> 00:02:23,710 However, Pico is one of the most well-known security issues in Python, and in fact, the official Python document was that using Pico can be unsafe, especially when loading untrusted data. 22 00:02:24,350 --> 00:02:32,510 So in 2021, someone raised an exception on GitHub and called for a solution to address the Pico issue in PyTorch. 23 00:02:32,510 --> 00:02:39,030 And finally, in 2022, PyTorch released a notable update introducing the waste-loading parameter. 24 00:02:39,910 --> 00:02:42,870 And let's briefly analyze the implementation of waste-loading. 25 00:02:42,870 --> 00:02:49,930 As you can see that by default, waste-loading is set to false, and it will use Pico to load the model. 26 00:02:49,930 --> 00:02:58,830 And if we set waste-loading equal true, you can see that it will use something called waste-only and Pico, and you can consider it as a restricted Pico. 27 00:02:59,030 --> 00:03:01,290 So now, let's try it out. 28 00:03:01,290 --> 00:03:06,510 So first, since by default, the waste-loading is false, and we will use Pico to load the model. 29 00:03:06,510 --> 00:03:12,670 So here we can easily create an eval model and use this reduce magic method. 30 00:03:12,670 --> 00:03:24,590 And you can see that after we save the model, and then we load this model, and you can see that we successfully execute the system command and we get the output route. 31 00:03:26,030 --> 00:03:36,170 And however, if we set waste-loading equal true, and you can see that it just threw an exception, and it seems that the vulnerability is effectively mitigated. 32 00:03:36,470 --> 00:03:43,790 And also on the official PyTorch website, and you can see that the consider-toys-to-load with waste-loading equal true is also secure. 33 00:03:43,790 --> 00:03:49,870 And it also warns that loading and trusting checkpoint with waste-loading equals false must never be done. 34 00:03:49,870 --> 00:03:59,250 And additionally, very similar security issues are discovered in other PyTorch-based components, and they often fix it by using waste-loading equal true. 35 00:03:59,250 --> 00:04:01,110 And here is an example. 36 00:04:01,110 --> 00:04:08,110 So initially, VLM used torch.load with all waste-loading equal true, and which introduced a security risk. 37 00:04:08,110 --> 00:04:12,610 And they fix it by simply add the waste-loading equal true parameter. 38 00:04:13,890 --> 00:04:24,490 And so not only VLM, and in general, the number of software is found to be using torch.load without waste-loading equal true, and the fix is also the same way, just adding the parameter. 39 00:04:24,490 --> 00:04:29,810 But here comes the question, can we blend in trust and security or waste-loading? 40 00:04:31,310 --> 00:04:36,110 So next part, we will dive deeper into it, how waste-loading actually works. 41 00:04:36,870 --> 00:04:40,890 And earlier, we point out that waste-loading is something like a restricted Pico. 42 00:04:40,890 --> 00:04:46,810 So before we analyze how waste-loading is implemented, and we need to understand how Pico works. 43 00:04:47,450 --> 00:04:56,290 And Pico is something like an interpreter, and it reads and interprets each opcode in sequence, and it's executing the corresponding operation. 44 00:04:56,290 --> 00:05:03,750 So for example, here, we first encounter the global opcode, and it will use the load global function. 45 00:05:03,750 --> 00:05:08,150 And you can see that it will call found class, and it will import this model. 46 00:05:08,150 --> 00:05:15,610 And so here, after we execute this command, and you can see that it will get the system function and push it onto the stack. 47 00:05:16,150 --> 00:05:20,190 And since now, we get the function, and we need to get the arguments. 48 00:05:20,230 --> 00:05:25,250 And so here, we can use the unicode opcode to read the string. 49 00:05:25,250 --> 00:05:27,810 And so here, we will get the Huamai. 50 00:05:27,870 --> 00:05:33,850 And since arguments must be in turbo format, and we need to wrap this string into a turbo. 51 00:05:33,850 --> 00:05:39,150 So we use this turbo1 opcode, and you can see that it will replace it with the turbo. 52 00:05:39,250 --> 00:05:44,850 And so here, after we execute the load turbo, and you can see that we wrap this string into a turbo. 53 00:05:44,850 --> 00:05:47,870 Now, we get the function and its arguments. 54 00:05:48,250 --> 00:05:52,710 So now, we can use the reduce opcode to execute this function. 55 00:05:52,710 --> 00:05:56,550 So here, we use the reduce, and it will execute the load reduce function. 56 00:05:56,650 --> 00:06:01,350 And you can see that it will get the arguments, get the function, and call it. 57 00:06:01,350 --> 00:06:03,490 So finally, we can get a command execution. 58 00:06:04,290 --> 00:06:06,910 So how does Visconi address this issue? 59 00:06:07,670 --> 00:06:16,210 And through the above example, and we can roughly say that the most dangerous part of the pcode deserialization is load global and load reduce. 60 00:06:16,210 --> 00:06:20,690 So Visconi and pcode just add some restriction to this dangerous opcode. 61 00:06:20,690 --> 00:06:27,330 Looking at the code, you can see that the load global function has some blacklist and whitelist. 62 00:06:28,810 --> 00:06:33,830 And also, load reduce is restricted in a similar way, and it has a whitelist. 63 00:06:35,610 --> 00:06:40,290 And so in general, Visconi is implemented using a whitelist and a blacklist. 64 00:06:40,290 --> 00:06:41,790 So how can we bypass? 65 00:06:42,750 --> 00:06:50,490 And a common approach is to analyze the whitelist and check whether there are any potential dangerous functions that could be exploited. 66 00:06:50,570 --> 00:06:54,670 And I did the same, but I didn't find anything useful in the end. 67 00:06:55,090 --> 00:06:58,530 And we are also limited by fixed ways of thinking. 68 00:06:58,530 --> 00:07:05,990 So for example, here in this case, most of us may only see the obvious whitelist and blacklist mechanism and stop here. 69 00:07:05,990 --> 00:07:12,310 But however, in reality, the loading process of Torch.load with Visconi equal true is quite complex. 70 00:07:12,310 --> 00:07:17,290 So is it possible that there might be some issues as well in the loading process? 71 00:07:17,290 --> 00:07:23,150 So I tried to conduct a complete analysis of the Visconi workflow to ensure nothing is missed. 72 00:07:24,070 --> 00:07:33,210 So I started analyzing the entire Torch.load process and stepping into the code and debugging the code line by line. 73 00:07:33,210 --> 00:07:38,970 And during one of my analysis, I noticed something very strange in the Torch.g.load. 74 00:07:38,970 --> 00:07:40,390 So what is that? 75 00:07:40,450 --> 00:07:42,170 And I had no idea with this. 76 00:07:42,170 --> 00:07:51,110 So I just searched it on Google and the document just said that Torch.g.load is something to use to load models in the TorchScript format. 77 00:07:51,110 --> 00:07:54,530 So now you can understand that why we named this topic. 78 00:07:54,830 --> 00:07:58,550 Yes, we will analyze and exploit the TorchScript engine. 79 00:07:59,290 --> 00:08:00,610 Hello, everyone. 80 00:08:00,610 --> 00:08:05,630 This part will cover the basics of TorchScript and its code implementation. 81 00:08:07,070 --> 00:08:14,730 TorchScript is used for deploying models in environments without a Python interpreter, such as CPP and mobile. 82 00:08:14,730 --> 00:08:24,390 It can be compiled from Python code through scripting or tracing, and saved as a PDF file which can be loaded and run in CPP and mobile. 83 00:08:24,390 --> 00:08:28,670 The save and load process involves serialization. 84 00:08:28,670 --> 00:08:41,830 I will explain how Python code is compiled to TorchScript, the serialization and deserialization process, the structure of PDF files, and finally, how it executes. 85 00:08:42,290 --> 00:08:50,130 First, we can use TorchJIT Creator to script one Python function to TorchScript. 86 00:08:50,130 --> 00:08:57,070 The steps to compile are, first, press Python source code into a Python AST. 87 00:08:57,070 --> 00:09:01,310 Second, convert the Python AST to a JIT AST. 88 00:09:01,310 --> 00:09:05,550 Third, transform the JIT AST into an AR graph. 89 00:09:06,150 --> 00:09:16,950 The AR graph initially contains many unnecessary nodes, which are eliminated through optimization to make it more concise. 90 00:09:18,270 --> 00:09:21,890 Let's take a deep look about the compile process. 91 00:09:21,890 --> 00:09:26,670 Before we start, I need to show what is the function and model in this context. 92 00:09:27,070 --> 00:09:32,470 You can see that one is a function, the other is a class. 93 00:09:32,470 --> 00:09:39,500 The scripting process for these two are somewhat different, so we will introduce them separately. 94 00:09:40,650 --> 00:09:43,830 Let's look at the function first. 95 00:09:43,850 --> 00:09:49,670 The compile process is handled within the script mpl function. 96 00:09:49,670 --> 00:09:55,530 There are two main functions, getJITDev and JITScriptCompile. 97 00:09:55,530 --> 00:10:00,210 The getJITDev function performs two main tasks. 98 00:10:00,330 --> 00:10:06,370 First, it uses the AST library to convert Python code into a Python AST. 99 00:10:06,370 --> 00:10:15,110 And second, it calls buildDev to transform that Python AST into a self-implemented JIT AST. 100 00:10:17,050 --> 00:10:21,290 JITScriptCompile is a function bound from CPP to Python. 101 00:10:21,290 --> 00:10:31,110 With its implementation in the CPP layer, it further converts the JIT AST to AR within the CPP code. 102 00:10:32,070 --> 00:10:41,510 It eventually invokes the toAR function, which finishes the transformation from JIT AST to AR. 103 00:10:41,610 --> 00:10:49,070 Additionally, toAR also calls some optimization functions to simplify the AR graph. 104 00:10:49,070 --> 00:10:52,530 Now the function compile process is done. 105 00:10:52,530 --> 00:10:57,010 A high-level understanding of the process is enough for this sharing. 106 00:10:57,010 --> 00:11:06,590 If you are interested in the compile source code details, you can use the code stack I have provided to navigate through the source code. 107 00:11:07,350 --> 00:11:09,750 Then let's look at the model. 108 00:11:09,950 --> 00:11:14,470 The overall process is similar to that of functions. 109 00:11:14,470 --> 00:11:18,150 Expect that there is an additional step at the beginning. 110 00:11:18,150 --> 00:11:21,330 Retrieving all functions from the model. 111 00:11:21,330 --> 00:11:26,870 It needs to retrieve functions and compile functions one by one. 112 00:11:26,870 --> 00:11:31,870 The stub fn function is responsible for handling this. 113 00:11:32,490 --> 00:11:38,630 Stub's fn is analyzed for infer methods to compile in this connect. 114 00:11:38,630 --> 00:11:43,710 Let's see what the infer method to compile function does. 115 00:11:44,270 --> 00:11:55,310 In the infer methods to compile function, it first uses dir to get all attributes and methods of the model. 116 00:11:55,310 --> 00:12:07,390 After filtering, it saves the methods that need to be exported, thereby collecting all functions in the model that requires compilation. 117 00:12:08,750 --> 00:12:24,550 The make stub fn method converts the collected functions into JLTST using the getJLTDEF function, which is the same one used during function compilation. 118 00:12:25,510 --> 00:12:50,600 Back to create a separate model MPL, the method stubs variable stores the JLTST we just converted, and the create methods and properties from stubs fn takes two method stubs as input and is responsible for converting it to AR. 119 00:12:52,220 --> 00:12:59,780 We can see that this call stack is similar to the call stack for function compilation. 120 00:13:00,190 --> 00:13:05,450 Both eventually finish the conversion into AR function. 121 00:13:05,450 --> 00:13:11,310 Now the model compile process is done. 122 00:13:11,310 --> 00:13:15,330 Overall, some key steps are the same as for function. 123 00:13:15,330 --> 00:13:23,070 Both use getJLTDEF to convert Python to JLTST, then convert it to AR through toAR. 124 00:13:24,270 --> 00:13:30,470 The serialization filter can save models and deploy them to other environments. 125 00:13:30,470 --> 00:13:34,090 Use touchsave to save model as pdfile. 126 00:13:34,090 --> 00:13:37,250 Use touchload to load pdfile as model. 127 00:13:37,450 --> 00:13:40,650 The Python code here is converted from AR. 128 00:13:40,650 --> 00:13:44,750 You will notice it's slightly different than the original code. 129 00:13:46,070 --> 00:13:52,390 Let's see how separate function and separate model is serialized. 130 00:13:52,570 --> 00:13:58,330 Separate function has an additional step compared to separate model. 131 00:13:58,330 --> 00:14:02,470 It needs to be converted to separate model first. 132 00:14:02,470 --> 00:14:06,370 After that, both call serialize for serialization. 133 00:14:06,430 --> 00:14:15,630 During the serialization process, some information is stored in the data.pkl and constants.pkl in big format. 134 00:14:15,630 --> 00:14:23,010 Additionally, it saves the Python code converted from AR and debug info to the code folder. 135 00:14:24,830 --> 00:14:32,990 To summarize the save process, for touch function, first convert it to touch model. 136 00:14:32,990 --> 00:14:36,030 The remaining process is the same. 137 00:14:36,030 --> 00:14:43,950 First, the app value corresponding to the model is serialized in PQL format as data.pkl. 138 00:14:44,330 --> 00:14:51,270 Second, obtain code and debug info via Python print and write to code directory. 139 00:14:51,970 --> 00:14:56,730 Third, save tensor constants to constants.pkl. 140 00:14:56,730 --> 00:14:59,710 Now the serialization is done. 141 00:14:59,710 --> 00:15:03,670 Let's look at the detail of the PTFEW. 142 00:15:05,030 --> 00:15:11,310 The PTFEW is compressed achieve using ZIP compression. 143 00:15:11,870 --> 00:15:16,410 The field tree after decompression is shown above. 144 00:15:16,410 --> 00:15:21,250 And we can use PicoTools to disassemble it. 145 00:15:21,270 --> 00:15:26,750 Above is the disassembled output of data.pkl. 146 00:15:26,750 --> 00:15:38,210 The meaning of this PicoTools is create an object named touch placeholder model and set its training attribute to true. 147 00:15:38,210 --> 00:15:43,130 And the touch placeholder model object is a secret model. 148 00:15:43,150 --> 00:15:49,070 So when interpreting data.pkl, secret model object is created. 149 00:15:51,270 --> 00:15:58,970 The constants.pkl contains Pico code, which can create a value object with tensor. 150 00:15:59,230 --> 00:16:03,550 The touch.py field contains Python code strings. 151 00:16:03,550 --> 00:16:12,150 It's the same as the content of the code attribute in secret model because they are obtained in the same way. 152 00:16:12,150 --> 00:16:20,750 OK, now we understand the three most important parts saved in the serialized field. 153 00:16:20,750 --> 00:16:27,110 Data.pkl, constants.pkl, and the source code in the code directory. 154 00:16:27,450 --> 00:16:34,690 Let's see how these parts are restored into a secret model. 155 00:16:35,890 --> 00:16:48,610 We can see that in the deserialized function, the three main parts of the serialized field are converted into a secret model. 156 00:16:48,610 --> 00:16:51,970 Let's look at the function implementation. 157 00:16:53,530 --> 00:17:00,210 Deserialize will call read achieve to read constants.pkl and data.pkl. 158 00:17:00,210 --> 00:17:07,250 Then we'll get one model in CPP, which is a secret model in Python. 159 00:17:07,830 --> 00:17:21,870 During the deserialization process, first I'm picking constants.pkl to obtain tensor constants, then save them in constants.table. 160 00:17:21,870 --> 00:17:29,450 Second, I'm picking data.pkl during the process of I'm picking data.pkl. 161 00:17:31,710 --> 00:17:44,750 Relevant source code is read from the code directory and pressed as needed, and the related constants are also read from the constants.table. 162 00:17:44,750 --> 00:17:57,910 The code processing process includes converting Python code to custom tokens, and then transforming tokens into JIT-ST, and finally into AR. 163 00:17:57,910 --> 00:18:06,950 This process differs significantly from the earlier Python-to-Tetrascript compilation. 164 00:18:08,570 --> 00:18:17,710 To summarize the load process, first, reach main logic via deserialization. 165 00:18:17,710 --> 00:18:29,430 Second, call read achieve to read constants.pkl, convert constants to n-values by I'm picking and save them to constants.table. 166 00:18:30,230 --> 00:18:36,930 Third, call read achieve to read data.pkl, restore corresponding n-values by I'm picking data. 167 00:18:38,410 --> 00:18:55,570 Fourth, during data.pkl I'm picking, source importer reads code fields and constants.table to restore AR through pressTab to find namedTab to import namedTab. 168 00:18:55,570 --> 00:19:04,510 Now the deserialization is done, let's take a look at how Tetrascript is running. 169 00:19:04,930 --> 00:19:18,090 The AR graph contains many nodes, and every node contains three parts, yin, output, and opcode. 170 00:19:18,090 --> 00:19:21,190 Opcode is the key to execution. 171 00:19:21,770 --> 00:19:33,730 The process of executing Tetrascript is to iterate through the AR and convert it into instructions. 172 00:19:33,730 --> 00:19:37,870 Then interpret the instructions. 173 00:19:37,870 --> 00:19:41,410 Every instruction has one opcode. 174 00:19:41,410 --> 00:19:52,370 There is a switch table here that finds the corresponding process logic through the op and the execute set. 175 00:19:52,590 --> 00:20:00,030 Now we have a basic understanding of the Tetrascript workflow. 176 00:20:00,940 --> 00:20:05,010 While reading the code, I discovered something interesting. 177 00:20:05,010 --> 00:20:11,150 There is one opcode named op, and it can do a call on operator table. 178 00:20:11,150 --> 00:20:15,990 An operator table contains many functions corresponding to operators. 179 00:20:15,990 --> 00:20:20,070 I'm curious about what operators they are. 180 00:20:21,500 --> 00:20:31,470 Some built-in functions register themselves as operators, requiring op instructions to call corresponding functions. 181 00:20:31,670 --> 00:20:41,850 The registerOperator class manages these operators, and registers them by registerOperator function. 182 00:20:41,850 --> 00:20:48,110 I page the PyTorch code and add one function to output all operators. 183 00:20:48,110 --> 00:20:53,130 You can see there are over 2000 operators here. 184 00:20:54,570 --> 00:20:58,890 Are all these operators safe? 185 00:20:59,530 --> 00:21:10,910 During our code audit of these operators, we discovered two interesting operators, save and fulfill. 186 00:21:11,510 --> 00:21:17,990 Here we can see the corresponding implementations of these two functions. 187 00:21:17,990 --> 00:21:24,630 The save function will save specified value as a model to specified field. 188 00:21:25,370 --> 00:21:30,390 This can lead to arbitrary field writes. 189 00:21:30,390 --> 00:21:36,150 But the saved field contains a lot of dirty data, which model information. 190 00:21:36,170 --> 00:21:46,290 The fulfill function will read the field which I specified, and convert the field contained to tensor. 191 00:21:46,290 --> 00:21:51,310 Then return the tensor, we can get the field contained from the tensor. 192 00:21:52,810 --> 00:21:57,210 Now we know these two operators have vulnerabilities. 193 00:21:58,650 --> 00:22:01,550 But there is still a problem. 194 00:22:01,550 --> 00:22:04,210 How to call them from touch script? 195 00:22:05,470 --> 00:22:12,230 To get the answer, we need to first understand the operator registering process. 196 00:22:12,230 --> 00:22:19,930 The getBuildingTable function registers some object member functions to building of ops. 197 00:22:20,050 --> 00:22:27,790 And during this process, it also adds prefixes to the member functions for rename. 198 00:22:27,790 --> 00:22:37,730 Finally, the address of these functions and their modified names will be placed into built-in table. 199 00:22:37,730 --> 00:22:52,370 During the touch script compilation process, two shrugged values will be triggered, where it checks whether the Python object exists in the built-in table. 200 00:22:52,370 --> 00:22:56,910 If it exists, it returns a built-in function. 201 00:22:57,630 --> 00:23:05,990 Finally, this built-in function will be inserted into the AR graph through emitter built-in call. 202 00:23:06,650 --> 00:23:20,930 Back to the built-in registering process, we now understand that add and save may come from one of these objects in models containing built-ins. 203 00:23:20,930 --> 00:23:35,950 By testing each object individually for the presence of a save function, we will find that the save function exists in the touch object. 204 00:23:36,090 --> 00:23:40,710 Adding from field can also be obtained in the same way. 205 00:23:41,350 --> 00:23:50,130 So, we just need to call touchSave() or touchFromField() to get arbitrary field write ability in touch script. 206 00:23:50,830 --> 00:24:05,290 Now, we can try writing a field to get RCE, but since there are some dirty characters, only specified special fields will work. 207 00:24:06,710 --> 00:24:26,790 Though we want to call and type a field because of a permission mismatch, our script uses touchSave(), which writes a field with 644 permissions, but the current demo requires 6000 permissions. 208 00:24:27,690 --> 00:24:30,370 Here is one poke video. 209 00:25:06,270 --> 00:25:08,820 Okay, you can see we get RCE. 210 00:25:12,180 --> 00:25:20,770 The vulnerabilities we have discussed so far might be more similar to logic vulnerabilities. 211 00:25:20,850 --> 00:25:26,910 On the other hand, some hackers may prefer memory-related vulnerabilities. 212 00:25:26,910 --> 00:25:31,750 We have also discovered a few overflow issues. 213 00:25:32,470 --> 00:25:40,950 Here you can see that when we load this modelpt field, it triggers a heap overflow. 214 00:25:40,950 --> 00:25:49,290 As a result, we can observe that the heap address and the loaded address of the library are leaked. 215 00:25:51,630 --> 00:25:54,230 This is one poke video. 216 00:26:10,270 --> 00:26:15,430 Okay, you can see we get RCE by memory bug. 217 00:26:16,510 --> 00:26:23,030 But due to time limited, we won't go into them in great detail here. 218 00:26:23,030 --> 00:26:25,710 We hope to share them in the future. 219 00:26:27,950 --> 00:26:31,890 This is the full details of the CVE. 220 00:26:33,010 --> 00:26:37,190 The fix is also relatively simple. 221 00:26:37,190 --> 00:26:43,970 It prevents the use of touchscript when voice-only is enabled. 222 00:26:44,510 --> 00:26:47,370 So what is the impact of this vulnerability? 223 00:26:47,830 --> 00:26:55,210 The entire AI ecosystem, like this house and petology, is one of the fundamental components. 224 00:26:55,210 --> 00:27:03,970 If there is an issue with the petology, just like we have removed one of the bottom-level components, the entire AI ecosystem is then compromised. 225 00:27:04,690 --> 00:27:08,350 We did a simple search on GitHub for projects using voice-only code. 226 00:27:08,470 --> 00:27:12,990 We can see that in fact, many projects use it in this way. 227 00:27:13,230 --> 00:27:19,170 Here we select two well-known projects as an example to illustrate the impact of this vulnerability. 228 00:27:19,390 --> 00:27:22,490 One is VOM and the other is Transformers. 229 00:27:22,490 --> 00:27:30,610 VOM is a high-performance library for efficient large-language model inference and optimized for speed and memory usage. 230 00:27:30,990 --> 00:27:32,390 So why did I choose it? 231 00:27:32,390 --> 00:27:42,190 Because it has a CVE number and you can see that it uses the torch.load function and the voice-only parameter is the default value of force, so it has an RCE vulnerability. 232 00:27:42,650 --> 00:27:46,190 The fix is very simple, just add the voice-only parameter. 233 00:27:46,550 --> 00:27:53,650 This seems to solve the problem, but because of the petology issue, mitigation ends up being ineffective. 234 00:27:54,730 --> 00:27:58,950 And the sea harbor you once saw was actually also waters. 235 00:28:00,030 --> 00:28:11,470 And at the same time, I found a very interesting phenomenon and you can see that when I check this requirements.cpu.txt and you can see that it just hard-coded the torch version. 236 00:28:11,850 --> 00:28:16,990 And also in the GPU version, you can see that it also hard-coded the torch version. 237 00:28:17,350 --> 00:28:18,750 So what does this mean? 238 00:28:18,750 --> 00:28:28,210 It means that even if PyTorch released a new patched version and users of VRM cannot update it timely because VRM has hard-coded the version. 239 00:28:28,210 --> 00:28:33,650 So as a result, the users will remain exposed to this vulnerability for a long period. 240 00:28:34,430 --> 00:28:36,410 And so now let's set up the environment. 241 00:28:36,410 --> 00:28:45,290 Since the latest VRM has already patched its issue, so we need to install the old version, exactly 0.7.3. 242 00:28:45,290 --> 00:28:51,070 And you can see that when you install VRM, then it will install the exact version of torch. 243 00:28:52,250 --> 00:28:58,310 And so here we will use this function as an example to illustrate the existence of the vulnerability. 244 00:28:59,330 --> 00:29:02,230 And at first, I didn't think too much about that. 245 00:29:02,230 --> 00:29:08,410 I just want to take the poke from the previous vulnerability and just hoping for one should succeed. 246 00:29:08,430 --> 00:29:14,570 And you can see that finally, we will definitely enter the logic we want and it will load our email model. 247 00:29:14,570 --> 00:29:15,990 So we are ready to proceed. 248 00:29:16,570 --> 00:29:20,950 But it failed and you can see that we don't create this fail, so why? 249 00:29:21,970 --> 00:29:34,610 And let's take a look at the previous poke and you can see that after we use torch.load to load this model and we need to call the model to invoke the model in order to trigger this forward logic. 250 00:29:35,050 --> 00:29:40,090 But here you can see after we load this evil model and it didn't invoke the model. 251 00:29:40,090 --> 00:29:43,190 It just fetched the items and then deleted the model. 252 00:29:43,190 --> 00:29:45,370 So this model was not invoked. 253 00:29:46,170 --> 00:29:48,810 And is it really an end? 254 00:29:49,750 --> 00:29:56,230 And at that point, I noticed the error message and it says that the model don't have the attribute items. 255 00:29:56,230 --> 00:29:59,130 And this error message gave me some inspiration. 256 00:30:00,490 --> 00:30:08,070 And items is essentially a keyword in Python and it is used to iterate the dictionary type object. 257 00:30:08,170 --> 00:30:11,390 So you can see that in fact, items is a function. 258 00:30:11,390 --> 00:30:14,390 So here can we spoof the function name? 259 00:30:15,130 --> 00:30:22,590 And so here I just try for the first time and you can see that I change the function name from forward to item and just run the code. 260 00:30:22,590 --> 00:30:27,690 And you can see that why it is still saying that our model don't have the items attribute. 261 00:30:28,910 --> 00:30:43,110 But if we write in this way and you can see that we just call the items function in our forward logic and we run a code and you can see that we successfully create a field and this means we succeed. 262 00:30:43,330 --> 00:30:52,790 And this is very strange and the reason is that when retrieving model functions, it determines whether these functions need to be exported. 263 00:30:52,790 --> 00:31:04,750 For functions not decorated as exports and a lazy export strategy is adopted, meaning that they are only exported if called within the exported function. 264 00:31:04,790 --> 00:31:11,330 So here you can see that in the left picture, we just decorated our items function with exported. 265 00:31:11,330 --> 00:31:16,850 So here it will export the item function and we can get this item attribute. 266 00:31:16,930 --> 00:31:26,730 And in the right picture and you can see that since we call it in our exported function forward and our object, we also have this item function. 267 00:31:27,670 --> 00:31:34,990 And so finally, we report our ability to the official team and who highly acknowledge our work. 268 00:31:35,010 --> 00:31:40,970 And you can see that I said it's very interesting since PyTorch document claims it is safe. 269 00:31:41,670 --> 00:31:45,630 And the patch is very simple, just change this version. 270 00:31:46,570 --> 00:31:48,170 And next, Transformers. 271 00:31:48,210 --> 00:31:59,030 Transformers is a popular open source library by Hugging Face and provided pre-trained models and tools for natural language processing tasks using the transformer-based architecture. 272 00:31:59,970 --> 00:32:03,790 And Transformers also implemented some security hardening measures. 273 00:32:03,790 --> 00:32:09,210 For example, here you can see that it just used which only equals true to load the model. 274 00:32:10,150 --> 00:32:21,210 And for now, we set our environment and you can see that since the latest version of Transformers also fixed this issue and we need to install our old version 4.51.3. 275 00:32:21,390 --> 00:32:34,290 And here, this is the official document example from Transformers and you can see that we need to load the model from Hugging Face and create a pipeline and then we can create our conversation. 276 00:32:34,290 --> 00:32:36,670 So, here, for example, we just ask a question. 277 00:32:36,670 --> 00:32:41,670 And you can see that just give me some answer. 278 00:32:42,390 --> 00:32:52,530 And here, this is my demo project and you can see that we only have three fields, readme, config.json, and a test PyTorch field. 279 00:32:52,530 --> 00:32:54,390 And it doesn't contain any evil code. 280 00:32:55,150 --> 00:33:02,610 And if we run the code and you can see that it will use Torch.load to load our remote PyTorch model. 281 00:33:03,030 --> 00:33:10,510 And let me introduce this code and when we load a remote Hugging Face repo, then it will load this model. 282 00:33:10,510 --> 00:33:15,770 And by default, fields in C tensors or PyTorch is allowed. 283 00:33:16,950 --> 00:33:22,950 And just like the previous VRM vulnerability and it will call the keys function. 284 00:33:23,570 --> 00:33:31,250 So, we can just change the function from items to keys and we save the project in our local repo. 285 00:33:31,890 --> 00:33:38,430 And, of course, if we run this code and you can see that we can exploit and we can create this field. 286 00:33:39,290 --> 00:33:46,490 And after that, we call this vulnerability to Hugging Face and you can see that it just patched it. 287 00:33:46,490 --> 00:33:48,330 And the patch is also very simple. 288 00:33:48,330 --> 00:33:51,690 You can see that it can check Torch.load is safe. 289 00:33:51,690 --> 00:33:56,530 It checks the Torch version greater or equal than 2.6. 290 00:33:57,250 --> 00:34:00,370 And finally, it defends a summary. 291 00:34:00,690 --> 00:34:05,110 So, now, if you are still using your own version of PyTorch, please update. 292 00:34:05,850 --> 00:34:07,910 And here is also some recommendations. 293 00:34:07,910 --> 00:34:15,910 So, for example, from the model format perspective, we should use more secure format like safe tensors. 294 00:34:16,150 --> 00:34:26,090 And also from the model community perspective, we should scan and flag malicious models and Hugging Face has already done the relevant work. 295 00:34:26,270 --> 00:34:33,250 And also from the user perspective, we should not load untrusted models and it is better to load them in a sandbox. 296 00:34:34,650 --> 00:34:36,610 So, any questions? 297 00:34:38,530 --> 00:34:40,410 And thanks again for listening. 298 00:34:40,410 --> 00:34:44,290 And if you have any questions, please feel free to contact us at any time.