-
Notifications
You must be signed in to change notification settings - Fork 165
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
[WIP] cleanup(sinsp)!: enforce some runtime checks and remove an extra space from evt.args
#1609
Closed
Closed
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
dd65717
style(modern_bpf): reword a comment
Andreagit97 2af68fe
new(tests): add a test for unix sockets
Andreagit97 dc57b7e
fix(sinsp): remove an extra " "
Andreagit97 ea5cb97
update(sinsp)!: add some validation checks on `evt.` filters
Andreagit97 ea29c47
update(tests): rework a test on user id
Andreagit97 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1076,6 +1076,7 @@ uint8_t* sinsp_filter_check_event::extract(sinsp_evt *evt, OUT uint32_t* len, bo | |
case TYPE_CPU: | ||
RETURN_EXTRACT_VAR(evt->m_cpuid); | ||
case TYPE_ARGRAW: | ||
evt->check_param_name_exists(m_argname); | ||
return extract_argraw(evt, len, m_arginfo->name); | ||
break; | ||
case TYPE_ARGSTR: | ||
|
@@ -1087,15 +1088,12 @@ uint8_t* sinsp_filter_check_event::extract(sinsp_evt *evt, OUT uint32_t* len, bo | |
|
||
if(m_argid != -1) | ||
{ | ||
if(m_argid >= (int32_t)evt->get_num_params()) | ||
{ | ||
return NULL; | ||
} | ||
|
||
evt->check_param_id_exists(m_argid); | ||
argstr = evt->get_param_as_str(m_argid, &resolved_argstr, m_inspector->get_buffer_format()); | ||
} | ||
else | ||
{ | ||
evt->check_param_name_exists(m_argname); | ||
argstr = evt->get_param_value_str(m_argname.c_str(), &resolved_argstr, m_inspector->get_buffer_format()); | ||
} | ||
|
||
|
@@ -1159,6 +1157,10 @@ uint8_t* sinsp_filter_check_event::extract(sinsp_evt *evt, OUT uint32_t* len, bo | |
} | ||
} | ||
|
||
if(!m_strstorage.empty()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this was an extra space at the end of the string There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh again some issues with string handling ... |
||
{ | ||
m_strstorage.pop_back(); | ||
} | ||
RETURN_EXTRACT_STRING(m_strstorage); | ||
} | ||
break; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
/* | ||
Copyright (C) 2023 The Falco Authors. | ||
|
||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
|
||
http://www.apache.org/licenses/LICENSE-2.0 | ||
|
||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
|
||
*/ | ||
|
||
#include <gtest/gtest.h> | ||
#include <test/sinsp_with_test_input.h> | ||
#include <test/test_utils.h> | ||
|
||
// Note: | ||
// 1. We don't save the type of the unix socket: datagram or stream | ||
// 2. Do we want to keep the tuple in this way `9c758d0f->9c758d0a /tmp/stream.sock`? | ||
TEST_F(sinsp_with_test_input, CONNECT_parse_unix_socket) | ||
{ | ||
add_default_init_thread(); | ||
open_inspector(); | ||
|
||
int64_t return_value = 0; | ||
int64_t client_fd = 9; | ||
|
||
// We need the enter event because we store it and we use it in the exit one. | ||
// We only store it, we don't create a fdinfo, if the enter event is missing | ||
// we don't parse the exit one. | ||
auto evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SOCKET_SOCKET_E, 3, (uint32_t)PPM_AF_UNIX, | ||
(uint32_t)SOCK_STREAM, (uint32_t)0); | ||
auto fdinfo = evt->get_fd_info(); | ||
ASSERT_FALSE(fdinfo); | ||
|
||
evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SOCKET_SOCKET_X, 1, client_fd); | ||
|
||
/* FDINFO associated with the event */ | ||
fdinfo = evt->get_fd_info(); | ||
ASSERT_TRUE(fdinfo); | ||
ASSERT_TRUE(fdinfo->is_unix_socket()); | ||
// todo! do we want this? In the end a unix socket could be of type datagram or stream | ||
ASSERT_EQ(fdinfo->get_l4proto(), scap_l4_proto::SCAP_L4_NA); | ||
ASSERT_TRUE(fdinfo->is_role_none()); | ||
ASSERT_FALSE(fdinfo->is_socket_connected()); | ||
// The socket syscall doesn't populate the name of the socket | ||
ASSERT_EQ(fdinfo->m_name, ""); | ||
|
||
/* FDINFO associated with the thread */ | ||
auto init_tinfo = m_inspector.get_thread_ref(INIT_TID, false).get(); | ||
ASSERT_TRUE(init_tinfo); | ||
fdinfo = init_tinfo->get_fd(client_fd); | ||
ASSERT_TRUE(fdinfo); | ||
ASSERT_TRUE(fdinfo->is_unix_socket()); | ||
ASSERT_EQ(fdinfo->get_l4proto(), scap_l4_proto::SCAP_L4_NA); | ||
ASSERT_TRUE(fdinfo->is_role_none()); | ||
ASSERT_FALSE(fdinfo->is_socket_connected()); | ||
ASSERT_EQ(fdinfo->m_name, ""); | ||
|
||
// We don't need the enter event! | ||
std::vector<uint8_t> socktuple = test_utils::pack_unix_socktuple(0x9c758d0f, 0x9c758d0a, "/tmp/stream.sock"); | ||
evt = add_event_advance_ts(increasing_ts(), INIT_TID, PPME_SOCKET_CONNECT_X, 3, return_value, | ||
scap_const_sized_buffer{socktuple.data(), socktuple.size()}, client_fd); | ||
|
||
/* FDINFO associated with the event */ | ||
fdinfo = evt->get_fd_info(); | ||
ASSERT_TRUE(fdinfo); | ||
ASSERT_TRUE(fdinfo->is_unix_socket()); | ||
ASSERT_EQ(fdinfo->get_l4proto(), scap_l4_proto::SCAP_L4_NA); | ||
ASSERT_TRUE(fdinfo->is_role_client()); | ||
ASSERT_TRUE(fdinfo->is_socket_connected()); | ||
// Note: `9c758d0f` is the kernel pointer to the socket that performs the connection. | ||
// `9c758d0a` is the kernel pointer to the socket that receives the connection. | ||
ASSERT_EQ(fdinfo->m_name, "9c758d0f->9c758d0a /tmp/stream.sock"); | ||
// we don't have code to populate this `m_name_raw` for sockets. | ||
ASSERT_EQ(fdinfo->m_name_raw, ""); | ||
|
||
/* FDINFO associated with the thread */ | ||
fdinfo = init_tinfo->get_fd(client_fd); | ||
ASSERT_TRUE(fdinfo); | ||
ASSERT_TRUE(fdinfo->is_unix_socket()); | ||
ASSERT_EQ(fdinfo->get_l4proto(), scap_l4_proto::SCAP_L4_NA); | ||
ASSERT_TRUE(fdinfo->is_role_client()); | ||
ASSERT_TRUE(fdinfo->is_socket_connected()); | ||
ASSERT_EQ(fdinfo->m_name, "9c758d0f->9c758d0a /tmp/stream.sock"); | ||
ASSERT_EQ(fdinfo->m_name_raw, ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these filter checks like
TYPE_ARGRAW
are very particular because they are related in some way to a specific event, for exampleevt.arg.uid
is a valid filter-check forsetuid
events but not forexecve
events. So to do a proper validation during filter-check parsing time we should find a way to correlate theevt.type
with these fieldsThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
at the moment we crash at runtime which is not the ideal thing, but on the other side using wrong filter checks is not an ideal thing in the same way :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Moreover, we need to keep attention when we use these filter checks, for example, if the condition is
evt.type in (open, openat,...)
these kind of fields should be used because they could be valid for some events but not for others! For example,evt.arg.dirfd
is valid foropenat
but not foropen