From: David Laight <david.laight.linux@gmail.com>
To: "Thomas Weißschuh" <linux@weissschuh.net>
Cc: Willy Tarreau <w@1wt.eu>,
linux-kernel@vger.kernel.org,
Danish Khateeb <danishkhateeb03@gmail.com>,
hch@lst.de
Subject: Re: [PATCH v2 3/4] tools/nolibc: add support for fcntl()
Date: Sun, 6 Dec 2026 14:42:56 +0000 [thread overview]
Message-ID: <20261206144256.05bd50b1@pumpkin> (raw)
In-Reply-To: <82fbde7b-8896-4909-88dc-c535abeba76b@message-id.t-8ch.de>
On Sun, 6 Dec 2026 14:42:30 +0100
Thomas Weißschuh <linux@weissschuh.net> wrote:
> Hi!
>
> On 2026-12-06 13:08:03+0000, David Laight wrote:
> > On Sat, 5 Dec 2026 15:25:36 +0100
> > Willy Tarreau <w@1wt.eu> wrote:
> > > On Wed, Dec 02, 2026 at 08:29:48AM +0100, Thomas Weißschuh wrote:
> > > > Add the fcntl() function.
> > > >
> > > > Special handling is necessary for 'struct flock'.
> > > > The definition from the UAPI headers is not large-file capable.
> > > > Provide a custom definition which is compatible with 'struct flock64'
> > > > on 32-bit systems and 'struct flock' on 64-bit ones.
> > > >
> > > > Signed-off-by: Thomas Weißschuh <linux@weissschuh.net>
> > > (...)
> > > > --- a/tools/include/nolibc/types.h
> > > > +++ b/tools/include/nolibc/types.h
> > > > @@ -32,6 +32,21 @@ struct timeval {
> > > > #include <linux/time.h>
> > > > #undef timeval
> > > >
> > > > +struct flock {
> > > > + short l_type;
> > > > + short l_whence;
> > > > + __kernel_loff_t l_start;
> > > > + __kernel_loff_t l_len;
> > > > + __kernel_pid_t l_pid;
> > > > +#if defined(__sparc__)
> > > > + short __pad;
> > > > +#endif
> > > > +};
> > >
> > > The commit message makes no mention of this pad and nothing here explains
> > > why it is necessary nor if other architectures might need it in the
> > > future. I suspect it might be that __kernel_pid_t would be 16-bit there,
> > > but I really don't know. I think a comment here in front of__pad to say
> > > why/when it's needed would help.
> >
> > My brain remembers something about sparc having an extra field.
> > But I can't remember what it was used for, and it was __unused when the
> > file was added to Linux for 1.3.44.
> > The corresponding types.h has a 32bit pid_t - so it isn't just an
> > explicit pad.
> > (Although SunOS might have had a 16bit pid and made the pad reasonable.)
> >
> > I think it also pointless, The size of the structure isn't passed into the
> > kernel (it would need and ioctl() that used IORW()) and the kernel doesn't
> > seem to have ever cleared the user field.
>
> Because the size is not passed into the kernel it is important to have
> the padding in the nolibc type. The kernel will read/write as many bytes
> as its UAPI definition has. If we leave off the padding member the
> kernel will read/write out of bounds.
For some reason I was thinking the kernel would only read/write the fields
it was going to look at.
> This will work most of the time for fcntl(), as the bytes are written as
> they were read just before. However it is racy and can break in
> wonderous ways if the out of bounds access is in a different mapping.
>
> We don't care about the MIPS padding/sysid as these are specific to
> 32-bit 'struct flock' and there the nolibc 'struct flock' is really
> 'struct flock64'.
>
> I'll add some more explanations for this.
>
> > It might be relevant if you were compiling against the Linux headers but
> > expected to run on some other OS - but that just won't work.
> > (SYSV sparc binaries would 'just about' run on SunOS - but it was largely
> > theoretical and was responsible for some nasty bugs.)
>
> Nolibc only ever cares about running on Linux.
I was thinking more widely and wondering why the pad/unused were added
in the first place.
David
>
> > Rather more problematic is MIPS32, change 9f79b8b7 'simplified' the pad.
> > But managed to move the l_sysid field the other side of l_pid.
>
> Indeed.
>
> (...)
>
>
> Thomas
next prev parent reply other threads:[~2026-12-06 14:42 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-02 7:29 [PATCH v2 0/4] " Thomas Weißschuh
2026-12-02 7:29 ` [PATCH v2 1/4] tools/nolibc: derive clang target flags from ARCH if CROSS_COMPILE is not set Thomas Weißschuh
2026-12-05 14:33 ` Willy Tarreau
2026-12-02 7:29 ` [PATCH v2 2/4] selftests/nolibc: split out the structure member compatibility checks Thomas Weißschuh
2026-12-02 11:29 ` David Laight
2026-12-05 14:31 ` Willy Tarreau
2026-12-02 7:29 ` [PATCH v2 3/4] tools/nolibc: add support for fcntl() Thomas Weißschuh
2026-12-05 14:25 ` Willy Tarreau
2026-12-05 14:56 ` Thomas Weißschuh
2026-12-05 16:08 ` Willy Tarreau
2026-12-06 13:08 ` David Laight
2026-12-06 13:42 ` Thomas Weißschuh
2026-12-06 14:42 ` David Laight [this message]
2026-12-02 7:29 ` [PATCH v2 4/4] tools/nolibc: remove the open-coded fcntl() in dup2() Thomas Weißschuh
2026-12-05 14:26 ` Willy Tarreau
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261206144256.05bd50b1@pumpkin \
--to=david.laight.linux@gmail.com \
--cc=danishkhateeb03@gmail.com \
--cc=hch@lst.de \
--cc=linux-kernel@vger.kernel.org \
--cc=linux@weissschuh.net \
--cc=w@1wt.eu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®