1 00:00:02,450 --> 00:00:04,510 Hey everyone, I'm Suha. 2 00:00:04,510 --> 00:00:06,550 I'm really excited to be here today. 3 00:00:06,550 --> 00:00:08,270 So, let's get started. 4 00:00:08,270 --> 00:00:11,190 I want to talk to you about ML security. 5 00:00:11,330 --> 00:00:19,970 Specifically, I want to talk about this new class of exploits I identified called incubated ML exploits that combine backdoors and input handling bugs. 6 00:00:19,970 --> 00:00:23,450 Don't worry if you don't know too much about ML or ML security. 7 00:00:23,450 --> 00:00:26,310 I'll explain all the important stuff as we go along. 8 00:00:27,490 --> 00:00:31,310 So, who am I and why am I even talking to you today? 9 00:00:31,310 --> 00:00:36,170 I'm an engineer at Trail of Bits where I focus on AI and ML security. 10 00:00:36,170 --> 00:00:38,130 I've been in the field for a few years now. 11 00:00:38,130 --> 00:00:41,550 I graduated from Georgia Tech and I'm originally from Queens. 12 00:00:41,910 --> 00:00:49,690 Outside of work, I like Brazilian Jiu-Jitsu, trying new restaurants, making things, and an obscure card game called Q-Birds. 13 00:00:50,390 --> 00:00:59,690 So, it's becoming pretty clear with ML and AI popping up everywhere, people are figuring out how to trick these systems based on how these models work. 14 00:00:59,730 --> 00:01:04,390 Maybe you've seen someone use prompt injection to convince a chatbot to give them a refund. 15 00:01:04,390 --> 00:01:10,250 Or maybe you've seen this story right here of protesters tricking self-driving cars with traffic cones. 16 00:01:10,790 --> 00:01:16,310 Notice the fact that this trick is rooted in an understanding of the training data for these models. 17 00:01:17,190 --> 00:01:23,030 So, how can we actually construct our own useful exploits against ML systems? 18 00:01:24,670 --> 00:01:27,370 Let's play a game of pretend real quick. 19 00:01:27,370 --> 00:01:32,270 You're a college student and you really, really want the prize money for a robotics competition. 20 00:01:32,290 --> 00:01:35,810 So, naturally, you decide to sabotage another team. 21 00:01:35,990 --> 00:01:38,290 Side note, I don't recommend this. 22 00:01:38,290 --> 00:01:39,350 I don't condone this. 23 00:01:39,350 --> 00:01:41,110 I've never done it myself. 24 00:01:41,190 --> 00:01:50,250 But anyway, the competition requires teams to build a tiny autonomous vehicle that uses a specific pre-trained model and stops at stop signs. 25 00:01:50,250 --> 00:01:54,670 So, you find out that some of these stop signs have these little stickers on them. 26 00:01:54,670 --> 00:01:58,970 And you also find some flaws with how they've stored and distributed the model. 27 00:01:58,970 --> 00:02:01,870 Which, by the way, isn't out of the question. 28 00:02:01,890 --> 00:02:08,490 ML artifacts are often widely shared without any meaningful or substantial trust mechanisms. 29 00:02:08,650 --> 00:02:15,270 So, you decide to grab that file and inject a model backdoor in it using a file format RCE of some kind. 30 00:02:15,270 --> 00:02:16,590 And then you put it back. 31 00:02:16,590 --> 00:02:27,410 Then, on the day of the competition, you sit back and you just watch as your competitor's vehicle just plows through and ignores every stop sign with a sticker on it. 32 00:02:27,410 --> 00:02:33,090 What you just did is execute an incubated ML exploit, which is what my talk is all about. 33 00:02:34,050 --> 00:02:38,490 So, obviously, the stakes of this story is just a lost robotics competition. 34 00:02:38,490 --> 00:02:44,550 But the idea of attacking a real autonomous vehicle is a hallmark of model backdoor research. 35 00:02:44,550 --> 00:02:47,110 And you can see that with the image on the left. 36 00:02:47,110 --> 00:02:50,550 So, I'll let you use your imagination to raise the stakes. 37 00:02:51,770 --> 00:02:59,050 So, in my talk, first I'm going to tell you about this framework that I've been using to bridge the gap between model and system security. 38 00:02:59,050 --> 00:03:03,070 Because we can't continue to treat models as standalone objects. 39 00:03:03,130 --> 00:03:09,610 Next, I'll tell you about these input handling bugs I found in model serialization and connect them to backdoors. 40 00:03:09,630 --> 00:03:13,630 I'll do that by taking a page out of this subfield called langsec. 41 00:03:13,630 --> 00:03:20,910 So, effectively, I'll be going through a bunch of examples of incubated ML exploits and use langsec to organize them. 42 00:03:21,430 --> 00:03:23,990 But first, I need to explain some stuff. 43 00:03:24,050 --> 00:03:27,830 What even is a model vulnerability or an ML backdoor? 44 00:03:38,850 --> 00:03:48,290 So, super briefly, you can think of ML models as these squishy, flexible sequences of linear algebra operations that are trained on tons and tons of data. 45 00:03:48,370 --> 00:03:52,630 There's a pretty popular saying, all models are wrong, but some are useful. 46 00:03:52,630 --> 00:03:55,110 We're just saying that these models aren't perfect. 47 00:03:55,110 --> 00:04:00,390 There are many different ways they can mess up or get tripped up by something that might be unexpected to us. 48 00:04:00,390 --> 00:04:03,210 And that's the basis of such model vulnerabilities. 49 00:04:03,210 --> 00:04:10,630 While popular examples of model vulnerabilities include model inversion and membership inference, we're zooming in on one specific type. 50 00:04:10,630 --> 00:04:11,870 Model backdoors. 51 00:04:12,690 --> 00:04:21,250 So, to be precise about it, a backdoor attack allows a malicious actor to force an ML model to produce specific outputs given specific inputs. 52 00:04:21,250 --> 00:04:26,230 Now, there's a couple of things that I think make backdoors really interesting to study. 53 00:04:26,310 --> 00:04:31,270 First up, you can use them as primitives for other model vulnerabilities, like membership inference. 54 00:04:31,330 --> 00:04:35,510 You can also identify pre-existing, quote-unquote, natural backdoors in them. 55 00:04:35,510 --> 00:04:39,910 And there's also some pretty strong evidence that suggests that this is an inherent threat. 56 00:04:41,010 --> 00:04:49,790 Now, while there's a lot of awesome research on ML model attacks, they can actually be pretty hard to exploit in the real world, with some exceptions, of course. 57 00:04:49,790 --> 00:04:57,430 While there are multiple reasons for this, one thing that really sticks out to me is the big gap between research and the real world. 58 00:04:59,790 --> 00:05:06,430 So, for the most part, many attacks and attack frameworks and tools restrict their analysis to this formulation. 59 00:05:06,550 --> 00:05:10,490 An ML model receives an input and produces an output. 60 00:05:10,490 --> 00:05:14,950 But this isn't an accurate representation of what an ML system actually looks like. 61 00:05:14,950 --> 00:05:17,490 There's so much more going on in practice. 62 00:05:18,210 --> 00:05:23,350 Here's a software architecture diagram for an ML system reviewed by Trail of Bits recently. 63 00:05:23,350 --> 00:05:26,690 This is a system that uses the Ask Astro tool for RAG. 64 00:05:26,690 --> 00:05:29,630 And I've circled where the model actually is in this photo. 65 00:05:29,630 --> 00:05:30,790 Do you see what I mean? 66 00:05:30,790 --> 00:05:33,730 We need to be looking at all of this holistically. 67 00:05:33,930 --> 00:05:39,270 There's a large and evolving landscape of tools being used in and for ML systems. 68 00:05:39,270 --> 00:05:42,210 And that brings me to the exploit framework. 69 00:05:43,070 --> 00:05:47,290 So, the title of my talk references an incubated ML exploit. 70 00:05:47,290 --> 00:05:54,310 But there's this larger category of exploits called hybrid ML exploits that are important to think about first. 71 00:05:55,450 --> 00:06:01,050 Specifically, a hybrid ML exploit chains a system security issue with a model vulnerability. 72 00:06:01,090 --> 00:06:04,310 This can go in either direction, and you can see that on the diagram. 73 00:06:04,310 --> 00:06:12,270 You can have a model vulnerability that exposes a system security issue, or you could use a system security issue to exploit a model vulnerability. 74 00:06:13,170 --> 00:06:15,630 So, this part's pretty important. 75 00:06:15,630 --> 00:06:22,390 The big issue that I see with ML security is that model security and system security are treated separately. 76 00:06:22,390 --> 00:06:28,690 But what I need you to understand is that if you only know model security, you're missing a big piece. 77 00:06:28,690 --> 00:06:33,250 And if you're only covering system security, you're still missing a big piece. 78 00:06:33,250 --> 00:06:39,150 And if you're treating the two processes completely independently, once again, you're missing a big piece. 79 00:06:39,150 --> 00:06:43,230 You're then entirely ignoring the potential for hybrid ML exploits. 80 00:06:43,230 --> 00:06:44,890 This is an emergent property. 81 00:06:44,890 --> 00:06:53,310 So, your model is embedded in a system, and it's going to interact with all of the different system components in new and exploitable ways. 82 00:06:53,530 --> 00:06:58,170 So, one thing you'll notice is that there's a lot of screenshots of paper titles on this slide. 83 00:06:58,170 --> 00:07:03,830 That's because there have been specific instances of hybrid ML exploits in the literature and in practice. 84 00:07:04,090 --> 00:07:06,330 They're just not called that explicitly. 85 00:07:06,590 --> 00:07:09,530 Exploitable software gadgets have been used for backdoors. 86 00:07:09,530 --> 00:07:14,530 The summoning demons paper up there at the top chained model evasion and memory corruption. 87 00:07:14,530 --> 00:07:23,090 And the learn system security paper next to it has an example of a poisoning attack that caused an exponential memory blowup in an index structure. 88 00:07:23,430 --> 00:07:29,230 But the ML security literature framework and tools are largely limited to just that. 89 00:07:29,230 --> 00:07:31,710 Specific instances or implications. 90 00:07:31,710 --> 00:07:37,810 What I'm trying to do here, what I want to be doing here, is treating this interaction explicitly and systematically. 91 00:07:37,850 --> 00:07:39,870 And that's why I made this framework. 92 00:07:40,530 --> 00:07:45,050 So, one kind of system security issue is an input handling bug. 93 00:07:45,050 --> 00:07:48,970 And one kind of model vulnerability is a model backdoor. 94 00:07:49,230 --> 00:07:53,230 Put that together and we get an incubated ML exploit. 95 00:07:53,230 --> 00:08:00,230 Which is a type of hybrid ML exploit where an attacker uses input handling bug to inject a backdoor. 96 00:08:00,230 --> 00:08:04,250 So, I made this diagram to make the distinction between the two pretty clear. 97 00:08:04,710 --> 00:08:07,070 And here's the definition again. 98 00:08:07,070 --> 00:08:09,390 I'm going to leave the framework here for now. 99 00:08:09,390 --> 00:08:15,710 We did end up going into a bit of a more formal model of exploitation including this exploit schema. 100 00:08:15,710 --> 00:08:17,630 But we'll return to that later. 101 00:08:18,590 --> 00:08:25,710 So, to backdoor a pre-existing model, the attacker should be able to change the parameters or the architecture. 102 00:08:25,710 --> 00:08:31,570 Now, at the level of extraction we're dealing with, we can put input and component manipulation on the side for now. 103 00:08:31,570 --> 00:08:35,890 But how this actually plays out can vary a lot. 104 00:08:35,890 --> 00:08:41,050 For example, sometimes the attacker has control over some element of the training process. 105 00:08:41,050 --> 00:08:46,450 And they use that to sneak in some manipulated data that changes the model's parameters. 106 00:08:46,450 --> 00:08:48,470 That's usually called data poisoning. 107 00:08:48,650 --> 00:08:53,490 Or they might go a step further and fiddle with the model's source code to change the architecture. 108 00:08:55,190 --> 00:09:00,550 Now, before we talk about exploits, I want to explain a few things about input handling bugs. 109 00:09:10,090 --> 00:09:12,830 So, an ML model is stored as a file. 110 00:09:12,830 --> 00:09:15,590 To process these models, you need parsers. 111 00:09:15,590 --> 00:09:20,870 And parsing these files into objects and back is deserialization and serialization. 112 00:09:21,350 --> 00:09:27,530 But wait, quoting Ange Albertini here, a file has no intrinsic meaning. 113 00:09:27,530 --> 00:09:34,130 The meaning of a file, its type, its validity, its contents can be different for each parser or interpreter. 114 00:09:34,290 --> 00:09:42,510 Now, this is the reason we can make cool, potentially malicious file artifacts like polyglots and ambiguous files, which I'll talk more about later. 115 00:09:43,350 --> 00:09:48,990 So, I'm focused very specifically on bugs that arise when you parse ML model files. 116 00:09:49,090 --> 00:09:54,130 There's also cool bugs in other parts of the pipeline, but I'm picking ML model files for several reasons. 117 00:09:54,130 --> 00:09:59,470 The first reason is, and I'm sure you all will agree with me on this, the most important. 118 00:09:59,470 --> 00:10:00,690 I think it's fun. 119 00:10:00,970 --> 00:10:07,670 But more seriously, the security of ML file formats has become increasingly important. 120 00:10:07,670 --> 00:10:11,830 Real malicious model files have been found on the Hugging Face Hub, for example. 121 00:10:11,910 --> 00:10:15,730 And there's also just an absolute ton of ML file formats out there. 122 00:10:15,730 --> 00:10:26,170 I've tried to list and organize them in the repository in the middle, but what's important for you to take away is that there's a large set of possibilities for these exploits, as well as just fun hacks with these formats. 123 00:10:26,270 --> 00:10:30,730 And there's already a lot of great work in this area, as shown on my slide. 124 00:10:31,530 --> 00:10:40,210 So, file format tricks are within the realm of LangSec, but this field actually thinks more abstractly about inputs as a general class. 125 00:10:40,210 --> 00:10:43,610 LangSec applies formal language theory to system security. 126 00:10:43,610 --> 00:10:49,770 It focuses on exploring input handling bugs, or parser problems, as a big root cause for security issues. 127 00:10:49,770 --> 00:10:55,710 After all, lots of impactful vulnerabilities like Heartbleed and Android Masterkey have been parser bugs. 128 00:10:55,710 --> 00:11:01,450 Now, while I like formal language theory, this talk isn't Theoretical Computer Science 101. 129 00:11:01,850 --> 00:11:14,410 So, just know that fundamentally what LangSec is saying is, hey, let's treat all of the inputs as a specific language, and make our code just capable enough to understand that language properly. 130 00:11:15,050 --> 00:11:19,870 So, my work is centered around a specific taxonomy of input handling bugs. 131 00:11:19,870 --> 00:11:22,010 And these are all the different bug classes. 132 00:11:22,010 --> 00:11:23,710 There are eight different types. 133 00:11:23,710 --> 00:11:27,150 Quick note, these categories aren't actually completely distinct from each other. 134 00:11:27,150 --> 00:11:30,270 The one you choose comes from a root cause analysis. 135 00:11:30,610 --> 00:11:37,530 So, with the exception of one, I'm going to show you multiple examples of each in ML Tools, and use them to build an ML Backdoor. 136 00:11:38,250 --> 00:11:42,530 So, I'm going to run that one more time. 137 00:11:42,670 --> 00:11:53,170 In order to show that input handling bugs are a vector, I identified issues with ML Model Serialization across these different bug classes in order to construct ML Backdoors. 138 00:11:53,910 --> 00:11:57,510 So, now we can dive into the most fun part, exploits. 139 00:11:57,510 --> 00:12:03,690 Now, for the sake of time, I'm going to focus more on the useful gadgets for these exploits. 140 00:12:12,240 --> 00:12:21,260 So, these are some characters that play important roles in the ML ecosystem that can help us understand the impact of these exploits. 141 00:12:21,260 --> 00:12:24,240 So, Alice, she distributes models. 142 00:12:24,240 --> 00:12:27,220 She takes open source LLMs and fine-tunes them. 143 00:12:27,820 --> 00:12:32,080 The models she distributes are what everyone else in our story is going to be using. 144 00:12:32,800 --> 00:12:37,200 Bob is a frontline user who directly uses Alice's models in his own life. 145 00:12:37,200 --> 00:12:40,040 Maybe he has a nice chat interface pulled up. 146 00:12:40,740 --> 00:12:41,700 There's Dave. 147 00:12:41,700 --> 00:12:45,560 Dave is a developer who is trying to integrate these models into products. 148 00:12:45,980 --> 00:12:50,520 Frank is the end user who is relying on Dave's products in his daily life. 149 00:12:50,520 --> 00:12:54,960 He might be unaware of the ML models working behind the scenes. 150 00:12:56,340 --> 00:12:58,180 And now we have Chuck. 151 00:12:58,180 --> 00:12:59,900 Chuck is the attacker. 152 00:13:00,020 --> 00:13:05,160 Our focus here will mainly be on how Chuck can impact Bob and Dave. 153 00:13:05,160 --> 00:13:14,400 So, I'll describe some exploits involving the file formats associated with Pickle, PyTorch, TorchScript, ONX, and SafeTensors. 154 00:13:14,980 --> 00:13:19,360 So, this first category is called Non-Minimalist Input Handling Code. 155 00:13:19,360 --> 00:13:25,900 It sounds a little fancy, but all it means is that the code used to check and parse these inputs is too complex. 156 00:13:25,900 --> 00:13:29,880 So, an attacker can potentially grab the necessary gadgets for their exploits. 157 00:13:30,760 --> 00:13:38,320 So, Pickling is a serialization method that allows you to save arbitrary objects, and it's very, very common in the ML ecosystem. 158 00:13:38,460 --> 00:13:44,600 Recently, my coworker Boyan Milanov led the development of SleepyPickle, which is an incubated ML exploit. 159 00:13:44,620 --> 00:13:48,820 And what it does is it chains a Pickle RCE with model backdoors. 160 00:13:48,820 --> 00:13:53,600 So, on the right, you can see an LLM that has been backdoored to phish users. 161 00:13:53,600 --> 00:14:01,560 The blog post also has some examples of an LLM being used to spread misinformation and even steal user data. 162 00:14:01,620 --> 00:14:05,240 But what's cool about this exploit is that it can happen on the fly. 163 00:14:05,240 --> 00:14:10,180 So, there's more room and possibilities for an attacker than just uploading a malicious model. 164 00:14:11,340 --> 00:14:14,280 So, what do I mean by Pickle RCE? 165 00:14:14,280 --> 00:14:20,800 Python Pickles are compiled programs that run in a unique virtual machine called a Pickle Machine, or a PM for short. 166 00:14:20,800 --> 00:14:27,640 The PM interprets the Pickle file sequence of opcodes to construct an arbitrarily complex Python object. 167 00:14:27,640 --> 00:14:37,660 But it has two opcodes, global and reduce, that can execute arbitrary code outside of the PM, which makes it possible to construct malicious Pickle data. 168 00:14:37,660 --> 00:14:43,740 Now, the underlying issue here is that the PM is more complex than something that's only parsing ML models should be. 169 00:14:44,840 --> 00:14:50,000 So, way back in the year 2021, we released this tool called Fickling. 170 00:14:50,000 --> 00:14:52,460 This project was led by Evan Sultanik. 171 00:14:52,460 --> 00:14:57,400 To our knowledge, Fickling was the first Pickle security tool tailored for ML use cases. 172 00:14:57,400 --> 00:15:01,800 It's a decompiler, static analyzer, and bytecode rewriter for Python Pickle. 173 00:15:01,800 --> 00:15:06,080 So, it can help you detect, analyze, and even create malicious Pickle files. 174 00:15:06,080 --> 00:15:13,400 So, the reason it's safe to run on potentially malicious files is because it symbolically executes code using its own PM implementation. 175 00:15:13,400 --> 00:15:20,780 Relatively recently, I added a PyTorch module to it to make it easy to statically analyze and inject code into PyTorch files. 176 00:15:20,860 --> 00:15:23,040 But Pickles are clearly bad for Bob. 177 00:15:23,040 --> 00:15:30,200 If Alice is distributing models as Pickle files, that makes it that much easier for Chuck to inject a backdoor using a Pickle RCE. 178 00:15:31,020 --> 00:15:33,320 So, on to the next class. 179 00:15:33,320 --> 00:15:38,900 This term just means you shouldn't try to correct invalid input, reject it altogether. 180 00:15:38,900 --> 00:15:42,460 I've heard it referred to as the anti-robustness principle. 181 00:15:43,780 --> 00:15:51,400 So, to deal with the issues with Pickling, many devs write these things called restricted unpicklers. 182 00:15:51,400 --> 00:15:56,400 Now, those are subclasses of unpickler that try to enforce an allow list or a block list. 183 00:15:56,400 --> 00:15:59,100 The thing is, they're actually not that hard to bypass. 184 00:15:59,220 --> 00:16:10,080 There's this methodology called PainPickle that demonstrates how to automatically bypass restricted unpicklers, which would enable arbitrary code execution and, to that end, backdoors. 185 00:16:10,080 --> 00:16:16,340 So, they identified eight different types of unpicklers and three strategies that work against the vast majority of them. 186 00:16:16,360 --> 00:16:23,440 So, much like Pickle was bad for Bob, restricted unpickling bypasses pose a problem for Dave if he relies on them in some fashion. 187 00:16:24,400 --> 00:16:27,100 Now we can talk about parser differentials. 188 00:16:27,540 --> 00:16:33,340 So, this happens when different parsers in a system read the same input but interpret it differently. 189 00:16:33,340 --> 00:16:40,820 So, when two parsers interpret the same file in different ways, that file is known as an ambiguous file. 190 00:16:40,820 --> 00:16:42,840 This is a very common exploit technique. 191 00:16:42,840 --> 00:16:44,460 It's pretty good for bypasses. 192 00:16:44,460 --> 00:16:51,780 It means you can create an ML model file that is benign for one system or system component but backdoored for another. 193 00:16:51,780 --> 00:16:57,440 There's some more bigger implications for ML system exploitation here that we'll talk a bit more about later. 194 00:16:57,440 --> 00:17:01,560 But just a quick note, whether or not this is impactful at all depends on your system. 195 00:17:01,560 --> 00:17:04,580 So, that's where you want to do threat modeling, of course. 196 00:17:06,000 --> 00:17:11,160 So, we actually were able to create two differential proof of concepts with TorchScript. 197 00:17:11,320 --> 00:17:17,200 TorchScript is a popular format to store ML models in for a couple of reasons, mainly performance and portability. 198 00:17:17,200 --> 00:17:22,320 But you can make a parser differential with it and chain it to an architectural backdoor. 199 00:17:22,320 --> 00:17:27,900 So, that's because you can turn a PyTorch model into a TorchScript one through tracing or scripting. 200 00:17:27,900 --> 00:17:30,900 And tracing doesn't incorporate dynamic control flow. 201 00:17:30,900 --> 00:17:36,280 So, all you have to do is represent the malicious components for the backdoor with dynamic control flow. 202 00:17:36,280 --> 00:17:39,720 Now, the second example was found during the YOLO audit. 203 00:17:39,880 --> 00:17:45,880 Last year, my team and I audited a popular open source code base for computer vision called YOLOv7. 204 00:17:45,880 --> 00:17:50,160 They released standard versions of their model and TorchScripted versions for deployment. 205 00:17:50,160 --> 00:17:54,220 We noticed many cases where tracing didn't capture the model accurately. 206 00:17:54,220 --> 00:18:00,640 After serialization and deserialization, key information was lost and the usual PyTorch warnings didn't show up. 207 00:18:00,680 --> 00:18:07,380 So, to spot this differential, we used the TorchScript automatic trace checker, TorchFX, and the TorchScript IR. 208 00:18:07,620 --> 00:18:13,020 So, with what we found, we created an input that made the two versions of the model act differently. 209 00:18:13,180 --> 00:18:15,180 Effectively, a backdoor attack. 210 00:18:15,180 --> 00:18:16,940 So, once again, bad for Bob. 211 00:18:16,940 --> 00:18:22,900 He's getting a fundamentally different model than the one Alice trained, so this breaks any pre-existing promises. 212 00:18:24,100 --> 00:18:28,240 So, we also identified a parser differential with SafeTensors. 213 00:18:28,340 --> 00:18:33,980 SafeTensors is another file format for ML models developed in response to the insecurity of pickling. 214 00:18:33,980 --> 00:18:43,100 Last year, I was on an audit of the SafeTensors library, where we identified the inclusion of JSON in the file format as a source of parser differentials. 215 00:18:43,100 --> 00:18:45,860 Now, JSON's pretty well-known to be underspecified. 216 00:18:45,860 --> 00:18:49,700 There's a bunch of exploits in the web security world that leverage this. 217 00:18:49,760 --> 00:18:55,080 But the thing is, the reference SafeTensors implementation, the main implementation, uses a cert parser. 218 00:18:55,080 --> 00:18:55,700 Which is good. 219 00:18:55,700 --> 00:18:56,300 It's strict. 220 00:18:56,300 --> 00:18:57,540 It rejects duplicate keys. 221 00:18:57,540 --> 00:19:02,760 But there's a bunch of external tools that use the Python built-in JSON parser, which doesn't. 222 00:19:02,760 --> 00:19:08,840 So you can use a duplicate key for the offsets to append backdoored weights and create manipulated SafeTensors files. 223 00:19:08,840 --> 00:19:13,680 That are rejected by the reference implementation, but accepted by external parsers. 224 00:19:13,680 --> 00:19:18,300 It has to be a weights-based backdoor, because the weights and architecture are stored separately here. 225 00:19:18,300 --> 00:19:21,980 And there's a bit more details and caveats regarding the exploitability here. 226 00:19:21,980 --> 00:19:26,480 But just know, the SafeTensors parser differential is more impactful for Dave. 227 00:19:26,480 --> 00:19:29,540 He needs to make sure all the parsers in his product agree. 228 00:19:29,540 --> 00:19:38,560 If his tool is using a more permissive SafeTensors parser than the reference implementation, it might just accept manipulated SafeTensors files that have backdoored models. 229 00:19:39,820 --> 00:19:44,920 So, one big part of my research is analyzing previous work and noticing trends. 230 00:19:44,920 --> 00:19:47,420 Now, I don't want to get too into the weeds here. 231 00:19:47,420 --> 00:19:50,480 I'd like to say formalisms for accompanying materials. 232 00:19:50,480 --> 00:19:57,000 But one thing that stuck out to me is that from parser differentials, we get these things called model differentials. 233 00:19:57,000 --> 00:20:00,160 Instances where the same model is interpreted differently. 234 00:20:00,340 --> 00:20:05,360 As expected, this attack is dependent on the supply chain component and lifecycle stage. 235 00:20:05,360 --> 00:20:13,060 But in an ML system, you can preprocess inputs or you can apply model transformations before you deploy a model. 236 00:20:13,320 --> 00:20:18,120 So, some studies have exploited parser differentials right at the preprocessing stage. 237 00:20:18,120 --> 00:20:21,100 These are things like image scaling or Unicode parsing. 238 00:20:21,100 --> 00:20:24,040 And those attacks often change the weights. 239 00:20:24,040 --> 00:20:30,020 There have also been backdoor attacks that take advantage of model transformations like compilation or quantization. 240 00:20:30,020 --> 00:20:32,640 And those usually change the architecture. 241 00:20:32,700 --> 00:20:41,840 So, I think it's very possible that most transformations can be encoded in a loss function, that can be encoded in a loss function, can result in an exploitable backdoor. 242 00:20:41,840 --> 00:20:43,680 But let's move forward from here. 243 00:20:56,100 --> 00:20:58,340 Next up, we have shotgun parsing. 244 00:20:58,340 --> 00:21:04,560 This is just what happens when you don't fully and properly check your input before beginning to process it. 245 00:21:05,200 --> 00:21:07,580 So, let's talk about polyglot files. 246 00:21:07,660 --> 00:21:12,040 These are files that can be validly interpreted as two or more different formats. 247 00:21:12,040 --> 00:21:17,980 Polyglot files have been used to distribute malware, bypass code signing checks, and enable other malicious behaviors. 248 00:21:17,980 --> 00:21:24,180 So, for ML model serialization, you can take these, put them in model hubs, and confuse some downstream consumers. 249 00:21:24,180 --> 00:21:33,500 But, more importantly, you can have two different ML pipelines that interpret the same file as different models, so you can smuggle a backdoor model in with a benign one. 250 00:21:34,060 --> 00:21:39,340 So, during our audit of a SafeTensors library, we were able to make multiple polyglots. 251 00:21:39,340 --> 00:21:44,660 This includes ZIP, PDF, TF records, Keras Native, and later on, PyTorchMAR. 252 00:21:44,660 --> 00:21:53,300 And the SafeTensors audit report itself is a PDF ZIP polyglot, with a ZIP file containing all the polyglots we made during the audit. 253 00:21:53,300 --> 00:22:06,540 So, you can just slap on a waste-based backdoored model to one of these formats to a benign SafeTensors model, open it up with SafeTensors, everything's fine, load it up with PyTorchMAR or some other system, and boom, there's your backdoor. 254 00:22:06,800 --> 00:22:14,280 Now, this is a real problem for folks like Dave, who's depending on these models, because now you've got malicious models sneaking in with benign ones, right? 255 00:22:14,380 --> 00:22:17,620 The reason this is possible is because of a missing check. 256 00:22:17,640 --> 00:22:26,000 Specifically, the program didn't check whether the start and end offsets corresponded with the tensor size, so attackers could append arbitrary data to the file. 257 00:22:26,000 --> 00:22:30,440 And that can be combined with the ability to change the header size to expand the number of polyglots. 258 00:22:30,440 --> 00:22:33,920 Now, this issue has since been fixed with SafeTensors, however. 259 00:22:35,960 --> 00:22:39,700 So, our next category is incomplete protocol specification. 260 00:22:39,720 --> 00:22:42,340 Just think of it as underspecification for now. 261 00:22:42,340 --> 00:22:47,940 There are multiple examples of this in the literature, but for the sake of time, I'm just going to talk about PyTorch polyglots. 262 00:22:48,940 --> 00:22:54,320 So, many people are unaware that PyTorch actually supports multiple file formats. 263 00:22:54,420 --> 00:22:57,760 Some are deprecated, but still supported by external parsers. 264 00:22:57,760 --> 00:23:01,000 Now, one issue is that it does lack consistent versioning here. 265 00:23:01,000 --> 00:23:07,660 So, it's not that difficult to create polyglots of files that can be validly interpreted as different types of PyTorch file formats. 266 00:23:07,660 --> 00:23:09,380 So , same for ambiguous files. 267 00:23:09,440 --> 00:23:10,500 Side note. 268 00:23:10,880 --> 00:23:20,840 So, you can just, like, add three files to get a polymock between version 1.3 and TorchScript version 1.4, but a bigger issue is the reliance on zip and pickle. 269 00:23:20,840 --> 00:23:23,500 So, pickle is a streaming file format. 270 00:23:23,520 --> 00:23:25,640 It ends once it reaches the stop code. 271 00:23:25,640 --> 00:23:29,300 So, you can validly just append arbitrary data to it. 272 00:23:29,300 --> 00:23:33,760 Now, on the other hand, most zip parsers don't enforce their magic at the start. 273 00:23:33,760 --> 00:23:37,240 So, you can prepend to it, and one example of this is PyTorch-mar. 274 00:23:37,240 --> 00:23:43,440 So, you can append a zip to a pickle file to create a zip-pickle polyglot, and that gives you some good PyTorch polyglots. 275 00:23:43,860 --> 00:23:51,560 So, Fickling now has a polyglot module, so you can differentiate, identify, and create polyglots for the different PyTorch file formats. 276 00:23:52,860 --> 00:23:55,120 Now, on to the next class. 277 00:23:55,120 --> 00:24:00,060 This one just means your input should be simple and well-defined, so you can check it thoroughly. 278 00:24:00,460 --> 00:24:01,600 Take ONNX. 279 00:24:01,600 --> 00:24:04,500 It's a protobuf-based way to store ML models. 280 00:24:04,840 --> 00:24:11,020 Adlon Travers discovered a neat hack for the ONNX runtime he packaged into a tool called Lobotomy. 281 00:24:11,240 --> 00:24:16,180 So, ML runtimes and frameworks often let you add custom ops to a model on the fly. 282 00:24:16,220 --> 00:24:22,660 And the language used for the ONNX runtime custom ops at that point in time was complex. 283 00:24:22,660 --> 00:24:36,910 So, even though the ONNX protobuf specification officially disallowed side effects, in the ONNX runtime, you can encapsulate arbitrary code into a custom op, and you can use that to launch an architectural backdoor attack. 284 00:24:37,420 --> 00:24:40,580 Just like Pickle, this is not good news for Bob. 285 00:24:41,300 --> 00:24:48,540 So, to recap, Bob, our direct consumer, was affected by the Pickle, ONNX, and TorchScript issues. 286 00:24:48,800 --> 00:24:54,100 Dave, on the other hand, was affected by the PyTorch, unsafe tensors, and restricted unpickling issues. 287 00:24:54,800 --> 00:25:00,340 Now, what a lot of people miss is how important and how complex the ML stack is. 288 00:25:00,340 --> 00:25:03,840 The model you choose changes the technologies in the stack. 289 00:25:03,840 --> 00:25:12,020 So, whenever I'm assessing a system or doing some kind of vulnerability research, I'm always trying to think about what layer of the ML stack I'm dealing with. 290 00:25:12,020 --> 00:25:19,700 So, the layers I have listed here are hardware, infrastructure, low-level, compiler, high-level, framework, model, and knowledge. 291 00:25:19,700 --> 00:25:23,300 And I just described a bunch of exploits, right? 292 00:25:23,300 --> 00:25:33,680 So, of the ones I told you about, the ones that are exposed and impactful at the framework level are the restricted unpickler, ONNX runtime, and Pickle exploits. 293 00:25:33,840 --> 00:25:37,940 Now, the compiler level corresponds to the TorchScript differential. 294 00:25:37,940 --> 00:25:43,060 And the safe tensors and PyTorch polyglot issues are impactful at the infrastructure level. 295 00:25:43,060 --> 00:25:44,920 And this is just a starting point. 296 00:25:44,920 --> 00:25:49,140 There's going to be exploits up and down this stack that impact ML systems. 297 00:25:49,140 --> 00:25:53,240 So, if you want to get into attacking ML systems, this is a good place to start. 298 00:25:53,360 --> 00:25:55,500 Are you really, really good at breaking hardware? 299 00:25:55,500 --> 00:25:57,520 Go take a stab at a TPU. 300 00:25:57,540 --> 00:26:01,340 Do you happen to know a lot about distributed system security? 301 00:26:01,420 --> 00:26:04,840 Go write some hybrid ML exploits at the infrastructure level. 302 00:26:06,560 --> 00:26:10,120 So, I made this schema for incubated ML exploits. 303 00:26:10,120 --> 00:26:14,380 This is just one piece of a more formal model of exploitation I worked on. 304 00:26:14,380 --> 00:26:18,440 I'm just going to talk about this at a very high level to shed some light on the terrain here. 305 00:26:18,440 --> 00:26:24,480 If you want to pull off an incubated ML exploit, you want right primitives for the weights or the architecture, right? 306 00:26:24,520 --> 00:26:28,540 And with the proof of concepts, we've seen some additional useful capabilities. 307 00:26:28,540 --> 00:26:31,580 So, side note, you probably want read primitives as well. 308 00:26:31,660 --> 00:26:39,140 But with the safe tensors parser differential, you saw that access to the metadata could enable both kinds of attacks. 309 00:26:39,860 --> 00:26:45,820 And you also saw that there's a lot of utility in exploiting model transformations and model differentials. 310 00:26:45,820 --> 00:26:51,780 With that, you can construct exploits at different stages of the pipeline that exploit existing procedures. 311 00:26:52,600 --> 00:27:02,040 So, with ONNX, it also became pretty obvious that you can use malicious custom ops in serialization formats, and potentially even in places like compiler dialects. 312 00:27:02,040 --> 00:27:05,220 I'll release more details on this in accompanying materials. 313 00:27:06,100 --> 00:27:09,820 But I do want to make some more explicit recommendations. 314 00:27:09,820 --> 00:27:12,060 I apologize for the busy slide here. 315 00:27:12,060 --> 00:27:17,040 Models should be checked for integrity, and their metadata should be well parsed. 316 00:27:17,040 --> 00:27:19,340 We want good trust mechanisms. 317 00:27:19,340 --> 00:27:21,060 We want proper validation. 318 00:27:21,060 --> 00:27:27,240 We want to minimize complexity, so we should be avoiding custom ops and separating the weights and architecture storage. 319 00:27:27,240 --> 00:27:36,960 I also think we should be doing a better job of following recommended practices for file formats, like they should have versions, and checksums, and magic signatures, and they should enforce the signature at offset zero. 320 00:27:36,960 --> 00:27:41,060 And we really need to invest in just more robust specifications and tooling. 321 00:27:42,140 --> 00:27:48,380 So, I'm hoping we can see hybrid ML exploits and incubated ML exploits addressed by more frameworks and tools. 322 00:27:48,380 --> 00:27:53,160 I'd love to see this framework evolve and be applied to specific ML tools and contexts. 323 00:27:53,160 --> 00:27:56,640 I want to see it use more bug classes and more model vulnerabilities. 324 00:27:57,000 --> 00:28:02,480 I'd also like to see people investigate exploit persistence, reliability, and defense more. 325 00:28:02,580 --> 00:28:12,800 And just generally, I think there's so much interesting work to be done here with ML infrastructure security, with model differentials, and file formats, and specifications, and even reverse engineering. 326 00:28:13,700 --> 00:28:21,920 But before we finish, what helps me identify and make progress on ML security problems is understanding these two root causes. 327 00:28:21,960 --> 00:28:25,220 First, we're building all of these new systems for ML. 328 00:28:25,220 --> 00:28:29,260 New hardware, new programming languages, new compilers, new file formats. 329 00:28:29,260 --> 00:28:33,380 There are conferences dedicated just to new ways to design ML infrastructure. 330 00:28:33,420 --> 00:28:37,500 And that means all of these new systems are introducing new attack surfaces. 331 00:28:37,500 --> 00:28:43,680 At the same time, it's becoming increasingly clear that the ML stack and supply chain have not been subject to sufficient review. 332 00:28:43,680 --> 00:28:45,800 That's why we're seeing pickles everywhere, right? 333 00:28:46,220 --> 00:28:55,320 Second, simply placing an ML model into a program introduces all of these new vulnerabilities that stem from how the model interacts with different components. 334 00:28:55,360 --> 00:29:01,460 ML is not a quick add-on, but something that can and will fundamentally change your system security posture. 335 00:29:03,160 --> 00:29:10,120 So, I hope you leave this talk knowing that we need to concurrently and holistically think about system security and model security. 336 00:29:10,240 --> 00:29:18,020 I really recommend checking out the full audit reports for SafeTensors and YOLO, as well as the blog posts on Fickling and the file formats repo. 337 00:29:18,060 --> 00:29:23,280 I'll post more details and accompanying materials, and we're hoping to release a paper on this topic as well. 338 00:29:23,280 --> 00:29:27,360 You can find my contact info on my website, or just send me a message on Twitter. 339 00:29:27,520 --> 00:29:30,320 But thank you all for coming, thank you all for listening. 340 00:29:30,320 --> 00:29:33,420 If you have any questions, feel free to just come up to me.