Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update(gvisor): implement parsing for procfs regular files #430

Merged
merged 2 commits into from
Jun 24, 2022
Merged
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions userspace/libscap/engine/gvisor/gvisor.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ struct procfs_result {
std::string error;
// the resulting thread information
scap_threadinfo tinfo;
// the fdinfos associated with this thread
std::vector<scap_fdinfo> fdinfos;
};

/*!
Expand Down
47 changes: 47 additions & 0 deletions userspace/libscap/engine/gvisor/parsers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ limitations under the License.
#include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <netinet/in.h>
#include <linux/un.h>
#include <arpa/inet.h>
Expand Down Expand Up @@ -877,6 +878,52 @@ procfs_result parse_procfs_json(const std::string &input, const std::string &san
}
tinfo.clone_ts = root["clone_ts"].asUInt64();

// fdinfos

// set error so that we can understand that parsing failed here
res.error = "Error parsing fdlist";

std::vector<scap_fdinfo> &fds = res.fdinfos;
if(!root.isMember("fdlist") || !root["fdlist"].isArray())
{
return res;
}
for(Json::Value::ArrayIndex i = 0; i != root["fdlist"].size(); i++)
{
Json::Value &entry = root["fdlist"][i];
scap_fdinfo fdinfo;

if(!entry.isMember("number") || !entry["number"].isUInt64())
{
return res;
}
fdinfo.fd = entry["number"].asUInt64();

if(!entry.isMember("mode") || !entry["mode"].isUInt64())
{
return res;
}

if(!entry.isMember("path") || !entry["path"].isString())
{
return res;
}

uint64_t mode = entry["mode"].asUInt64();

if(S_ISREG(mode))
{
fdinfo.type = SCAP_FD_FILE_V2;
strlcpy(fdinfo.info.regularinfo.fname, entry["path"].asCString(), SCAP_MAX_PATH_SIZE);
}
else
{
continue;
}

fds.push_back(fdinfo);
}

res.status = SCAP_SUCCESS;
res.error = "";
return res;
Expand Down
2 changes: 2 additions & 0 deletions userspace/libscap/engine/gvisor/scap_gvisor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ uint32_t engine::get_threadinfos(uint64_t *n, const scap_threadinfo **tinfos)
std::vector<std::string> &sandboxes = sandboxes_res.output;

m_threadinfos_threads.clear();
m_threadinfos_fds.clear();

for(const auto &sandbox : sandboxes)
{
Expand All @@ -356,6 +357,7 @@ uint32_t engine::get_threadinfos(uint64_t *n, const scap_threadinfo **tinfos)
}

m_threadinfos_threads.emplace_back(res.tinfo);
m_threadinfos_fds[res.tinfo.tid] = res.fdinfos;
}
}

Expand Down