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

fix(userspace): solving batch of recent regressions #1524

Merged
merged 3 commits into from
Nov 29, 2023

Conversation

jasondellaluce
Copy link
Contributor

What type of PR is this?

/kind bug

Any specific area of the project related to this PR?

/area libscap

/area libsinsp

Does this PR require a change in the driver versions?

What this PR does / why we need it:

Which issue(s) this PR fixes:

I was able to run a bunch of experiments on the current mainline and came up with few bugs that caused inconsistencies or segfaults.

Special notes for your reviewer:

Does this PR introduce a user-facing change?:

NONE

@jasondellaluce
Copy link
Contributor Author

/milestone 0.14.0

@poiana poiana added this to the 0.14.0 milestone Nov 29, 2023
@poiana poiana added the size/M label Nov 29, 2023
@poiana
Copy link
Contributor

poiana commented Nov 29, 2023

LGTM label has been added.

Git tree hash: 9c071a36e7f0602785b3a44ba07a56bb775052d5

@@ -88,7 +88,7 @@ bool sinsp_container_manager::remove_inactive_containers()
});

auto containers = m_containers.lock();
if (m_inspector->m_sinsp_stats_v2)
if (m_inspector != nullptr && m_inspector->m_sinsp_stats_v2)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to check for m_inspector != nullptr before dereferencing the stats_v2 buffer. I was able to reproduce segfault in some common legit code paths. cc @incertum

Copy link
Contributor

@incertum incertum Nov 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @jasondellaluce yes in that original PR we had discussions about checking m_inspector but it was wanted to not do so for the most part. Glad you checked on this one instance where we should have kept it ❤️ !

@@ -585,15 +585,15 @@ static int32_t scap_proc_add_from_proc(struct scap_linux_platform* linux_platfor
f = fopen(filename, "r");
if(f == NULL)
{
return SCAP_SUCCESS;
return scap_errprintf(error, errno, "can't find valid proc dir in %s", dir_name);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the past, returning SCAP_SUCCESS was fair enough, since the actual result thread info allocation happened below and the caller could still check for a NULL out thread info. Now, we can’t rely on the NULL result, since the caller is responsible of allocating it. As a consequence, for invalid thread IDs we always returned bogus scap thread infos. So IMO this is easily fixable by returning SCAP_FAILURE there, since they are actual failure scenarios.

@poiana
Copy link
Contributor

poiana commented Nov 29, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: gnosek, jasondellaluce, LucaGuerra

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [LucaGuerra,gnosek,jasondellaluce]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@@ -88,7 +88,7 @@ bool sinsp_container_manager::remove_inactive_containers()
});

auto containers = m_containers.lock();
if (m_inspector->m_sinsp_stats_v2)
if (m_inspector != nullptr && m_inspector->m_sinsp_stats_v2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In line 69 we dereference the inspector 🤔

	if(m_inspector->m_lastevent_ts >
		m_last_flush_time_ns + m_inspector->m_inactive_container_scan_time_ns)
		m_last_flush_time_ns + m_inspector->m_inactive_container_scan_time_ns)

Not sure if we want to add an extra check also above of remove these checks like before

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it is also used at line 66

@poiana poiana merged commit cabe6d3 into master Nov 29, 2023
21 checks passed
@poiana poiana deleted the fix/misc-recent-regressions branch November 29, 2023 14:26
@Andreagit97
Copy link
Member

uhm i didn't see there was already a second approve

@LucaGuerra
Copy link
Contributor

And I didn't notice other uses of m_inspector. @jasondellaluce perhaps it would make sense to fix them in a subsequent PR ;)

Also, I was confused by m_inspector checks as well because it was not clear if that could or could not be NULL so some comment may be useful for the next person.

@incertum
Copy link
Contributor

+1 re #1524 (comment) since for the most part we don't check m_inspector a comment explaining why it's needed here would be great!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants