Skip to content

compat/linux: return EBADF for O_PATH mmap() and xattr operations#2181

Open
ilovegrape wants to merge 1 commit into
freebsd:mainfrom
ilovegrape:open13-fix-src
Open

compat/linux: return EBADF for O_PATH mmap() and xattr operations#2181
ilovegrape wants to merge 1 commit into
freebsd:mainfrom
ilovegrape:open13-fix-src

Conversation

@ilovegrape
Copy link
Copy Markdown

@ilovegrape ilovegrape commented May 7, 2026

This fixes LTP open13, which expects O_PATH mmap() and fgetxattr()
to fail with EBADF, but FreeBSD returned EACCES for mmap() and
EOPNOTSUPP for fgetxattr().

Apply the same EBADF handling to fsetxattr(), fremovexattr(), and
flistxattr() so the xattr paths stay consistent.

@ilovegrape ilovegrape changed the title compat/linux: return EBADF for LTP open13 O_PATH operations compat/linux: return EBADF for O_PATH mmap() and fgetxattr() May 7, 2026
@lwhsu lwhsu self-assigned this May 7, 2026
@ilovegrape ilovegrape force-pushed the open13-fix-src branch 2 times, most recently from 8ec198c to 63c88bc Compare May 7, 2026 10:28
@ilovegrape ilovegrape changed the title compat/linux: return EBADF for O_PATH mmap() and fgetxattr() compat/linux: return EBADF for O_PATH mmap() and xattr operations May 7, 2026
@ricardobranco777
Copy link
Copy Markdown
Contributor

I suggest to open a bug report in https://bugs.freebsd.org with what is failing and then add a tag with PR: 1234567 in the commit message so it gets more visibility. :)

@ilovegrape
Copy link
Copy Markdown
Author

ilovegrape commented May 22, 2026

I suggest to open a bug report in https://bugs.freebsd.org with what is failing and then add a tag with PR: 1234567 in the commit message so it gets more visibility. :)

I don't have an account, and I need to request one...
Maybe the same is required for #2181 ?

@ricardobranco777 How do you think if I create a patch in Phabricator?

@ricardobranco777
Copy link
Copy Markdown
Contributor

I suggest to open a bug report in https://bugs.freebsd.org with what is failing and then add a tag with PR: 1234567 in the commit message so it gets more visibility. :)

I don't have an account, and I need to request one... Maybe the same is required for #2181 ?

You can use any e-mail to create an account in Bugzilla.

@ricardobranco777 How do you think if I create a patch in Phabricator?

I dunno. Haven't used it yet.

@ilovegrape
Copy link
Copy Markdown
Author

You can use any e-mail to create an account in Bugzilla.

I requested the account once again according to the process just now

This fixes LTP open13, which expects O_PATH mmap() and fgetxattr()
to fail with EBADF, but FreeBSD returned EACCES for mmap() and
EOPNOTSUPP for fgetxattr().

Apply the same EBADF handling to fsetxattr(), fremovexattr(), and
flistxattr() so the xattr paths stay consistent.

PR:             295537
Signed-off-by: YAO, Xin <mr.yaoxin@outlook.com>
@ilovegrape
Copy link
Copy Markdown
Author

Hi @ricardobranco777

Bug fired with commit msg updated, any further comments?

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295537

@ricardobranco777
Copy link
Copy Markdown
Contributor

Hi @ricardobranco777

Bug fired with commit msg updated, any further comments?

https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=295537

Thank you. Including a minimal reproducer also helps. :)

@ilovegrape
Copy link
Copy Markdown
Author

Updated with the comments below on the PR case.

Using the curren FreeBSD 16.0 code, there are 4 failures of the LTP test case open13

$ /opt/ltp/testcases/bin/open13
tst_tmpdir.c:317: TINFO: Using /tmp/LTP_opeJ6gQkD as tmpdir (tmpfs filesystem)
tst_test.c:2047: TINFO: LTP version: 20260130
tst_test.c:2050: TINFO: Tested kernel: 5.15.0 FreeBSD 16.0-CURRENT #2 main-n286042-28d85db46b48: Sun May 24 21 x86_64
tst_kconfig.c:71: TINFO: Couldn't locate kernel config!
tst_test.c:1877: TINFO: Overall timeout per run is 0h 00m 30s
open13.c:77: TPASS: read() on original FD : EBADF (9)
open13.c:79: TPASS: read() on duplicated FD : EBADF (9)
open13.c:77: TPASS: write() on original FD : EBADF (9)
open13.c:79: TPASS: write() on duplicated FD : EBADF (9)
open13.c:77: TPASS: fchmod() on original FD : EBADF (9)
open13.c:79: TPASS: fchmod() on duplicated FD : EBADF (9)
open13.c:77: TPASS: fchown() on original FD : EBADF (9)
open13.c:79: TPASS: fchown() on duplicated FD : EBADF (9)
open13.c:77: TPASS: ioctl() on original FD : EBADF (9)
open13.c:79: TPASS: ioctl() on duplicated FD : EBADF (9)
open13.c:77: TFAIL: mmap() on original FD expected EBADF: EACCES (13)
open13.c:79: TFAIL: mmap() on duplicated FD expected EBADF: EACCES (13)
open13.c:77: TFAIL: fgetxattr() on original FD expected EBADF: EOPNOTSUPP (95)
open13.c:79: TFAIL: fgetxattr() on duplicated FD expected EBADF: EOPNOTSUPP (95)

Summary:
passed 10
failed 4
broken 0
skipped 0
warnings 0

And all passed after the fix

$ /opt/ltp/testcases/bin/open13
tst_tmpdir.c:317: TINFO: Using /tmp/LTP_opeiIAOHE as tmpdir (tmpfs filesystem)
tst_test.c:2047: TINFO: LTP version: 20260130
tst_test.c:2050: TINFO: Tested kernel: 5.15.0 FreeBSD 16.0-CURRENT #10 open13-fix-src-22b97fbf255b-dirty: Thu x86_64
tst_kconfig.c:71: TINFO: Couldn't locate kernel config!
tst_test.c:1877: TINFO: Overall timeout per run is 0h 00m 30s
open13.c:77: TPASS: read() on original FD : EBADF (9)
open13.c:79: TPASS: read() on duplicated FD : EBADF (9)
open13.c:77: TPASS: write() on original FD : EBADF (9)
open13.c:79: TPASS: write() on duplicated FD : EBADF (9)
open13.c:77: TPASS: fchmod() on original FD : EBADF (9)
open13.c:79: TPASS: fchmod() on duplicated FD : EBADF (9)
open13.c:77: TPASS: fchown() on original FD : EBADF (9)
open13.c:79: TPASS: fchown() on duplicated FD : EBADF (9)
open13.c:77: TPASS: ioctl() on original FD : EBADF (9)
open13.c:79: TPASS: ioctl() on duplicated FD : EBADF (9)
open13.c:77: TPASS: mmap() on original FD : EBADF (9)
open13.c:79: TPASS: mmap() on duplicated FD : EBADF (9)
open13.c:77: TPASS: fgetxattr() on original FD : EBADF (9)
open13.c:79: TPASS: fgetxattr() on duplicated FD : EBADF (9)

Summary:
passed 14
failed 0
broken 0
skipped 0
warnings 0

@shkhln
Copy link
Copy Markdown
Contributor

shkhln commented May 24, 2026

The description makes it seem like it would be enough to convert EOPNOTSUPP to EBADF, but the patch itself is a bit more elaborate. Is there any reason for that?

@ilovegrape
Copy link
Copy Markdown
Author

The description makes it seem like it would be enough to convert EOPNOTSUPP to EBADF, but the patch itself is a bit more elaborate. Is there any reason for that?

The patch is only intended to return EBADF for O_PATH file descriptors, not to rewrite all EOPNOTSUPP errors.

Comment thread sys/compat/linux/linux_mmap.c
error = getvnode(td, fd, rights, &fp);
if (error != 0)
return (error);
fdrop(fp, td);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

There is a TOTTOU race.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Good point, I need to think a little deeply into it...

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.

5 participants