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

RBAC: Fix use-after-free in security::acl_store #17414

Merged
merged 2 commits into from
Mar 27, 2024

Conversation

oleiman
Copy link
Member

@oleiman oleiman commented Mar 26, 2024

acl_store: Sub node_hash_map for flat_hash_map in remove_bindings

We maintain a running vector of roles principal views to delete from a small
cache maintained by each matched acl_entry_set. The value type is a view to
avoid excessive copying, but that view is always into the principal component
of a key entry (acl_binding) in a flat_hash_map.

This is problematic because any insertion into flat_hash_map might result in
a rehash, invalidating key pointers (including the pointer to key struct member
contained in the principal_view), resulting in use-after-free errors whenever
the following conditions are met:

  • More than one binding is deleted from the ACL store
    • i.e. > 1 binding matches the provided filters
  • One of those bindings is to a role principal

This commit also adds a test for this (common) situation. I've verified that
without this change, the test does indeed crash as expected.

Fixes https://github.com/redpanda-data/core-internal/issues/1202

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v23.3.x
  • v23.2.x

Release Notes

  • none

Written this way initially to (hopefully) keep hold of its memory,
but erase_to_end effectively decays to clear if erasing all elements.

Signed-off-by: Oren Leiman <oren.leiman@redpanda.com>
@oleiman oleiman self-assigned this Mar 26, 2024
@oleiman oleiman changed the title RBAC: Fix use-after-free in security::authorizer RBAC: Fix use-after-free in security::acl_store Mar 26, 2024
dotnwat
dotnwat previously approved these changes Mar 26, 2024
src/v/security/acl.cc Show resolved Hide resolved
We maintain a running vector of roles principal views to delete from a small
cache maintained by each matched acl_entry_set. The value type is a view to
avoid excessive copying, but that view is always into the principal component
of a key entry (acl_binding) in a flat_hash_map.

This is problematic because any insertion into flat_hash_map might result in
a rehash, invalidating key pointers (including the pointer to key struct member
contained in the principal_view), resulting in use-after-free errors whenever
the following conditions are met:

- More than one binding is deleted from the ACL store
  - i.e. > 1 binding matches the provided filters
- One of those bindings is to a role principal

This commit also adds a test for this (common) situation. I've verified that
*without* this change, the test does indeed crash as expected.

Signed-off-by: Oren Leiman <oren.leiman@redpanda.com>
@oleiman oleiman merged commit 1d4f70b into redpanda-data:dev Mar 27, 2024
17 checks passed
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.

None yet

4 participants