dd027f554392973cfa568cc04376cf733e8eef55
[platform/core/test/security-tests.git] / src / security-manager-tests / common / sm_commons.cpp
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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 #include <algorithm>
18 #include <cstring>
19 #include <ftw.h>
20 #include <grp.h>
21 #include <string>
22 #include <sys/capability.h>
23 #include <sys/stat.h>
24 #include <sys/types.h>
25 #include <unistd.h>
26 #include <cstdlib>
27
28 #include <unordered_set>
29 #include <vector>
30
31 #include <security-manager-types.h>
32 #include <sys/smack.h>
33
34 #include <cynara_test_client.h>
35 #include <dpl/test/test_runner.h>
36 #include <memory.h>
37 #include <sm_api.h>
38 #include <sm_commons.h>
39 #include <sm_db.h>
40 #include <synchronization_pipe.h>
41 #include <sm_request.h>
42 #include <tests_common.h>
43 #include "tzplatform.h"
44
45 using namespace SecurityManagerTest;
46
47 // Common const values
48
49 const privileges_t SM_ALLOWED_PRIVILEGES = {
50     "http://tizen.org/privilege/display",
51     "http://tizen.org/privilege/nfc"
52 };
53
54 const privileges_t SM_DENIED_PRIVILEGES  = {
55     "http://tizen.org/privilege/bluetooth",
56     "http://tizen.org/privilege/power"
57 };
58
59 const privileges_t SM_NO_PRIVILEGES  = {
60 };
61
62 const std::vector<std::string> SM_ALLOWED_GROUPS = {"db_browser", "db_alarm"};
63
64 const std::string uidToStr(const uid_t uid)
65 {
66     return std::to_string(static_cast<unsigned int>(uid));
67 }
68
69 // Common implementation details
70
71 std::string generateProcessLabel(const std::string &appId, const std::string &pkgId, bool isHybrid)
72 {
73     (void) pkgId;
74     (void) isHybrid;
75     return "User::App::" + appId;
76 }
77
78 std::string generatePathRWLabel(const std::string &pkgId)
79 {
80     return "User::Pkg::" + pkgId;
81 }
82
83 static std::string genPath(int app_num, const char *postfix) {
84     char buf[16];
85     sprintf(buf, "%02d", app_num);
86     return TzPlatformConfig::globalAppDir() + "/sm_test_" + std::string(buf) + "_pkg_id_full/" + std::string(postfix);
87 }
88
89 std::string genRWPath(int app_num) {
90     return genPath(app_num, "app_dir");
91 }
92 std::string genROPath(int app_num) {
93     return genPath(app_num, "app_dir_ro");
94 }
95 std::string genPublicROPath(int app_num) {
96     return genPath(app_num, "app_dir_public_ro");
97 }
98
99 std::string genOwnerRWOthersROPath(int app_num) {
100     return genPath(app_num, "app_dir_rw_others_ro");
101 }
102
103 static std::string generatePkgLabelOwnerRWothersRO(const std::string &pkgId)
104 {
105     return "User::Pkg::" + pkgId + "::SharedRO";
106 }
107
108 // Common DB/nftw checks
109
110 // nftw doesn't allow passing user data to functions. Work around by using global variable
111 static std::string nftw_expected_label;
112 bool nftw_expected_transmute;
113 bool nftw_expected_exec;
114
115 static int nftw_check_sm_labels_app_dir(const char *fpath, const struct stat *sb,
116                               const char* correctLabel, bool transmute_test, bool exec_test)
117 {
118     int result;
119     CStringPtr labelPtr;
120     char* label = nullptr;
121
122     /* ACCESS */
123     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_ACCESS);
124     RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
125     labelPtr.reset(label);
126     RUNNER_ASSERT_MSG(label != nullptr, "ACCESS label on " << fpath << " is not set");
127     result = strcmp(correctLabel, label);
128     RUNNER_ASSERT_MSG(result == 0, "ACCESS label on " << fpath << " is incorrect"
129             " (should be '" << correctLabel << "' and is '" << label << "')");
130
131
132     /* EXEC */
133     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_EXEC);
134     RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
135     labelPtr.reset(label);
136
137     if (S_ISREG(sb->st_mode) && (sb->st_mode & S_IXUSR) && exec_test) {
138         RUNNER_ASSERT_MSG(label != nullptr, "EXEC label on " << fpath << " is not set");
139         result = strcmp(correctLabel, label);
140         RUNNER_ASSERT_MSG(result == 0, "Incorrect EXEC label on executable file " << fpath);
141     } else
142         RUNNER_ASSERT_MSG(label == nullptr, "EXEC label on " << fpath << " is set");
143
144
145     /* TRANSMUTE */
146     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_TRANSMUTE);
147     RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
148     labelPtr.reset(label);
149
150     if (S_ISDIR(sb->st_mode) && transmute_test == true) {
151         RUNNER_ASSERT_MSG(label != nullptr, "TRANSMUTE label on " << fpath << " is not set at all");
152         RUNNER_ASSERT_MSG(strcmp(label,"TRUE") == 0,
153                 "TRANSMUTE label on " << fpath << " is not set properly: '"<<label<<"'");
154     } else {
155         RUNNER_ASSERT_MSG(label == nullptr, "TRANSMUTE label on " << fpath << " is set");
156     }
157
158     return 0;
159 }
160
161 static int nftw_check_sm_labels(const char *fpath, const struct stat *sb,
162                                int /*typeflag*/, struct FTW* /*ftwbuf*/)
163 {
164     return nftw_check_sm_labels_app_dir(fpath, sb,
165         nftw_expected_label.c_str(), nftw_expected_transmute, nftw_expected_exec);
166 }
167
168 int nftw_check_labels_non_app_dir(const char *fpath, const struct stat* /*sb*/,
169                                   int /*typeflag*/, struct FTW* /*ftwbuf*/)
170 {
171     int result;
172     CStringPtr labelPtr;
173     char* label = nullptr;
174
175     /* ACCESS */
176     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_ACCESS);
177     labelPtr.reset(label);
178     RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
179     result = strcmp("canary_label", labelPtr.get());
180     RUNNER_ASSERT_MSG(result == 0, "ACCESS label on " << fpath << " is overwritten");
181
182     /* EXEC */
183     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_EXEC);
184     labelPtr.reset(label);
185     RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
186     result = strcmp("canary_label", labelPtr.get());
187     RUNNER_ASSERT_MSG(result == 0, "EXEC label on " << fpath << " is overwritten");
188
189     /* TRANSMUTE */
190     result = smack_lgetlabel(fpath, &label, SMACK_LABEL_TRANSMUTE);
191     labelPtr.reset(label);
192     RUNNER_ASSERT_MSG(result == 0, "Could not get label for the path");
193     RUNNER_ASSERT_MSG(labelPtr.get() == nullptr, "TRANSMUTE label on " << fpath << " is set");
194
195     return 0;
196 }
197
198 static int nftw_set_labels_non_app_dir(const char *fpath, const struct stat* /*sb*/,
199                                 int /*typeflag*/, struct FTW* /*ftwbuf*/)
200 {
201     smack_lsetlabel(fpath, "canary_label", SMACK_LABEL_ACCESS);
202     smack_lsetlabel(fpath, "canary_label", SMACK_LABEL_EXEC);
203     smack_lsetlabel(fpath, nullptr, SMACK_LABEL_TRANSMUTE);
204
205     return 0;
206 }
207
208 int nftw_remove_labels(const char *fpath, const struct stat* /*sb*/,
209                        int /*typeflag*/, struct FTW* /*ftwbuf*/)
210 {
211     smack_lsetlabel(fpath, nullptr, SMACK_LABEL_ACCESS);
212     smack_lsetlabel(fpath, nullptr, SMACK_LABEL_EXEC);
213     smack_lsetlabel(fpath, nullptr, SMACK_LABEL_TRANSMUTE);
214
215     return 0;
216 }
217
218 static const std::string SM_DENIED_PATH = TzPlatformConfig::globalAppDir() + "/non_app_dir";
219
220 void check_app_permissions(const char *const app_id, const char *const pkg_id,
221                            const char *const user, const privileges_t &allowed_privs,
222                            const privileges_t &denied_privs)
223 {
224     (void) pkg_id;
225     std::string smackLabel = generateProcessLabel(app_id, pkg_id);
226
227     CynaraTestClient::Client ctc;
228
229     for (auto &priv : allowed_privs) {
230         ctc.check(smackLabel.c_str(), "", user, priv.c_str(), CYNARA_API_ACCESS_ALLOWED);
231     }
232
233     for (auto &priv : denied_privs) {
234         ctc.check(smackLabel.c_str(), "", user, priv.c_str(), CYNARA_API_ACCESS_DENIED);
235     }
236 }
237
238
239 void check_app_after_install(const char *const app_id, const char *const pkg_id)
240 {
241     TestSecurityManagerDatabase dbtest;
242     dbtest.test_db_after__app_install(app_id, pkg_id);
243 }
244
245 static void check_app_gids(const char *const app_id, const std::vector<gid_t> &allowed_gids)
246 {
247     int ret;
248     gid_t main_gid = getgid();
249     std::unordered_set<gid_t> reference_gids(allowed_gids.begin(), allowed_gids.end());
250
251     // Reset supplementary groups
252     ret = setgroups(0, NULL);
253     RUNNER_ASSERT_MSG(ret != -1, "Unable to set supplementary groups");
254
255     Api::setProcessGroups(app_id);
256
257     ret = getgroups(0, nullptr);
258     RUNNER_ASSERT_MSG(ret != -1, "Unable to get supplementary groups");
259
260     std::vector<gid_t> actual_gids(ret);
261     ret = getgroups(ret, actual_gids.data());
262     RUNNER_ASSERT_MSG(ret != -1, "Unable to get supplementary groups");
263
264     for (const auto &gid : actual_gids) {
265         RUNNER_ASSERT_MSG(gid == main_gid || reference_gids.count(gid) > 0,
266             "Application shouldn't get access to group " << gid);
267         reference_gids.erase(gid);
268     }
269
270     RUNNER_ASSERT_MSG(reference_gids.empty(), "Application didn't get access to some groups");
271 }
272
273 static const char *const ANY_USER_REPRESENTATION = "anyuser";/*this may be actually any string*/
274
275 void check_app_after_install(const char *const app_id, const char *const pkg_id,
276                              const privileges_t &allowed_privs,
277                              const privileges_t &denied_privs,
278                              const std::vector<std::string> &allowed_groups)
279 {
280     TestSecurityManagerDatabase dbtest;
281     dbtest.test_db_after__app_install(app_id, pkg_id);
282
283     /*Privileges should be granted to all users if root installs app*/
284     check_app_permissions(app_id, pkg_id, ANY_USER_REPRESENTATION, allowed_privs, denied_privs);
285
286     /* Setup mapping of gids to privileges */
287     /* Do this for each privilege for extra check */
288     for (const auto &privilege : allowed_privs) {
289         dbtest.setup_privilege_groups(privilege, allowed_groups);
290     }
291
292     std::vector<gid_t> allowed_gids;
293
294     for (const auto &groupName : allowed_groups) {
295         errno = 0;
296         struct group* grp = getgrnam(groupName.c_str());
297         RUNNER_ASSERT_ERRNO_MSG(grp, "Group: " << groupName << " not found");
298         allowed_gids.push_back(grp->gr_gid);
299     }
300
301     check_app_gids(app_id, allowed_gids);
302 }
303
304 void check_path(const std::string &path, const std::string &label) {
305     nftw_expected_label = label;
306     nftw_expected_transmute = true;
307     nftw_expected_exec = false;
308
309     // check labels
310     int result = nftw(path.c_str(), &nftw_check_sm_labels, FTW_MAX_FDS, FTW_PHYS);
311     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << path);
312 }
313
314 void check_app_path_after_install(int app_num, const char *pkgId, bool others_enabled)
315 {
316     std::string SM_RW_PATH = genRWPath(app_num);
317     std::string SM_RO_PATH = genROPath(app_num);
318     std::string SM_PUBLIC_RO_PATH = genPublicROPath(app_num);
319     int result;
320
321     nftw_expected_label = generatePathRWLabel(pkgId);
322     nftw_expected_transmute = true;
323     nftw_expected_exec = false;
324
325     result = nftw(SM_RW_PATH.c_str(), &nftw_check_sm_labels, FTW_MAX_FDS, FTW_PHYS);
326     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << SM_RW_PATH);
327
328     nftw_expected_label = generatePathRWLabel(pkgId) + "::RO";
329     nftw_expected_transmute = false;
330     nftw_expected_exec = false;
331
332     result = nftw(SM_RO_PATH.c_str(), &nftw_check_sm_labels, FTW_MAX_FDS, FTW_PHYS);
333     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << SM_RO_PATH);
334
335     nftw_expected_label = "User::Home";
336     nftw_expected_transmute = true;
337     nftw_expected_exec = false;
338
339     result = nftw(SM_PUBLIC_RO_PATH.c_str(), &nftw_check_sm_labels, FTW_MAX_FDS, FTW_PHYS);
340     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << SM_PUBLIC_RO_PATH);
341
342     result = nftw(SM_DENIED_PATH.c_str(), &nftw_check_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
343     RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << SM_DENIED_PATH);
344
345     // owner RW, others RO
346     if(others_enabled) {
347         std::string SM_OWNER_RW_OTHERS_RO_PATH = genOwnerRWOthersROPath(app_num);
348         nftw_expected_label = generatePkgLabelOwnerRWothersRO(pkgId);
349         nftw_expected_transmute = true;
350         nftw_expected_exec = false;
351
352         result = nftw(SM_OWNER_RW_OTHERS_RO_PATH.c_str(), &nftw_check_sm_labels, FTW_MAX_FDS, FTW_PHYS);
353         RUNNER_ASSERT_MSG(result == 0, "Unable to check Smack labels for " << SM_OWNER_RW_OTHERS_RO_PATH);
354     }
355 }
356
357 void check_app_after_uninstall(const char *const app_id, const char *const pkg_id,
358                                const bool is_pkg_removed)
359 {
360     TestSecurityManagerDatabase dbtest;
361     dbtest.test_db_after__app_uninstall(app_id, pkg_id, is_pkg_removed);
362 }
363
364 void check_app_after_uninstall(const char *const app_id, const char *const pkg_id,
365                                const privileges_t &privileges, const bool is_pkg_removed)
366 {
367     TestSecurityManagerDatabase dbtest;
368     dbtest.test_db_after__app_uninstall(app_id, pkg_id, is_pkg_removed);
369
370
371     /*Privileges should not be granted anymore to any user*/
372     check_app_permissions(app_id, pkg_id, ANY_USER_REPRESENTATION, SM_NO_PRIVILEGES, privileges);
373 }
374
375 std::string access_opposite(std::string &access) {
376     static const std::map<char, int> access_mapping = {{'r', 0}, {'w', 1}, {'x', 2}, {'a', 3},
377                                                        {'t', 4}, {'l', 5}};
378     //May write implies may lock
379     if (access.find('w') != std::string::npos && access.find('l') == std::string::npos) {
380         access.append("l");
381     }
382     std::string access_opposite = "rwxatl";
383     for (char c : access) {
384         access_opposite[access_mapping.at(c)] = '-';
385     }
386     auto it = std::remove_if(access_opposite.begin(), access_opposite.end(), [](char c) {return c == '-';});
387     access_opposite.erase(it, access_opposite.end());
388     return access_opposite;
389 }
390
391 void check_exact_smack_accesses(const std::string &subject, const std::string &object,
392                                 const std::string &access) {
393     std::string access_str(access);
394     auto no_access = access_opposite(access_str);
395     for (char c : access_str) {
396         int ret = smack_have_access(subject.c_str(), object.c_str(), std::string(1, c).c_str());
397         RUNNER_ASSERT_MSG(ret >= 0, "smack_have_access failed: <" << subject << ">, <" << object
398                           << ">, <" << c << "> errno=" << strerror(errno));
399         RUNNER_ASSERT_MSG(ret == 1, "Access " << c << " from " << subject << " to "
400                           << object << " not given");
401     }
402
403     for (char c : no_access) {
404         int ret = smack_have_access(subject.c_str(), object.c_str(), std::string(1, c).c_str());
405         RUNNER_ASSERT_MSG(ret >= 0, "smack_have_access failed: <" << subject << ">, <" << object
406                           << ">, <" << c << "> errno=" << strerror(errno));
407         RUNNER_ASSERT_MSG(ret == 0, "Access " << c << " from " << subject << " to "
408                           << object << " unnecessarily given");
409     }
410 }
411
412 CapsSetsUniquePtr setCaps(const char *cap_string)
413 {
414     CapsSetsUniquePtr caps(cap_init());
415     caps.reset(cap_from_text(cap_string));
416     RUNNER_ASSERT_MSG(caps, "can't convert capabilities from text");
417     int result = cap_set_proc(caps.get());
418     RUNNER_ASSERT_MSG(result == 0, "can't set capabilities. Result: " << result);
419     return caps;
420 }
421
422 static void prepare_app_path(int app_num, bool others_enabled = false)
423 {
424     std::string SM_RW_PATH = genRWPath(app_num);
425     std::string SM_RO_PATH = genROPath(app_num);
426     std::string SM_PUBLIC_RO_PATH = genPublicROPath(app_num);
427     int result;
428
429     result = nftw(SM_RW_PATH.c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
430     RUNNER_ASSERT_MSG(result == 0, "Unable to clean Smack labels in " << SM_RW_PATH);
431
432     result = nftw(SM_RO_PATH.c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
433     RUNNER_ASSERT_MSG(result == 0, "Unable to clean Smack labels in " << SM_RO_PATH);
434
435     result = nftw(SM_PUBLIC_RO_PATH.c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
436     RUNNER_ASSERT_MSG(result == 0, "Unable to clean Smack labels in " << SM_PUBLIC_RO_PATH);
437
438     if(others_enabled) {
439         std::string SM_OWNER_RW_OTHERS_RO_PATH = genOwnerRWOthersROPath(app_num);
440         result = nftw(SM_OWNER_RW_OTHERS_RO_PATH.c_str(), &nftw_remove_labels, FTW_MAX_FDS, FTW_PHYS);
441         RUNNER_ASSERT_MSG(result == 0, "Unable to clean Smack labels in " << SM_OWNER_RW_OTHERS_RO_PATH);
442     }
443
444     result = nftw(SM_DENIED_PATH.c_str(), &nftw_set_labels_non_app_dir, FTW_MAX_FDS, FTW_PHYS);
445     RUNNER_ASSERT_MSG(result == 0, "Unable to set Smack labels in " << SM_DENIED_PATH);
446 }
447
448 void prepare_app_env(int app_num, bool others_enabled)
449 {
450     prepare_app_path(app_num, others_enabled);
451 }
452
453 void install_app(const char *app_id, const char *pkg_id, uid_t uid, app_install_type type,
454                  bool check_after)
455 {
456     InstallRequest request;
457     request.setAppId(app_id);
458     request.setPkgId(pkg_id);
459     request.setUid(uid);
460     if (type != SM_APP_INSTALL_NONE)
461         request.setInstallType(type);
462     Api::install(request);
463
464     if (check_after)
465         check_app_after_install(app_id, pkg_id);
466 }
467
468 void uninstall_app(const char *app_id, const char *pkg_id, bool expect_pkg_removed,
469                    app_install_type type, bool check_after)
470 {
471     InstallRequest request;
472     request.setAppId(app_id);
473     if (type != SM_APP_INSTALL_NONE)
474         request.setInstallType(type);
475     Api::uninstall(request);
476
477     if (check_after)
478         check_app_after_uninstall(app_id, pkg_id, expect_pkg_removed);
479 }
480
481 static const std::string EXEC_FILE("exec");
482 static const std::string NORMAL_FILE("normal");
483 static const std::string LINK_PREFIX("link_to_");
484
485 static void createTestDir(const std::string &dir)
486 {
487     mode_t dirMode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
488     mode_t execFileMode = S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH;
489     mode_t normalFileMode = S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH;
490
491     mktreeSafe(dir, dirMode);
492     creatSafe(dir + "/" + EXEC_FILE, execFileMode);
493     creatSafe(dir + "/" + NORMAL_FILE, normalFileMode);
494     symlinkSafe(dir + "/" + EXEC_FILE, dir + "/" + LINK_PREFIX + EXEC_FILE);
495     symlinkSafe(dir + "/" + NORMAL_FILE, dir + "/" + LINK_PREFIX + NORMAL_FILE);
496 }
497
498 static void createInnerAppDir(const std::string &dir, const std::string &nonAppDir)
499 {
500     createTestDir(dir);
501
502     symlinkSafe(nonAppDir, dir + "/" + LINK_PREFIX + "non_app_dir");
503     symlinkSafe(nonAppDir + "/" + EXEC_FILE,
504                 dir + "/" + LINK_PREFIX + "non_app_" + EXEC_FILE);
505     symlinkSafe(nonAppDir + "/" + NORMAL_FILE,
506                 dir + "/" + LINK_PREFIX + "non_app_" + NORMAL_FILE);
507 }
508
509 static const std::string nonAppDirPath(const TemporaryTestUser &user)
510 {
511     return TMP_DIR + "/" + user.getUserName();
512 }
513
514 static void generateAppDir(const TemporaryTestUser &user,
515        const std::string &appId, const std::string &pkgId)
516 {
517     const std::string dir = TzPlatformConfig::appDirPath(user, appId, pkgId);
518     const std::string nonAppDir = nonAppDirPath(user);
519
520     createInnerAppDir(dir, nonAppDir);
521     createInnerAppDir(dir + "/.inner_dir", nonAppDir);
522     createInnerAppDir(dir + "/inner_dir", nonAppDir);
523 }
524
525 static void generateNonAppDir(const TemporaryTestUser &user)
526 {
527     const std::string dir = nonAppDirPath(user);
528
529     createTestDir(dir);
530     createTestDir(dir + "/.inner_dir");
531     createTestDir(dir + "/inner_dir");
532 }
533
534 void createTestDirs(const TemporaryTestUser &user,
535                     const std::string &appId, const std::string &pkgId)
536 {
537     generateAppDir(user, appId, pkgId);
538     generateNonAppDir(user);
539 }
540
541 void removeTestDirs(const TemporaryTestUser &user,
542                     const std::string &appId, const std::string &pkgId)
543 {
544     removeDir(TzPlatformConfig::appDirPath(user, appId, pkgId));
545     removeDir(nonAppDirPath(user));
546 }
547
548 pid_t runInChild(const std::function<void(void)> &process) {
549     pid_t pid = fork();
550     RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
551
552     if (pid == 0) {
553         process();
554         exit(EXIT_SUCCESS);
555     }
556     return pid;
557 }
558
559 void runInChildParentWait(const std::function<void(void)> &process) {
560     SynchronizationPipe pipe;
561     pid_t pid = fork();
562     RUNNER_ASSERT_ERRNO_MSG(pid >= 0, "fork failed");
563
564     if (pid == 0) {
565         pipe.claimChildEp();
566
567         process();
568
569         pipe.post();
570         exit(EXIT_SUCCESS);
571     } else {
572         pipe.claimParentEp();
573         pipe.wait();
574     }
575 }