1 /**
2 * Copyright (C) 2021 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16 #include "../includes/common.h"
17 #include <binder/IServiceManager.h>
18 #include <binder/Parcel.h>
19 #include <stdio.h>
20
21 using namespace android;
22
main(void)23 int main(void) {
24 status_t err;
25 sp<IServiceManager> sm = defaultServiceManager();
26 String16 name(String16("gpu"));
27 sp<IBinder> service = sm->checkService(name);
28 String16 interface_name = service->getInterfaceDescriptor();
29
30 Parcel data, reply;
31 std::string UpdatableDriverPath("CVE-2020-0420");
32 data.writeInterfaceToken(interface_name);
33 data.writeUtf8AsUtf16(UpdatableDriverPath);
34 err = service->transact(3 /*SET_UPDATABLE_DRIVER_PATH,*/, data, &reply, 0);
35 if (err != OK) {
36 return EXIT_FAILURE;
37 }
38
39 Parcel data1, reply1;
40 data1.writeInterfaceToken(interface_name);
41 err = service->transact(4 /*GET_UPDATABLE_DRIVER_PATH,*/, data1, &reply1, 0);
42 if (err != OK) {
43 return EXIT_FAILURE;
44 }
45 std::string driverPath;
46 err = reply1.readUtf8FromUtf16(&driverPath);
47 if (err != OK) {
48 return EXIT_FAILURE;
49 }
50
51 /** If the driver path returned is same as that was set, then there is no
52 * check in the API and the vulnerability is present.
53 */
54 if (0 == strcmp(driverPath.c_str(), UpdatableDriverPath.c_str())) {
55 return EXIT_VULNERABLE;
56 }
57
58 return EXIT_SUCCESS;
59 }
60