MCPcopy Create free account
hub / github.com/MhmRdd/NoHello / switchnsto

Function switchnsto

module/src/main/cpp/utils.cpp:161–186  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161bool switchnsto(pid_t pid) {
162 int fd = pidfd_open(pid, 0);
163 if (fd != -1) {
164 int res = setns(fd, CLONE_NEWNS);
165 close(fd);
166 if (!res)
167 return true;
168 else {
169 LOGE("setns(procfd_open(%d, 0) -> %d, CLONE_NEWNS): %s", pid, fd, strerror(errno));
170 goto fallback;
171 }
172 } else {
173 LOGE("pidfd_open: %s", strerror(errno));
174 }
175 fallback:
176 std::string path = "/proc/" + std::to_string(pid) + "/ns/mnt";
177 fd = open(path.c_str(), O_RDONLY);
178 if (fd != -1) {
179 int res = setns(fd, CLONE_NEWNS);
180 close(fd);
181 return res == 0;
182 } else {
183 LOGE("open: %s", strerror(errno));
184 }
185 return false;
186}
187
188bool isuserapp(int uid) {
189 int appid = uid % AID_USER_OFFSET;

Callers 1

NoRootFunction · 0.85

Calls 1

pidfd_openFunction · 0.85

Tested by

no test coverage detected