From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=5.0 tests=DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H4,RCVD_IN_MSPIKE_WL autolearn=ham autolearn_force=no version=3.4.4 Received: from second.openwall.net (second.openwall.net [193.110.157.125]) by inbox.vuxu.org (Postfix) with SMTP id E076021F1F for ; Tue, 23 Apr 2024 11:35:43 +0200 (CEST) Received: (qmail 19932 invoked by uid 550); 23 Apr 2024 09:35:40 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Reply-To: musl@lists.openwall.com Received: (qmail 19903 invoked from network); 23 Apr 2024 04:39:30 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713847160; x=1714451960; darn=lists.openwall.com; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=0eVoTckteJXd4x4iXCCuGp7mJv3XfMg4SPf6O/GsOwg=; b=SyzfYU4tVh9B+iKp9Pja5afPKM6He5y+QoJmDMsZt+BfbGB4CqdU8ndM5wuYCmJTjB pCL0NXDQWImwzszi1nh+qoJIEQoFYhHO6kIlpNdBogKAmjvVGbMdWxdmiIduxo7gZqYH QNlYfulIksEmwB/7pTQEwZXKUBrSUhHvxsA2dvqL5nWLkAyy0ktdBzfU9js9hE725X55 AfnEmG8wsqZupbJ9ECFw/3NlHKqivzx2uDmUl8gJo3YT18JTOhCCg9Y0uVgV7pwDq+GW 5Jzz2cWNBeTq6w+kx3k07Efb42CXLtKLZB77sKeIqIyYSvNPJWUhCEwvGNmlwcyqkG/6 1QyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713847160; x=1714451960; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=0eVoTckteJXd4x4iXCCuGp7mJv3XfMg4SPf6O/GsOwg=; b=vE0sUo/XL+Xblb32xbXjN2cdE7wVHSgvtqO825SU3vVBiarclV/opg5UQIzTrnabe9 A2sNy2gLe0nczGGOOX3w+hnMR6LhfZBowrQjBSJRrJQ7jfSuXGEdopCyyITFMPAqSR40 wujPJnHOGTbjZlwDBbrSkLYXmhd0ui8D9E6dEQLbjyQLvaSkkrw2WAlxrTtPTvaUrqX9 EcJXmWoc0QnzR/71gKQyEDjQtABgJjXHQd0PGrso34pFTwdLdvmTprlvnt05+C53SQBF 4JIjSKYcWNBnM0S4jZcn567SzkvIXou2BqOUcjsMl0D5EOurYVnY7jNSsx60JnMI7Pzn KyjA== X-Gm-Message-State: AOJu0YzX7nGYYPCMAUIX9ZTuT8kgF6OZPo/MZiQoRaoCtrJAXfrfma/s J8J88ZIV77ikG53oMY+pGPQioFYcn2IGLquRWOCo2chP/rep1mFV X-Google-Smtp-Source: AGHT+IEz69MbLn1NaKkOIgqgrDUjCWLW/HhKWuucEHquxAMoHHYG6ITEpnuapLefOyjzjJz8o30TFA== X-Received: by 2002:a17:902:f682:b0:1e3:e242:4dc9 with SMTP id l2-20020a170902f68200b001e3e2424dc9mr12073936plg.33.1713847160123; Mon, 22 Apr 2024 21:39:20 -0700 (PDT) From: Tony Ambardar X-Google-Original-From: Tony Ambardar Date: Mon, 22 Apr 2024 21:39:17 -0700 To: Rich Felker Cc: musl@lists.openwall.com Message-ID: References: <20240421153640.379015-1-Tony.Ambardar@gmail.com> <20240422224726.GL4163@brightrain.aerifal.cx> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20240422224726.GL4163@brightrain.aerifal.cx> Subject: Re: [musl] [PATCH v1] add renameat2 linux syscall wrapper On Mon, Apr 22, 2024 at 06:47:26PM -0400, Rich Felker wrote: > On Sun, Apr 21, 2024 at 08:36:40AM -0700, Tony Ambardar wrote: > > This syscall is available since Linux 3.15 and also implemented in glibc > > from version 2.28. It is commonly used in filesystem or security contexts. > > > > Defines RENAME_NOREPLACE, RENAME_EXCHANGE, RENAME_WHITEOUT are guarded by > > _GNU_SOURCE as with glibc. > > > > Signed-off-by: Tony Ambardar > > --- > > include/stdio.h | 7 +++++++ > > src/linux/renameat2.c | 8 ++++++++ > > 2 files changed, 15 insertions(+) > > create mode 100644 src/linux/renameat2.c > > > > diff --git a/include/stdio.h b/include/stdio.h > > index cb858618..8312c3bf 100644 > > --- a/include/stdio.h > > +++ b/include/stdio.h > > @@ -158,6 +158,13 @@ char *ctermid(char *); > > #define L_ctermid 20 > > #endif > > > > +#if defined(_GNU_SOURCE) > > +#define RENAME_NOREPLACE (1 << 0) > > +#define RENAME_EXCHANGE (1 << 1) > > +#define RENAME_WHITEOUT (1 << 2) > > + > > +int renameat2(int, const char *, int, const char *, unsigned int); > > +#endif > > s/unsigned int/unsigned/ and maybe just write out the constants? I > think that's the style musl uses most places. Right, the constants-by-shift mirrored glibc and I saw these also in musl e.g. hwcap.h, elf.h, mount.h, syslog.h, etc. I'm not wedded to either but just wanted to be consistent. Please confirm a preference and I'll update. > > > #if defined(_XOPEN_SOURCE) || defined(_GNU_SOURCE) \ > > || defined(_BSD_SOURCE) > > diff --git a/src/linux/renameat2.c b/src/linux/renameat2.c > > new file mode 100644 > > index 00000000..3062aa15 > > --- /dev/null > > +++ b/src/linux/renameat2.c > > @@ -0,0 +1,8 @@ > > +#define _GNU_SOURCE > > +#include > > +#include "syscall.h" > > + > > +int renameat2(int oldfd, const char *old, int newfd, const char *new, unsigned int flags) > > +{ > > + return syscall(SYS_renameat2, oldfd, old, newfd, new, flags); > > +} > > -- > > 2.34.1 > > This probably at least needs to support flags==0 on kernels without > SYS_renameat2 by calling renameat in that case. Then I'm not sure if > ENOSYS should be kept if the new syscall is missing, or just EINVAL or > whatever is used to report unsupported flags. I had wondered about this too and looked at all 'arch/.../syscall.h.in' files. All arches support SYS_renameat2, but riscv, aarch64, loongarch64 and or1k are missing SYS_rename and/or SYS_renameat. Also, current code in stdio/rename.c and unistd/renameat.c may fall back _unconditionally_ to use SYS_renameat2 in these cases, with the assumption it's always present. I think this means we're OK? Or do we allow for old kernels which lack SYS_renameat2, in which case some existing code would need updating? > Rich Thanks, Tony