Skip to content

fix: libmount not notify mount event - #23

Merged
Zeno-sole merged 1 commit into
deepin-community:masterfrom
wangrong1069:pr0826
Aug 26, 2026
Merged

fix: libmount not notify mount event#23
Zeno-sole merged 1 commit into
deepin-community:masterfrom
wangrong1069:pr0826

Conversation

@wangrong1069

@wangrong1069 wangrong1069 commented Aug 26, 2026

Copy link
Copy Markdown
Contributor

When mnt_context_mount() retries a failed mount as read-only, it calls mnt_context_prepare_update() again, which invokes mnt_update_start() a second time. Without checking whether act_fd is already open, the old fd is overwritten and leaked, and its LOCK_SH prevents mnt_update_end() from unlinking the act file.

Guard mnt_update_start() with an act_fd >= 0 check: if the act file is already open and locked, reuse the existing fd instead of opening a new one.

When mnt_context_mount() fails in mnt_context_do_mount(), the mnt_context_update_tabs() call is guarded by if (!rc) and gets skipped. This means mnt_update_end() -- the only function that unlinks /run/mount/utab.act -- never runs, leaving the act file orphaned on disk.

mnt_free_update() only close()s act_fd without releasing the lock or unlinking the act file. Fix this by calling mnt_update_end() before unreffing members, which properly unlocks, unlinks and closes the act file. Add a fallback close() for the case where mnt_update_end() fails to acquire the lock and returns early without closing the fd.

The utab.act file was introduced in v2.40 (commit 9218c96) and this leak has been present since then through the current master. A leftover utab.act causes mnt_monitor's
kernel_event_verify() to veil all subsequent kernel mount events (monitor.c: kernel_veiled + access(utab.act)==0), making consumers like udisksd miss real mount/umount notifications.

PMS: BUG-374891
Upstream: util-linux/util-linux#4572

Summary by Sourcery

Fix libmount active update file handling so failed or retried mounts do not suppress subsequent kernel mount events.

Bug Fixes:

  • Prevent libmount from leaking and orphaning the utab.act file during mount retries and failed mount cleanup, ensuring mount event notifications continue to reach consumers.

Enhancements:

  • Reuse an existing active update file descriptor during repeated mount preparation and properly finalize update state during cleanup.

Chores:

  • Add Debian packaging patches and changelog entries for the libmount mount-event notification fixes.

When mnt_context_mount() retries a failed mount as read-only, it calls
mnt_context_prepare_update() again, which invokes mnt_update_start() a
second time.  Without checking whether act_fd is already open, the old
fd is overwritten and leaked, and its LOCK_SH prevents mnt_update_end()
from unlinking the act file.

Guard mnt_update_start() with an act_fd >= 0 check: if the act file is
already open and locked, reuse the existing fd instead of opening a new
one.

When mnt_context_mount() fails in mnt_context_do_mount(), the
mnt_context_update_tabs() call is guarded by if (!rc) and gets
skipped. This means mnt_update_end() -- the only function that
unlinks /run/mount/utab.act -- never runs, leaving the act file
orphaned on disk.

mnt_free_update() only close()s act_fd without releasing the lock
or unlinking the act file. Fix this by calling mnt_update_end()
before unreffing members, which properly unlocks, unlinks and
closes the act file. Add a fallback close() for the case where
mnt_update_end() fails to acquire the lock and returns early
without closing the fd.

The utab.act file was introduced in v2.40 (commit 9218c96)
and this leak has been present since then through the current
master. A leftover utab.act causes mnt_monitor's
kernel_event_verify() to veil all subsequent kernel mount events
(monitor.c: kernel_veiled + access(utab.act)==0), making
consumers like udisksd miss real mount/umount notifications.

PMS: BUG-374891
Upstream: util-linux/util-linux#4572
@sourcery-ai

sourcery-ai Bot commented Aug 26, 2026

Copy link
Copy Markdown
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Fixes libmount’s utab.act lifecycle across mount retries and failures by reusing existing locks/descriptors and reliably ending updates, preventing orphaned act files that can veil subsequent kernel mount events.

File-Level Changes

Change Details Files
Prevent mount-update state corruption and descriptor leaks when mount preparation is retried.
  • Reuse an already-open act-file descriptor instead of reopening and overwriting it.
  • Preserve the existing lock and update state across read-only mount retries.
debian/patches/libmount-mnt_update_start-reuse-existing-act-fd.patch
Ensure the act file is fully finalized when update cleanup occurs, including failed mounts.
  • Finalize updates from mnt_free_update() so the act file is unlocked, unlinked, and closed.
  • Add a close fallback when mnt_update_end() cannot acquire the lock.
  • Avoid skipping cleanup after mnt_context_do_mount() failure.
debian/patches/libmount-mnt_free_update-properly-end-act-file.patch
Package and enable the libmount fixes in the Debian build.
  • Register both patches in the patch series.
  • Document the bug fix in the Debian changelog.
debian/patches/series
debian/changelog

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

@deepin-ci-robot

Copy link
Copy Markdown
Contributor

[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 assign tsic404 for approval. 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

@github-actions

Copy link
Copy Markdown

TAG Bot

TAG: 2.40.4-3deepin14
EXISTED: no
DISTRIBUTION: unstable

@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 reviewed your changes and they look great!


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.

@Zeno-sole
Zeno-sole merged commit 7f1072f into deepin-community:master Aug 26, 2026
6 checks passed
@Zeno-sole

Copy link
Copy Markdown
Contributor

/integrate

@github-actions

Copy link
Copy Markdown

AutoIntegrationPr Bot
auto integrate with pr url: deepin-community/Repository-Integration#4512
PrNumber: 4512
PrBranch: auto-integration-32952862175

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.

3 participants