Bug 259504 - fuser doesn't find processes due to wrong fsid type
Summary: fuser doesn't find processes due to wrong fsid type
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 12.2-RELEASE
Hardware: Any Any
: --- Affects Many People
Assignee: Andriy Gapon
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-10-28 14:02 UTC by Markus Wild
Modified: 2021-11-08 06:02 UTC (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Wild 2021-10-28 14:02:04 UTC
fuser {file} is supposed to return all pids that have {file} open. It doesn't:

# fuser /usr/local/sbin/httpd 
/usr/local/sbin/httpd:

cause seems to be a wrong type of fsid in fuser.c. With the following change:

--- a/usr.bin/fstat/fuser.c
+++ b/usr.bin/fstat/fuser.c
@@ -92,7 +92,7 @@ struct consumer {
        STAILQ_ENTRY(consumer)  next;
 };
 struct reqfile {
-       uint32_t        fsid;
+       uint64_t        fsid;
        uint64_t        fileid;
        const char      *name;
        STAILQ_HEAD(, consumer) consumers;


fuser does again what it's supposed to do:
# fuser /usr/local/sbin/httpd 
/usr/local/sbin/httpd:   871x   870x   869x   868x   867x   832x

The bug seems to be present in releases since 12 up to at least 13-releng (didn't check 14).
Comment 1 commit-hook freebsd_committer freebsd_triage 2021-11-01 06:54:38 UTC
A commit in branch main references this bug:

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

commit e18fbe6f19ed106f035c7d2aaeade6eb55cc0b5a
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2021-11-01 06:40:17 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2021-11-01 06:45:26 +0000

    fuser: restore functionality by fixing fsid type

    Use types from sys/stat.h for the filesystem and inode numbers for extra
    safety.

    PR:             259504
    Reported by:    Markus Wild <freebsd-bugs@virtualtec.ch>
    MFC after:      1 week

 usr.bin/fstat/fuser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 2 Andriy Gapon freebsd_committer freebsd_triage 2021-11-01 06:55:56 UTC
(In reply to Markus Wild from comment #0)
Thank you very much for the analysis and the fix.
Submitted in a slightly different form.
Comment 3 Markus Wild 2021-11-01 07:41:42 UTC
Thanks for taking care of this!

Shouldn't then <libprocstat.h> also be changed to non-generic 
types? struct vnstat uses uint64_t etc.
Comment 4 Andriy Gapon freebsd_committer freebsd_triage 2021-11-01 18:04:07 UTC
(In reply to Markus Wild from comment #3)
That's an interesting question.
I think that libprocstat.h should not be changed as it operates with fixed size types because of libkvm, etc.  At the same time, fuser uses both libprocstat and sys/stat.h interfaces.  So, it kind of bridges between struct stat and struct vnstat.
Comment 5 commit-hook freebsd_committer freebsd_triage 2021-11-08 05:56:38 UTC
A commit in branch stable/13 references this bug:

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

commit df838c540632ce3840f78a9067dd9de32458c71a
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2021-11-01 06:40:17 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2021-11-08 05:55:30 +0000

    fuser: restore functionality by fixing fsid type

    Use types from sys/stat.h for the filesystem and inode numbers for extra
    safety.

    PR:             259504
    Reported by:    Markus Wild <freebsd-bugs@virtualtec.ch>
    MFC after:      1 week

    (cherry picked from commit e18fbe6f19ed106f035c7d2aaeade6eb55cc0b5a)

 usr.bin/fstat/fuser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2021-11-08 06:01:39 UTC
A commit in branch stable/12 references this bug:

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

commit d3aca6fe9bf97ea22bb9bee365b616bcb77a1220
Author:     Andriy Gapon <avg@FreeBSD.org>
AuthorDate: 2021-11-01 06:40:17 +0000
Commit:     Andriy Gapon <avg@FreeBSD.org>
CommitDate: 2021-11-08 05:59:01 +0000

    fuser: restore functionality by fixing fsid type

    Use types from sys/stat.h for the filesystem and inode numbers for extra
    safety.

    PR:             259504
    Reported by:    Markus Wild <freebsd-bugs@virtualtec.ch>
    MFC after:      1 week

    (cherry picked from commit e18fbe6f19ed106f035c7d2aaeade6eb55cc0b5a)

 usr.bin/fstat/fuser.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)