Thread View: muc.lists.netbsd.tech.kern
5 messages
5 total messages
Started by Aiman Najjar
Sat, 17 Oct 2026 03:00
compat_linux: open: Supporting O_NOATIME
Author: Aiman Najjar
Date: Sat, 17 Oct 2026 03:00
Date: Sat, 17 Oct 2026 03:00
37 lines
3767 bytes
3767 bytes
Hello tech-kern, I'm new to NetBSD and I am interested in contributing to compat_linux. I've had a chance to look at the work Henrique did for the LTP as part of GSoC, I am interested in working on some of the failing test cases. In particular, `open02` test case seems like a good candidate for a first patch. The failing test case passes `O_NOATIME` mode flag to open, and expects it to fail with `EPERM` error. My question: what is the correct way to address this, do we: 1) add native support for `O_NOATIME`, which allows users to flag (or hint) that they don't want the file's access time to be updated (useful for backup solutions processing large amount of files), or 2) do we emulate it, somehow, at `compat_linux` layer (e.g. only support this behavior when the module is installed) or 3) Do we only check for user privileges (which would make the test pass) but do not actually implement the behavior? Additionally, re. privilege check: Linux checks the privilege by ensuring process effective UID matches the file owner UID, or if the process has `CAP_FOWNER` [*]. On NetBSD, I presume we'd only do the first check? Also, stumbled upon a similar discussion in FreeBSD forums: https://forums.freebsd.org/threads/o_noatime-option-in-open.92523/ Thanks, Aiman [*] https://manpages.debian.org/trixie/manpages-dev/openat.2.en.html#O_NOATIME -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: compat_linux: open: Supporting O_NOATIME
Author: Mouse
Date: Sat, 17 Oct 2026 03:35
Date: Sat, 17 Oct 2026 03:35
16 lines
2011 bytes
2011 bytes
> Additionally, re. privilege check: Linux checks the privilege by > ensuring process effective UID matches the file owner UID, or if the > process has `CAP_FOWNER` [*]. On NetBSD, I presume we'd only do the > first check? I'd be inclined to replace the second part with "or is root" (I can't recall how that's spelled these days), not just drop it. /~\ The ASCII Mouse \ / Ribbon Campaign X Against HTML mouse@rodents-montreal.org / \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: compat_linux: open: Supporting O_NOATIME
Author: Michael van Elst
Date: Sat, 17 Oct 2026 06:35
Date: Sat, 17 Oct 2026 06:35
23 lines
1930 bytes
1930 bytes
aiman.najjar@hurranet.com (Aiman Najjar) writes: >My question: what is the correct way to address this, do we: 1) add >native support for `O_NOATIME` Access times are a feature of the underlying filesystem. There is no way to handle that in a syscall or syscall emulation layer alone, if the filesystem doesn't implement such a feature. Even in Linux, O_NOATIME is optional and behaviour depends on the specific filesystem. So a valid implementation could just ignore the flag (which could be done in the compat layer, if it isn't already). N.B. I also doubt that such a stealth access feature should be available to a regular account. It needs at least a mount option (similar to noatime) that enables the behaviour. -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: compat_linux: open: Supporting O_NOATIME
Author: Aiman Najjar
Date: Sat, 17 Oct 2026 13:27
Date: Sat, 17 Oct 2026 13:27
56 lines
4602 bytes
4602 bytes
Thank you for the feedback! On 10/16/26 23:35, Mouse wrote: > I'd be inclined to replace the second part with "or is root" (I can't > recall how that's spelled these days), not just drop it. On 10/17/26 02:35, Michael van Elst wrote: > So a valid implementation could just ignore the flag (which could be done in the compat layer, if it isn't already). Sounds good on both counts, I will go ahead and attempt a patch that validates privileges as discussed (based on UID or is root), and otherwise ignore the flag. Thanks again. Aiman On 10/16/26 23:00, Aiman Najjar wrote: > Hello tech-kern, > > I'm new to NetBSD and I am interested in contributing to compat_linux. > > I've had a chance to look at the work Henrique did for the LTP as part > of GSoC, I am interested in working on some of the failing test cases. > > In particular, `open02` test case seems like a good candidate for a > first patch. The failing test case passes `O_NOATIME` mode flag to open, > and expects it to fail with `EPERM` error. > > My question: what is the correct way to address this, do we: 1) add > native support for `O_NOATIME`, which allows users to flag (or hint) > that they don't want the file's access time to be updated (useful for > backup solutions processing large amount of files), or 2) do we emulate > it, somehow, at `compat_linux` layer (e.g. only support this behavior > when the module is installed) or 3) Do we only check for user privileges > (which would make the test pass) but do not actually implement the behavior? > > Additionally, re. privilege check: Linux checks the privilege by > ensuring process effective UID matches the file owner UID, or if the > process has `CAP_FOWNER` [*]. On NetBSD, I presume we'd only do the > first check? > > Also, stumbled upon a similar discussion in FreeBSD forums: > https://forums.freebsd.org/threads/o_noatime-option-in-open.92523/ > > Thanks, > Aiman > > [*] > https://manpages.debian.org/trixie/manpages-dev/openat.2.en.html#O_NOATIME -- Posted automagically by a mail2news gateway at muc.de e.V. Please direct questions, flames, donations, etc. to news-admin@muc.de
Re: compat_linux: open: Supporting O_NOATIME
Author: Aiman Najjar
Date: Sun, 18 Oct 2026 19:33
Date: Sun, 18 Oct 2026 19:33
147 lines
7030 bytes
7030 bytes
Hi tech-kern@,
I've prepared a patch for this below, BUT, in retrospect, I am not sure how
consequential this fix is. The privilege check exists only to prevent
processes from bypassing file access time "atime" update if they don't
own the file or are not root, but we don't plan to offer that behavior
anyway, i.e. atime will always be updated regardless of whether a
process passes or fails the checks.
In other words, the patch is mostly cosmetic for purposes of passing the
LTP test. With that in mind, I came up with these available
options based on my research:
1. Do nothing, Linux binaries that pass O_NOATIME will still work.
Unless a program uses this API to validate ownership of files or root
privileges (unlikely and weird), program correctness should not be
affected.
2. Implement a naive check. My patch does that, it checks file ownership
when O_NOATIME is set, then delegates to the native sys_open(at)
implementation. This suffers from a potential TOCTOU, but keeps the
compat_linux layer a thin shim. It has performance implications as it
will resolve the path twice, which would be even worse for backup software
than doing nothing.
3. Implement a more robust check: Based on my research, it seems a
MODULE_HOOK is the right way to add compatibility code inside the
native sys_open(at) path. This would solve issues in #2 but would turn
compat_linux into more than a translation layer, which does not seem to
be worth it in this case.
4. Maybe there are other options that don't suffer from issues in #2 and
still get us to pass the LTP test, would be happy to look into those
based on any feedback.
In closing, I did not actually submit a patch to GNATS as my personal
assessment is that option #1 (doing nothing) is probably better, but
would appreciate your comments otherwise, regardless, it has been a very
useful learning exercise, I appreciated the well-written kernel
developer manual pages :)
diff --git a/sys/compat/linux/common/linux_file.c b/sys/compat/linux/common/linux_file.c
index 66b95278e..42a79491a 100644
--- a/sys/compat/linux/common/linux_file.c
+++ b/sys/compat/linux/common/linux_file.c
@@ -233,10 +233,38 @@ linux_sys_open(struct lwp *l, const struct linux_sys_open_args *uap,
syscallarg(int) flags;
syscallarg(linux_umode_t) mode;
} */
- int error, fl;
+ int error, fl, lflags, uid;
struct sys_open_args boa;
+ struct pathbuf *pb;
+ struct nameidata nd;
+ struct vattr va;
fl = linux_to_bsd_ioflags(SCARG(uap, flags));
+ lflags = SCARG(uap, flags);
+ uid = kauth_cred_geteuid(l->l_cred);
+
+ if (lflags & LINUX_O_NOATIME) {
+ error = pathbuf_copyin(SCARG(uap, path), &pb);
+ if (error)
+ return error;
+
+ NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, pb);
+ if ((error = namei(&nd)) == 0) {
+ if ((error = VOP_GETATTR(nd.ni_vp, &va, l->l_cred)))
+ goto out;
+
+ if (uid != va.va_uid &&
+ kauth_authorize_generic(l->l_cred,
+ KAUTH_GENERIC_ISSUSER, NULL) != 0) {
+ error = EPERM;
+ }
+ out:
+ vput(nd.ni_vp);
+ }
+ pathbuf_destroy(pb);
+ if (error)
+ return error;
+ }
memset(&boa, 0, sizeof(boa));
SCARG(&boa, path) = SCARG(uap, path);
@@ -260,10 +288,55 @@ linux_sys_openat(struct lwp *l, const struct linux_sys_openat_args *uap,
syscallarg(int) flags;
syscallarg(linux_umode_t) mode;
} */
- int error, fl;
+ int error, fl, lflags, uid;
struct sys_openat_args boa;
+ struct pathbuf *pb;
+ struct nameidata nd;
+ struct vattr va;
+ struct vnode *dvp = NULL;
+ const char *pathstring = NULL;
+ file_t *dfp = NULL;
fl = linux_to_bsd_ioflags(SCARG(uap, flags));
+ lflags = SCARG(uap, flags);
+ uid = kauth_cred_geteuid(l->l_cred);
+
+ if (lflags & LINUX_O_NOATIME) {
+ error = pathbuf_copyin(SCARG(uap, path), &pb);
+ if (error)
+ return error;
+
+ pathstring = pathbuf_stringcopy_get(pb);
+ if (SCARG(uap, fd) != AT_FDCWD && pathstring[0] != '/') {
+ if ((error = fd_getvnode(SCARG(uap, fd), &dfp)) != 0)
+ goto out2;
+ dvp = dfp->f_vnode;
+ }
+
+ NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF, pb);
+ if (dvp != NULL)
+ NDAT(&nd, dvp);
+
+ if ((error = namei(&nd)) == 0) {
+ if ((error = VOP_GETATTR(nd.ni_vp, &va, l->l_cred)))
+ goto out1;
+
+ if (uid != va.va_uid &&
+ kauth_authorize_generic(l->l_cred,
+ KAUTH_GENERIC_ISSUSER, NULL) != 0) {
+ error = EPERM;
+ }
+out1:
+ vput(nd.ni_vp);
+ }
+ if (dvp != NULL)
+ fd_putfile(SCARG(uap, fd));
+out2:
+ pathbuf_stringcopy_put(pb, pathstring);
+ pathbuf_destroy(pb);
+ if (error)
+ return error;
+ }
memset(&boa, 0, sizeof(boa));
SCARG(&boa, fd) = SCARG(uap, fd);
--
Posted automagically by a mail2news gateway at muc.de e.V.
Please direct questions, flames, donations, etc. to news-admin@muc.de
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads