-
Notifications
You must be signed in to change notification settings - Fork 169
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
fix(userspace/libsinsp): multiple fixes related to rawargs. #2130
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -139,6 +139,8 @@ | |
|
||
case PT_L4PROTO: // This can be resolved in the future | ||
case PT_UINT8: | ||
case PT_FLAGS8: | ||
case PT_ENUMFLAGS8: | ||
if(print_format == PF_DEC || print_format == PF_ID) { | ||
return *(uint8_t*)rawval; | ||
} else if(print_format == PF_OCT || print_format == PF_HEX) { | ||
|
@@ -150,6 +152,8 @@ | |
|
||
case PT_PORT: // This can be resolved in the future | ||
case PT_UINT16: | ||
case PT_FLAGS16: | ||
case PT_ENUMFLAGS16: | ||
if(print_format == PF_DEC || print_format == PF_ID) { | ||
return *(uint16_t*)rawval; | ||
} else if(print_format == PF_OCT || print_format == PF_HEX) { | ||
|
@@ -160,6 +164,10 @@ | |
} | ||
|
||
case PT_UINT32: | ||
case PT_FLAGS32: | ||
case PT_ENUMFLAGS32: | ||
case PT_UID: | ||
case PT_GID: | ||
if(print_format == PF_DEC || print_format == PF_ID) { | ||
return *(uint32_t*)rawval; | ||
} else if(print_format == PF_OCT || print_format == PF_HEX) { | ||
|
@@ -292,12 +300,14 @@ | |
return m_getpropertystr_storage.data(); | ||
case PT_L4PROTO: // This can be resolved in the future | ||
case PT_UINT8: | ||
case PT_FLAGS8: | ||
case PT_ENUMFLAGS8: | ||
if(print_format == PF_OCT) { | ||
prfmt = (char*)"%" PRIo8; | ||
} else if(print_format == PF_DEC || print_format == PF_ID) { | ||
prfmt = (char*)"%" PRIu8; | ||
} else if(print_format == PF_HEX) { | ||
prfmt = (char*)"%" PRIu8; | ||
prfmt = (char*)"%" PRIX8; | ||
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. Fix print format for 8,16,32bits types for PF_HEX. |
||
} else { | ||
ASSERT(false); | ||
return NULL; | ||
|
@@ -311,12 +321,14 @@ | |
return m_getpropertystr_storage.data(); | ||
case PT_PORT: // This can be resolved in the future | ||
case PT_UINT16: | ||
case PT_FLAGS16: | ||
case PT_ENUMFLAGS16: | ||
if(print_format == PF_OCT) { | ||
prfmt = (char*)"%" PRIo16; | ||
} else if(print_format == PF_DEC || print_format == PF_ID) { | ||
prfmt = (char*)"%" PRIu16; | ||
} else if(print_format == PF_HEX) { | ||
prfmt = (char*)"%" PRIu16; | ||
prfmt = (char*)"%" PRIX16; | ||
} else { | ||
ASSERT(false); | ||
return NULL; | ||
|
@@ -329,12 +341,16 @@ | |
rawval_cast<uint16_t>(rawval)); | ||
return m_getpropertystr_storage.data(); | ||
case PT_UINT32: | ||
case PT_FLAGS32: | ||
case PT_ENUMFLAGS32: | ||
case PT_UID: | ||
case PT_GID: | ||
if(print_format == PF_OCT) { | ||
prfmt = (char*)"%" PRIo32; | ||
} else if(print_format == PF_DEC || print_format == PF_ID) { | ||
prfmt = (char*)"%" PRIu32; | ||
} else if(print_format == PF_HEX) { | ||
prfmt = (char*)"%" PRIu32; | ||
prfmt = (char*)"%" PRIX32; | ||
} else { | ||
ASSERT(false); | ||
return NULL; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -549,6 +549,13 @@ int32_t sinsp_filter_check_event::parse_field_name(std::string_view val, | |
|
||
res = extract_arg("evt.rawarg", val, &m_arginfo); | ||
|
||
// These fields will be overridden with correct ones from the current event | ||
// while extracting from event. | ||
// But we also need to set them at init time to something different than `PT_DYN` | ||
// to allow `eval_filter` expressions to be properly compiled. | ||
// Note: even if they'll be overridden, | ||
// it is safe to guess that eg: `size` param will always be a numeric type. | ||
// Of course if we had a `size` param that is string, it would be troublesome. | ||
Comment on lines
+557
to
+558
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. i would just remove this since we have already found a corner case ( 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. Yep i am afraid that we forgot once again 😆 |
||
m_customfield.m_type = m_arginfo->type; | ||
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. Per-comment: store the first one found to allow proper compilation of filters on this field; this works fine unless we have an event param, eg: |
||
m_customfield.m_print_format = m_arginfo->fmt; | ||
} else if(STR_MATCH("evt.around")) { | ||
|
@@ -650,10 +657,15 @@ void sinsp_filter_check_event::validate_filter_value(const char* str, uint32_t l | |
} | ||
} | ||
|
||
uint8_t* extract_argraw(sinsp_evt* evt, uint32_t* len, const char* argname) { | ||
const sinsp_evt_param* pi = evt->get_param_by_name(argname); | ||
uint8_t* sinsp_filter_check_event::extract_argraw(sinsp_evt* evt, | ||
uint32_t* len, | ||
const char* argname) { | ||
auto pi = evt->get_param_by_name(argname); | ||
|
||
if(pi != NULL) { | ||
m_arginfo = pi->get_info(); | ||
m_customfield.m_type = m_arginfo->type; | ||
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. Store correct field type and print format from the being-extracted event. |
||
m_customfield.m_print_format = m_arginfo->fmt; | ||
*len = pi->m_len; | ||
return (uint8_t*)pi->m_val; | ||
} else { | ||
|
@@ -1192,7 +1204,7 @@ uint8_t* sinsp_filter_check_event::extract_single(sinsp_evt* evt, | |
m_val.u16 = evt->get_cpuid(); | ||
RETURN_EXTRACT_VAR(m_val.u16); | ||
case TYPE_ARGRAW: | ||
return extract_argraw(evt, len, m_arginfo->name); | ||
return extract_argraw(evt, len, m_argname.c_str()); | ||
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. Use |
||
break; | ||
case TYPE_ARGSTR: { | ||
const char* resolved_argstr; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -210,3 +210,48 @@ TEST_F(sinsp_with_test_input, EVT_FILTER_check_evt_arg_uid) { | |
ASSERT_EQ(get_field_as_string(evt, "evt.arg[0]"), "<NA>"); | ||
ASSERT_EQ(get_field_as_string(evt, "evt.args"), "uid=5(<NA>)"); | ||
} | ||
|
||
// Test that for rawarg.X we are correctly retrieving the correct field type/format. | ||
TEST_F(sinsp_with_test_input, rawarg_madness) { | ||
add_default_init_thread(); | ||
open_inspector(); | ||
|
||
// [PPME_SYSCALL_EPOLL_CREATE_E] = {"epoll_create", EC_WAIT | EC_SYSCALL, EF_CREATES_FD | | ||
// EF_MODIFIES_STATE, 1, { {"size", PT_INT32, PF_DEC} } }, | ||
sinsp_evt* evt = | ||
add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_EPOLL_CREATE_E, 1, (int32_t)-22); | ||
ASSERT_EQ(get_field_as_string(evt, "evt.rawarg.size"), "-22"); | ||
ASSERT_TRUE(eval_filter(evt, "evt.rawarg.size < -20")); | ||
|
||
// [PPME_SYSCALL_SIGNALFD4_X] = {"signalfd4", EC_SIGNAL | EC_SYSCALL, EF_CREATES_FD | | ||
// EF_MODIFIES_STATE, 2, {{"res", PT_FD, PF_DEC}, {"flags", PT_FLAGS16, PF_HEX, file_flags}}}, | ||
evt = add_event_advance_ts(increasing_ts(), | ||
1, | ||
PPME_SYSCALL_SIGNALFD4_X, | ||
2, | ||
(int64_t)-1, | ||
(uint16_t)512); | ||
// 512 in hex is 200 | ||
ASSERT_EQ(get_field_as_string(evt, "evt.rawarg.flags"), "200"); | ||
ASSERT_TRUE(eval_filter(evt, "evt.rawarg.flags < 515")); | ||
|
||
// [PPME_SYSCALL_TIMERFD_CREATE_E] = {"timerfd_create",EC_TIME | EC_SYSCALL,EF_CREATES_FD | | ||
// EF_MODIFIES_STATE,2,{{"clockid", PT_UINT8, PF_DEC},{"flags", PT_UINT8, PF_HEX}}}, | ||
evt = add_event_advance_ts(increasing_ts(), | ||
1, | ||
PPME_SYSCALL_TIMERFD_CREATE_E, | ||
2, | ||
(uint8_t)-1, | ||
(uint8_t)255); | ||
// 255 in hex is FF | ||
ASSERT_EQ(get_field_as_string(evt, "evt.rawarg.flags"), "FF"); | ||
ASSERT_TRUE(eval_filter(evt, "evt.rawarg.flags <= 255")); | ||
|
||
// [PPME_SYSCALL_BRK_4_E] = {"brk", EC_MEMORY | EC_SYSCALL, EF_NONE, 1, {{"addr", PT_UINT64, | ||
// PF_HEX}}} | ||
uint64_t addr = UINT64_MAX; | ||
evt = add_event_advance_ts(increasing_ts(), 1, PPME_SYSCALL_BRK_4_E, 1, addr); | ||
// UINT64_MAX is FFFFFFFFFFFFFFFF | ||
ASSERT_EQ(get_field_as_string(evt, "evt.rawarg.addr"), "FFFFFFFFFFFFFFFF"); | ||
ASSERT_ANY_THROW(eval_filter(evt, "evt.rawarg.addr > 0")); // PT_SOCKADDR is not comparable | ||
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 issue is still present: even f the 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. yep not sure what to do here, one thing could be to rename some parameters to avoid the issue. We should reach a point where params with the same name have the same type, but yes this would be a breaking change... |
||
} |
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.
We did not support
FLAGS
andENUMFLAGS
in rawval_to_{json,string}.