Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f90de49e authored by Kalesh Singh's avatar Kalesh Singh
Browse files

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: default avatarKalesh Singh <kaleshsingh@google.com>
parent 8097002e
Loading
Loading
Loading
Loading
+5 −7
Original line number Original line Diff line number Diff line
@@ -195,22 +195,20 @@ static void LockAllSystemPages() {
            return;
            return;
        }
        }
        auto start = reinterpret_cast<const void*>(map.start);
        auto start = reinterpret_cast<const void*>(map.start);
        auto len = map.end - map.start;
        uint64_t len = android::procinfo::MappedFileSize(map);
        if (!len) {
        if (!len) {
            return;
            return;
        }
        }

        if (mlock(start, len) < 0) {
        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;
            ok = false;
        }
        }
    };
    };


    if (!android::procinfo::ReadProcessMaps(getpid(), callback) || !ok) {
    if (!android::procinfo::ReadProcessMaps(getpid(), callback) || !ok) {
        LOG(FATAL) << "Could not process /proc/" << getpid() << "/maps file for init, "
        LOG(FATAL) << "Could not process /proc/" << getpid() << "/maps file for init";
                   << "falling back to mlockall().";
        if (mlockall(MCL_CURRENT) < 0) {
            LOG(FATAL) << "mlockall failed";
        }
    }
    }
}
}