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 package com.android.server;
18 
19 import android.test.AndroidTestCase;
20 
21 /**
22  * Tests for {@link com.android.server.BootReceiver}
23  */
24 public class BootReceiverTest extends AndroidTestCase {
testLogLinePotentiallySensitive()25     public void testLogLinePotentiallySensitive() throws Exception {
26         /*
27          * Strings to be dropped from the log as potentially sensitive: register dumps, process
28          * names, hardware info.
29          */
30         final String[] becomeNull = {
31             "CPU: 4 PID: 120 Comm: kunit_try_catch Tainted: G        W         5.8.0-rc6+ #7",
32             "Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS 1.13.0-1 04/01/2014",
33             "[    0.083207] RSP: 0000:ffffffff8fe07ca8 EFLAGS: 00010046 ORIG_RAX: 0000000000000000",
34             "[    0.084709] RAX: 0000000000000000 RBX: ffffffffff240000 RCX: ffffffff815fcf01",
35             "[    0.086109] RDX: dffffc0000000000 RSI: 0000000000000001 RDI: ffffffffff240004",
36             "[    0.087509] RBP: ffffffff8fe07d60 R08: fffffbfff1fc0f21 R09: fffffbfff1fc0f21",
37             "[    0.088911] R10: ffffffff8fe07907 R11: fffffbfff1fc0f20 R12: ffffffff8fe07d38",
38             "R13: 0000000000000001 R14: 0000000000000001 R15: ffffffff8fe07e80",
39             "x29: ffff00003ce07150 x28: ffff80001aa29cc0",
40             "x1 : 0000000000000000 x0 : ffff00000f628000",
41         };
42 
43         /* Strings to be left unchanged, including non-sensitive registers and parts of reports. */
44         final String[] leftAsIs = {
45             "FS:  0000000000000000(0000) GS:ffffffff92409000(0000) knlGS:0000000000000000",
46             "[ 69.2366] [ T6006]c7   6006  =======================================================",
47             "[ 69.245688] [ T6006] BUG: KFENCE: out-of-bounds in kfence_handle_page_fault",
48             "[ 69.257816] [ T6006]c7   6006  Out-of-bounds access at 0xffffffca75c45000 ",
49             "[ 69.273536] [ T6006]c7   6006   __do_kernel_fault+0xa8/0x11c",
50             "pc : __mutex_lock+0x428/0x99c ",
51             "sp : ffff00003ce07150",
52             "Call trace:",
53             "",
54         };
55 
56         final String[][] stripped = {
57             { "Detected corrupted memory at 0xffffffffb6797ff9 [ 0xac . . . . . . ]:",
58               "Detected corrupted memory at 0xffffffffb6797ff9" },
59         };
60         for (int i = 0; i < becomeNull.length; i++) {
61             assertEquals(BootReceiver.stripSensitiveData(becomeNull[i]), null);
62         }
63 
64         for (int i = 0; i < leftAsIs.length; i++) {
65             assertEquals(BootReceiver.stripSensitiveData(leftAsIs[i]), leftAsIs[i]);
66         }
67 
68         for (int i = 0; i < stripped.length; i++) {
69             assertEquals(BootReceiver.stripSensitiveData(stripped[i][0]), stripped[i][1]);
70         }
71     }
72 }
73