|
|
Message-ID: <20261116233806.GS5716@brightrain.aerifal.cx>
Date: Mon, 16 Nov 2026 18:38:07 -0500
From: Rich Felker <dalias@...c.org>
To: Curtis Wu <alr_public@...mail.com>, musl@...ts.openwall.com
Subject: Re: [PATCH] x32: fix syscall param layouts for
pwrite/pwritev/preadv
On Mon, Nov 16, 2026 at 05:43:41PM +0100, Szabolcs Nagy wrote:
> * Curtis Wu <alr_public@...mail.com> [2026-11-16 09:56:11 +0800]:
> > The pwrite(3) implementation in musl libc, in the general case, uses the
> > split-offset convention for param layout:
> >
> > __syscall_cp(SYS_pwritev2, fd, iov, count, ofs_lo, ofs_hi, flags)
> >
> > This applies even on 64-bit architectures such as x86_64. Unfortunately, x32
> > doesn't follow such convention, and x32 kernel syscall ABI takes instead
> > just one syscall param for offset, routed to compat_sys_pwritev64v2() in
> > kernel:
> >
> > __syscall_cp(SYS_pwritev2, fd, iov, count, ofs, flags)
> >
> > Therefore the pwrite(3) unistd function is incorrect on x32. Same applies to
> > pwritev(3)/preadv(3) in unistd/ and the pwritev2(2)/preadv2(2) syscall
> > wrappers.
> >
>
> i can confirm this and that x32 is special
> https://github.com/torvalds/linux/blob/v7.3/arch/x86/include/asm/unistd.h#L29
> https://github.com/torvalds/linux/blob/v7.3/fs/read_write.c#L1280
It looks like the source of the breakage is commit
4ee5c0d05ce9b4e48e586a1ee168f166d191ddda, wherein the author thought
the native 64-bit preadv/pwritev used single 64-bit arguments and was
trying to make x32 follow same convention.
We should check if any other 32-bit-ABI-on=64-bit archs are affected,
like mips n32.
I really dislike copying whole source files to x32-specific versions
like this, since they could easily be overlooked when making future
changes. But I also dislike adding hacks specific to one bogus arch to
a shared file. If there are other archs affected tho, the choice to
put the conditional logic in a shared file would be more clear.
It might make sense to remove the offending syscall macros on x32 and
replace them with the 64-suffixed ones like the kernel uses:
-__NR_preadv
-__NR_pwritev
-__NR_preadv2
-__NR_pwritev2
+__NR_preadv64
+__NR_pwritev64
+__NR_preadv64v2
+__NR_pwritev64v2
Then the shared file could use the alternate argument convention when
these are present.
> > diff --git a/src/linux/x32/preadv2.c b/src/linux/x32/preadv2.c
> > new file mode 100644
> > index 0000000..11e368c
> > --- /dev/null
> > +++ b/src/linux/x32/preadv2.c
> > @@ -0,0 +1,15 @@
> > +#define _GNU_SOURCE
> > +#include <sys/uio.h>
> > +#include <unistd.h>
> > +#include "syscall.h"
> > +
> > +ssize_t preadv2(int fd, const struct iovec *iov, int count, off_t ofs, int
> > flags)
> > +{
> > +#ifdef SYS_preadv
>
> not sure why this #ifdef exists in the generic code,
> maybe for future targets. in any case x32 has preadv.
Indeed if we do go with x32-specific fork of the code, this #ifdef
doesn't need to be in the x32 version. It's purely for future archs
which I'd expect to lack the old syscall.
Rich
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.