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=-1.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, T_SCC_BODY_TEXT_LINE,URIBL_BLACK 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 234C6232F5 for ; Sun, 18 Feb 2024 03:27:21 +0100 (CET) Received: (qmail 30355 invoked by uid 550); 18 Feb 2024 02:24:01 -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 30308 invoked from network); 18 Feb 2024 02:24:00 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rtone.fr; s=google; t=1708223220; x=1708828020; darn=lists.openwall.com; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=U4h7tQxl8ygKL6pUkV8QoaG8wWXmj4yNNKZTOpwQ+TE=; b=fLARdxkI4Ct5imxGxT3wzIHNdHkrjdlGbV9c4w0WbewiZLl41kSkoZpr2XsA5jWSmn a+hjrn2CDHQc7QA+ivLI9lr4QkNfXnQ23krA2wfnKXDxwyeJbQ4n0x5ccTeS4XqtkCfc I3U5OjJ38xv1K3upIyugXWmMqsYb7oEK9w9jM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708223220; x=1708828020; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U4h7tQxl8ygKL6pUkV8QoaG8wWXmj4yNNKZTOpwQ+TE=; b=vEETrvyzzcXph+zN3R8J8N4bQx0DVCI0g6Ijg0rj+ZtGFPgEJ9KMUDjmi786K3sJOw Wd3bANSmDz+y4TmnIvXniexfYVXEYrT9akJPrvkMMLLmbiYgqwaQQe2xD7K1ln/mESoM s3cg0j7Ea8a6wdrtxQcXBKnd/sG5fz7x2t88eh9Atq4mWY9vbDmRjhWpC4rp8iWmLo0q da5XXgSGCG9ZtsVKHnVlGl1Sea0J26dTqv160ZR9Kq5FyYHE5nVWs2thS4DgINu+34WT Q8YGQjGLqQE7h+wnuRmK/Qr2kuQa2koKW6zlI2TsDd1ExJOZqHAI5D7FdzluRV29qcbW cxGA== X-Gm-Message-State: AOJu0YzuCpVcNXW6P/ok+K+KkOPPVlx4LE53nv2uUHo+HfEUB1WiRCg/ +uQ4STMaAXvwUNm0V0YpUrGP4aA44kAFJhZsgbO61GBpsWhY2oTIrsbmEWtS87X64KaAGlyYu4X U X-Google-Smtp-Source: AGHT+IGZlncEvEM7ua6iuEUmX9pcbT2JyXzLCg9O2l3MCRCEG2wz5pwQEfopktki2Q7s/HHLFNc0aw== X-Received: by 2002:a5d:5348:0:b0:33b:74a3:dcfb with SMTP id t8-20020a5d5348000000b0033b74a3dcfbmr5478720wrv.1.1708223219672; Sat, 17 Feb 2024 18:26:59 -0800 (PST) From: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= To: musl@lists.openwall.com Cc: =?UTF-8?q?Ga=C3=ABl=20PORTAY?= Date: Sun, 18 Feb 2024 03:26:42 +0100 Message-ID: <20240218022650.1097269-1-gael.portay@rtone.fr> X-Mailer: git-send-email 2.43.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: [musl] [PATCH v2 0/8] use new SYS_fchmodat2 syscall to implement fchmodat with flags hello, this patch serie adds the syscall SYS_fchmodat2 to implement fchmodat(). it has landed in linux v6.6. fhe first five patches catch up the gap of syscall numbers. the sixth patch removes the spurious flag argument from the syscall SYS_fchmodat (linux lacks for that argument actually). the seventh patch defines the syscall itself in headers. the last patch uses the syscall SYS_fchmodat2 to implement fchmodat() if flags are passed. the same way the syscall SYS_faccessat2 was used to implement faccessat() with flags. it wat tested locally on x86_64 (only), with a dummy test-fchmodat.c. here is what strace says if no flags are passed: gportay@archlinux ~/src/musl $ strace ./lib/libc.so ./test-fchmodat . file 0664 0 execve("./lib/libc.so", ["./lib/libc.so", "./test-fchmodat", ".", "file", "0664", "0"], 0x7ffc172ccc68 /* 34 vars */) = 0 arch_prctl(ARCH_SET_FS, 0x765732cf7ba8) = 0 set_tid_address(0x765732cf8018) = 367709 open("./test-fchmodat", O_RDONLY|O_LARGEFILE) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\20\0\0\0\0\0\0"..., 960) = 960 mmap(NULL, 20480, PROT_READ, MAP_PRIVATE, 3, 0) = 0x765732c58000 mmap(0x765732c59000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0x1000) = 0x765732c59000 mmap(0x765732c5a000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED, 3, 0x2000) = 0x765732c5a000 mmap(0x765732c5b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x2000) = 0x765732c5b000 close(3) = 0 brk(NULL) = 0x5555568a6000 brk(0x5555568a8000) = 0x5555568a8000 mmap(0x5555568a6000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x5555568a6000 mprotect(0x765732cf4000, 4096, PROT_READ) = 0 mprotect(0x765732c5b000, 4096, PROT_READ) = 0 fchmodat(AT_FDCWD, "file", 0664) = 0 exit_group(0) = ? +++ exited with 0 +++ it uses the syscall fchmodat. and what strace says if AT_SYMLINK_NOFOLLOW is passed: gportay@archlinux ~/src/musl $ strace ./lib/libc.so ./test-fchmodat . file 0664 0x100 execve("./lib/libc.so", ["./lib/libc.so", "./test-fchmodat", ".", "file", "0664", "0x100"], 0x7ffcd7228278 /* 34 vars */) = 0 arch_prctl(ARCH_SET_FS, 0x7318d8907ba8) = 0 set_tid_address(0x7318d8908018) = 367715 open("./test-fchmodat", O_RDONLY|O_LARGEFILE) = 3 read(3, "\177ELF\2\1\1\0\0\0\0\0\0\0\0\0\3\0>\0\1\0\0\0\260\20\0\0\0\0\0\0"..., 960) = 960 mmap(NULL, 20480, PROT_READ, MAP_PRIVATE, 3, 0) = 0x7318d8868000 mmap(0x7318d8869000, 4096, PROT_READ|PROT_EXEC, MAP_PRIVATE|MAP_FIXED, 3, 0x1000) = 0x7318d8869000 mmap(0x7318d886a000, 4096, PROT_READ, MAP_PRIVATE|MAP_FIXED, 3, 0x2000) = 0x7318d886a000 mmap(0x7318d886b000, 8192, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_FIXED, 3, 0x2000) = 0x7318d886b000 close(3) = 0 brk(NULL) = 0x55555563d000 brk(0x55555563f000) = 0x55555563f000 mmap(0x55555563d000, 4096, PROT_NONE, MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0) = 0x55555563d000 mprotect(0x7318d8904000, 4096, PROT_READ) = 0 mprotect(0x7318d886b000, 4096, PROT_READ) = 0 fchmodat2(AT_FDCWD, "file", 0664, AT_SYMLINK_NOFOLLOW) = 0 exit_group(0) = ? +++ exited with 0 +++ it uses the syscall fchmodat2! #include #include #include #include #include #include #include int main(int argc, char * const argv[]) { int dfd = AT_FDCWD, flags = 0, ret = EXIT_FAILURE; mode_t mode; if (argc < 4) { fprintf(stderr, "Too few arguments\n"); exit(EXIT_FAILURE); } else if (argc > 5) { fprintf(stderr, "Too many arguments\n"); exit(EXIT_FAILURE); } mode = strtoul(argv[3], NULL, 0); if (argc == 5) flags = strtoul(argv[4], NULL, 0); if (strcmp(argv[1], "-") == 0) { dfd = open(argv[1], O_DIRECTORY); if (dfd == -1) { perror("open"); return EXIT_FAILURE; } } if (fchmodat(dfd, argv[2], mode, flags)) { perror("fchmodat"); goto exit; } ret = EXIT_SUCCESS; exit: if (dfd != AT_FDCWD) if (close(dfd)) perror("close"); return ret; } changes since v1: - catchup syscall gap - add missing syscall number for aarch64 regards, Gaƫl PORTAY (8): bits/syscall.h: add process_madvise from linux v5.14 bits/syscall.h: add process_mrelease from linux v5.15 bits/syscall.h: add futex_waitv from linux v5.16 bits/syscall.h: add set_mempolicy_home_node from linux v5.17 bits/syscall.h: add cachestat from linux v6.4 remove flag argument from fchmodat syscall bits/syscall.h: add __NR_fchmodat2 from linux v6.6 use new SYS_fchmodat2 syscall to implement fchmodat with flags arch/aarch64/bits/syscall.h.in | 6 ++++++ arch/arm/bits/syscall.h.in | 6 ++++++ arch/i386/bits/syscall.h.in | 6 ++++++ arch/m68k/bits/syscall.h.in | 6 ++++++ arch/microblaze/bits/syscall.h.in | 6 ++++++ arch/mips/bits/syscall.h.in | 6 ++++++ arch/mips64/bits/syscall.h.in | 6 ++++++ arch/mipsn32/bits/syscall.h.in | 6 ++++++ arch/or1k/bits/syscall.h.in | 6 ++++++ arch/powerpc/bits/syscall.h.in | 6 ++++++ arch/powerpc64/bits/syscall.h.in | 6 ++++++ arch/riscv64/bits/syscall.h.in | 6 ++++++ arch/s390x/bits/syscall.h.in | 6 ++++++ arch/sh/bits/syscall.h.in | 6 ++++++ arch/x32/bits/syscall.h.in | 6 ++++++ arch/x86_64/bits/syscall.h.in | 6 ++++++ src/stat/fchmodat.c | 7 ++++++- 17 files changed, 102 insertions(+), 1 deletion(-) -- 2.43.2