init: snapuserd: Fix ranges for mlock()
It cannot be assumed that file mappings in /proc/<pid>/maps will be completely backed by the underlying file. [1] Use MappedFileSize() to deduce the correct ranges for the mlock() calls when locking system pages in the OTA path. While at it also clean up the some unreachable code (mlockall()), and improve error logging. [1] SIGBUS at https://man7.org/linux/man-pages/man2/mmap.2.html#RETURN_VALUE Test: Incremental OTA Bug: 324952273 Change-Id: Ia2ab150e1b8de8c638f5b1acc1de83deb7ac5cff Signed-off-by: Kalesh Singh <kaleshsingh@google.com>
This commit is contained in:
parent
8097002e09
commit
f90de49e0e
1 changed files with 5 additions and 7 deletions
|
|
@ -195,22 +195,20 @@ static void LockAllSystemPages() {
|
|||
return;
|
||||
}
|
||||
auto start = reinterpret_cast<const void*>(map.start);
|
||||
auto len = map.end - map.start;
|
||||
uint64_t len = android::procinfo::MappedFileSize(map);
|
||||
if (!len) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mlock(start, len) < 0) {
|
||||
LOG(ERROR) << "mlock failed, " << start << " for " << len << " bytes.";
|
||||
PLOG(ERROR) << "\"" << map.name << "\": mlock(" << start << ", " << len
|
||||
<< ") failed: pgoff = " << map.pgoff;
|
||||
ok = false;
|
||||
}
|
||||
};
|
||||
|
||||
if (!android::procinfo::ReadProcessMaps(getpid(), callback) || !ok) {
|
||||
LOG(FATAL) << "Could not process /proc/" << getpid() << "/maps file for init, "
|
||||
<< "falling back to mlockall().";
|
||||
if (mlockall(MCL_CURRENT) < 0) {
|
||||
LOG(FATAL) << "mlockall failed";
|
||||
}
|
||||
LOG(FATAL) << "Could not process /proc/" << getpid() << "/maps file for init";
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue