Skip to content

Conversation

@opsiff
Copy link
Member

@opsiff opsiff commented Feb 24, 2025

mainline inclusion
from mainline-v6.7-rc1
category: security

__read_mostly predates __ro_after_init. Many variables which are marked __read_mostly should have been __ro_after_init from day 1.

Also, mark some stuff as "const" and "__init" while I'm at it.

[akpm@linux-foundation.org: revert sysctl_nr_open_min, sysctl_nr_open_max changes due to arm warning] [akpm@linux-foundation.org: coding-style cleanups] Link: https://lkml.kernel.org/r/4f6bb9c0-abba-4ee4-a7aa-89265e886817@p183
Signed-off-by: Alexey Dobriyan adobriyan@gmail.com
Signed-off-by: Andrew Morton akpm@linux-foundation.org
(cherry picked from commit 68279f9)
Signed-off-by: Wentao Guan guanwentao@uniontech.com

Summary by Sourcery

Marks several kernel variables and data structures as read-only after initialization using the __ro_after_init macro. This change enhances memory protection and security by preventing unintended modifications to these variables after the initialization phase. Additionally, some variables are marked as const and the __init macro is used where appropriate.

Enhancements:

  • Marks several variables and data structures as __ro_after_init instead of __read_mostly, indicating that they are read-only after initialization. This provides better memory protection and potentially improves security by preventing unintended modifications after the initialization phase.
  • Marks some variables as const and uses the __init macro where appropriate.

mainline inclusion
from mainline-v6.7-rc1
category: security

__read_mostly predates __ro_after_init. Many variables which are marked
__read_mostly should have been __ro_after_init from day 1.

Also, mark some stuff as "const" and "__init" while I'm at it.

[akpm@linux-foundation.org: revert sysctl_nr_open_min, sysctl_nr_open_max changes due to arm warning]
[akpm@linux-foundation.org: coding-style cleanups]
Link: https://lkml.kernel.org/r/4f6bb9c0-abba-4ee4-a7aa-89265e886817@p183
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
(cherry picked from commit 68279f9)
Signed-off-by: Wentao Guan <guanwentao@uniontech.com>
@sourcery-ai
Copy link

sourcery-ai bot commented Feb 24, 2025

Reviewer's Guide by Sourcery

This pull request replaces __read_mostly with __ro_after_init for variables that should be read-only after initialization. It also marks shmem_init_inodecache and shmem_destroy_inodecache as __init.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Replaced __read_mostly with __ro_after_init for variables that should be read-only after initialization.
  • Changed sysctl_mount_max from __read_mostly to __ro_after_init.
  • Changed m_hash_mask from __read_mostly to __ro_after_init.
  • Changed m_hash_shift from __read_mostly to __ro_after_init.
  • Changed mp_hash_mask from __read_mostly to __ro_after_init.
  • Changed mp_hash_shift from __read_mostly to __ro_after_init.
  • Changed mount_hashtable from __read_mostly to __ro_after_init.
  • Changed mountpoint_hashtable from __read_mostly to __ro_after_init.
  • Changed mnt_cache from __read_mostly to __ro_after_init.
  • Changed fs_kobj to __ro_after_init.
  • Changed pwq_release_worker to __ro_after_init.
  • Changed system_wq from __read_mostly to __ro_after_init.
  • Changed system_highpri_wq from __read_mostly to __ro_after_init.
  • Changed system_long_wq from __read_mostly to __ro_after_init.
  • Changed system_unbound_wq from __read_mostly to __ro_after_init.
  • Changed system_freezable_wq from __read_mostly to __ro_after_init.
  • Changed system_power_efficient_wq from __read_mostly to __ro_after_init.
  • Changed system_freezable_power_efficient_wq from __read_mostly to __ro_after_init.
  • Changed dentry_cache from __read_mostly to __ro_after_init.
  • Changed d_hash_shift from __read_mostly to __ro_after_init.
  • Changed dentry_hashtable from __read_mostly to __ro_after_init.
  • Changed names_cachep from __read_mostly to __ro_after_init.
  • Changed i_hash_mask from __read_mostly to __ro_after_init.
  • Changed i_hash_shift from __read_mostly to __ro_after_init.
  • Changed inode_hashtable from __read_mostly to __ro_after_init.
  • Changed inode_cachep from __read_mostly to __ro_after_init.
  • Changed fanotify_mark_cache from __read_mostly to __ro_after_init.
  • Changed fanotify_fid_event_cachep from __read_mostly to __ro_after_init.
  • Changed fanotify_path_event_cachep from __read_mostly to __ro_after_init.
  • Changed fanotify_perm_event_cachep from __read_mostly to __ro_after_init.
  • Changed shm_mnt to __ro_after_init.
  • Changed shmem_inode_cachep to __ro_after_init.
  • Changed bdev_cachep from __read_mostly to __ro_after_init.
  • Changed blockdev_superblock from __read_mostly to __ro_after_init.
  • Changed bd_mnt to __ro_after_init.
  • Changed epi_cache from __read_mostly to __ro_after_init.
  • Changed pwq_cache from __read_mostly to __ro_after_init.
  • Changed ephead_cache from __read_mostly to __ro_after_init.
  • Changed dnotify_struct_cache from __read_mostly to __ro_after_init.
  • Changed dnotify_mark_cache from __read_mostly to __ro_after_init.
  • Changed dnotify_group from __read_mostly to __ro_after_init.
  • Changed kernfs_node_cache to __ro_after_init.
  • Changed kernfs_iattrs_cache to __ro_after_init.
  • Changed kernfs_locks to __ro_after_init.
  • Changed anon_inode_mnt from __read_mostly to __ro_after_init.
  • Changed anon_inode_inode to __ro_after_init.
  • Changed bh_cachep from __read_mostly to __ro_after_init.
  • Changed max_buffer_heads to __ro_after_init.
  • Changed flctx_cache from __read_mostly to __ro_after_init.
  • Changed filelock_cache from __read_mostly to __ro_after_init.
  • Changed audit_tree_group to __ro_after_init.
  • Changed audit_tree_mark_cachep from __read_mostly to __ro_after_init.
  • Changed cdev_map to __ro_after_init.
  • Changed dio_cache from __read_mostly to __ro_after_init.
  • Changed fasync_cache from __read_mostly to __ro_after_init.
  • Changed filp_cachep from __read_mostly to __ro_after_init.
  • Changed inotify_inode_mark_cachep from __read_mostly to __ro_after_init.
  • Changed pipe_mnt from __read_mostly to __ro_after_init.
  • Changed userfaultfd_ctx_cachep from __read_mostly to __ro_after_init.
  • Changed task_group_cache from __read_mostly to __ro_after_init.
  • Changed user_ns_cachep from __read_mostly to __ro_after_init.
  • Changed obj_cache from __read_mostly to __ro_after_init.
  • Changed mm_slot_cache from __read_mostly to __ro_after_init.
  • Changed iint_cache from __read_mostly to __ro_after_init.
fs/namespace.c
kernel/workqueue.c
fs/dcache.c
fs/inode.c
fs/notify/fanotify/fanotify_user.c
mm/shmem.c
block/bdev.c
fs/eventpoll.c
fs/notify/dnotify/dnotify.c
fs/kernfs/mount.c
fs/anon_inodes.c
fs/buffer.c
fs/locks.c
kernel/audit_tree.c
fs/char_dev.c
fs/direct-io.c
fs/fcntl.c
fs/file_table.c
fs/notify/inotify/inotify_user.c
fs/pipe.c
fs/userfaultfd.c
kernel/sched/core.c
kernel/user_namespace.c
lib/debugobjects.c
mm/khugepaged.c
security/integrity/iint.c
Marked shmem_init_inodecache and shmem_destroy_inodecache as __init.
  • Added __init to shmem_init_inodecache.
  • Added __init to shmem_destroy_inodecache.
mm/shmem.c

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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @opsiff - I've reviewed your changes - here's some feedback:

Overall Comments:

  • This looks like a good cleanup, converting __read_mostly to __ro_after_init where appropriate.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@deepin-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: sourcery-ai[bot]
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

@opsiff opsiff merged commit 229b582 into deepin-community:linux-6.6.y Feb 24, 2025
4 of 5 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.

2 participants