Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 29 additions & 19 deletions bundle/lib/source/DobbyConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -791,31 +791,41 @@ bool DobbyConfig::updateBundleConfig(const ContainerId& id, std::shared_ptr<rt_d

bool DobbyConfig::isApparmorProfileLoaded(const char *profile) const
{
DIR *d = NULL;
bool status = false;
int fd = open("/proc/self/attr/current", O_WRONLY);
struct dirent *cur_dir = NULL;
Comment thread
goruklu marked this conversation as resolved.
size_t profile_len = strlen(profile);

if (fd < 0)
{
AI_LOG_ERROR("/proc/self/attr/current open failed");
return status;
d = opendir("/sys/kernel/security/apparmor/policy/profiles/");
if(!d) {
AI_LOG_SYS_ERROR(errno, "opendir() failed on apparmorfs policy directory.");
return false;
}
char profile_name[256];
snprintf(profile_name, sizeof(profile_name), "permprofile %s", profile);

if (write(fd, profile_name, strlen(profile_name)) < 0)
{
if (errno == ENOENT)
AI_LOG_INFO("Apparmor profile [%s] doesn't exist", profile);
else
AI_LOG_ERROR("/proc/self/attr/current write failed");

errno = 0;
while((cur_dir = readdir(d)) != NULL) {
if(strlen(cur_dir->d_name) >= (profile_len + 2)) {
Comment thread
goruklu marked this conversation as resolved.
if(!strncmp(cur_dir->d_name, profile, profile_len) &&
cur_dir->d_name[profile_len] == '.' &&
isdigit(cur_dir->d_name[profile_len + 1])) {
Comment thread
goruklu marked this conversation as resolved.

status = true;
AI_LOG_INFO("AppArmor profile [%s] is loaded.", profile);
break;
}
}
}
else
{
status = true;
AI_LOG_INFO("Apparmor profile [%s] is loaded", profile);

if(!status) {
AI_LOG_INFO("AppArmor profile [%s] not found.", profile);
}

close(fd);
if(!cur_dir && errno) {
AI_LOG_SYS_ERROR(errno, "readdir() failed on apparmorfs policy directory");
}

closedir(d);

return status;
}

Expand Down
Loading