Bug 283420 - mount -p doesn't display correctly unionfs mounts
Summary: mount -p doesn't display correctly unionfs mounts
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: CURRENT
Hardware: Any Any
: --- Affects Only Me
Assignee: Jason A. Harmening
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2024-12-19 17:26 UTC by Olivier Cochard
Modified: 2025-01-09 06:12 UTC (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Olivier Cochard freebsd_committer freebsd_triage 2024-12-19 17:26:19 UTC
mount -p (displaying in fstab format) is buggy with unionfs mounts.

How to reproduce:

$ mkdir -p /tmp/jails/usr/local
$ mount -t unionfs -o below -o noatime /usr/local /tmp/jails/testing/usr/local
$ mount | grep unionfs
<below>:/usr/local on /tmp/jails/usr/local (unionfs, NFS exported, local, noatime, nfsv4acls)
$ $ mount -p | grep unionfs
/u                      /tmp/jails/usr/local unionfs    rw,noatime,nfsv4acls    0 0

=> It is displaying "/u" in place of "/usr/local".
Comment 1 commit-hook freebsd_committer freebsd_triage 2024-12-30 00:42:09 UTC
A commit in branch main references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=a314c60625af1829b7e12c3a4cedb74d7f69d074

commit a314c60625af1829b7e12c3a4cedb74d7f69d074
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2024-12-22 06:36:30 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2024-12-30 00:39:49 +0000

    mount(8): Avoid truncation when fstab-formatting unionfs mount info

    When displaying unionfs mounts in fstab format (`mount -p`), mount(8)
    currently uses strlcpy to remove the disposition prefix from the mount
    name returned by getmntinfo(3).  But strlcpy, like strcpy before it,
    does not guarantee correct behavior if the source and destination
    buffers overlap.

    Just offset the buffer and avoid the destructive copy in the first
    place.

    PR:             283420
    Reviewed by:    imp (previous version), olce
    MFC after:      1 week
    Differential Revision: https://reviews.freebsd.org/D48177

 sbin/mount/mount.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)
Comment 2 commit-hook freebsd_committer freebsd_triage 2025-01-09 06:12:16 UTC
A commit in branch stable/14 references this bug:

URL: https://cgit.FreeBSD.org/src/commit/?id=6584e5a1c54ff24ed7c9eb80a884b4e7f54e7288

commit 6584e5a1c54ff24ed7c9eb80a884b4e7f54e7288
Author:     Jason A. Harmening <jah@FreeBSD.org>
AuthorDate: 2024-12-22 06:36:30 +0000
Commit:     Jason A. Harmening <jah@FreeBSD.org>
CommitDate: 2025-01-09 06:10:00 +0000

    mount(8): Avoid truncation when fstab-formatting unionfs mount info

    When displaying unionfs mounts in fstab format (`mount -p`), mount(8)
    currently uses strlcpy to remove the disposition prefix from the mount
    name returned by getmntinfo(3).  But strlcpy, like strcpy before it,
    does not guarantee correct behavior if the source and destination
    buffers overlap.

    Just offset the buffer and avoid the destructive copy in the first
    place.

    PR:             283420
    Reviewed by:    imp (previous version), olce
    Differential Revision: https://reviews.freebsd.org/D48177

    (cherry picked from commit a314c60625af1829b7e12c3a4cedb74d7f69d074)

 sbin/mount/mount.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)