Bug 273405 - wc /dev/wmistat0 fails with EBADF
Summary: wc /dev/wmistat0 fails with EBADF
Status: Closed FIXED
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: 13.2-STABLE
Hardware: amd64 Any
: Normal Affects Some People
Assignee: Dag-Erling Smørgrav
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-08-28 17:00 UTC by John F. Carr
Modified: 2023-09-08 10:14 UTC (History)
3 users (show)

See Also:
des: mfc-stable14+
des: mfc-stable13+
des: mfc-stable12+


Attachments
truss -f wc /dev/wmistat0 (17.77 KB, text/plain)
2023-08-28 17:00 UTC, John F. Carr
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description John F. Carr 2023-08-28 17:00:44 UTC
Created attachment 244424 [details]
truss -f wc /dev/wmistat0

If I cat /dev/wmistat0 I see

GUID                                  INST EXPE METH STR EVENT OID
{ABBC0F6A-8EA1-11D1-00A0-C90629100000}   1 NO   WMAA NO  NO    AA
{05901221-D566-11D1-B2F0-00A0C9062910}   1 NO   NO   NO  NO    BA

If instead I wc /dev/wmistat0 I see a "Bad file descriptor" error.  The may be related to capsicum sandboxing.  Output of truss is attached.
Comment 1 John F. Carr 2023-08-28 17:27:25 UTC
Driver function acpi_wmi_wmistat_read prohibits reads except by the same process ID that opened the device.  The PID check was in the first version of the driver in 2009.  This is a very odd restriction.  It is stricter than allowing only one file descriptor to attach to the device or only allowing the generated data to be read once.
Comment 2 Dag-Erling Smørgrav freebsd_committer freebsd_triage 2023-08-28 22:01:45 UTC
https://reviews.freebsd.org/D41621
Comment 3 commit-hook freebsd_committer freebsd_triage 2023-08-29 17:25:02 UTC
A commit in branch main references this bug:

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

commit 28977cb9bc15a7f1fb7d28e14cd03f8dafd4e155
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-08-29 17:23:16 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-08-29 17:23:16 +0000

    wmistat: don't restrict reading to the pid that opened the fd.

    PR:             273405
    MFC after:      1 week
    Reviewed by:    emaste
    Differential Revision:  https://reviews.freebsd.org/D41621

 sys/dev/acpi_support/acpi_wmi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Comment 4 commit-hook freebsd_committer freebsd_triage 2023-09-07 20:29:17 UTC
A commit in branch stable/14 references this bug:

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

commit f41c23ee5b347c422f79630345af8a22bc9a5190
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-08-29 17:23:16 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-09-07 20:28:30 +0000

    wmistat: don't restrict reading to the pid that opened the fd.

    PR:             273405
    MFC after:      1 week
    Reviewed by:    emaste
    Differential Revision:  https://reviews.freebsd.org/D41621

    (cherry picked from commit 28977cb9bc15a7f1fb7d28e14cd03f8dafd4e155)

    Approved by:    re (gjb)

 sys/dev/acpi_support/acpi_wmi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Comment 5 commit-hook freebsd_committer freebsd_triage 2023-09-08 10:13:10 UTC
A commit in branch stable/12 references this bug:

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

commit 9f9ba5669212d3df01d007fb54056e37814fc438
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-08-29 17:23:16 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-09-08 10:12:21 +0000

    wmistat: don't restrict reading to the pid that opened the fd.

    PR:             273405
    MFC after:      1 week
    Reviewed by:    emaste
    Differential Revision:  https://reviews.freebsd.org/D41621

    (cherry picked from commit 28977cb9bc15a7f1fb7d28e14cd03f8dafd4e155)

 sys/dev/acpi_support/acpi_wmi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
Comment 6 commit-hook freebsd_committer freebsd_triage 2023-09-08 10:14:13 UTC
A commit in branch stable/13 references this bug:

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

commit 17ed300f0833c8e6dd6bce95748f5dbe33050a3c
Author:     Dag-Erling Smørgrav <des@FreeBSD.org>
AuthorDate: 2023-08-29 17:23:16 +0000
Commit:     Dag-Erling Smørgrav <des@FreeBSD.org>
CommitDate: 2023-09-08 10:09:22 +0000

    wmistat: don't restrict reading to the pid that opened the fd.

    PR:             273405
    MFC after:      1 week
    Reviewed by:    emaste
    Differential Revision:  https://reviews.freebsd.org/D41621

    (cherry picked from commit 28977cb9bc15a7f1fb7d28e14cd03f8dafd4e155)

 sys/dev/acpi_support/acpi_wmi.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)