[v7,0/4] Add close_range, closefrom, and posix_spawn_file_actions_closefrom_np

Message ID 20210706145839.1658623-1-adhemerval.zanella@linaro.org
Headers
Series Add close_range, closefrom, and posix_spawn_file_actions_closefrom_np |

Message

Adhemerval Zanella July 6, 2021, 2:58 p.m. UTC
  Linux v5.9 added a new close_range syscall, which allows the caller to
issue the kernel to close or set close-on-exec on a range of file
descriptors.

This patchset export the syscall along with two GNU extensions:
closefrom, with similar semantics from other systems ((Solaris, OpenBSD,
NetBSD, FreeBSD); and posix_spawn_file_actions_closefrom_np, which
allows use close_range semantic on posix_spawn().

The first patch is libsupport one for the tests.  The second patch adds
the Linux specific close_range syscall.  The third adds the GNU extension
closefrom(), which use close_range() if available.  The firth adds the
posix_spawn extension.

Adhemerval Zanella (4):
  support: Add support_stack_alloc
  linux: Add close_range
  io: Add closefrom [BZ #10353]
  posix: Add posix_spawn_file_actions_addclosefrom_np

 NEWS                                          |  12 +
 include/bits/unistd_ext.h                     |   6 +
 include/unistd.h                              |   1 +
 io/Makefile                                   |   4 +-
 io/Versions                                   |   3 +
 io/closefrom.c                                |  34 ++
 io/tst-closefrom.c                            | 152 +++++++++
 manual/llio.texi                              |  59 ++++
 posix/Makefile                                |   4 +-
 posix/Versions                                |   1 +
 posix/spawn.h                                 |   8 +
 posix/spawn_faction_addclosefrom.c            |  57 ++++
 posix/spawn_faction_destroy.c                 |   1 +
 posix/spawn_int.h                             |   6 +
 posix/tst-spawn5.c                            | 284 ++++++++++++++++
 posix/unistd.h                                |   6 +
 support/Makefile                              |   1 +
 support/support.h                             |  19 ++
 support/support_stack_alloc.c                 |  79 +++++
 support/xsigstack.c                           |  43 +--
 sysdeps/generic/spawn_int_def.h               |  24 ++
 sysdeps/mach/hurd/i386/libc.abilist           |   2 +
 sysdeps/mach/hurd/spawni.c                    |   4 +
 sysdeps/posix/spawni.c                        |   4 +
 sysdeps/unix/sysv/linux/Makefile              |   6 +-
 sysdeps/unix/sysv/linux/Versions              |   1 +
 sysdeps/unix/sysv/linux/aarch64/libc.abilist  |   3 +
 sysdeps/unix/sysv/linux/alpha/libc.abilist    |   3 +
 sysdeps/unix/sysv/linux/arc/libc.abilist      |   3 +
 sysdeps/unix/sysv/linux/arm/be/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/arm/le/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/bits/unistd_ext.h     |  22 ++
 sysdeps/unix/sysv/linux/closefrom.c           |  36 +++
 sysdeps/unix/sysv/linux/closefrom_fallback.c  |  99 ++++++
 sysdeps/unix/sysv/linux/csky/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/hppa/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/i386/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/ia64/libc.abilist     |   3 +
 .../sysv/linux/m68k/coldfire/libc.abilist     |   3 +
 .../unix/sysv/linux/m68k/m680x0/libc.abilist  |   3 +
 .../sysv/linux/microblaze/be/libc.abilist     |   3 +
 .../sysv/linux/microblaze/le/libc.abilist     |   3 +
 .../sysv/linux/mips/mips32/fpu/libc.abilist   |   3 +
 .../sysv/linux/mips/mips32/nofpu/libc.abilist |   3 +
 .../sysv/linux/mips/mips64/n32/libc.abilist   |   3 +
 .../sysv/linux/mips/mips64/n64/libc.abilist   |   3 +
 sysdeps/unix/sysv/linux/nios2/libc.abilist    |   3 +
 .../linux/powerpc/powerpc32/fpu/libc.abilist  |   3 +
 .../powerpc/powerpc32/nofpu/libc.abilist      |   3 +
 .../linux/powerpc/powerpc64/be/libc.abilist   |   3 +
 .../linux/powerpc/powerpc64/le/libc.abilist   |   3 +
 .../unix/sysv/linux/riscv/rv32/libc.abilist   |   3 +
 .../unix/sysv/linux/riscv/rv64/libc.abilist   |   3 +
 .../unix/sysv/linux/s390/s390-32/libc.abilist |   3 +
 .../unix/sysv/linux/s390/s390-64/libc.abilist |   3 +
 sysdeps/unix/sysv/linux/sh/be/libc.abilist    |   3 +
 sysdeps/unix/sysv/linux/sh/le/libc.abilist    |   3 +
 .../sysv/linux/sparc/sparc32/libc.abilist     |   3 +
 .../sysv/linux/sparc/sparc64/libc.abilist     |   3 +
 sysdeps/unix/sysv/linux/spawn_int_def.h       |  25 ++
 sysdeps/unix/sysv/linux/spawni.c              |  34 +-
 sysdeps/unix/sysv/linux/syscalls.list         |   1 +
 sysdeps/unix/sysv/linux/tst-close_range.c     | 303 ++++++++++++++++++
 .../unix/sysv/linux/x86_64/64/libc.abilist    |   3 +
 .../unix/sysv/linux/x86_64/x32/libc.abilist   |   3 +
 65 files changed, 1380 insertions(+), 57 deletions(-)
 create mode 100644 include/bits/unistd_ext.h
 create mode 100644 io/closefrom.c
 create mode 100644 io/tst-closefrom.c
 create mode 100644 posix/spawn_faction_addclosefrom.c
 create mode 100644 posix/tst-spawn5.c
 create mode 100644 support/support_stack_alloc.c
 create mode 100644 sysdeps/generic/spawn_int_def.h
 create mode 100644 sysdeps/unix/sysv/linux/closefrom.c
 create mode 100644 sysdeps/unix/sysv/linux/closefrom_fallback.c
 create mode 100644 sysdeps/unix/sysv/linux/spawn_int_def.h
 create mode 100644 sysdeps/unix/sysv/linux/tst-close_range.c
  

Comments

DJ Delorie July 6, 2021, 7:28 p.m. UTC | #1
My 32-bit trybot detected a regresion on i686[*]

https://www.delorie.com/trybots/32bit/2424.html
NONE -> FAIL : misc/tst-close_range

Is this expected?

[*] well, x86_64 with -m32
  
Adhemerval Zanella July 6, 2021, 7:33 p.m. UTC | #2
On 06/07/2021 16:28, DJ Delorie wrote:
> 
> My 32-bit trybot detected a regresion on i686[*]
> 
> https://www.delorie.com/trybots/32bit/2424.html
> NONE -> FAIL : misc/tst-close_range
> 
> Is this expected?
> 
> [*] well, x86_64 with -m32
> 

Not really, I will take a took.  Do we have the .out output somewhere?
  
Adhemerval Zanella July 6, 2021, 7:38 p.m. UTC | #3
On 06/07/2021 16:33, Adhemerval Zanella wrote:
> 
> 
> On 06/07/2021 16:28, DJ Delorie wrote:
>>
>> My 32-bit trybot detected a regresion on i686[*]
>>
>> https://www.delorie.com/trybots/32bit/2424.html
>> NONE -> FAIL : misc/tst-close_range
>>
>> Is this expected?
>>
>> [*] well, x86_64 with -m32
>>
> 
> Not really, I will take a took.  Do we have the .out output somewhere?
> 

How the trybot handles UNSUPPORTED (exit status 77)? On kernel older than
5.9 the test will fail with:

i686-linux-gnu$ make test t=misc/tst-close_range
[...]
UNSUPPORTED: misc/tst-close_range
original exit status 77
error: ../sysdeps/unix/sysv/linux/tst-close_range.c:60: close_range not supported
[...]

Maybe is it the case? I have tested on both x86_64 and i686 with on both
kernel 5.11 and 4.15 and on 4.15 the test does show UNSUPPORTED.
  
DJ Delorie July 6, 2021, 7:42 p.m. UTC | #4
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> Not really, I will take a took.  Do we have the .out output somewhere?

Yet another thing to try to scrape out of the test container before
throwing it away...
  
DJ Delorie July 6, 2021, 7:47 p.m. UTC | #5
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> How the trybot handles UNSUPPORTED (exit status 77)? On kernel older than
> 5.9 the test will fail with:

It only reports tests that differ from the baseline (pre-patch) and
report "FAIL".  In theory, UNSUPPORTED should be unreported.

The trybot runs 5.8.15-301.fc33.x86_64
  
Adhemerval Zanella July 6, 2021, 8:23 p.m. UTC | #6
On 06/07/2021 16:47, DJ Delorie wrote:
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>> How the trybot handles UNSUPPORTED (exit status 77)? On kernel older than
>> 5.9 the test will fail with:
> 
> It only reports tests that differ from the baseline (pre-patch) and
> report "FAIL".  In theory, UNSUPPORTED should be unreported.
> 
> The trybot runs 5.8.15-301.fc33.x86_64

I ran the testcase on the exactly same kernel:

[azanella@localhost i686-linux-gnu]$ uname -a
Linux localhost.localdomain 5.8.15-301.fc33.x86_64 #1 SMP Thu Oct 15 16:58:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
[azanella@localhost i686-linux-gnu]$ ./testrun.sh misc/tst-close_range
error: ../sysdeps/unix/sysv/linux/tst-close_range.c:60: close_range not supported
[azanella@localhost i686-linux-gnu]$ echo $?
77

This is expected output for a kernel older than 5.9. Maybe something
wrong on how the trybot handles newer UNSUPPORTED?
  
DJ Delorie July 6, 2021, 8:30 p.m. UTC | #7
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> I ran the testcase on the exactly same kernel:
>
> [azanella@localhost i686-linux-gnu]$ uname -a
> Linux localhost.localdomain 5.8.15-301.fc33.x86_64 #1 SMP Thu Oct 15 16:58:06 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux
> [azanella@localhost i686-linux-gnu]$ ./testrun.sh misc/tst-close_range
> error: ../sysdeps/unix/sysv/linux/tst-close_range.c:60: close_range not supported
> [azanella@localhost i686-linux-gnu]$ echo $?
> 77
>
> This is expected output for a kernel older than 5.9. Maybe something
> wrong on how the trybot handles newer UNSUPPORTED?

Dunno, this is all new stuff ;-)

I'm doing a non-container build of that tree to see what happens.  The
container has the fedora-latest image but runs on whatever kernel is
running on the host.  The trybot just looks at the *.sum files.
  
DJ Delorie July 6, 2021, 9:33 p.m. UTC | #8
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> This is expected output for a kernel older than 5.9. Maybe something
> wrong on how the trybot handles newer UNSUPPORTED?

A non-container build returns UNSUPPORTED.  A repeat container build
returns FAIL.

misc/tst-close_range.out is:
https://www.delorie.com/trybots/32bit/2424.tst-close_range.out
  
Adhemerval Zanella July 7, 2021, 2:14 a.m. UTC | #9
On 06/07/2021 18:33, DJ Delorie wrote:
> Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
>> This is expected output for a kernel older than 5.9. Maybe something
>> wrong on how the trybot handles newer UNSUPPORTED?
> 
> A non-container build returns UNSUPPORTED.  A repeat container build
> returns FAIL.
> 
> misc/tst-close_range.out is:
> https://www.delorie.com/trybots/32bit/2424.tst-close_range.out
> 

This really seems the old issue when runtime syscall filter returns EPERM
instead of ENOSYS for non supported or filtered syscall (specially because
you are running on a 5.8 kernel).
  
DJ Delorie July 7, 2021, 2:26 a.m. UTC | #10
Adhemerval Zanella <adhemerval.zanella@linaro.org> writes:
> This really seems the old issue when runtime syscall filter returns EPERM
> instead of ENOSYS for non supported or filtered syscall (specially because
> you are running on a 5.8 kernel).

Yup, that sounds like a container-specific bug!

Thanks for looking into this.  From my point of view, "it's not the
trybot" is enough of a resolution for me ;-)