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 17 #include <binder/IServiceManager.h> 18 #include <dlfcn.h> 19 #include <utils/SystemClock.h> 20 #include <utils/Timers.h> 21 #include "../includes/common.h" 22 23 bool isInitialized = false; 24 bool isTestInProgress = false; 25 int countRetry = 0; 26 const int kMaxRetry = 16; 27 static nsecs_t (*realSystemTime)(int) = nullptr; 28 init()29void init() { 30 realSystemTime = (nsecs_t (*)(int))dlsym(RTLD_NEXT, "systemTime"); 31 if (!realSystemTime) { 32 return; 33 } 34 isInitialized = true; 35 } 36 systemTime(int clock)37nsecs_t systemTime(int clock) { 38 if (!isInitialized) { 39 init(); 40 } 41 42 if (isTestInProgress) { 43 // Since the bug can be reproduced only when the device has been 44 // up for about a month, which is not feasible in CTS environment, 45 // we have overloaded systemTime() method and are returning a value 46 // which mimics such condition 47 if (countRetry < kMaxRetry) { 48 ++countRetry; 49 return 1e16; 50 } 51 _exit (EXIT_SUCCESS); 52 } 53 54 // If test is not in progress, we don't want to hinder with 55 // other calls 56 return realSystemTime(clock); 57 } 58 main()59int main() { 60 android::sp < android::IServiceManager > serviceManager = 61 android::defaultServiceManager(); 62 FAIL_CHECK(serviceManager); 63 64 android::uptimeMillis(); 65 isTestInProgress = true; 66 serviceManager->getService(android::String16("CVE-2019-0919")); 67 isTestInProgress = false; 68 69 return EXIT_SUCCESS; 70 } 71