2 * Copyright (C) 2013 Samsung Electronics. All rights reserved.
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
13 * THIS SOFTWARE IS PROVIDED BY APPLE INC. AND ITS CONTRIBUTORS ``AS IS''
14 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
15 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
16 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR ITS CONTRIBUTORS
17 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
18 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
19 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
20 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
21 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
22 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
23 * THE POSSIBILITY OF SUCH DAMAGE.
26 #if ENABLE(TIZEN_PROCESS_PERMISSION_CONTROL)
31 #include <sys/types.h>
33 #include <sys/smack.h>
34 #include <sys/capability.h>
35 #include <wtf/Assertions.h>
39 bool changeProcessSmackLabel(const char* defaultExecutablePath, const char* currentExecutablePath)
41 ASSERT(defaultExecutablePath && currentExecutablePath);
43 // this case needs not to change smack label
44 if (!strcmp(defaultExecutablePath, currentExecutablePath))
47 // check if this process is launched as abnormal way
49 if (smack_lgetlabel(currentExecutablePath, &newLabel, SMACK_LABEL_EXEC) < 0)
52 if (smack_set_label_for_self(newLabel) < 0) {
61 bool dropProcessCapability()
63 // in case of root user, any capabilities aren't dropped
67 cap_user_header_t header;
70 header = static_cast<cap_user_header_t>(malloc(sizeof(*header)));
71 data = static_cast<cap_user_data_t>(calloc(sizeof(*data), _LINUX_CAPABILITY_U32S_3));
73 // check if header and data is allocated normally
74 ASSERT(header && data);
76 header->pid = getpid();
77 header->version = _LINUX_CAPABILITY_VERSION_3;
79 // read already granted capabilities of this process
80 if (capget(header, data) < 0) {
86 // remove process capability for CAP_MAC_ADMIN
87 data[CAP_TO_INDEX(CAP_MAC_ADMIN)].inheritable &= ~CAP_TO_MASK(CAP_MAC_ADMIN);
88 data[CAP_TO_INDEX(CAP_MAC_ADMIN)].permitted &= ~CAP_TO_MASK(CAP_MAC_ADMIN);
89 data[CAP_TO_INDEX(CAP_MAC_ADMIN)].effective &= ~CAP_TO_MASK(CAP_MAC_ADMIN);
92 if (capset(header, data) < 0)
101 } // namespace WebKit