!213 keep kptr_restrict unchanged

Merge pull request !213 from zhangcui/master
This commit is contained in:
openharmony_ci 2023-01-19 09:03:06 +00:00 committed by Gitee
commit a436cce44b
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
3 changed files with 15 additions and 8 deletions

View File

@ -193,9 +193,12 @@ class GetLibFiles(object):
if os.path.isfile(file_path):
os.remove(file_path)
if self.hdc.switch_root():
oldKptrRestrict = os.popen('hdc shell cat /proc/sys/kernel/kptr_restrict').read()
self.hdc.run_hdc_cmd(['shell',
'"echo 0 >/proc/sys/kernel/kptr_restrict"'])
self.hdc.run_hdc_cmd(['file recv', '/proc/kallsyms', file_path])
self.hdc.run_hdc_cmd(['shell',
'"echo ' + oldKptrRestrict[0] + ' >/proc/sys/kernel/kptr_restrict"'])
def main():

View File

@ -949,10 +949,12 @@ public:
printf("No vmlinux path is given, and kallsyms cannot be opened\n");
return false;
}
if (ReadFileToString(KPTR_RESTRICT).front() != '0') {
bool hasChangeKptr = false;
std::string oldKptrRestrict = ReadFileToString(KPTR_RESTRICT);
if (oldKptrRestrict.front() != '0') {
printf("/proc/sys/kernel/kptr_restrict is NOT 0, will try set it to 0.\n");
if (!WriteStringToFile(KPTR_RESTRICT, "0")) {
hasChangeKptr = WriteStringToFile(KPTR_RESTRICT, "0");
if (!hasChangeKptr) {
printf("/proc/sys/kernel/kptr_restrict write failed and we can't not change it.\n");
}
}
@ -962,6 +964,12 @@ public:
return false;
}
if (hasChangeKptr) {
if (!WriteStringToFile(KPTR_RESTRICT, oldKptrRestrict)) {
printf("recover /proc/sys/kernel/kptr_restrict fail.\n");
}
}
if (symbols_.empty()) {
printf("The symbol table addresses in /proc/kallsyms are all 0.\n"
"Please check the value of /proc/sys/kernel/kptr_restrict, it "

View File

@ -277,11 +277,7 @@ HWTEST_F(SymbolsFileTest, LoadKernelSymbols, TestSize.Level1)
ASSERT_EQ(symbolsFile->LoadSymbols(), true);
const std::vector<Symbol> &symbols = symbolsFile->GetSymbols();
if (KptrRestrict()) {
EXPECT_EQ(symbols.empty(), true);
} else {
EXPECT_EQ(symbols.empty(), false);
}
EXPECT_EQ(symbols.empty(), false);
std::string modulesMap = ReadFileToString("/proc/modules");
int lines = std::count(modulesMap.begin(), modulesMap.end(), '\n');