Skip to content

kabi: keep keyring index identities private - #2268

Merged
opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-11-17-kabi
Nov 17, 2026
Merged

opsiff merged 1 commit into
deepin-community:linux-6.6.yfrom
opsiff:linux-6.6.y-2026-11-17-kabi

Conversation

@opsiff

@opsiff opsiff commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Restore the frozen key_type, key_tag, keyring_index_key and key layouts while retaining address-independent keyring ordering. Store type and domain identities and per-key indexes in private, reference-counted XArrays instead of extending public structures.

Direct RCU lookups borrow existing identities without allocating, while key publication and link edits own the references needed across type unregister and domain teardown.

Fixes: ab9e532 ("keys: make keyring indexes independent of kernel addresses")

Summary by Sourcery

Keep keyring index identities private without expanding public key structures or changing address-independent ordering.

Bug Fixes:

  • Restore the frozen public key and keyring index layouts while preserving address-independent keyring ordering.

Enhancements:

  • Move key type, domain, and per-key index identities into private reference-counted XArrays.
  • Ensure RCU lookups and keyring link edits safely retain identities across type unregister and domain teardown.

@sourcery-ai

sourcery-ai Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Data structures

Restore the frozen public structure layouts by removing index identities and cached IDs from key types, tags, index keys, and keys.

  • include/linux/key-type.h L164 (removed lines)
  • include/linux/key.h L111 (removed lines), L133 (removed lines), L254 (removed lines)

Add private identity and per-key index records backed by reference-counted XArrays, and adjust search context to carry a private lookup key.

  • security/keys/internal.h L124
  • security/keys/keyring.c L20, L44-172, L179-197

API

Change the internal link-begin interface to receive the key when available, enabling reuse of its published private index.

  • security/keys/internal.h L96-100, L109
  • security/keys/keyring.c L1614-1628

Uses of the API

Update key allocation, linking, construction, and movement callers to use private-index allocation and the revised link-begin interface.

  • security/keys/key.c L365-1067 (6 small edits)
  • security/keys/keyring.c L1830, L2019
  • security/keys/request_key.c L443, L464

Implementation

Manage identity references and private per-key index allocation, hashing, lookup, and destruction while preserving address-independent ordering.

  • security/keys/keyring.c L372-419, L1645-1662, L1876-1889 (+28 small edits)

Release private key indexes during key garbage collection.

  • security/keys/gc.c L190

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@dongert
dongert requested a balanced review from Copilot November 17, 2026 05:36
@deepin-ci-robot

Copy link
Copy Markdown

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please ask for approval from opsiff. For more information see the Code Review Process.

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

Details Needs approval from an approver in each of these files:

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

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 1 issue

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="security/keys/keyring.c" line_range="152" />
<code_context>
+			      const struct keyring_index_key *key)
+{
+	memset(index, 0, sizeof(*index));
+	index->key = *key;
+	if (!index->key.domain_tag) {
+		if (index->key.type->flags & KEY_TYPE_NET_DOMAIN)
</code_context>
<issue_to_address>
**Existing keys are missed**

When a direct search or update lookup uses a nonempty description prefix whose inline index bytes are not populated, `keyring_index_lookup()` copies the caller’s index key without finalizing its description prefix, and `hash_key_type_and_desc()` only sets the hash. The associative-array lookup compares a different `x` chunk from the one stored for the key, so direct searches and update lookups miss existing keys.

Finalize the description prefix in the index key before the associative-array lookup.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨

Comment thread security/keys/keyring.c Resolved

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 Changes recommended

A link delayed across type teardown can prepare an edit using the wrong type identities, placing the key on the wrong tree path and breaking lookup or unlink.

3 open issues
What changed in this PR

This PR restores the frozen public key structure layouts while preserving address-independent keyring ordering. It moves index identities and their lifetime management into private storage.

Changes:

  • Remove identity fields from public key, key-type, domain, and index structures.
  • Use private, reference-counted XArrays for identities, per-key indexes, and link-edit indexes.
  • Adapt searches, linking, allocation, and cleanup to use private indexes.
File Description
security/​keys/​keyring.c Implements private identities and indexes for searches and link operations.
security/​keys/​key.c Allocates private indexes and adds error-path cleanup.
security/​keys/​internal.h Declares index lifecycle helpers and private search-context storage.
security/​keys/​gc.c Releases private indexes during key destruction.
include/​linux/​key.h Removes identity fields to restore public structure layouts.
include/​linux/​key-type.h Removes the public key-type identity field.

Review effort: Balanced

Comment thread security/keys/keyring.c Resolved
Comment thread security/keys/key.c Resolved
Comment thread security/keys/keyring.c Resolved
deepin inclusion
category: kabi

Restore the frozen key_type, key_tag, keyring_index_key and key layouts while retaining address-independent keyring ordering. Store type and domain identities and per-key indexes in private, reference-counted XArrays instead of extending public structures.

Direct RCU lookups borrow existing identities without allocating. Existing keys also reuse their published indexes for link edits, keeping edit preparation, insertion and unlink on the original tree path across type unregister and domain teardown. Only an edit prepared before key allocation owns a temporary index, which is carried in the edit leaf pointer.

Finalize inline descriptions in private lookup keys so direct searches see the same chunks as published indexes. Route private-index allocation failures through the description cleanup path.

Fixes: ab9e532 ("keys: make keyring indexes independent of kernel addresses")
Signed-off-by: shaoyang <shaoyang@uniontech.com>
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@opsiff
opsiff force-pushed the linux-6.6.y-2026-11-17-kabi branch from ff6ec8c to 3c110f4 Compare November 17, 2026 06:24
@dongert
dongert requested a balanced review from Copilot November 17, 2026 06:26

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Needs a closer look

Changes to keyring leaf representation and identity ownership require specialized human review, RCU/refcount stress testing, and frozen-ABI validation across x86_64/aarch64, including CONFIG_KEYP, that static inspection cannot provide.

No open issues 🎉

3 resolved since last review

Review effort: Balanced

@opsiff
opsiff merged commit b3af1e5 into deepin-community:linux-6.6.y Nov 17, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants