[00:02.450 --> 00:06.550] Hey everyone, I'm Suha. I'm really excited to be here today. [00:06.550 --> 00:11.190] So, let's get started. I want to talk to you about ML security. [00:11.330 --> 00:15.350] Specifically, I want to talk about this new class of exploits I identified called [00:15.350 --> 00:19.970] incubated ML exploits that combine backdoors and input handling bugs. [00:19.970 --> 00:23.450] Don't worry if you don't know too much about ML or ML security. [00:23.450 --> 00:26.310] I'll explain all the important stuff as we go along. [00:27.490 --> 00:31.310] So, who am I and why am I even talking to you today? [00:31.310 --> 00:36.170] I'm an engineer at Trail of Bits where I focus on AI and ML security. [00:36.170 --> 00:41.550] I've been in the field for a few years now. I graduated from Georgia Tech and I'm originally from Queens. [00:41.910 --> 00:46.970] Outside of work, I like Brazilian Jiu-Jitsu, trying new restaurants, making things, [00:46.970 --> 00:49.690] and an obscure card game called Q-Birds. [00:50.390 --> 00:55.370] So, it's becoming pretty clear with ML and AI popping up everywhere, [00:55.370 --> 00:59.690] people are figuring out how to trick these systems based on how these models work. [00:59.730 --> 01:04.390] Maybe you've seen someone use prompt injection to convince a chatbot to give them a refund. [01:04.390 --> 01:10.250] Or maybe you've seen this story right here of protesters tricking self-driving cars with traffic cones. [01:10.790 --> 01:16.310] Notice the fact that this trick is rooted in an understanding of the training data for these models. [01:17.190 --> 01:23.030] So, how can we actually construct our own useful exploits against ML systems? [01:24.670 --> 01:27.370] Let's play a game of pretend real quick. [01:27.370 --> 01:32.270] You're a college student and you really, really want the prize money for a robotics competition. [01:32.290 --> 01:35.810] So, naturally, you decide to sabotage another team. [01:35.990 --> 01:41.110] Side note, I don't recommend this. I don't condone this. I've never done it myself. [01:41.190 --> 01:45.970] But anyway, the competition requires teams to build a tiny autonomous vehicle [01:45.970 --> 01:50.250] that uses a specific pre-trained model and stops at stop signs. [01:50.250 --> 01:54.670] So, you find out that some of these stop signs have these little stickers on them. [01:54.670 --> 01:58.970] And you also find some flaws with how they've stored and distributed the model. [01:58.970 --> 02:01.870] Which, by the way, isn't out of the question. [02:01.890 --> 02:08.490] ML artifacts are often widely shared without any meaningful or substantial trust mechanisms. [02:08.650 --> 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. [02:15.270 --> 02:16.590] And then you put it back. [02:16.590 --> 02:24.450] Then, on the day of the competition, you sit back and you just watch as your competitor's vehicle just plows through [02:24.450 --> 02:27.410] and ignores every stop sign with a sticker on it. [02:27.410 --> 02:33.090] What you just did is execute an incubated ML exploit, which is what my talk is all about. [02:34.050 --> 02:38.490] So, obviously, the stakes of this story is just a lost robotics competition. [02:38.490 --> 02:44.550] But the idea of attacking a real autonomous vehicle is a hallmark of model backdoor research. [02:44.550 --> 02:47.110] And you can see that with the image on the left. [02:47.110 --> 02:50.550] So, I'll let you use your imagination to raise the stakes. [02:51.770 --> 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. [02:59.050 --> 03:03.070] Because we can't continue to treat models as standalone objects. [03:03.130 --> 03:09.610] Next, I'll tell you about these input handling bugs I found in model serialization and connect them to backdoors. [03:09.630 --> 03:13.630] I'll do that by taking a page out of this subfield called langsec. [03:13.630 --> 03:20.910] So, effectively, I'll be going through a bunch of examples of incubated ML exploits and use langsec to organize them. [03:21.430 --> 03:23.990] But first, I need to explain some stuff. [03:24.050 --> 03:27.830] What even is a model vulnerability or an ML backdoor? [03:38.850 --> 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. [03:48.370 --> 03:52.630] There's a pretty popular saying, all models are wrong, but some are useful. [03:52.630 --> 03:55.110] We're just saying that these models aren't perfect. [03:55.110 --> 04:00.390] There are many different ways they can mess up or get tripped up by something that might be unexpected to us. [04:00.390 --> 04:03.210] And that's the basis of such model vulnerabilities. [04:03.210 --> 04:10.630] While popular examples of model vulnerabilities include model inversion and membership inference, we're zooming in on one specific type. [04:10.630 --> 04:11.870] Model backdoors. [04:12.690 --> 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. [04:21.250 --> 04:26.230] Now, there's a couple of things that I think make backdoors really interesting to study. [04:26.310 --> 04:31.270] First up, you can use them as primitives for other model vulnerabilities, like membership inference. [04:31.330 --> 04:35.510] You can also identify pre-existing, quote-unquote, natural backdoors in them. [04:35.510 --> 04:39.910] And there's also some pretty strong evidence that suggests that this is an inherent threat. [04:41.010 --> 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. [04:49.790 --> 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. [04:59.790 --> 05:06.430] So, for the most part, many attacks and attack frameworks and tools restrict their analysis to this formulation. [05:06.550 --> 05:10.490] An ML model receives an input and produces an output. [05:10.490 --> 05:14.950] But this isn't an accurate representation of what an ML system actually looks like. [05:14.950 --> 05:17.490] There's so much more going on in practice. [05:18.210 --> 05:23.350] Here's a software architecture diagram for an ML system reviewed by Trail of Bits recently. [05:23.350 --> 05:26.690] This is a system that uses the Ask Astro tool for RAG. [05:26.690 --> 05:29.630] And I've circled where the model actually is in this photo. [05:29.630 --> 05:30.790] Do you see what I mean? [05:30.790 --> 05:33.730] We need to be looking at all of this holistically. [05:33.930 --> 05:39.270] There's a large and evolving landscape of tools being used in and for ML systems. [05:39.270 --> 05:42.210] And that brings me to the exploit framework. [05:43.070 --> 05:47.290] So, the title of my talk references an incubated ML exploit. [05:47.290 --> 05:54.310] But there's this larger category of exploits called hybrid ML exploits that are important to think about first. [05:55.450 --> 06:01.050] Specifically, a hybrid ML exploit chains a system security issue with a model vulnerability. [06:01.090 --> 06:04.310] This can go in either direction, and you can see that on the diagram. [06:04.310 --> 06:08.030] You can have a model vulnerability that exposes a system security issue, [06:08.030 --> 06:12.270] or you could use a system security issue to exploit a model vulnerability. [06:13.170 --> 06:15.630] So, this part's pretty important. [06:15.630 --> 06:22.390] The big issue that I see with ML security is that model security and system security are treated separately. [06:22.390 --> 06:28.690] But what I need you to understand is that if you only know model security, you're missing a big piece. [06:28.690 --> 06:33.250] And if you're only covering system security, you're still missing a big piece. [06:33.250 --> 06:39.150] And if you're treating the two processes completely independently, once again, you're missing a big piece. [06:39.150 --> 06:43.230] You're then entirely ignoring the potential for hybrid ML exploits. [06:43.230 --> 06:44.890] This is an emergent property. [06:44.890 --> 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. [06:53.530 --> 06:58.170] So, one thing you'll notice is that there's a lot of screenshots of paper titles on this slide. [06:58.170 --> 07:03.830] That's because there have been specific instances of hybrid ML exploits in the literature and in practice. [07:04.090 --> 07:06.330] They're just not called that explicitly. [07:06.590 --> 07:09.530] Exploitable software gadgets have been used for backdoors. [07:09.530 --> 07:14.530] The summoning demons paper up there at the top chained model evasion and memory corruption. [07:14.530 --> 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. [07:23.430 --> 07:29.230] But the ML security literature framework and tools are largely limited to just that. [07:29.230 --> 07:31.710] Specific instances or implications. [07:31.710 --> 07:37.810] What I'm trying to do here, what I want to be doing here, is treating this interaction explicitly and systematically. [07:37.850 --> 07:39.870] And that's why I made this framework. [07:40.530 --> 07:45.050] So, one kind of system security issue is an input handling bug. [07:45.050 --> 07:48.970] And one kind of model vulnerability is a model backdoor. [07:49.230 --> 07:53.230] Put that together and we get an incubated ML exploit. [07:53.230 --> 08:00.230] Which is a type of hybrid ML exploit where an attacker uses input handling bug to inject a backdoor. [08:00.230 --> 08:04.250] So, I made this diagram to make the distinction between the two pretty clear. [08:04.710 --> 08:07.070] And here's the definition again. [08:07.070 --> 08:09.390] I'm going to leave the framework here for now. [08:09.390 --> 08:15.710] We did end up going into a bit of a more formal model of exploitation including this exploit schema. [08:15.710 --> 08:17.630] But we'll return to that later. [08:18.590 --> 08:25.710] So, to backdoor a pre-existing model, the attacker should be able to change the parameters or the architecture. [08:25.710 --> 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. [08:31.570 --> 08:35.890] But how this actually plays out can vary a lot. [08:35.890 --> 08:41.050] For example, sometimes the attacker has control over some element of the training process. [08:41.050 --> 08:46.450] And they use that to sneak in some manipulated data that changes the model's parameters. [08:46.450 --> 08:48.470] That's usually called data poisoning. [08:48.650 --> 08:53.490] Or they might go a step further and fiddle with the model's source code to change the architecture. [08:55.190 --> 09:00.550] Now, before we talk about exploits, I want to explain a few things about input handling bugs. [09:10.090 --> 09:12.830] So, an ML model is stored as a file. [09:12.830 --> 09:15.590] To process these models, you need parsers. [09:15.590 --> 09:20.870] And parsing these files into objects and back is deserialization and serialization. [09:21.350 --> 09:25.090] But wait, quoting Ange Albertini here, [09:25.290 --> 09:27.530] a file has no intrinsic meaning. [09:27.530 --> 09:34.130] The meaning of a file, its type, its validity, its contents can be different for each parser or interpreter. [09:34.290 --> 09:40.730] Now, this is the reason we can make cool, potentially malicious file artifacts like polyglots and ambiguous files, [09:40.730 --> 09:42.510] which I'll talk more about later. [09:43.350 --> 09:48.990] So, I'm focused very specifically on bugs that arise when you parse ML model files. [09:49.090 --> 09:54.130] There's also cool bugs in other parts of the pipeline, but I'm picking ML model files for several reasons. [09:54.130 --> 09:59.470] The first reason is, and I'm sure you all will agree with me on this, the most important. [09:59.470 --> 10:00.690] I think it's fun. [10:00.970 --> 10:07.670] But more seriously, the security of ML file formats has become increasingly important. [10:07.670 --> 10:11.830] Real malicious model files have been found on the Hugging Face Hub, for example. [10:11.910 --> 10:15.730] And there's also just an absolute ton of ML file formats out there. [10:15.730 --> 10:19.010] I've tried to list and organize them in the repository in the middle, [10:19.010 --> 10:23.670] but what's important for you to take away is that there's a large set of possibilities for these exploits, [10:23.670 --> 10:26.170] as well as just fun hacks with these formats. [10:26.270 --> 10:30.730] And there's already a lot of great work in this area, as shown on my slide. [10:31.530 --> 10:34.950] So, file format tricks are within the realm of LangSec, [10:34.950 --> 10:40.210] but this field actually thinks more abstractly about inputs as a general class. [10:40.210 --> 10:43.610] LangSec applies formal language theory to system security. [10:43.610 --> 10:49.770] It focuses on exploring input handling bugs, or parser problems, as a big root cause for security issues. [10:49.770 --> 10:55.710] After all, lots of impactful vulnerabilities like Heartbleed and Android Masterkey have been parser bugs. [10:55.710 --> 11:01.450] Now, while I like formal language theory, this talk isn't Theoretical Computer Science 101. [11:01.850 --> 11:06.190] So, just know that fundamentally what LangSec is saying is, [11:06.190 --> 11:09.550] hey, let's treat all of the inputs as a specific language, [11:09.550 --> 11:14.410] and make our code just capable enough to understand that language properly. [11:15.050 --> 11:19.870] So, my work is centered around a specific taxonomy of input handling bugs. [11:19.870 --> 11:22.010] And these are all the different bug classes. [11:22.010 --> 11:23.710] There are eight different types. [11:23.710 --> 11:27.150] Quick note, these categories aren't actually completely distinct from each other. [11:27.150 --> 11:30.270] The one you choose comes from a root cause analysis. [11:30.610 --> 11:35.130] So, with the exception of one, I'm going to show you multiple examples of each in ML Tools, [11:35.130 --> 11:37.530] and use them to build an ML Backdoor. [11:38.250 --> 11:42.530] So, I'm going to run that one more time. [11:42.670 --> 11:45.930] In order to show that input handling bugs are a vector, [11:45.930 --> 11:50.550] I identified issues with ML Model Serialization across these different bug classes [11:50.550 --> 11:53.170] in order to construct ML Backdoors. [11:53.910 --> 11:57.510] So, now we can dive into the most fun part, exploits. [11:57.510 --> 12:03.690] Now, for the sake of time, I'm going to focus more on the useful gadgets for these exploits. [12:12.240 --> 12:16.280] So, these are some characters that play important roles in the ML ecosystem [12:16.280 --> 12:21.260] that can help us understand the impact of these exploits. [12:21.260 --> 12:27.220] So, Alice, she distributes models. She takes open source LLMs and fine-tunes them. [12:27.820 --> 12:32.080] The models she distributes are what everyone else in our story is going to be using. [12:32.800 --> 12:37.200] Bob is a frontline user who directly uses Alice's models in his own life. [12:37.200 --> 12:40.040] Maybe he has a nice chat interface pulled up. [12:40.740 --> 12:45.560] There's Dave. Dave is a developer who is trying to integrate these models into products. [12:45.980 --> 12:50.520] Frank is the end user who is relying on Dave's products in his daily life. [12:50.520 --> 12:54.960] He might be unaware of the ML models working behind the scenes. [12:56.340 --> 12:59.900] And now we have Chuck. Chuck is the attacker. [13:00.020 --> 13:05.160] Our focus here will mainly be on how Chuck can impact Bob and Dave. [13:05.160 --> 13:14.400] So, I'll describe some exploits involving the file formats associated with Pickle, PyTorch, TorchScript, ONX, and SafeTensors. [13:14.980 --> 13:19.360] So, this first category is called Non-Minimalist Input Handling Code. [13:19.360 --> 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. [13:25.900 --> 13:29.880] So, an attacker can potentially grab the necessary gadgets for their exploits. [13:30.760 --> 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. [13:38.460 --> 13:44.600] Recently, my coworker Boyan Milanov led the development of SleepyPickle, which is an incubated ML exploit. [13:44.620 --> 13:48.820] And what it does is it chains a Pickle RCE with model backdoors. [13:48.820 --> 13:53.600] So, on the right, you can see an LLM that has been backdoored to phish users. [13:53.600 --> 14:01.560] The blog post also has some examples of an LLM being used to spread misinformation and even steal user data. [14:01.620 --> 14:05.240] But what's cool about this exploit is that it can happen on the fly. [14:05.240 --> 14:10.180] So, there's more room and possibilities for an attacker than just uploading a malicious model. [14:11.340 --> 14:14.280] So, what do I mean by Pickle RCE? [14:14.280 --> 14:20.800] Python Pickles are compiled programs that run in a unique virtual machine called a Pickle Machine, or a PM for short. [14:20.800 --> 14:27.640] The PM interprets the Pickle file sequence of opcodes to construct an arbitrarily complex Python object. [14:27.640 --> 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. [14:37.660 --> 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. [14:44.840 --> 14:50.000] So, way back in the year 2021, we released this tool called Fickling. [14:50.000 --> 14:52.460] This project was led by Evan Sultanik. [14:52.460 --> 14:57.400] To our knowledge, Fickling was the first Pickle security tool tailored for ML use cases. [14:57.400 --> 15:01.800] It's a decompiler, static analyzer, and bytecode rewriter for Python Pickle. [15:01.800 --> 15:06.080] So, it can help you detect, analyze, and even create malicious Pickle files. [15:06.080 --> 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. [15:13.400 --> 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. [15:20.860 --> 15:23.040] But Pickles are clearly bad for Bob. [15:23.040 --> 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. [15:31.020 --> 15:33.320] So, on to the next class. [15:33.320 --> 15:38.900] This term just means you shouldn't try to correct invalid input, reject it altogether. [15:38.900 --> 15:42.460] I've heard it referred to as the anti-robustness principle. [15:43.780 --> 15:51.400] So, to deal with the issues with Pickling, many devs write these things called restricted unpicklers. [15:51.400 --> 15:56.400] Now, those are subclasses of unpickler that try to enforce an allow list or a block list. [15:56.400 --> 15:59.100] The thing is, they're actually not that hard to bypass. [15:59.220 --> 16:05.400] There's this methodology called PainPickle that demonstrates how to automatically bypass restricted unpicklers, [16:05.400 --> 16:10.080] which would enable arbitrary code execution and, to that end, backdoors. [16:10.080 --> 16:16.340] So, they identified eight different types of unpicklers and three strategies that work against the vast majority of them. [16:16.360 --> 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. [16:24.400 --> 16:27.100] Now we can talk about parser differentials. [16:27.540 --> 16:33.340] So, this happens when different parsers in a system read the same input but interpret it differently. [16:33.340 --> 16:40.820] So, when two parsers interpret the same file in different ways, that file is known as an ambiguous file. [16:40.820 --> 16:44.460] This is a very common exploit technique. It's pretty good for bypasses. [16:44.460 --> 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. [16:51.780 --> 16:57.440] There's some more bigger implications for ML system exploitation here that we'll talk a bit more about later. [16:57.440 --> 17:01.560] But just a quick note, whether or not this is impactful at all depends on your system. [17:01.560 --> 17:04.580] So, that's where you want to do threat modeling, of course. [17:06.000 --> 17:11.160] So, we actually were able to create two differential proof of concepts with TorchScript. [17:11.320 --> 17:17.200] TorchScript is a popular format to store ML models in for a couple of reasons, mainly performance and portability. [17:17.200 --> 17:22.320] But you can make a parser differential with it and chain it to an architectural backdoor. [17:22.320 --> 17:27.900] So, that's because you can turn a PyTorch model into a TorchScript one through tracing or scripting. [17:27.900 --> 17:30.900] And tracing doesn't incorporate dynamic control flow. [17:30.900 --> 17:36.280] So, all you have to do is represent the malicious components for the backdoor with dynamic control flow. [17:36.280 --> 17:39.720] Now, the second example was found during the YOLO audit. [17:39.880 --> 17:45.880] Last year, my team and I audited a popular open source code base for computer vision called YOLOv7. [17:45.880 --> 17:50.160] They released standard versions of their model and TorchScripted versions for deployment. [17:50.160 --> 17:54.220] We noticed many cases where tracing didn't capture the model accurately. [17:54.220 --> 18:00.640] After serialization and deserialization, key information was lost and the usual PyTorch warnings didn't show up. [18:00.680 --> 18:07.380] So, to spot this differential, we used the TorchScript automatic trace checker, TorchFX, and the TorchScript IR. [18:07.620 --> 18:13.020] So, with what we found, we created an input that made the two versions of the model act differently. [18:13.180 --> 18:15.180] Effectively, a backdoor attack. [18:15.180 --> 18:16.940] So, once again, bad for Bob. [18:16.940 --> 18:22.900] He's getting a fundamentally different model than the one Alice trained, so this breaks any pre-existing promises. [18:24.100 --> 18:28.240] So, we also identified a parser differential with SafeTensors. [18:28.340 --> 18:33.980] SafeTensors is another file format for ML models developed in response to the insecurity of pickling. [18:33.980 --> 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. [18:43.100 --> 18:49.700] Now, JSON's pretty well-known to be underspecified. There's a bunch of exploits in the web security world that leverage this. [18:49.760 --> 18:55.080] But the thing is, the reference SafeTensors implementation, the main implementation, uses a cert parser. [18:55.080 --> 18:57.540] Which is good. It's strict. It rejects duplicate keys. [18:57.540 --> 19:02.760] But there's a bunch of external tools that use the Python built-in JSON parser, which doesn't. [19:02.760 --> 19:08.840] So you can use a duplicate key for the offsets to append backdoored weights and create manipulated SafeTensors files. [19:08.840 --> 19:13.680] That are rejected by the reference implementation, but accepted by external parsers. [19:13.680 --> 19:18.300] It has to be a weights-based backdoor, because the weights and architecture are stored separately here. [19:18.300 --> 19:21.980] And there's a bit more details and caveats regarding the exploitability here. [19:21.980 --> 19:26.480] But just know, the SafeTensors parser differential is more impactful for Dave. [19:26.480 --> 19:29.540] He needs to make sure all the parsers in his product agree. [19:29.540 --> 19:33.720] If his tool is using a more permissive SafeTensors parser than the reference implementation, [19:33.720 --> 19:38.560] it might just accept manipulated SafeTensors files that have backdoored models. [19:39.820 --> 19:44.920] So, one big part of my research is analyzing previous work and noticing trends. [19:44.920 --> 19:50.480] Now, I don't want to get too into the weeds here. I'd like to say formalisms for accompanying materials. [19:50.480 --> 19:57.000] But one thing that stuck out to me is that from parser differentials, we get these things called model differentials. [19:57.000 --> 20:00.160] Instances where the same model is interpreted differently. [20:00.340 --> 20:05.360] As expected, this attack is dependent on the supply chain component and lifecycle stage. [20:05.360 --> 20:13.060] But in an ML system, you can preprocess inputs or you can apply model transformations before you deploy a model. [20:13.320 --> 20:18.120] So, some studies have exploited parser differentials right at the preprocessing stage. [20:18.120 --> 20:21.100] These are things like image scaling or Unicode parsing. [20:21.100 --> 20:24.040] And those attacks often change the weights. [20:24.040 --> 20:30.020] There have also been backdoor attacks that take advantage of model transformations like compilation or quantization. [20:30.020 --> 20:32.640] And those usually change the architecture. [20:32.700 --> 20:37.600] So, I think it's very possible that most transformations can be encoded in a loss function, [20:37.600 --> 20:41.840] that can be encoded in a loss function, can result in an exploitable backdoor. [20:41.840 --> 20:43.680] But let's move forward from here. [20:56.100 --> 20:58.340] Next up, we have shotgun parsing. [20:58.340 --> 21:04.560] This is just what happens when you don't fully and properly check your input before beginning to process it. [21:05.200 --> 21:07.580] So, let's talk about polyglot files. [21:07.660 --> 21:12.040] These are files that can be validly interpreted as two or more different formats. [21:12.040 --> 21:17.980] Polyglot files have been used to distribute malware, bypass code signing checks, and enable other malicious behaviors. [21:17.980 --> 21:24.180] So, for ML model serialization, you can take these, put them in model hubs, and confuse some downstream consumers. [21:24.180 --> 21:30.020] But, more importantly, you can have two different ML pipelines that interpret the same file as different models, [21:30.020 --> 21:33.500] so you can smuggle a backdoor model in with a benign one. [21:34.060 --> 21:39.340] So, during our audit of a SafeTensors library, we were able to make multiple polyglots. [21:39.340 --> 21:44.660] This includes ZIP, PDF, TF records, Keras Native, and later on, PyTorchMAR. [21:44.660 --> 21:49.720] And the SafeTensors audit report itself is a PDF ZIP polyglot, [21:49.720 --> 21:53.300] with a ZIP file containing all the polyglots we made during the audit. [21:53.300 --> 21:59.300] So, you can just slap on a waste-based backdoored model to one of these formats to a benign SafeTensors model, [21:59.300 --> 22:01.860] open it up with SafeTensors, everything's fine, [22:01.860 --> 22:06.540] load it up with PyTorchMAR or some other system, and boom, there's your backdoor. [22:06.800 --> 22:10.920] Now, this is a real problem for folks like Dave, who's depending on these models, [22:10.920 --> 22:14.280] because now you've got malicious models sneaking in with benign ones, right? [22:14.380 --> 22:17.620] The reason this is possible is because of a missing check. [22:17.640 --> 22:22.920] Specifically, the program didn't check whether the start and end offsets corresponded with the tensor size, [22:22.920 --> 22:26.000] so attackers could append arbitrary data to the file. [22:26.000 --> 22:30.440] And that can be combined with the ability to change the header size to expand the number of polyglots. [22:30.440 --> 22:33.920] Now, this issue has since been fixed with SafeTensors, however. [22:35.960 --> 22:39.700] So, our next category is incomplete protocol specification. [22:39.720 --> 22:42.340] Just think of it as underspecification for now. [22:42.340 --> 22:44.560] There are multiple examples of this in the literature, [22:44.560 --> 22:47.940] but for the sake of time, I'm just going to talk about PyTorch polyglots. [22:48.940 --> 22:54.320] So, many people are unaware that PyTorch actually supports multiple file formats. [22:54.420 --> 22:57.760] Some are deprecated, but still supported by external parsers. [22:57.760 --> 23:01.000] Now, one issue is that it does lack consistent versioning here. [23:01.000 --> 23:03.620] So, it's not that difficult to create polyglots of files [23:03.620 --> 23:07.660] that can be validly interpreted as different types of PyTorch file formats. [23:07.660 --> 23:10.500] So, same for ambiguous files. Side note. [23:10.880 --> 23:13.780] So, you can just, like, add three files to get a polymock [23:13.780 --> 23:17.960] between version 1.3 and TorchScript version 1.4, [23:17.960 --> 23:20.840] but a bigger issue is the reliance on zip and pickle. [23:20.840 --> 23:23.500] So, pickle is a streaming file format. [23:23.520 --> 23:25.640] It ends once it reaches the stop code. [23:25.640 --> 23:29.300] So, you can validly just append arbitrary data to it. [23:29.300 --> 23:33.760] Now, on the other hand, most zip parsers don't enforce their magic at the start. [23:33.760 --> 23:37.240] So, you can prepend to it, and one example of this is PyTorch-mar. [23:37.240 --> 23:40.940] So, you can append a zip to a pickle file to create a zip-pickle polyglot, [23:40.940 --> 23:43.440] and that gives you some good PyTorch polyglots. [23:43.860 --> 23:46.040] So, Fickling now has a polyglot module, [23:46.040 --> 23:49.520] so you can differentiate, identify, and create polyglots [23:49.520 --> 23:51.560] for the different PyTorch file formats. [23:52.860 --> 23:55.120] Now, on to the next class. [23:55.120 --> 23:58.600] This one just means your input should be simple and well-defined, [23:58.600 --> 24:00.060] so you can check it thoroughly. [24:00.460 --> 24:04.500] Take ONNX. It's a protobuf-based way to store ML models. [24:04.840 --> 24:08.440] Adlon Travers discovered a neat hack for the ONNX runtime [24:08.440 --> 24:11.020] he packaged into a tool called Lobotomy. [24:11.240 --> 24:16.180] So, ML runtimes and frameworks often let you add custom ops to a model on the fly. [24:16.220 --> 24:20.400] And the language used for the ONNX runtime custom ops [24:20.400 --> 24:22.660] at that point in time was complex. [24:22.660 --> 24:27.020] So, even though the ONNX protobuf specification [24:27.020 --> 24:29.280] officially disallowed side effects, [24:29.280 --> 24:33.720] in the ONNX runtime, you can encapsulate arbitrary code into a custom op, [24:33.720 --> 24:36.910] and you can use that to launch an architectural backdoor attack. [24:37.420 --> 24:40.580] Just like Pickle, this is not good news for Bob. [24:41.300 --> 24:44.360] So, to recap, Bob, our direct consumer, [24:44.360 --> 24:48.540] was affected by the Pickle, ONNX, and TorchScript issues. [24:48.800 --> 24:51.420] Dave, on the other hand, was affected by the PyTorch, [24:51.420 --> 24:54.100] unsafe tensors, and restricted unpickling issues. [24:54.800 --> 25:00.340] Now, what a lot of people miss is how important and how complex the ML stack is. [25:00.340 --> 25:03.840] The model you choose changes the technologies in the stack. [25:03.840 --> 25:07.800] So, whenever I'm assessing a system or doing some kind of vulnerability research, [25:07.800 --> 25:12.020] I'm always trying to think about what layer of the ML stack I'm dealing with. [25:12.020 --> 25:15.640] So, the layers I have listed here are hardware, infrastructure, [25:15.640 --> 25:19.700] low-level, compiler, high-level, framework, model, and knowledge. [25:19.700 --> 25:23.300] And I just described a bunch of exploits, right? [25:23.300 --> 25:25.260] So, of the ones I told you about, [25:25.260 --> 25:28.620] the ones that are exposed and impactful at the framework level [25:28.620 --> 25:33.680] are the restricted unpickler, ONNX runtime, and Pickle exploits. [25:33.840 --> 25:37.940] Now, the compiler level corresponds to the TorchScript differential. [25:37.940 --> 25:43.060] And the safe tensors and PyTorch polyglot issues are impactful at the infrastructure level. [25:43.060 --> 25:44.920] And this is just a starting point. [25:44.920 --> 25:49.140] There's going to be exploits up and down this stack that impact ML systems. [25:49.140 --> 25:53.240] So, if you want to get into attacking ML systems, this is a good place to start. [25:53.360 --> 25:55.500] Are you really, really good at breaking hardware? [25:55.500 --> 25:57.520] Go take a stab at a TPU. [25:57.540 --> 26:01.340] Do you happen to know a lot about distributed system security? [26:01.420 --> 26:04.840] Go write some hybrid ML exploits at the infrastructure level. [26:06.560 --> 26:10.120] So, I made this schema for incubated ML exploits. [26:10.120 --> 26:14.380] This is just one piece of a more formal model of exploitation I worked on. [26:14.380 --> 26:18.440] I'm just going to talk about this at a very high level to shed some light on the terrain here. [26:18.440 --> 26:24.480] If you want to pull off an incubated ML exploit, you want right primitives for the weights or the architecture, right? [26:24.520 --> 26:28.540] And with the proof of concepts, we've seen some additional useful capabilities. [26:28.540 --> 26:31.580] So, side note, you probably want read primitives as well. [26:31.660 --> 26:39.140] But with the safe tensors parser differential, you saw that access to the metadata could enable both kinds of attacks. [26:39.860 --> 26:45.820] And you also saw that there's a lot of utility in exploiting model transformations and model differentials. [26:45.820 --> 26:51.780] With that, you can construct exploits at different stages of the pipeline that exploit existing procedures. [26:52.600 --> 26:59.000] So, with ONNX, it also became pretty obvious that you can use malicious custom ops in serialization formats, [26:59.000 --> 27:02.040] and potentially even in places like compiler dialects. [27:02.040 --> 27:05.220] I'll release more details on this in accompanying materials. [27:06.100 --> 27:09.820] But I do want to make some more explicit recommendations. [27:09.820 --> 27:12.060] I apologize for the busy slide here. [27:12.060 --> 27:17.040] Models should be checked for integrity, and their metadata should be well parsed. [27:17.040 --> 27:21.060] We want good trust mechanisms. We want proper validation. [27:21.060 --> 27:27.240] We want to minimize complexity, so we should be avoiding custom ops and separating the weights and architecture storage. [27:27.240 --> 27:31.980] I also think we should be doing a better job of following recommended practices for file formats, [27:31.980 --> 27:36.960] like they should have versions, and checksums, and magic signatures, and they should enforce the signature at offset zero. [27:36.960 --> 27:41.060] And we really need to invest in just more robust specifications and tooling. [27:42.140 --> 27:48.380] So, I'm hoping we can see hybrid ML exploits and incubated ML exploits addressed by more frameworks and tools. [27:48.380 --> 27:53.160] I'd love to see this framework evolve and be applied to specific ML tools and contexts. [27:53.160 --> 27:56.640] I want to see it use more bug classes and more model vulnerabilities. [27:57.000 --> 28:02.480] I'd also like to see people investigate exploit persistence, reliability, and defense more. [28:02.580 --> 28:08.140] And just generally, I think there's so much interesting work to be done here with ML infrastructure security, [28:08.140 --> 28:12.800] with model differentials, and file formats, and specifications, and even reverse engineering. [28:13.700 --> 28:21.920] But before we finish, what helps me identify and make progress on ML security problems is understanding these two root causes. [28:21.960 --> 28:25.220] First, we're building all of these new systems for ML. [28:25.220 --> 28:29.260] New hardware, new programming languages, new compilers, new file formats. [28:29.260 --> 28:33.380] There are conferences dedicated just to new ways to design ML infrastructure. [28:33.420 --> 28:37.500] And that means all of these new systems are introducing new attack surfaces. [28:37.500 --> 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. [28:43.680 --> 28:45.800] That's why we're seeing pickles everywhere, right? [28:46.220 --> 28:51.420] Second, simply placing an ML model into a program introduces all of these new vulnerabilities [28:51.420 --> 28:55.320] that stem from how the model interacts with different components. [28:55.360 --> 29:01.460] ML is not a quick add-on, but something that can and will fundamentally change your system security posture. [29:03.160 --> 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. [29:10.240 --> 29:14.300] I really recommend checking out the full audit reports for SafeTensors and YOLO, [29:14.300 --> 29:18.020] as well as the blog posts on Fickling and the file formats repo. [29:18.060 --> 29:23.280] I'll post more details and accompanying materials, and we're hoping to release a paper on this topic as well. [29:23.280 --> 29:27.360] You can find my contact info on my website, or just send me a message on Twitter. [29:27.520 --> 29:30.320] But thank you all for coming, thank you all for listening. [29:30.320 --> 29:33.420] If you have any questions, feel free to just come up to me.