From patchwork Thu Oct 3 14:13:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adhemerval Zanella Netto X-Patchwork-Id: 832396 Delivered-To: patch@linaro.org Received: by 2002:adf:8b52:0:b0:367:895a:4699 with SMTP id v18csp286290wra; Thu, 3 Oct 2024 07:15:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCW1+7IKVsOJjg0KtIHCoQ8hcQt6E4FdUS6EYtwGQkT2SFSy5O3ZfbO0QDbxt+ZF4INXVzVTwQ==@linaro.org X-Google-Smtp-Source: AGHT+IFDbMZdadoGJE+LUrESqppI1JormlhYK7uZpWoagZpU1O80UUKi/K9pCHW/j8GblA6EWeFq X-Received: by 2002:a05:622a:11ca:b0:456:847d:4799 with SMTP id d75a77b69052e-45d8055e00emr101900441cf.51.1727964913856; Thu, 03 Oct 2024 07:15:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1727964913; cv=pass; d=google.com; s=arc-20240605; b=HhxGW835tXj/QAqtt+eAIg6RhU1bYZRT/a+t9cu5tZdAZ5HZ78Q87Lg2kL8jYus79N Ks8OsHhmvRVwIPs952CbSa0hdVY2NPVGUHkWWkwTniLdtTn/JV3Obf6xtjFHD7efo5Dy MPBmV09u1J0h2sDqNOnq/Ab8fd6LsCeNZa8nbp42YTvpYRKYilWPvcctQcv7Dm8ZXK1k 0AIODCBbxmwd8NK+gZ7FuRT5IyD8R0oVbhseQGzooQMSoOwzOQDynMuQAXcwUydEnmjA Ol4kOJ9Jxi5l1F3mRZ+rsds6EbLBw9sh8PCW6G60pnPhTWtIlpu5y4Vk2ve2mUXmJ/4C c2tw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:to:from:dkim-signature :arc-filter:dmarc-filter:delivered-to; bh=e0Ov0Fh2YR59fgQFA4x5dEI5wrKjOanmw4u3ubn58VQ=; fh=dHLBnA+MhGtNtN2B2JMAELi4oD+gmgMg7DL8H0jYbkI=; b=fkVMJDBPhkl7yzyWGq4vsCIOW6FawsmhNyesUMIaLeJKWivMUhGaGz8IERa6l0bgTx VUhMDVQkDqnQdgA3YC8L3MIMjajPjpfaTgTRXqe2p35K3Dbtxixwu/l1TpmnoxrGTrmC ubi9xuVARzEGgCBcAwlZhqTyWVWjtRdlG1+/7sXPvsiMJTKPKzawNJo3gksBIuCyo8Q4 7pL49J9c9tKx8N2RuNrkVsxmAry50iwOjHhjigDKW0NrtbuEKmHSnS0qdwG2Xu5dxUSX Z9UqqZf74N1GdQGvZHQZWs6g/bNWpSd32upYccKPmo9Ta1th9ZhBZ+joDvvOLVPXtECn rCVw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CmXTftUr; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id d75a77b69052e-45d9524da5dsi8704031cf.64.2024.10.03.07.15.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 07:15:13 -0700 (PDT) Received-SPF: pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CmXTftUr; arc=pass (i=1); spf=pass (google.com: domain of libc-alpha-bounces~patch=linaro.org@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="libc-alpha-bounces~patch=linaro.org@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 571FA384A81A for ; Thu, 3 Oct 2024 14:15:13 +0000 (GMT) X-Original-To: libc-alpha@sourceware.org Delivered-To: libc-alpha@sourceware.org Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by sourceware.org (Postfix) with ESMTPS id 1FC2B3858CDB for ; Thu, 3 Oct 2024 14:14:58 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 1FC2B3858CDB Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=linaro.org ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 1FC2B3858CDB Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::62b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727964903; cv=none; b=gW3i9zp8gcxtApw98mtSAvc8Fj1Hwp4BxC461y4RTi9n7TW3DHKfsDglaN95+lAWMTwdN333ONZL7x+/rQkreVMrD99p6/6rHUCX4fJ1FiP9DhHc4VjXv7gsTTif1Gf0X+pjdXGAokiBx57++XZ+6orboCJNSwwtyQ1UqWJMr70= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1727964903; c=relaxed/simple; bh=UkK+1YgCw/GNde5Fl1QuG85Vus+iLphKINuqEbJ6Oeg=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=KJzYIr38K7Ajgo6aLEypRBQGG7e7katTOi5bKpPKAcnv8FETPzuzlmcYO1TnMsz6n3FfNwQnz0M5DJeoN0ml3psx3QdheeT7SLMHT+PjKV9OTV9FNYVLT8FIzhcfTjvd+RzhX/NX6krEpAO39jXYST0RZ77c3VJdHr8Eiq3RIm4= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-20b49ee353cso9515155ad.2 for ; Thu, 03 Oct 2024 07:14:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727964897; x=1728569697; darn=sourceware.org; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date:message-id:reply-to; bh=e0Ov0Fh2YR59fgQFA4x5dEI5wrKjOanmw4u3ubn58VQ=; b=CmXTftUryfG255zQp/G7snO2kzoAF5rM5JFKw06uW1C7QFd+QtRdfb0kX3U9TVzGzz hTDC0NY3H+3NWEth9yKLqgIwroIgXLBsN8XHVeqV46NYq0EtVdT+Zye3A2O38DdgU9GE matvwA/oxwNvcSCdym7i7+U9KwkRP5Cx5CFL6UjRILwvld8mEGESEncr9RMcmyveQ0nk c03sjD7p86jIPgNnfZ4m0+mRcvXaDwBN5qcjIiegeM6Nnc7QYIANOij37LckfA5FvAno +dMxNB8PFmClmK90eo49e2oHGXNnHtUex/cq/hXnQfiZvz/LvmimLRbyX9KU+zNHI/kK NtwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727964897; x=1728569697; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=e0Ov0Fh2YR59fgQFA4x5dEI5wrKjOanmw4u3ubn58VQ=; b=Q+Tx/ceSwd4XVeWyld8CgKLOVJZjfelQgivRCDu6TXs0JFWnHeAqMDJo2xvLHXW0IO Ldsg2pL8Z6vdNHdKxGfJRKeADtwM85DhNValD7ThI7JVejnYMP1XdcTxyO+vKvqgW0hV YyCodf/lAc0YzHmWikf3gQLkdbNrG1ZHQvidvWwVCnggCAdNMkxG5uDghI5OM0NLD/iQ lKg9eXlRApGZT15F4hd+tXvscyCf11I9ZgZebTwvWrqufjPP+0om+Cavdvgh2oWmRKnT EtGVceEb+UV/VOI2HXYWFSO16zBLeB28R07C++tBmg1s231NMR4UjlhPY1oTfHkn1kFx pdVA== X-Gm-Message-State: AOJu0YzLAdMtpGmnyP2XQL40tEUBvHSauK6/+oo43Of8IzKqSLhJcENy xQMtZx4CXQ5Saj+Um3cYwsiRe56NguX1vAn8s2mYbP+XipY3SWcAOiu3xaAXqykQ/iuZs0M7Epu DRi0= X-Received: by 2002:a17:902:e54d:b0:20b:6457:31e3 with SMTP id d9443c01a7336-20bc59ec8b5mr104231095ad.3.1727964895243; Thu, 03 Oct 2024 07:14:55 -0700 (PDT) Received: from mandiga.. ([2804:1b3:a7c1:b563:7492:69d4:7967:bf0d]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-20beeca186esm9566855ad.98.2024.10.03.07.14.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Oct 2024 07:14:54 -0700 (PDT) From: Adhemerval Zanella To: libc-alpha@sourceware.org Subject: [PATCH] linux: Add openat2 (BZ 31664) Date: Thu, 3 Oct 2024 11:13:14 -0300 Message-ID: <20241003141451.3299056-1-adhemerval.zanella@linaro.org> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Spam-Status: No, score=-12.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: libc-alpha@sourceware.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Libc-alpha mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libc-alpha-bounces~patch=linaro.org@sourceware.org The openat2 syscall was added on Linux 5.6, as an extension of openat. Different than other open-like functions, the kernel only provides the LFS variant (so files larger than 4GB always succeed, as other functions with offset larger than off_t). Also, imilar to other open functions, the new symbol is a cancellable entrypoint. The test case added only stresses some of the syscalls provided functionalities and it is based on an existent kernel self-test. Since the prototype does not use variadic arguments, there is no need to add a fortify wrapper to catch wrong usages. The documentation mostly defers to the Linux manual pages. Checked on x86_64-linux-gnu. --- This patch follows the recent sched_setattr inclusion on how to handle the new kABI syscall with extensible fields, where it up to the caller to not use it where it might case ABI issues with different TU. --- NEWS | 4 + manual/llio.texi | 97 +++++++ sysdeps/unix/sysv/linux/Makefile | 14 + sysdeps/unix/sysv/linux/Versions | 1 + sysdeps/unix/sysv/linux/aarch64/libc.abilist | 1 + sysdeps/unix/sysv/linux/alpha/libc.abilist | 1 + sysdeps/unix/sysv/linux/arc/libc.abilist | 1 + sysdeps/unix/sysv/linux/arm/be/libc.abilist | 1 + sysdeps/unix/sysv/linux/arm/le/libc.abilist | 1 + sysdeps/unix/sysv/linux/bits/fcntl-linux.h | 22 ++ sysdeps/unix/sysv/linux/bits/openat2.h | 61 +++++ sysdeps/unix/sysv/linux/csky/libc.abilist | 1 + sysdeps/unix/sysv/linux/hppa/libc.abilist | 1 + sysdeps/unix/sysv/linux/i386/libc.abilist | 1 + .../sysv/linux/loongarch/lp64/libc.abilist | 1 + .../sysv/linux/m68k/coldfire/libc.abilist | 1 + .../unix/sysv/linux/m68k/m680x0/libc.abilist | 1 + .../sysv/linux/microblaze/be/libc.abilist | 1 + .../sysv/linux/microblaze/le/libc.abilist | 1 + .../sysv/linux/mips/mips32/fpu/libc.abilist | 1 + .../sysv/linux/mips/mips32/nofpu/libc.abilist | 1 + .../sysv/linux/mips/mips64/n32/libc.abilist | 1 + .../sysv/linux/mips/mips64/n64/libc.abilist | 1 + sysdeps/unix/sysv/linux/nios2/libc.abilist | 1 + sysdeps/unix/sysv/linux/openat2.c | 29 ++ sysdeps/unix/sysv/linux/or1k/libc.abilist | 1 + .../linux/powerpc/powerpc32/fpu/libc.abilist | 1 + .../powerpc/powerpc32/nofpu/libc.abilist | 1 + .../linux/powerpc/powerpc64/be/libc.abilist | 1 + .../linux/powerpc/powerpc64/le/libc.abilist | 1 + .../unix/sysv/linux/riscv/rv32/libc.abilist | 1 + .../unix/sysv/linux/riscv/rv64/libc.abilist | 1 + .../unix/sysv/linux/s390/s390-32/libc.abilist | 1 + .../unix/sysv/linux/s390/s390-64/libc.abilist | 1 + sysdeps/unix/sysv/linux/sh/be/libc.abilist | 1 + sysdeps/unix/sysv/linux/sh/le/libc.abilist | 1 + .../sysv/linux/sparc/sparc32/libc.abilist | 1 + .../sysv/linux/sparc/sparc64/libc.abilist | 1 + sysdeps/unix/sysv/linux/tst-openat2-consts.py | 63 +++++ sysdeps/unix/sysv/linux/tst-openat2.c | 259 ++++++++++++++++++ .../unix/sysv/linux/x86_64/64/libc.abilist | 1 + .../unix/sysv/linux/x86_64/x32/libc.abilist | 1 + 42 files changed, 583 insertions(+) create mode 100644 sysdeps/unix/sysv/linux/bits/openat2.h create mode 100644 sysdeps/unix/sysv/linux/openat2.c create mode 100755 sysdeps/unix/sysv/linux/tst-openat2-consts.py create mode 100644 sysdeps/unix/sysv/linux/tst-openat2.c diff --git a/NEWS b/NEWS index b1ae1c31ca..8a8eeb0896 100644 --- a/NEWS +++ b/NEWS @@ -31,6 +31,10 @@ Major new features: * The iconv program now supports converting files in place. The program automatically uses a temporary file if required. +* On Linux, the openat2 function has been added. It is an extension of + openat and provides a superset of its functionality. It is supported only + in LFS mode and it is a cancellable entrypoint. + Deprecated and removed features, and other changes affecting compatibility: * The big-endian ARC port (arceb-linux-gnu) has been removed. diff --git a/manual/llio.texi b/manual/llio.texi index a035c3e20f..77c551eff5 100644 --- a/manual/llio.texi +++ b/manual/llio.texi @@ -218,6 +218,103 @@ new, extended API using 64 bit file sizes and offsets transparently replaces the old API. @end deftypefun +@deftp {Data Type} {struct open_how} +@standards{Linux, fcntl.h} +The @code{open_how} structure describes how to open a file using @code{openat2}. + +@strong{Portability note:} In the future, additional fields can be added +to @code{struct open_how} at the end, so that the size of this data +type changes. Do not use it in places where this matters, such as +structure fields in installed header files, where such a change could +impact the application binary interface (ABI). + +The following generic fields are available. + +@table @code +@item flags +This field specifies the file creation and file status flags to use when +opening the file. +All of the @code{O_*} flags defined for @code{openat} are valid. +Different than @code{openat}, @code{openat2} returns an error for unknown +or conflicting values. + +@item mode +This field specifies the mode for the new file, similar to @code{mode} +argument of @code{openat}. Different than @code{openat}, @code{openat2} +returns an error for invalid value (like value larger than @code{07777}). + +@item resolve +This is a bitmask of flags that modify the way in @strong{all} components +of @code{pathname}. It allows trusted programs to restrict how untrusted +paths are resolved. The following generic flags are available. +@table @code +@item RESOLVE_NO_XDEV +Disallow traversal of mount points during path resolution (including all +bind mounts). +@item RESOLVE_NO_MAGICLINKS +Disallow all @strong{magic-link} resolution during path resolution. Magic +links are simbolic link-like objects that are found in @strong{procfs}; +for example the @code{/proc/pid/exe}. +@item RESOLVE_NO_SYMLINKS +Disallow resolution of symbolic links during path resolution. +This option implies @code{RESOLVE_NO_MAGICLINKS}. +@item RESOLVE_BENEATH +Do not permit the path resolution to succeed if any component of the +resolution is not a descendant of the directory indicated by @code{dirfd}. +@item RESOLVE_IN_ROOT +Treat the directory referred to by @code{dirfd} as the root directory +while resolving the @code{pathname}. +@item RESOLVE_CACHED +Make the open operation fail unless all path components are already +present in the kernel's lookup cache. +@end table +@end table + +For additional information, consult the manual page @manpageurl{openat2,2}. +@xref{Linux Kernel}. +@end deftp + + +@deftypefun int openat2 (int @var{dirfd}, const char *@var{pathname}, struct open_how @var{how}, size_t @var{size}) +@standards{Linux, fcntl.h} +@safety{@mtsafe{}@assafe{}@acsafe{}} +This function is a extension of the @code{openat} and provides a superset of its +functionality. @xref{Descriptor-Relative Access}. + +The @code{size} define the expected size of @code{how} data structure. +It is recommended to initialize unused fields to zero, either using +@code{memset}, or using a structure initializer. + +On failure, @code{openat2} returns @math{-1} and sets @code{errno}. The +following errors are related the way extensibility is handled. +@table @code +@item E2BIG +An extension that the kernel does support was specified in @code{how}, +or a larger struct was used with non-zero fields. +@item EAGAIN +@code{how.resolve} contains either RESOLVE_IN_ROOT or RESOLVE_BENEATH, and +the kernel could not ensure that @code{".."} component did not escape. Or +@code{RESOLVE_CACHED} was set, and the open operation cannot be performed +using only cached information. +@item EINVAL +And unknown flag or invalid value was used on @code{how}; or @code{mode} +is non-zero, but @code{how.flags} does not contain @code{O_CREAT} or +@code{O_TMPFILE}, or @code{size} is smaller than the ones supported +by the kernel. +@end table + +It can also return all the errors @code{openat} returns, or other errors +due new fields added by the kernel. + +Similar to @code{openat}, @code{openat2} is a cancellation point. + +@strong{NB:} Different than other open-like functions, the kernel only +provides the LFS variant. When the sources are translated with +@code{_FILE_OFFSET_BITS == 64} this function are not routed a different +symbol. +@end deftypefun + + @deftypefn {Obsolete function} int creat (const char *@var{filename}, mode_t @var{mode}) @standards{POSIX.1, fcntl.h} @safety{@prelim{}@mtsafe{}@assafe{}@acsafe{@acsfd{}}} diff --git a/sysdeps/unix/sysv/linux/Makefile b/sysdeps/unix/sysv/linux/Makefile index 7df51a325c..6bf48b72a2 100644 --- a/sysdeps/unix/sysv/linux/Makefile +++ b/sysdeps/unix/sysv/linux/Makefile @@ -135,6 +135,7 @@ sysdep_headers += \ bits/mman-linux.h \ bits/mman-map-flags-generic.h \ bits/mman-shared.h \ + bits/openat2.h \ bits/procfs-extra.h \ bits/procfs-id.h \ bits/procfs-prregset.h \ @@ -606,6 +607,7 @@ sysdep_routines += \ internal_statvfs \ open64_nocancel \ open_nocancel \ + openat2 \ openat64_nocancel \ openat_nocancel \ pread64_nocancel \ @@ -626,7 +628,19 @@ tests += \ tst-fallocate64 \ tst-getcwd-smallbuff \ tst-o_path-locks \ + tst-openat2 \ # tests + +tests-special += \ + $(objpfx)tst-openat2-consts.out \ + # tests-special +$(objpfx)tst-openat2-consts.out: ../sysdeps/unix/sysv/linux/tst-openat2-consts.py + $(sysdeps-linux-python) \ + ../sysdeps/unix/sysv/linux/tst-openat2-consts.py \ + $(sysdeps-linux-python-cc) \ + < /dev/null > $@ 2>&1; $(evaluate-test) +$(objpfx)tst-openat2-consts.out: $(sysdeps-linux-python-deps) + endif ifeq ($(subdir),elf) diff --git a/sysdeps/unix/sysv/linux/Versions b/sysdeps/unix/sysv/linux/Versions index 213ff5f1fe..4c3de39ae3 100644 --- a/sysdeps/unix/sysv/linux/Versions +++ b/sysdeps/unix/sysv/linux/Versions @@ -331,6 +331,7 @@ libc { GLIBC_2.41 { sched_getattr; sched_setattr; + openat2; } GLIBC_PRIVATE { # functions used in other libraries diff --git a/sysdeps/unix/sysv/linux/aarch64/libc.abilist b/sysdeps/unix/sysv/linux/aarch64/libc.abilist index 38db77e4f7..32cf38a77b 100644 --- a/sysdeps/unix/sysv/linux/aarch64/libc.abilist +++ b/sysdeps/unix/sysv/linux/aarch64/libc.abilist @@ -2748,5 +2748,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/alpha/libc.abilist b/sysdeps/unix/sysv/linux/alpha/libc.abilist index 637bfce9fb..29abb4800a 100644 --- a/sysdeps/unix/sysv/linux/alpha/libc.abilist +++ b/sysdeps/unix/sysv/linux/alpha/libc.abilist @@ -3095,6 +3095,7 @@ GLIBC_2.4 wcstold F GLIBC_2.4 wcstold_l F GLIBC_2.4 wprintf F GLIBC_2.4 wscanf F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/arc/libc.abilist b/sysdeps/unix/sysv/linux/arc/libc.abilist index 4a305cf730..49753aafea 100644 --- a/sysdeps/unix/sysv/linux/arc/libc.abilist +++ b/sysdeps/unix/sysv/linux/arc/libc.abilist @@ -2509,5 +2509,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/arm/be/libc.abilist b/sysdeps/unix/sysv/linux/arm/be/libc.abilist index 1d54f71b14..5b1f81c2b4 100644 --- a/sysdeps/unix/sysv/linux/arm/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/be/libc.abilist @@ -2801,6 +2801,7 @@ GLIBC_2.4 xdrstdio_create F GLIBC_2.4 xencrypt F GLIBC_2.4 xprt_register F GLIBC_2.4 xprt_unregister F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/arm/le/libc.abilist b/sysdeps/unix/sysv/linux/arm/le/libc.abilist index ff7e8bc40b..78ba01bcce 100644 --- a/sysdeps/unix/sysv/linux/arm/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/arm/le/libc.abilist @@ -2798,6 +2798,7 @@ GLIBC_2.4 xdrstdio_create F GLIBC_2.4 xencrypt F GLIBC_2.4 xprt_register F GLIBC_2.4 xprt_unregister F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h index 61c100d984..5005637e06 100644 --- a/sysdeps/unix/sysv/linux/bits/fcntl-linux.h +++ b/sysdeps/unix/sysv/linux/bits/fcntl-linux.h @@ -452,6 +452,28 @@ extern int name_to_handle_at (int __dfd, const char *__name, extern int open_by_handle_at (int __mountdirfd, struct file_handle *__handle, int __flags); +#ifdef __has_include +# if __has_include ("linux/openat2.h") +# include "linux/openat2.h" +# define __glibc_has_open_how 1 +# endif +#endif + +#include + +/* Similar to `openat' but the arguments are packed on HOW with the size + USIZE. If flags and mode from HOW are non-zero, then openat2 operates + like openat. + + Unlike openat2, unknown or invalid flags result in an error (EINVAL), + rather than being ignored. The mode must be zero unless one O_CREAT + or O_TMPFILE are set. + + The kernel does not support legacy non-LFS interface. */ +extern int openat2 (int __dfd, const char *__filename, struct open_how *__how, + size_t __usize) + __nonnull ((2, 3)); + #endif /* use GNU */ __END_DECLS diff --git a/sysdeps/unix/sysv/linux/bits/openat2.h b/sysdeps/unix/sysv/linux/bits/openat2.h new file mode 100644 index 0000000000..e47fdc4295 --- /dev/null +++ b/sysdeps/unix/sysv/linux/bits/openat2.h @@ -0,0 +1,61 @@ +/* openat2 definition. Linux specific. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#ifndef _FCNTL_H +# error "Never use directly; include instead." +#endif + +#ifndef __glibc_has_open_how +/* Arguments for how openat2 should open the target path. */ +struct open_how +{ + __uint64_t flags; + __uint64_t mode; + __uint64_t resolve; +}; +#endif + +/* how->resolve flags for openat2. */ +#ifndef RESOLVE_NO_XDEV +# define RESOLVE_NO_XDEV 0x01 /* Block mount-point crossings + (includes bind-mounts). */ +#endif +#ifndef RESOLVE_NO_MAGICLINKS +# define RESOLVE_NO_MAGICLINKS 0x02 /* Block traversal through procfs-style + "magic-links". */ +#endif +#ifndef RESOLVE_NO_SYMLINKS +# define RESOLVE_NO_SYMLINKS 0x04 /* Block traversal through all symlinks + (implies OEXT_NO_MAGICLINKS). */ +#endif +#ifndef RESOLVE_BENEATH +# define RESOLVE_BENEATH 0x08 /* Block "lexical" trickery like + "..", symlinks, and absolute + paths which escape the dirfd. */ +#endif +#ifndef RESOLVE_IN_ROOT +# define RESOLVE_IN_ROOT 0x10 /* Make all jumps to "/" and ".." + be scoped inside the dirfd + (similar to chroot). */ +#endif +#ifndef RESOLVE_CACHED +# define RESOLVE_CACHED 0x20 /* Only complete if resolution can be + completed through cached lookup. May + return -EAGAIN if that's not + possible. */ +#endif diff --git a/sysdeps/unix/sysv/linux/csky/libc.abilist b/sysdeps/unix/sysv/linux/csky/libc.abilist index c3ed65467d..5494cfdbbe 100644 --- a/sysdeps/unix/sysv/linux/csky/libc.abilist +++ b/sysdeps/unix/sysv/linux/csky/libc.abilist @@ -2785,5 +2785,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/hppa/libc.abilist b/sysdeps/unix/sysv/linux/hppa/libc.abilist index 8de7644a59..5415fc616a 100644 --- a/sysdeps/unix/sysv/linux/hppa/libc.abilist +++ b/sysdeps/unix/sysv/linux/hppa/libc.abilist @@ -2821,6 +2821,7 @@ GLIBC_2.4 sys_errlist D 0x400 GLIBC_2.4 sys_nerr D 0x4 GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/i386/libc.abilist b/sysdeps/unix/sysv/linux/i386/libc.abilist index 4fedf775d4..de987832b0 100644 --- a/sysdeps/unix/sysv/linux/i386/libc.abilist +++ b/sysdeps/unix/sysv/linux/i386/libc.abilist @@ -3005,6 +3005,7 @@ GLIBC_2.4 sys_errlist D 0x210 GLIBC_2.4 sys_nerr D 0x4 GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist index 0024282289..428676b88e 100644 --- a/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist +++ b/sysdeps/unix/sysv/linux/loongarch/lp64/libc.abilist @@ -2269,5 +2269,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist index 142595eb3e..f91a4c2aa6 100644 --- a/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/coldfire/libc.abilist @@ -2781,6 +2781,7 @@ GLIBC_2.4 xdrstdio_create F GLIBC_2.4 xencrypt F GLIBC_2.4 xprt_register F GLIBC_2.4 xprt_unregister F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist index 85e7746c10..a2223ef568 100644 --- a/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist +++ b/sysdeps/unix/sysv/linux/m68k/m680x0/libc.abilist @@ -2948,6 +2948,7 @@ GLIBC_2.4 sys_errlist D 0x210 GLIBC_2.4 sys_nerr D 0x4 GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist index 91dc1b8378..ff1e89a02f 100644 --- a/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/be/libc.abilist @@ -2834,5 +2834,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist index 3440e90f6f..466a17961e 100644 --- a/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/microblaze/le/libc.abilist @@ -2831,5 +2831,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist index 5ee7b8c52f..b01152adf6 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/fpu/libc.abilist @@ -2909,6 +2909,7 @@ GLIBC_2.4 renameat F GLIBC_2.4 symlinkat F GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist index 6cb6328e7c..652ecdabce 100644 --- a/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips32/nofpu/libc.abilist @@ -2907,6 +2907,7 @@ GLIBC_2.4 renameat F GLIBC_2.4 symlinkat F GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist index ae7474c0f0..72c430732b 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n32/libc.abilist @@ -2915,6 +2915,7 @@ GLIBC_2.4 renameat F GLIBC_2.4 symlinkat F GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist index cdf040dec2..091703e7d3 100644 --- a/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist +++ b/sysdeps/unix/sysv/linux/mips/mips64/n64/libc.abilist @@ -2817,6 +2817,7 @@ GLIBC_2.4 renameat F GLIBC_2.4 symlinkat F GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/nios2/libc.abilist b/sysdeps/unix/sysv/linux/nios2/libc.abilist index 773d4c5873..a78a596227 100644 --- a/sysdeps/unix/sysv/linux/nios2/libc.abilist +++ b/sysdeps/unix/sysv/linux/nios2/libc.abilist @@ -2873,5 +2873,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/openat2.c b/sysdeps/unix/sysv/linux/openat2.c new file mode 100644 index 0000000000..a2b134bab0 --- /dev/null +++ b/sysdeps/unix/sysv/linux/openat2.c @@ -0,0 +1,29 @@ +/* Linux openat2 syscall implementation. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +#include +#include +#include + +int +__openat2 (int dfd, const char *filename, struct open_how *how, + size_t usize) +{ + return SYSCALL_CANCEL (openat2, dfd, filename, how, usize); +} +weak_alias (__openat2, openat2) diff --git a/sysdeps/unix/sysv/linux/or1k/libc.abilist b/sysdeps/unix/sysv/linux/or1k/libc.abilist index c356a11b1c..a37db30b77 100644 --- a/sysdeps/unix/sysv/linux/or1k/libc.abilist +++ b/sysdeps/unix/sysv/linux/or1k/libc.abilist @@ -2259,5 +2259,6 @@ GLIBC_2.40 getcontext F GLIBC_2.40 makecontext F GLIBC_2.40 setcontext F GLIBC_2.40 swapcontext F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist index 7937f94cf0..4b02461515 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/fpu/libc.abilist @@ -3138,6 +3138,7 @@ GLIBC_2.4 wcstold F GLIBC_2.4 wcstold_l F GLIBC_2.4 wprintf F GLIBC_2.4 wscanf F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist index d6e35f31d2..f473ac3a6d 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc32/nofpu/libc.abilist @@ -3183,6 +3183,7 @@ GLIBC_2.4 wcstold F GLIBC_2.4 wcstold_l F GLIBC_2.4 wprintf F GLIBC_2.4 wscanf F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist index 2268d6890d..50a6f87278 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/be/libc.abilist @@ -2892,6 +2892,7 @@ GLIBC_2.4 wcstold F GLIBC_2.4 wcstold_l F GLIBC_2.4 wprintf F GLIBC_2.4 wscanf F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist index 7f61b14bc8..9bf9776095 100644 --- a/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/powerpc/powerpc64/le/libc.abilist @@ -2968,5 +2968,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist index 4187241f50..71c93f384f 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv32/libc.abilist @@ -2512,5 +2512,6 @@ GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F GLIBC_2.40 __riscv_hwprobe F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist index 8935beccac..5798f0fc62 100644 --- a/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist +++ b/sysdeps/unix/sysv/linux/riscv/rv64/libc.abilist @@ -2712,5 +2712,6 @@ GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F GLIBC_2.40 __riscv_hwprobe F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F diff --git a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist index e69dc7ccf6..27701d9469 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-32/libc.abilist @@ -3136,6 +3136,7 @@ GLIBC_2.4 wcstold F GLIBC_2.4 wcstold_l F GLIBC_2.4 wprintf F GLIBC_2.4 wscanf F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist index 7d860001d8..204a044815 100644 --- a/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist +++ b/sysdeps/unix/sysv/linux/s390/s390-64/libc.abilist @@ -2929,6 +2929,7 @@ GLIBC_2.4 wcstold F GLIBC_2.4 wcstold_l F GLIBC_2.4 wprintf F GLIBC_2.4 wscanf F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/sh/be/libc.abilist b/sysdeps/unix/sysv/linux/sh/be/libc.abilist index fcb8161841..92749c0601 100644 --- a/sysdeps/unix/sysv/linux/sh/be/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/be/libc.abilist @@ -2828,6 +2828,7 @@ GLIBC_2.4 sys_errlist D 0x210 GLIBC_2.4 sys_nerr D 0x4 GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/sh/le/libc.abilist b/sysdeps/unix/sysv/linux/sh/le/libc.abilist index 3fd078d125..76488dee2c 100644 --- a/sysdeps/unix/sysv/linux/sh/le/libc.abilist +++ b/sysdeps/unix/sysv/linux/sh/le/libc.abilist @@ -2825,6 +2825,7 @@ GLIBC_2.4 sys_errlist D 0x210 GLIBC_2.4 sys_nerr D 0x4 GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist index 1ce1fe9da7..7406d8c544 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc32/libc.abilist @@ -3157,6 +3157,7 @@ GLIBC_2.4 wcstold F GLIBC_2.4 wcstold_l F GLIBC_2.4 wprintf F GLIBC_2.4 wscanf F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist index 07507b86f6..2a22bf154c 100644 --- a/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist +++ b/sysdeps/unix/sysv/linux/sparc/sparc64/libc.abilist @@ -2793,6 +2793,7 @@ GLIBC_2.4 sys_errlist D 0x430 GLIBC_2.4 sys_nerr D 0x4 GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/tst-openat2-consts.py b/sysdeps/unix/sysv/linux/tst-openat2-consts.py new file mode 100755 index 0000000000..1623fafd94 --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-openat2-consts.py @@ -0,0 +1,63 @@ +#!/usr/bin/python3 +# Test that glibc's sys/openat2.h constants match the kernel's. +# Copyright (C) 2024 Free Software Foundation, Inc. +# This file is part of the GNU C Library. +# +# The GNU C Library is free software; you can redistribute it and/or +# modify it under the terms of the GNU Lesser General Public +# License as published by the Free Software Foundation; either +# version 2.1 of the License, or (at your option) any later version. +# +# The GNU C Library is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# Lesser General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with the GNU C Library; if not, see +# . + +import argparse +import sys + +import glibcextract +import glibcsyscalls + + +def main(): + """The main entry point.""" + parser = argparse.ArgumentParser( + description="Test that glibc's sys/openat2.h constants " + "match the kernel's.") + parser.add_argument('--cc', metavar='CC', + help='C compiler (including options) to use') + args = parser.parse_args() + + if glibcextract.compile_c_snippet( + '#include ', + args.cc).returncode != 0: + sys.exit (77) + + linux_version_headers = glibcsyscalls.linux_kernel_version(args.cc) + # Constants in glibc were updated to match Linux v6.8. When glibc + # constants are updated this value should be updated to match the + # released kernel version from which the constants were taken. + linux_version_glibc = (6, 8) + def check(cte, exclude=None): + return glibcextract.compare_macro_consts( + '#define _FCNTL_H\n' + '#include \n' + '#include \n', + '#include \n' + '#include \n', + args.cc, + cte, + exclude, + linux_version_glibc > linux_version_headers, + linux_version_headers > linux_version_glibc) + + status = check('RESOLVE.*') + sys.exit(status) + +if __name__ == '__main__': + main() diff --git a/sysdeps/unix/sysv/linux/tst-openat2.c b/sysdeps/unix/sysv/linux/tst-openat2.c new file mode 100644 index 0000000000..d0c26f2bce --- /dev/null +++ b/sysdeps/unix/sysv/linux/tst-openat2.c @@ -0,0 +1,259 @@ +/* Linux openat2 tests. + Copyright (C) 2024 Free Software Foundation, Inc. + This file is part of the GNU C Library. + + The GNU C Library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + The GNU C Library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with the GNU C Library; if not, see + . */ + +/* openat2 always return a file descriptor in LFS mode. */ +#define _FILE_OFFSET_BITS 64 + +#include +#include +#include +#include +#include +#include +#include + +static int dir_fd; + +static void +do_prepare (int argc, char *argv[]) +{ + char *temp_dir = support_create_temp_directory ("tst-openat2"); + dir_fd = xopen (temp_dir, O_RDONLY | O_DIRECTORY, 0); +} +#define PREPARE do_prepare + +static int +do_test_struct (void) +{ + static struct struct_test + { + struct open_how_ext + { + struct open_how inner; + int extra1; + int extra2; + int extra3; + } arg; + size_t size; + int err; + } tests[] = + { + { + /* Zero size. */ + .arg.inner.flags = O_RDONLY, + .size = 0, + .err = EINVAL, + }, + { + /* Normal struct. */ + .arg.inner.flags = O_RDONLY, + .size = sizeof (struct open_how), + }, + { + /* Larger struct, zeroed out the unused values. */ + .arg.inner.flags = O_RDONLY, + .size = sizeof (struct open_how_ext), + }, + { + /* Larger struct, non-zeroed out the unused values. */ + .arg.inner.flags = O_RDONLY, + .arg.extra1 = 0xdeadbeef, + .size = sizeof (struct open_how_ext), + .err = E2BIG, + }, + { + /* Larger struct, non-zeroed out the unused values. */ + .arg.inner.flags = O_RDONLY, + .arg.extra2 = 0xdeadbeef, + .size = sizeof (struct open_how_ext), + .err = E2BIG, + }, + }; + + for (struct struct_test *t = tests; t != array_end (tests); t++) + { + int fd = openat2 (AT_FDCWD, ".", (struct open_how *) &t->arg, t->size); + if (fd == -1 && errno == ENOSYS) + FAIL_UNSUPPORTED ("openat2 is not supported by the kernel"); + + if (t->err != 0) + { + TEST_COMPARE (fd, -1); + TEST_COMPARE (errno, t->err); + } + else + TEST_VERIFY (fd >= 0); + } + + return 0; +} + +static int +do_test_flags (void) +{ + static struct flag_test + { + struct open_how how; + int err; + } tests[] = + { + /* O_TMPFILE is incompatible with O_PATH and O_CREAT. */ + { .how.flags = O_TMPFILE | O_PATH | O_RDWR, .err = EINVAL }, + { .how.flags = O_TMPFILE | O_CREAT | O_RDWR, .err = EINVAL }, + + /* O_PATH only permits certain other flags to be set ... */ + { .how.flags = O_PATH | O_CLOEXEC }, + { .how.flags = O_PATH | O_DIRECTORY }, + { .how.flags = O_PATH | O_NOFOLLOW }, + /* ... and others are absolutely not permitted. */ + { .how.flags = O_PATH | O_RDWR, .err = EINVAL }, + { .how.flags = O_PATH | O_CREAT, .err = EINVAL }, + { .how.flags = O_PATH | O_EXCL, .err = EINVAL }, + { .how.flags = O_PATH | O_NOCTTY, .err = EINVAL }, + { .how.flags = O_PATH | O_DIRECT, .err = EINVAL }, + + /* ->mode must only be set with O_{CREAT,TMPFILE}. */ + { .how.flags = O_RDONLY, .how.mode = 0600, .err = EINVAL }, + { .how.flags = O_PATH, .how.mode = 0600, .err = EINVAL }, + { .how.flags = O_CREAT, .how.mode = 0600 }, + { .how.flags = O_TMPFILE | O_RDWR, .how.mode = 0600 }, + /* ->mode must only contain 0777 bits. */ + { .how.flags = O_CREAT, .how.mode = 0xFFFF, .err = EINVAL }, + { .how.flags = O_CREAT, .how.mode = 0xC000000000000000ULL, .err = EINVAL }, + { .how.flags = O_TMPFILE | O_RDWR, .how.mode = 0x1337, .err = EINVAL }, + { .how.flags = O_TMPFILE | O_RDWR, .how.mode = 0x0000A00000000000ULL, + .err = EINVAL }, + + /* ->resolve flags must not conflict. */ + { .how.flags = O_RDONLY, + .how.resolve = RESOLVE_BENEATH | RESOLVE_IN_ROOT, + .err = EINVAL }, + + /* ->resolve must only contain RESOLVE_* flags. */ + { .how.flags = O_RDONLY, + .how.resolve = 0x1337, .err = EINVAL }, + { .how.flags = O_CREAT, + .how.resolve = 0x1337, .err = EINVAL }, + { .how.flags = O_TMPFILE | O_RDWR, + .how.resolve = 0x1337, .err = EINVAL }, + { .how.flags = O_PATH, + .how.resolve = 0x1337, .err = EINVAL }, + + /* currently unknown upper 32 bit rejected. */ + { .how.flags = O_RDONLY | (1ULL << 63), + .how.resolve = 0, .err = EINVAL }, + }; + + for (struct flag_test *t = tests; t != array_end (tests); t++) + { + char *path; + if (t->how.flags & O_CREAT) + { + int temp_fd = create_temp_file ("tst-openat2.", &path); + TEST_VERIFY_EXIT (temp_fd != -1); + xunlink (path); + } + else + path = (char *) "."; + + int fd = openat2 (AT_FDCWD, path, &t->how, sizeof (struct open_how)); + if (fd != 0 && errno == EOPNOTSUPP) + { + /* Skip the testcase if FS does not support the operation (e.g. + valid O_TMPFILE on NFS). */ + continue; + } + + if (t->err != 0) + { + TEST_COMPARE (fd, -1); + TEST_COMPARE (errno, t->err); + } + else + TEST_VERIFY (fd >= 0); + } + + return 0; +} + +static int +do_test_basic (void) +{ + int fd; + + fd = openat2 (dir_fd, + "some-file", + &(struct open_how) + { + .flags = O_CREAT|O_RDWR|O_EXCL, + .mode = 0666, + }, + sizeof (struct open_how)); + TEST_VERIFY (fd != -1); + + xwrite (fd, "hello", 5); + + /* Before closing the file, try using this file descriptor to open + another file. This must fail. */ + { + int fd2 = openat2 (fd, + "should-not-work", + &(struct open_how) + { + .flags = O_CREAT|O_RDWR|O_EXCL, + .mode = 0666, + }, + sizeof (struct open_how)); + TEST_COMPARE (fd2, -1); + TEST_COMPARE (errno, ENOTDIR); + } + + /* Remove the created file. */ + int cwdfd = xopen (".", O_RDONLY | O_DIRECTORY, 0); + TEST_COMPARE (fchdir (dir_fd), 0); + xunlink ("some-file"); + TEST_COMPARE (fchdir (cwdfd), 0); + + xclose (dir_fd); + xclose (cwdfd); + + fd = openat2 (dir_fd, + "some-file", + &(struct open_how) + { + .flags = O_CREAT|O_RDWR|O_EXCL, + .mode = 0666, + }, + sizeof (struct open_how)); + TEST_COMPARE (fd, -1); + TEST_COMPARE (errno, EBADF); + + return 0; +} + +static int +do_test (void) +{ + do_test_struct (); + do_test_flags (); + do_test_basic (); + + return 0; +} + +#include diff --git a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist index 5acf49dbe8..5c5b239c20 100644 --- a/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/64/libc.abilist @@ -2744,6 +2744,7 @@ GLIBC_2.4 sys_errlist D 0x420 GLIBC_2.4 sys_nerr D 0x4 GLIBC_2.4 unlinkat F GLIBC_2.4 unshare F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F GLIBC_2.5 __readlinkat_chk F diff --git a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist index 02d1bb97dc..281fa6cfed 100644 --- a/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist +++ b/sysdeps/unix/sysv/linux/x86_64/x32/libc.abilist @@ -2763,5 +2763,6 @@ GLIBC_2.39 stdc_trailing_zeros_ui F GLIBC_2.39 stdc_trailing_zeros_ul F GLIBC_2.39 stdc_trailing_zeros_ull F GLIBC_2.39 stdc_trailing_zeros_us F +GLIBC_2.41 openat2 F GLIBC_2.41 sched_getattr F GLIBC_2.41 sched_setattr F