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
pkg/k8s: fix invalid memory address or nil pointer dereference #17642
Conversation
Since k8sMeta might return nil, we should check for it before accessing the fields of that structure otherwise we will risk on panic for a nil pointer dereference. Fixes: 63c0b29 ("Checks k8s metadata for pod before removing IP from ipccahe") Signed-off-by: André Martins <andre@cilium.io>
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.
Do we know if it's expected that we try to remove from the ipcache an IP address that isn't in the ipcache? /cc @Weil0ng
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.
🎉
So removal happens when we get an CEP delete event and the insertion should happen when we first get the add event for the CEP, correct? I could be missing something but if the k8s cache is synced, then we should always have the IP address in the ipcache before getting the delete event? |
@Weil0ng I think we might have received the CEP delete event for a CEP that didn't have any metadata in the ipcache. That could have happened before the k8s cache was synced. |
Yea makes sense. |
/test |
Can this be backported to 1.10? I stumbled across this crash today and was forced to switch to a CI image. |
This is fixing a bug, so per our backporting guidelines should be backported to v1.10. I think it was just an oversight before. @codablock Thanks for reporting it! 🙏 |
@codablock can you open a GH issue with the panic that you have seen? The bug this PR is fixing does not exist on v1.10 since the code was introduced in v1.11. That's why it was not marked as to be backported. /cc @pchaigno |
@aanm I don't have the logs anymore. But I later realised that I was on v1.11-rc0 due the Helm chart being on that version already. So I assume I got unlucky and was using a version that had the bug freshly introduced but the fix missing. |
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.
Just realized, shouldn't this line need fix too? https://github.com/cilium/cilium/blob/master/pkg/k8s/watchers/pod.go#L828
But maybe this is superseded by #17909 and doesn't require a separate fix?
no worries, my bad :) Will make sure to tag folks when it's a directed question next time. |
Since k8sMeta might return nil, we should check for it before accessing
the fields of that structure otherwise we will risk on panic for a nil
pointer dereference.
Fixes: 63c0b29 ("Checks k8s metadata for pod before removing IP from ipccahe")
Signed-off-by: André Martins andre@cilium.io