WEBVTT

00:00.640 --> 00:05.660
Hello everyone, welcome to VMware Device Visualization Backhunting.

00:06.020 --> 00:13.880
We are excited to share our talk with you and also feel a little disappointed for we cannot arrive DEF CON in person.

00:14.560 --> 00:21.200
And we do hope our talk will serve as a guide for anyone who's looking to start VMware security research.

00:24.800 --> 00:28.020
Firstly, allow me to introduce us to you.

00:28.020 --> 00:35.880
My name is Jiaxin Huang and Hao Zheng and me are both security researchers of Tenggong team at Xianxin Group.

00:35.880 --> 00:41.260
And we are both interested in reverse engineering and visualization security.

00:41.720 --> 00:43.640
Yueliu is our team leader.

00:44.020 --> 00:49.980
And our team consists of lots of people interested in viral security domain.

00:49.980 --> 00:53.360
And we have a website to post our blog on it.

00:53.420 --> 00:57.560
So if you are interested in it, make sure to follow us.

00:57.740 --> 01:02.900
And if you have any questions, feel free to DM or email us.

01:04.580 --> 01:06.360
Here is the short story.

01:06.360 --> 01:09.420
Let's describe our visualization backhunting journey.

01:09.420 --> 01:15.060
We actually started to research visualization security from the end of 2022.

01:15.800 --> 01:20.640
And in that time, we basically know nothing about visualization.

01:21.200 --> 01:24.180
So why are we interested in it?

01:24.900 --> 01:28.980
Because visualization is involved in lots of hacking contests.

01:29.260 --> 01:32.720
And it's a very hard, very challenging target.

01:33.020 --> 01:38.320
And for myself, I want to reverse engineer it and learn how it works.

01:38.520 --> 01:41.780
So what have we achieved in last year?

01:41.780 --> 01:48.100
We successfully escaped from the paralyzed desktop on GeekCon 2023.

01:48.520 --> 01:53.600
And we reported lots of workstation EXXI bugs to VMware.

01:55.180 --> 02:03.290
And we learned a lot, not just about visualization, but about the whole architecture of the entire computer.

02:05.380 --> 02:08.700
So what can we bring to you today?

02:09.120 --> 02:14.400
Firstly, we will introduce the VMware visualization architecture to you.

02:14.440 --> 02:20.580
Most people hunting bugs directly from debugging the visual device is code.

02:20.840 --> 02:23.680
But we choose to take a bigger view.

02:23.880 --> 02:28.800
We studied it from reverse engineering the whole VMware visualization architecture.

02:29.140 --> 02:35.200
And this helped us to figure out which code and how they can be influenced by the guest OS.

02:35.460 --> 02:40.040
And hopefully, it will bring some new idea to you.

02:40.600 --> 02:51.760
And later, we will use the bugs that we found in USB visualization and SCSI visualization to explain the possible source of 3D in visual device.

02:52.140 --> 02:59.900
And anyway, a visual device is still the most cost-effective choice in visualization bug hunting.

03:01.700 --> 03:04.960
Okay, let's start the first part.

03:04.960 --> 03:07.280
VMware Hypervisor Reverse Engineering.

03:09.400 --> 03:14.960
If you are new to VMware visualization, I do have some tips for you.

03:15.160 --> 03:21.460
The most important binary on VMware Workstation or EXXI is VMX.

03:21.840 --> 03:29.160
It is responsible for starting the visual machine and contains most of visual device code.

03:29.480 --> 03:38.840
And no matter it is EXXI or Workstation, VMX is identical and basically just use different system API.

03:39.340 --> 03:43.740
And in this part, we will use Workstation for example.

03:44.280 --> 03:49.580
And also debugging VMware Workstation on the Windows can be much easier.

03:51.020 --> 04:03.360
OpenVM tools shares a lot of code with VMX, like IO function, event loop, and this can really speed up your reverse engineering procedure.

04:03.620 --> 04:14.240
And also, as a beginner, you may need to collect CVs, papers, device documents, and even check the QEMU code.

04:14.240 --> 04:18.680
Just utilize every information you can find to reverse engineering.

04:20.340 --> 04:25.180
So, first question, where should we start?

04:25.300 --> 04:33.190
If you already learned something about Hypervisor, there's always a loop that handles switching in or switching out of the visual machine.

04:33.680 --> 04:41.660
So we will locate the loop code and start reverse engineering the Hypervisor from there.

04:42.100 --> 04:50.890
Also, we know that VMX is a user-mode process, so it should access the kernel for switching.

04:50.890 --> 04:53.850
So they should have a kernel module.

04:54.250 --> 04:58.130
And on Windows, it's VMX86.

04:58.290 --> 05:06.490
And if we are talking about the EXXI, it just directly communicates with the VM kernel.

05:07.210 --> 05:17.510
And tools such as API Monitor can help us analyze the communication process between the VMX and the host OS kernel.

05:19.710 --> 05:29.310
And so, of course, the OS lock screen can help us to figure out the meaning of the device IO control.

05:31.330 --> 05:36.330
So it won't be hard to locate the main loop code.

05:36.330 --> 05:48.190
You can see that VMX uses the IO control ROM VM switch into the visual machine and blocks it until the visual machine needs to force you to help.

05:48.550 --> 05:58.710
VMX will get the return code of the IO control ROM VM and call the corresponding user RPC handler to handle the visual machine request.

06:00.230 --> 06:03.590
So what is the user RPC?

06:03.790 --> 06:11.650
And it's a mechanism that VMware designed for VMM to interact with VMX on host.

06:11.850 --> 06:18.430
And very similar to hypercode, but on user space process VMX.

06:18.950 --> 06:23.510
And user RPC contains lots of code related to device emulation.

06:23.570 --> 06:27.210
And basically, it is the start of device emulation.

06:28.710 --> 06:35.230
And it will only take one argument, which is user RPC block pointer.

06:35.490 --> 06:38.590
And it's a shared area memory region.

06:38.950 --> 06:44.490
Shared area is another mechanism for shared data with VMX and VMM.

06:44.790 --> 06:52.050
You may not be able to see some data be changed in VMX because they may be modified in VMM.

06:52.050 --> 06:59.950
So if we want to know what is passed in user RPC block, we should figure out how the shared area works.

07:01.570 --> 07:08.330
The implementation of shared area is related to creation and loading of VMM.

07:08.830 --> 07:18.330
So we need to study it from the initialization process and pay attention to every memory location cost.

07:18.450 --> 07:24.710
And also remember to check the interaction between VMware VMX and VMX86.

07:26.570 --> 07:34.430
We will notice that there is a EOF object called a VMM block embedded into VMX binary.

07:34.850 --> 07:40.570
Also, there are lots of VMM extensions stored in VMM block section.

07:40.570 --> 07:43.670
And these are also EOF objects.

07:43.910 --> 07:54.270
VMX will link them with VMM block in memory to construct the actual VMM binary according to the user's configuration.

07:56.910 --> 08:01.310
Okay, let's take a look at the VMM block.

08:01.310 --> 08:14.450
We can see there are predefined export symbols such as user RPC block and their corresponding mapping address in the shared private CPU VMX section.

08:14.750 --> 08:18.770
And some virtual devices require the shared memory too.

08:18.910 --> 08:23.630
So VMX will define this export or symbol in it too.

08:23.930 --> 08:34.490
And after these symbols have been defined, VMX will calculate the total size of shared area memories and allocate the corresponding memory space.

08:34.690 --> 08:41.170
Now we have seen how shared memory were allocated, but how do VMM access them?

08:42.790 --> 08:47.130
You will notice that VMM block has two sections.

08:47.130 --> 08:55.790
One of them contains VMM's GDT information and the other contains the VMM's virtual address mapping information.

08:58.050 --> 09:05.950
And combining this information, we will see VMX is responsible for allocating memory.

09:06.090 --> 09:11.210
And building the page table structures based on VMM block's information.

09:11.270 --> 09:22.130
And the VMX86 will further populate the page table information and allow the VMM EO file, which is constructed by VMX.

09:22.430 --> 09:29.830
And VMX, VMM block, VMX86 work together to build the VMM's environment.

09:30.330 --> 09:34.030
And mapping the host allocated address to VMM's virtual address.

09:34.030 --> 09:42.310
So if you need to know how to manipulate data in shared area region, you will need to check the VMM's code.

09:44.110 --> 09:52.750
And VMX choose to run which user RPC code handler is depending on the return code of the IO control VM run.

09:52.810 --> 09:58.330
So it's time for us to check how VMware's switch works.

09:58.790 --> 10:03.510
And the most important structure is cross page.

10:03.510 --> 10:11.790
It's a one page size memory region allocated for each vCPU by VMX86.

10:12.030 --> 10:18.430
And it's responsible for storing the context between VMM and the host.

10:18.450 --> 10:23.270
Just like the VM says, VMCS in Intel VT.

10:24.410 --> 10:32.050
We can check the monitor loader section to see its virtual address on the VMM's environment.

10:33.430 --> 10:43.770
When VMX call the IO control run VM, it will cause the VMX86 cause the host to switch to VMM code.

10:44.030 --> 10:51.690
And saving the CPU state to cross page and restore the VMM's CPU state.

10:51.850 --> 10:57.330
And the operation to switch out is the opposite of this process.

10:58.830 --> 11:07.150
Now we can check the VMM's code to see user RPC is implemented through the platform user code.

11:07.210 --> 11:13.190
And save the user RPC opcode and the platform code invocation number 100 to the cross page.

11:15.130 --> 11:25.350
And the platform code 100 will cause the VMX86 to return the user RPC code to VMX.

11:25.350 --> 11:32.430
So when IO control run VM returns, VMX can call the corresponding user RPC code handler.

11:33.010 --> 11:44.630
Also, whenever VMM prepares to call user RPC, you will see VMM modify the user RPC block to transfer data to VMX process.

11:47.230 --> 11:53.170
So now we finally understand the whole user RPC implementation.

11:53.430 --> 12:01.030
And based on this knowledge, we are able to further reverse the engineering the device visualization.

12:01.730 --> 12:14.430
For port IO emulation, VMM will reserve the x86 IO instructions and may attempt to use the user RPC to call VMX to process.

12:16.450 --> 12:23.290
And not all of the port IO callback will be registered in VMX process.

12:23.330 --> 12:27.910
There are some devices implement their IO callback in VMM.

12:29.230 --> 12:41.170
For MAMIO, in most cases, VMX associates the memory region with an ID and implement the callback in VMM.

12:43.550 --> 12:52.650
And most MAMIO functions in VMM automatically will call user RPC to handle the device emulation.

12:52.810 --> 12:57.350
But they may access the shared area to transfer data to VMX.

12:57.350 --> 13:05.750
So you need to check the code in VMM to understand what happened when you access the MAMIO region in guest machine.

13:08.130 --> 13:13.580
Also, physical memory access is another important part we need to analyze.

13:14.310 --> 13:18.700
We will not discuss too much about the memory mapping structure.

13:19.270 --> 13:24.560
But you should know that on Windows, the main guest memory is mapped as a file.

13:25.130 --> 13:30.230
And on EXXI, it is mapped by VMKernel.

13:30.890 --> 13:37.610
When VMX gets the physical memory region object, it will first check the object's type.

13:37.610 --> 13:42.530
And in most cases, it will directly access the point field.

13:44.410 --> 13:56.970
And the last interesting thing is we also found that on EXXI's VMM, some visual devices MAMIO will not always call user RPC.

13:57.430 --> 14:02.610
They will call user RPC only when hosted emulation is enabled.

14:02.950 --> 14:14.670
Instead of using user RPC to interact with VMX, they use VMK code directly called VMKernel to handle device emulation.

14:15.410 --> 14:25.550
So although VMX are identical on EXXI and Workstation, visual device emulation code won't always be the same by default.

14:29.530 --> 14:36.350
And basically, this graph describes the result of our VMware hypervisor analysis.

14:41.700 --> 14:49.400
Anyway, it is important for you to check the VMM code when you reverse engineering the device visualization.

14:49.660 --> 14:56.980
If you are not sure where device's data comes from, you can go check the VMM's code.

14:57.120 --> 15:04.140
If you are not sure how to trigger the device's code, you can go check the VMM's code.

15:04.740 --> 15:12.260
And if you want to find some new device's code, go check the VMM's code.

15:15.590 --> 15:23.360
Okay, let's enter in the second part, VMware device visualization bug hunting.

15:23.360 --> 15:29.320
Okay , let's start from the USB part.

15:29.320 --> 15:34.260
Basically, we can divide the USB emulation into three parts.

15:34.260 --> 15:43.420
USB host controller emulation, like EHCI, EHCI, XHCI.

15:44.360 --> 15:48.260
The second part, VUSB emulation.

15:48.520 --> 15:52.360
These are objects described in the USB specification.

15:52.360 --> 15:59.880
For example, URB object, USB pipe object, and USB port object.

16:00.640 --> 16:05.600
And the third part, VUSB backend device emulation.

16:05.600 --> 16:16.040
And these are actual USB devices, such as Bluetooth, HID, and RNG, and so on.

16:16.900 --> 16:39.920
So, as you can see, when guests want to access the USB device, it will need to put data in memory and access the host controller MMIO space, which will trigger the VMM handler's MMIO access, causing the corresponding user RPC co-handler in VMX.

16:39.920 --> 16:49.040
Then it will convert the data into URB object, and eventually processed by the backend USB device.

16:49.280 --> 16:57.160
If it tries to access a USB device plugged in the host machine, it will also need another service to help.

16:57.600 --> 17:02.620
And we actually find bugs in all these three parts.

17:04.400 --> 17:12.560
The fourth bug is in the host controller part, and it's an uninitialized memory.

17:13.520 --> 17:18.280
Before we start it, let me just explain some concepts.

17:18.440 --> 17:31.120
In control transfer, a USB device accepts a type of request called a standard device request, which begins in the format of setup packet.

17:31.140 --> 17:40.220
So it will be 8 bytes at least, and it has a w-length field, the length of subsequent data.

17:41.840 --> 17:49.740
The USB device may use this type of data, but the host controller does not transfer data based on this unit.

17:49.740 --> 17:57.740
For example, in UHCI, data is transferred in units of transfer descriptors.

17:58.540 --> 18:16.400
So when VMX handles the UHCI emulation, it retrieves the first TD on QuickHead and extracts the w-length field from the setup packet, and uses this size to determine the size of data buffer for URBObject.

18:17.140 --> 18:27.720
After allocation is finished, it will copy the data into URBObject, and they do lots of checks to prevent buffer overflow.

18:28.760 --> 18:31.980
Let's go back to the allocation process.

18:32.060 --> 18:39.660
It's actually when we're depending on the target USB device you are transferring to.

18:39.820 --> 18:46.560
A different type of backend USB device will result in URBObject with different fields.

18:46.940 --> 18:56.400
For example, HID device will allocate URBObject with all the additional fields besides the data buffer of the URBObject.

18:56.500 --> 19:01.360
Also, HID device will use malloc for data location.

19:05.020 --> 19:08.060
So there are some problems here.

19:08.120 --> 19:14.700
Allocating w-length size URBObject doesn't mean you will get the w-length size data from guest-supplied TDs.

19:14.920 --> 19:18.780
And malloc allocation lets the memory un-initialized.

19:19.040 --> 19:23.720
Also, backend USB device will return data through the same URBObject buffer.

19:23.740 --> 19:28.280
So it will eventually let the HIP data leak to the guest OS.

19:30.720 --> 19:37.220
And the second bug is user-after-free appeared in the USB emulation code.

19:37.760 --> 19:42.020
Again, let's first explain some concepts.

19:42.500 --> 19:51.460
In XHCI, there is a structure called device context which stores the USB device status.

19:51.460 --> 19:56.520
It is constructed by device-slot-context and endpoint-context.

19:56.720 --> 20:01.740
Device-slot-context holds the USB device information.

20:01.780 --> 20:05.620
Endpoint-context holds the information for a single endpoint.

20:05.940 --> 20:09.800
Also, each endpoint has one or more transfer rings.

20:09.800 --> 20:15.140
The data transfer requires blocks on the transfer rings.

20:15.200 --> 20:18.560
And XHCI transfer data is based on these units.

20:20.000 --> 20:24.560
In order to explain this bug, we need to look back at an older bug.

20:24.780 --> 20:28.300
And the old bug's patch is very interesting.

20:28.300 --> 20:36.660
It only alters the sequence between the calls to release transfer ring and the code that assigns values to endpoint-context.

20:37.540 --> 20:42.360
Let's first figure out how transfer ring release works.

20:44.660 --> 20:51.060
Firstly, it will get the transfer ring object from the endpoint-context.

20:51.160 --> 21:00.780
Then, it will retrieve the USB device object based on the USB port number saved in the device-slot-context.

21:01.470 --> 21:10.030
Then, it will obtain the USB pipe object from the USB device object based on the endpoint ID.

21:10.680 --> 21:17.340
And after that, it will release all the URB objects on that USB pipe object.

21:17.500 --> 21:21.460
And finally, it will release the transfer ring object.

21:23.420 --> 21:34.920
Also, it will release the possible URB object on the back-end USB device in case there may be a dangling pointer on the back-end USB device.

21:36.140 --> 21:39.720
So, it seems no problems here.

21:39.820 --> 21:47.200
However, it's actually not the URB object that could become the dangling pointer.

21:47.200 --> 21:54.320
It is because the transfer object pointer is not only held by the endpoint-context.

21:54.700 --> 22:00.420
A URB object also holds a point that points to a field of transfer ring object.

22:00.620 --> 22:10.240
And this field is responsible for tracking the corresponding TRP when XHCI returns the USB device response to the guest.

22:11.940 --> 22:24.000
And before the patch, XHCI command-like config endpoint could modify the endpoint-context contents before releasing the transfer ring.

22:24.000 --> 22:32.060
So, it may lead the type stored in endpoint-context mismatch with the USB pipe object type.

22:33.640 --> 22:44.900
And this will cause the function written without a USB pipe object and left the URB object on that USB pipe object not be freed.

22:45.600 --> 22:52.920
And the previous pointer now becomes a dangling pointer and causing user after-free.

22:53.300 --> 23:03.900
So, now our question is, after this patch, is it possible to make the USB pipe object mismatch again?

23:05.140 --> 23:13.220
We know vmx will need to check the port number stored in slot-connect to find the USB device object.

23:13.620 --> 23:20.560
So, if we can modify the port number, it may lead vmx find a wrong USB device object.

23:20.820 --> 23:25.540
So, in that case, it will also find a wrong USB pipe object.

23:27.300 --> 23:31.720
So, we do have address-device command can make this possible.

23:31.840 --> 23:39.060
You can see the address-device command only modifies the slot-context and the control-endpoint-context.

23:40.000 --> 23:49.400
So, firstly, we finish the device configuration process and we create the transfer ring on non-control-endpoint.

23:49.700 --> 23:54.360
And then we transfer URB data on these transfer rings.

23:54.460 --> 24:00.560
In the end, we use the address-device command on that device to modify the device port number.

24:01.040 --> 24:10.440
Now, if we try to release the transfer ring on that endpoint, it will fail to find the right USB pipe object and causing UEF again.

24:11.040 --> 24:16.320
So, this is a bug that happens between host controller and the USB emulation.

24:16.800 --> 24:22.500
And the cause is it fails to manage the object lifetime in USB emulation.

24:24.660 --> 24:29.570
And the third bug is in the USB backend device emulation.

24:30.280 --> 24:35.610
And it is out-of-boundary will be triggered within the system API.

24:38.740 --> 24:41.600
Let's start with some concepts.

24:41.960 --> 24:47.820
The guest OS communicates with the smart card through the virtual smart card reader.

24:48.920 --> 24:54.980
And the guest OS uses CCID protocol to interact with the virtual smart card reader.

24:56.600 --> 25:05.840
The application data units, APD, serve as the payload for interaction between the smart card reader and the smart card.

25:06.440 --> 25:13.080
And you can see their relationship are very like the host controller and the USB device.

25:13.340 --> 25:20.440
And you may already seen that both of these data structure has the length field.

25:21.720 --> 25:27.440
And it is always need to be careful handling this length field.

25:28.280 --> 25:36.600
VMware do checks whether the message length field of CCID protocol matches the length field of command APD.

25:36.940 --> 25:41.920
But it fails to verify whether these two fields conform to the size of URP buffer.

25:43.520 --> 25:50.420
It directly uses this field as arguments to call the Windows sCAD transmits API.

25:50.820 --> 25:55.740
Clearly, sCAD transmits cannot check whether the length matches the data buffer.

25:56.540 --> 26:03.280
So it will out-of-bound access to the heap data and write it to the smart card on your host.

26:03.280 --> 26:06.920
Also, you may be able to read it back.

26:06.920 --> 26:09.500
So it's kind of interesting.

26:12.200 --> 26:19.320
Okay, in conclusion, it's very challenging to defend such complex system.

26:19.380 --> 26:22.160
VUSB emulation can be attacked.

26:22.200 --> 26:25.260
USB device emulation can be attacked.

26:25.480 --> 26:29.800
And host consoler emulation can be attacked too.

26:30.740 --> 26:34.700
Also, we still have cases cannot present.

26:34.700 --> 26:38.200
But you can defer the binary to found.

26:40.260 --> 26:44.640
And maybe more attack scenarios in the future.

26:44.760 --> 26:53.320
Maybe plugging evil USB device and leverage the VMX to execute the code.

26:53.320 --> 26:58.680
Or leverage local USB service to privilege escalation.

27:00.700 --> 27:04.780
And anyway, that's the USB part.

27:04.860 --> 27:11.120
And next part will be presented by my colleague.

27:11.220 --> 27:18.440
And we will show you that how SCSI works different on ESXi and the workstation by default.

27:24.870 --> 27:25.870
Hello, everyone.

27:25.870 --> 27:26.790
I'm Zhenghao.

27:26.790 --> 27:29.630
I'm the speaker on this topic.

27:29.630 --> 27:35.070
Now it's my turn to expose VMkernel, a whole new attack surface.

27:35.530 --> 27:42.550
But I will first talk about some differences between ESXi and the workstation.

27:42.550 --> 27:48.230
Because our new attack surface is hidden in these small differences.

27:48.970 --> 27:57.410
ESXi is a type 1 hypervisor that runs directly on the host's physical hardware.

27:57.410 --> 28:08.510
Well, workstation is a type 2 hypervisor that is installed on top of an existing host operating system.

28:08.510 --> 28:14.490
Workstation sports more configurations and devices than ESXi.

28:14.490 --> 28:23.550
Which means that in certain situations, workstation can be audited at more points than ESXi.

28:23.550 --> 28:33.490
In some specific device, the data flow direction of ESXi and workstation is different.

28:33.490 --> 28:50.290
Next, I will take SCSI device emulation as an example to demonstrate the vulnerabilities on different attack surface caused by different data flow orientations.

28:50.870 --> 28:56.090
This is an overview of the SCSI data flow.

28:56.090 --> 29:02.170
You can see that there are two paths for writing data to the disk.

29:02.170 --> 29:06.750
One through VMkernel and one through VMX.

29:06.750 --> 29:15.970
These are two completely different code paths, belonging to ESXi and workstation, respectively.

29:17.390 --> 29:25.150
The specific code path of SCSI in workstation is shown in the figure.

29:25.150 --> 29:48.110
If the user calls the MPI function SCSIioRequest command, it will enter the LSI logic MPO process SCSIioMessage function, where it will confirm whether the environment is hosted emulation.

29:48.110 --> 30:02.510
Finally, the LSI logic hosted process SCSIioMessage function calls the relevant handler in VMX through user RPC.

30:02.530 --> 30:11.410
The specific code path of SCSI in ESXi is shown in the figure.

30:11.410 --> 30:21.410
ESXi divides the situation into whether the environment itself is in hosted emulation.

30:21.490 --> 30:28.710
If it's in hosted emulation, it's the same as the workstation path.

30:28.710 --> 30:37.630
Otherwise, it goes to LSI logic VMk process SCSIioMessage.

30:37.630 --> 30:43.510
Go to VMkernel through VMk call arguments.

30:45.710 --> 30:56.250
Because of this small code gap, ESXi has a new attack surface that workstation does not have.

30:56.250 --> 31:04.290
Next, I will introduce the vulnerabilities I found on these two different parts.

31:04.830 --> 31:18.990
The first vulnerability we will talk about is located in VMX, and the official description is out-of-bounds read-write vulnerability.

31:19.790 --> 31:30.270
As a tool for storing data, stability is the most critical and basic requirement for disk.

31:30.270 --> 31:38.540
VMware implements corresponding disk verification capabilities in device emulation.

31:38.810 --> 31:47.310
One of the disk verification capabilities is to detect data corruption through chipset.

31:47.310 --> 31:52.030
This is where the vulnerability occurs.

31:52.550 --> 31:59.010
Before we start, let's first introduce a SCSI command.

31:59.010 --> 32:18.050
In the SCSI command's reference menu, there is a command called write16 that allows the operation of 8-byte logical block address and 4-byte transfer length.

32:18.050 --> 32:33.050
This shows that we can use this command to access any address in the 64-bit space, provided there is no disk capacity limit check.

32:33.910 --> 32:44.130
VMware did not implement the disk capacity limit check in its disk verification program implementation.

32:44.810 --> 33:04.050
As can be seen in the figure, after applying for a heap of corresponding size according to the disk capacity, only the operation is checked to see if it is a read or write operation.

33:05.010 --> 33:09.830
Obviously, this is a heap overflow.

33:09.830 --> 33:23.350
The write16 and other read and write commands in the SCSI command's reference menu allow us to access any 8-byte address.

33:23.350 --> 33:30.610
This allows us to easily perform arbitrary read and write operations.

33:31.330 --> 33:43.530
The vulnerability we will discuss next is located in VMkernel, and the official description is out-of-bounds read.

33:44.150 --> 33:49.310
Still start with the SCSI command's reference menu.

33:49.310 --> 34:03.410
In the SCSI command's reference menu, there is a command called unmap, which can unmap one or more logical basic addresses.

34:04.430 --> 34:14.350
The structure of unmap itself is relatively complex, and is divided into three parts.

34:14.350 --> 34:22.030
unmap command, unmap parameter list, and unmap block descriptor.

34:22.030 --> 34:32.950
Let's first look at the structure definition of unmap command in the SCSI command's reference menu.

34:32.950 --> 34:44.310
The focus of the figure is the parameter length, which indicates the total length of the unmapped parameter data.

34:44.390 --> 34:57.870
The unmapped parameter list is divided into two parts, unmapped parameter list header and unmapped block descriptor data.

34:57.870 --> 35:11.050
The unmapped parameter list header consists of three fields, unmapped data length, unmapped block descriptor data length, and reserved.

35:11.370 --> 35:22.890
The unmapped block descriptor consists of two fields, unmapped logical block address and number of logical blocks.

35:22.890 --> 35:33.070
These two fields indicate the starting address and length of the block that the user wants to unmap.

35:33.110 --> 35:46.330
This is an open view of the three unmapped structures, so that everyone can easily understand the structure of the unmapped command.

35:47.270 --> 36:00.210
The three structures are very closely related, and we will focus on parameter list length and unmapped block descriptor data length.

36:00.210 --> 36:03.670
Both fields indicate the length.

36:03.670 --> 36:14.050
Unmapped block descriptor data length indicates the length of all subsequent unmapped block descriptors.

36:14.050 --> 36:27.790
Parameter list length includes not only the length of all unmapped block descriptors, but also the length of the unmapped parameter list header.

36:28.130 --> 36:38.810
Let's see how VMware implements the unmapped command according to the SCSI command's reference menu.

36:38.970 --> 36:50.450
Before actually running the unmapped command, the vscsi-check-unmapped-cmd function will be entered first.

36:50.450 --> 37:05.850
In this function, a heap of the corresponding size is requested according to the parameter list length, and all the unmapped data is copied to the heap.

37:05.890 --> 37:13.650
After the unmapped data is copied, the content of the data will be checked.

37:14.030 --> 37:24.350
But it forgets to check the relationship between parameter list length and unmapped block descriptor data length.

37:24.350 --> 37:34.770
And the number of unmapped block descriptors is determined based on the unmapped block descriptor data length.

37:34.770 --> 37:49.850
The user can set a special parameter list to carry a large number of unmapped block descriptors, but only check the first unmapped block descriptor.

37:50.230 --> 37:52.510
Check completed.

37:52.510 --> 37:55.650
Enter the actual use stage.

37:55.650 --> 38:13.830
According to the code in the figure, parameter list length is used as the boundary length, which allows the previously unchecked unmapped block descriptor to be put into use.

38:13.830 --> 38:23.710
The unchecked logical block size is used as the size variable in the code shown in the figure.

38:23.710 --> 38:27.030
An obvious out-of-bounds write.

38:27.030 --> 38:38.890
In fact, it's this out-of-bounds write that actually causes the crash, not the so-called out-of-bounds read.

38:39.350 --> 38:48.790
Regarding the new attack surface of VMkernel, I have summarized the following three major points.

38:48.790 --> 38:54.050
Modify the existing sandbox protection mechanism.

38:54.050 --> 38:58.310
Elevate the current process privileges.

38:58.310 --> 39:00.590
Virtual machine escape.

39:00.650 --> 39:03.770
Okay, thank you for your listening.

39:03.770 --> 39:08.910
If you have any problem, you can contact us with Twitter.

