From patchwork Wed Jun 21 12:53:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287245 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3E720EB64D7 for ; Wed, 21 Jun 2023 12:54:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230050AbjFUMyC (ORCPT ); Wed, 21 Jun 2023 08:54:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjFUMyB (ORCPT ); Wed, 21 Jun 2023 08:54:01 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DF790198E; Wed, 21 Jun 2023 05:53:59 -0700 (PDT) X-QQ-mid: bizesmtp75t1687352030t6j173ww Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 20:53:49 +0800 (CST) X-QQ-SSF: 00200000000000D0V000000A0000000 X-QQ-FEAT: rZJGTgY0+YPZ7mrwklJEhXkxIhwVAUczV0XJnaL0tpQYWZHFFFHnfUHkJIX1z sWOoGTqB/Z5xI0uOG1O7jU4STKbVEZhWcePXhzT7VX5SBwKucKebhCloWNphgvPrsNvvRKW 6Nt5lrd2BHcm8T1TDQJeBHne0RhSELBHlqyotO+bh4mGc5cPHPAe4zayQAiaA25mdYqH93u jb4hWDuC7Eahb7t1ORs90h8wBddDcTWDUL5Mb8rXYLJind7Nv9ttrboZipA0b/Nv8V6bNyZ 62l8/Kmnn5sea08fk6yMMh2o3uREf9OLHTxDYbJnwxHcXNrqcXBCCE8Jvl7PY4TQMho+Ro9 7cHDlAfWcRQX50pU/xfYBSMarFOejMdOQPLx77w8enOSPAdvTZuN2z/BPxElg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 10490605076319373216 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 01/17] selftests/nolibc: stat_fault: silence NULL argument warning with glibc Date: Wed, 21 Jun 2023 20:53:45 +0800 Message-Id: <7edcfbe718bbaf145e303ef353d427373cec63dc.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Use another invalid address (void *)1 instead of NULL to silence this compile warning with glibc: $ make libc-test CC libc-test nolibc-test.c: In function ‘run_syscall’: nolibc-test.c:622:49: warning: null argument where non-null required (argument 1) [-Wnonnull] 622 | CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; | ^~~~ nolibc-test.c:304:79: note: in definition of macro ‘EXPECT_SYSER2’ 304 | do { if (!cond) pad_spc(llen, 64, "[SKIPPED]\n"); else ret += expect_syserr2(expr, expret, experr1, experr2, llen); } while (0) | ^~~~ nolibc-test.c:622:33: note: in expansion of macro ‘EXPECT_SYSER’ 622 | CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 486334981e60..99afec93dfae 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -619,7 +619,7 @@ int run_syscall(int min, int max) CASE_TEST(select_stdout); EXPECT_SYSNE(1, ({ fd_set fds; FD_ZERO(&fds); FD_SET(1, &fds); select(2, NULL, &fds, NULL, NULL); }), -1); break; CASE_TEST(select_fault); EXPECT_SYSER(1, select(1, (void *)1, NULL, NULL, 0), -1, EFAULT); break; CASE_TEST(stat_blah); EXPECT_SYSER(1, stat("/proc/self/blah", &stat_buf), -1, ENOENT); break; - CASE_TEST(stat_fault); EXPECT_SYSER(1, stat(NULL, &stat_buf), -1, EFAULT); break; + CASE_TEST(stat_fault); EXPECT_SYSER(1, stat((void *)1, &stat_buf), -1, EFAULT); break; CASE_TEST(stat_timestamps); EXPECT_SYSZR(1, test_stat_timestamps()); break; CASE_TEST(symlink_root); EXPECT_SYSER(1, symlink("/", "/"), -1, EEXIST); break; CASE_TEST(unlink_root); EXPECT_SYSER(1, unlink("/"), -1, EISDIR); break; From patchwork Wed Jun 21 12:54:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287246 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3AA37EB64D7 for ; Wed, 21 Jun 2023 12:55:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbjFUMzL (ORCPT ); Wed, 21 Jun 2023 08:55:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34428 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230226AbjFUMzK (ORCPT ); Wed, 21 Jun 2023 08:55:10 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 029FAE7D; Wed, 21 Jun 2023 05:55:08 -0700 (PDT) X-QQ-mid: bizesmtp66t1687352100tvb06x1e Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 20:54:59 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: znfcQSa1hKZcFXPQnd4RVj09C3OnkJWSkgLOL6bViSkPod9ouiMy9YOYaykXy MyO4BJF4HrBpb3CtZbIMxoxb0B6lkVlmh6fyGDCoX2fTYobW1h4DSy7NbZaBbeHKZE+Zi4C cvR4FQVVd+Cf4yDQRUKYc12aKstmn0hMbRbzp5rrpjwlrDEAarUPxpISJH7M8eSOMheHt+a 8oFAgquo0VJe41uTRGNumpHRqWbHfBcrCNjHOWvi4qAkef7DYMfiC6Uy/g7pm+tYbXaq/wO jUkX3tm2VVyxKprhTftxC7sgB/SLY5moBwhe3r7d0gAPAEQovCVxRFjIE8JEmo59d7CC69D VMjtnLwhGv/WiaoO/Ns0yAp9xcRJWoyympa24xwUHueqaviAbk= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 455061309582853142 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 02/17] selftests/nolibc: gettid: restore for glibc and musl Date: Wed, 21 Jun 2023 20:54:53 +0800 Message-Id: <7268483c95af54c95c1da6fd5d6d0d08c1be2392.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org As the gettid manpage [1] shows, glibc 2.30 has gettid support, so, let's enable the test for glibc >= 2.30. gettid works on musl too. [1]: https://man7.org/linux/man-pages/man2/gettid.2.html Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 99afec93dfae..739c9daa91b6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -548,6 +548,7 @@ int run_syscall(int min, int max) int tmp; int ret = 0; void *p1, *p2; + int has_gettid = 1; /* indicates whether or not /proc is mounted */ proc = stat("/proc", &stat_buf) == 0; @@ -555,6 +556,11 @@ int run_syscall(int min, int max) /* this will be used to skip certain tests that can't be run unprivileged */ euid0 = geteuid() == 0; + /* from 2.30, glibc provides gettid() */ +#if defined(__GLIBC_MINOR__) && defined(__GLIBC__) + has_gettid = __GLIBC__ > 2 || (__GLIBC__ == 2 && __GLIBC_MINOR__ >= 30); +#endif + for (test = min; test >= 0 && test <= max; test++) { int llen = 0; /* line length */ @@ -564,9 +570,7 @@ int run_syscall(int min, int max) switch (test + __LINE__ + 1) { CASE_TEST(getpid); EXPECT_SYSNE(1, getpid(), -1); break; CASE_TEST(getppid); EXPECT_SYSNE(1, getppid(), -1); break; -#ifdef NOLIBC - CASE_TEST(gettid); EXPECT_SYSNE(1, gettid(), -1); break; -#endif + CASE_TEST(gettid); EXPECT_SYSNE(has_gettid, gettid(), -1); break; CASE_TEST(getpgid_self); EXPECT_SYSNE(1, getpgid(0), -1); break; CASE_TEST(getpgid_bad); EXPECT_SYSER(1, getpgid(-1), -1, ESRCH); break; CASE_TEST(kill_0); EXPECT_SYSZR(1, kill(getpid(), 0)); break; From patchwork Wed Jun 21 12:56:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287247 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 40605EB64D7 for ; Wed, 21 Jun 2023 12:56:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230338AbjFUM4v (ORCPT ); Wed, 21 Jun 2023 08:56:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229995AbjFUM4u (ORCPT ); Wed, 21 Jun 2023 08:56:50 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ACE021AC; Wed, 21 Jun 2023 05:56:48 -0700 (PDT) X-QQ-mid: bizesmtp71t1687352198t3y4p8d8 Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 20:56:37 +0800 (CST) X-QQ-SSF: 00200000000000D0V000000A0000000 X-QQ-FEAT: kW11ei911QIEmMARb2D/9riz1PmfAVjY0VfqkkrlMxEhhNhhOM6Lop7SLtmUf wM8PfJZIXzcE8XffnD6KaOQeOPUIUkxe9Nnu0JrvGtyaukJEccdFZmu74ZhjuBWMDlyf/bB 4psKfa61jl09sqKWt7abjFYCwzUO+BwI9SXCuiLjmYlHyHWoemIaFVlpPiGgv8IMr5n7ET+ KeAp2NB2XWDWX6thOVS5g0df3C72/7zHaxp4D64GWf1elO0WAU2TDaB2yxfQdteVmxIrRyi 96Z64UweY4ajqpKnug/miPliEMgg+YM43kA/j4dsGVRiw7pLlS++xC3MajL5tLACqWofxWy kB+/1DhGQxhf/42v2D2iq0kru0MySKugpr1MnrhDLEVJNKKF/PkFecRbfqqyA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1937265591445148803 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 03/17] selftests/nolibc: add _LARGEFILE64_SOURCE for musl Date: Wed, 21 Jun 2023 20:56:03 +0800 Message-Id: <6b28c488dbbdee2d44d75fffe067feb884865861.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org _GNU_SOURCE Implies _LARGEFILE64_SOURCE in glibc, but in musl, the default configuration doesn't enable _LARGEFILE64_SOURCE. From include/dirent.h of musl, getdents64 is provided as getdents when _LARGEFILE64_SOURCE is defined. #if defined(_LARGEFILE64_SOURCE) ... #define getdents64 getdents #endif Let's define _LARGEFILE64_SOURCE to fix up this compile error: tools/testing/selftests/nolibc/nolibc-test.c: In function ‘test_getdents64’: tools/testing/selftests/nolibc/nolibc-test.c:453:8: warning: implicit declaration of function ‘getdents64’; did you mean ‘getdents’? [-Wimplicit-function-declaration] 453 | ret = getdents64(fd, (void *)buffer, sizeof(buffer)); | ^~~~~~~~~~ | getdents /usr/bin/ld: /tmp/ccKILm5u.o: in function `test_getdents64': nolibc-test.c:(.text+0xe3e): undefined reference to `getdents64' collect2: error: ld returned 1 exit status Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 739c9daa91b6..d43116553288 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -1,6 +1,7 @@ /* SPDX-License-Identifier: GPL-2.0 */ #define _GNU_SOURCE +#define _LARGEFILE64_SOURCE /* libc-specific include files * The program may be built in 3 ways: From patchwork Wed Jun 21 12:57:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287248 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6E4AEEB64D7 for ; Wed, 21 Jun 2023 12:58:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231779AbjFUM6G (ORCPT ); Wed, 21 Jun 2023 08:58:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35852 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230174AbjFUM6G (ORCPT ); Wed, 21 Jun 2023 08:58:06 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2ED4BE72; Wed, 21 Jun 2023 05:58:04 -0700 (PDT) X-QQ-mid: bizesmtp78t1687352274tr2s7sp4 Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 20:57:53 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: QityeSR92A3lpCGQzuzSiXYnrZ4Ms2NBo4oH5dQTYOsceoGFTIPlmCJgRv0R+ s4uzXOz3pXCl4KJPtMgReBObXqC/ju+Gu/brbsuDexhdK9Eo3NLUmlAxcPg1BVViKeVcIjh bjO8/XuAMPkegjfs4p8H9ey54mSrtIFLR0eN3N+By+bkUUMJuzawFdgH92uHSh2QaWb1yIZ nRs7r8IZInAoySDLFF1ZIEPddk2qWQKDYPdLKJSyrFdZ06BmZ5jfYvB55JTN769R8m3eGVB AT9eKVwW88mxy8H0m7WwLaFveZKY1sPCpddc4iXTPjzsPP/ZV8znhNgSY31/rGuKBTDvmIw d9Zi+dJo6NCAkeQMLScWh2IoKVaa51OkOXOHPpkbTtDtG69mrS/8wdW42FXtw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 8080205378424909828 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 04/17] selftests/nolibc: fix up kernel parameters support Date: Wed, 21 Jun 2023 20:57:41 +0800 Message-Id: <8e3e44492c986f691a778322e3eaf483e1734e90.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org kernel parameters allow pass two types of strings, one type is like 'noapic', another type is like 'panic=5', the first type is passed as arguments of the init program, the second type is passed as environment variables of the init program. when users pass kernel parameters like this: noapic NOLIBC_TEST=syscall our nolibc-test program will ignore the NOLIBC_TEST environment variable. Let's verify the first type (from arguments), if it is invalid, get the test setting from NOLIBC_TEST environment variable instead. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index d43116553288..ebec948ec808 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -951,6 +951,7 @@ int main(int argc, char **argv, char **envp) int ret = 0; int err; int idx; + int len, valid = 0; char *test; environ = envp; @@ -969,7 +970,19 @@ int main(int argc, char **argv, char **envp) * syscall:5-15[:.*],stdlib:8-10 */ test = argv[1]; - if (!test) + + /* verify the test setting from argv[1] */ + if (test) { + for (idx = 0; test_names[idx].name; idx++) { + len = strlen(test_names[idx].name); + if (strncmp(test, test_names[idx].name, len) == 0) { + valid = 1; + break; + } + } + } + + if (!valid) test = getenv("NOLIBC_TEST"); if (test) { From patchwork Wed Jun 21 12:58:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287249 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 11B68EB64D7 for ; Wed, 21 Jun 2023 12:59:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231671AbjFUM7m (ORCPT ); Wed, 21 Jun 2023 08:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37146 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231156AbjFUM7l (ORCPT ); Wed, 21 Jun 2023 08:59:41 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F326FAC; Wed, 21 Jun 2023 05:59:38 -0700 (PDT) X-QQ-mid: bizesmtp73t1687352369te3lj68z Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 20:59:28 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: xwvWJGGFd7Pp39HRCTQYRbgJy3bbvGHQ7WlZR48+2RLviBp/41ZiQ96oKRZr/ SilZzV0NenGnJQOAoEBB0FsmiBH7+SiFV9oelPczpDc5Rv6vON7sAY8uZqZwSd+t40quVga UlD5ndGNbGYHcYN65235Szzzn+W3uQJbRs+cM5+xVrvNtkhz8C96FkkUB4g30N+3iiIrT18 IQ6Ef+55Bvl/Wb4QA6h+fvhx0tjuE67lIQ90/3id1+HCtIisliMmEsk8Ug9bqvYo0ghVbrP B7xN3wcVi695bHsw5s8IapJuwl+GKCEXCNiaucghBROurHs1Z2GS5Y9guTFLTImqjkXOMkJ m22jHKU242jcgYr6CLmUguUae2HlOWvJPWimeF9ZtAi9dq0bot3TJaA2a7Ar64D7EGcWIyU X-QQ-GoodBg: 0 X-BIZMAIL-ID: 18004566144104333474 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 05/17] selftests/nolibc: stat_timestamps: remove procfs dependency Date: Wed, 21 Jun 2023 20:58:58 +0800 Message-Id: <5f80f3dae60f77c6b746578113e56c8fa6454143.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Since it is not really necessary to use /proc/self here, instead of adding a condition check, we use the always existing '/' path instead of /proc/self, this eventually let it work without procfs. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index ebec948ec808..2ef44176f7a9 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -520,7 +520,7 @@ static int test_stat_timestamps(void) if (sizeof(st.st_atim.tv_sec) != sizeof(st.st_atime)) return 1; - if (stat("/proc/self/", &st)) + if (stat("/", &st)) return 1; if (st.st_atim.tv_sec != st.st_atime || st.st_atim.tv_nsec > 1000000000) From patchwork Wed Jun 21 13:00:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287250 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E7C3EB64DC for ; Wed, 21 Jun 2023 13:00:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230076AbjFUNAx (ORCPT ); Wed, 21 Jun 2023 09:00:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37954 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230108AbjFUNAw (ORCPT ); Wed, 21 Jun 2023 09:00:52 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BAD8D1AC; Wed, 21 Jun 2023 06:00:50 -0700 (PDT) X-QQ-mid: bizesmtp65t1687352442tow0k82a Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:00:41 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: ILHsT53NKPiClSNJokhMYDBCmPxungrT3Z+CWJDyQNX3zu4qzLWhjv7TO/3Hn /N8B9E8eDY8EdrjCc7Jz6dJyueSDRep5azdaqdVyMFQYVxpSnf2LAKXuXjHzvidF8+mX6EB e5Ue0qtvGuZjh5LBUoEPh7E2IgsmHEEuFmESuk8i9WjkzTOkHBqjqPI+YYdG1iXXX9J40L+ 7DwACtW3ZjrR9UZ+Lf+GstYy7tDM9GvhRTboSxBRXLJ5mcOxhJbzSHpBT55cL9u+uGY82KR S82+3tyMLY2Hso2Z7zujZN91pH8jGSe3J1BPNU2GhGS3LLvtIB4/8s7CgHaHN5y8JADXQ5X EbMUU5cUoLYGmVPgqQEo6uoNF3USYfnsNQc05e0VbrrQQP2djYU8t5+QvZsOg== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 18188769316264056375 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 06/17] tools/nolibc: add rmdir() support Date: Wed, 21 Jun 2023 21:00:33 +0800 Message-Id: <12a992919bea416bbc073d869c90d03c5ad1c7ac.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org A reverse operation of mkdir is meaningful, add rmdir() here. This is required by nolibc-test to remove /proc if CONFIG_PROC_FS not enabled. Signed-off-by: Zhangjin Wu --- tools/include/nolibc/sys.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/tools/include/nolibc/sys.h b/tools/include/nolibc/sys.h index 856249a11890..8ddfd9185da6 100644 --- a/tools/include/nolibc/sys.h +++ b/tools/include/nolibc/sys.h @@ -716,6 +716,34 @@ int mkdir(const char *path, mode_t mode) return ret; } +/* + * int rmdir(const char *path); + */ + +static __attribute__((unused)) +int sys_rmdir(const char *path) +{ +#ifdef __NR_rmdir + return my_syscall1(__NR_rmdir, path); +#elif defined(__NR_unlinkat) + return my_syscall3(__NR_unlinkat, AT_FDCWD, path, AT_REMOVEDIR); +#else + return -ENOSYS; +#endif +} + +static __attribute__((unused)) +int rmdir(const char *path) +{ + int ret = sys_rmdir(path); + + if (ret < 0) { + SET_ERRNO(-ret); + ret = -1; + } + return ret; +} + /* * int mknod(const char *path, mode_t mode, dev_t dev); From patchwork Wed Jun 21 13:01:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287260 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 260DAEB64D7 for ; Wed, 21 Jun 2023 13:02:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230262AbjFUNCP (ORCPT ); Wed, 21 Jun 2023 09:02:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229675AbjFUNCO (ORCPT ); Wed, 21 Jun 2023 09:02:14 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E1F2E57; Wed, 21 Jun 2023 06:02:12 -0700 (PDT) X-QQ-mid: bizesmtp73t1687352523t66c15a0 Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:02:02 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: ILHsT53NKPibvyQvvp6lgPNrBJ9TrIOguRRJiNb+93n428pRzDPRiPmUoEoJO 7uoOFMcJa7vObbtOaqeAGyxKEVn82tPKKZ57jA/Pst6qecfTBHjqcB0JPpMMniwjOt3n3QS 6U6D1JpbsppF7CtxvnyBIflJDkvUmwhVYVdqGKW68VZgpqS/c34cHZDH7PIYvP8Mgz9U/Hp tvXxkP7BoJwW1HMiWZR83VblMBRfj9w/VPxPso5uaYlog4+EzMIcWk9hVYaLJIzmwkS3E28 t5EIJhPpKCcNP13QZYkYxgcbWLdavPdj93KRoXnUfKBxkVDeUoUDf3UwdG1x/bMjsGzUfYx dWZeNNORIEpl5ywH4on67PcH2u3kEDNQdflOz++xGrR7hzgzgjkW38vWIOE5A== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 14863239959184131679 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 07/17] selftests/nolibc: add a new rmdir() test case Date: Wed, 21 Jun 2023 21:01:45 +0800 Message-Id: <187bd4f7b4a611cedee3f2f8db04240a6aba3adb.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org A new rmdir_blah test case is added to remove a non-existing /blah, which expects failure with ENOENT errno. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 1 + 1 file changed, 1 insertion(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 2ef44176f7a9..9673c338d42e 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -612,6 +612,7 @@ int run_syscall(int min, int max) CASE_TEST(lseek_m1); EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break; CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; + CASE_TEST(rmdir_blah); EXPECT_SYSER(1, rmdir("/blah"), -1, ENOENT); break; CASE_TEST(open_tty); EXPECT_SYSNE(1, tmp = open("/dev/null", 0), -1); if (tmp != -1) close(tmp); break; CASE_TEST(open_blah); EXPECT_SYSER(1, tmp = open("/proc/self/blah", 0), -1, ENOENT); if (tmp != -1) close(tmp); break; CASE_TEST(poll_null); EXPECT_SYSZR(1, poll(NULL, 0, 0)); break; From patchwork Wed Jun 21 13:03:07 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287261 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5B2A1EB64D7 for ; Wed, 21 Jun 2023 13:03:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231962AbjFUNDj (ORCPT ); Wed, 21 Jun 2023 09:03:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230125AbjFUNDi (ORCPT ); Wed, 21 Jun 2023 09:03:38 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E91DA10D5; Wed, 21 Jun 2023 06:03:36 -0700 (PDT) X-QQ-mid: bizesmtp74t1687352607trbau5dm Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:03:25 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: ILHsT53NKPg/RSsp3DyOM0IrCTgvq+RSzeZGducQwjaxszgrcCMeeownE2tA4 +BVPLe7BzjU1z2iPHSeffjNHNylrfJxkTw57m2aYbxzx84fb52mICxq+p5vA7mqvHdVIvd1 USShcG2eswk8lOF/rzGVwlpHfpNt6LRyZKTHR8gEScymWSUOyv13eQiJfo7OcrTZyW3ZcXU dui8Sx9skGbMDWJX0xcHJDh+ull9vHRiROd+TOzWiKUYW3q8NzCavlpXzI1ewaHEygQ3+2u qOMjo+00peNcp0KDzjX2gbumc9P8O7C2GiBRLUxb5va5v9Im3Qwm6acbFFlXXw/mt6Tbv/p dyKpgBuGUatolsmvvt8loXCHCLD8b2iTJVO37PXUaiP9orbKeuX2KHUVNRf+A== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11819404568078845102 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 08/17] selftests/nolibc: fix up failures when there is no procfs Date: Wed, 21 Jun 2023 21:03:07 +0800 Message-Id: <6ba1291bf6a687dbd0d7dd20c65583a535157b17.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When there is no procfs support, the /proc is not mountable, but the /proc directory has been created in the prepare() stage and therefore, the checking of /proc in the run_syscall() stage will be always true and at last will fail all of the procfs dependent test cases. To solve this issue, one method is checking /proc/self instead of /proc, another one is removing the /proc directory completely (when there is really no procfs support), we apply the second method to avoid mislead the users. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 9673c338d42e..e5a218ef8a2d 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -928,8 +928,11 @@ int prepare(void) /* try to mount /proc if not mounted. Silently fail otherwise */ if (stat("/proc/.", &stat_buf) == 0 || mkdir("/proc", 0755) == 0) { - if (stat("/proc/self", &stat_buf) != 0) - mount("/proc", "/proc", "proc", 0, 0); + if (stat("/proc/self", &stat_buf) != 0) { + /* If not mountable, remove /proc completely to avoid misuse */ + if (mount("none", "/proc", "proc", 0, 0) != 0) + rmdir("/proc"); + } } return 0; From patchwork Wed Jun 21 13:04:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287262 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E6388EB64D7 for ; Wed, 21 Jun 2023 13:05:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232183AbjFUNFA (ORCPT ); Wed, 21 Jun 2023 09:05:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40234 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232167AbjFUNE4 (ORCPT ); Wed, 21 Jun 2023 09:04:56 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D89FE72; Wed, 21 Jun 2023 06:04:54 -0700 (PDT) X-QQ-mid: bizesmtp75t1687352685tczgblvp Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:04:44 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: 5q30pvLz2idzgSOyYQbpNYjI0MgF9s9bW85QWgt1mwrkwaEVbBHkq3sNw6XbB Tk+ffwDM2ZNSXpeVGrBPxLTlOoZuw7O6xm9hJZVGq7ssts7VoitYuxEd5BhNz0D21Tdi8Bl /gRzFmT2e6KsLmA7S0mPQiD0omrbNq+fR356wm3dPAwLRhXXKXrgrJc5ypiqoi36SYlGs+1 7HI7tFE2WQNIrcP5vWu82yzl7EuBU5/zHb/240UGRRRmFjCqhTwgcESQeEz64OHqZkZIubD 6YkTRjNNactYYsldZQIDDQfEudnbCHpaI0uDRFKKr4Sd3iau/3O4cOv4uQmsu3duG7yKwtm +rH3KchgTN3A6ESzsvrtQy4l+bOpd5W367G4bDwpmeiRjXHA4E6LbBz/Sk7Tw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 2912981568833336559 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 09/17] selftests/nolibc: rename proc variable to has_proc Date: Wed, 21 Jun 2023 21:04:31 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org More conditional variables will be added, let's rename them with more meaningful 'has_' or 'is_' prefix. This converts proc to has_proc to reflect whether or not proc/ is mounted. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index e5a218ef8a2d..929d43b95acc 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -544,15 +544,15 @@ int run_syscall(int min, int max) struct timezone tz; struct stat stat_buf; int euid0; - int proc; + int has_proc; int test; int tmp; int ret = 0; void *p1, *p2; int has_gettid = 1; - /* indicates whether or not /proc is mounted */ - proc = stat("/proc", &stat_buf) == 0; + /* indicates whether or not /proc is mounted */ + has_proc = stat("/proc", &stat_buf) == 0; /* this will be used to skip certain tests that can't be run unprivileged */ euid0 = geteuid() == 0; @@ -582,12 +582,12 @@ int run_syscall(int min, int max) CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); break; CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break; CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break; - CASE_TEST(chmod_net); EXPECT_SYSZR(proc, chmod("/proc/self/net", 0555)); break; - CASE_TEST(chmod_self); EXPECT_SYSER(proc, chmod("/proc/self", 0555), -1, EPERM); break; - CASE_TEST(chown_self); EXPECT_SYSER(proc, chown("/proc/self", 0, 0), -1, EPERM); break; + CASE_TEST(chmod_net); EXPECT_SYSZR(has_proc, chmod("/proc/self/net", 0555)); break; + CASE_TEST(chmod_self); EXPECT_SYSER(has_proc, chmod("/proc/self", 0555), -1, EPERM); break; + CASE_TEST(chown_self); EXPECT_SYSER(has_proc, chown("/proc/self", 0, 0), -1, EPERM); break; CASE_TEST(chroot_root); EXPECT_SYSZR(euid0, chroot("/")); break; CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; - CASE_TEST(chroot_exe); EXPECT_SYSER(proc, chroot("/proc/self/exe"), -1, ENOTDIR); break; + CASE_TEST(chroot_exe); EXPECT_SYSER(has_proc, chroot("/proc/self/exe"), -1, ENOTDIR); break; CASE_TEST(close_m1); EXPECT_SYSER(1, close(-1), -1, EBADF); break; CASE_TEST(close_dup); EXPECT_SYSZR(1, close(dup(0))); break; CASE_TEST(dup_0); tmp = dup(0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; @@ -608,7 +608,7 @@ int run_syscall(int min, int max) CASE_TEST(link_root1); EXPECT_SYSER(1, link("/", "/"), -1, EEXIST); break; CASE_TEST(link_blah); EXPECT_SYSER(1, link("/proc/self/blah", "/blah"), -1, ENOENT); break; CASE_TEST(link_dir); EXPECT_SYSER(euid0, link("/", "/blah"), -1, EPERM); break; - CASE_TEST(link_cross); EXPECT_SYSER(proc, link("/proc/self/net", "/blah"), -1, EXDEV); break; + CASE_TEST(link_cross); EXPECT_SYSER(has_proc, link("/proc/self/net", "/blah"), -1, EXDEV); break; CASE_TEST(lseek_m1); EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break; CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; From patchwork Wed Jun 21 13:05:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287271 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id B3D22EB64D7 for ; Wed, 21 Jun 2023 13:06:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231389AbjFUNGa (ORCPT ); Wed, 21 Jun 2023 09:06:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41488 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232131AbjFUNG3 (ORCPT ); Wed, 21 Jun 2023 09:06:29 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8811E57; Wed, 21 Jun 2023 06:06:27 -0700 (PDT) X-QQ-mid: bizesmtp65t1687352778tfzegumg Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:06:17 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: znfcQSa1hKYEx/R7zmeq5Pbdlh4EGiuKPzQGqg8HVlwQy22R4D7wTw/S/Dvan LTYrlLqMaz7n6ftUXrgKDFc4ydLGJIHgIWP7OY8waXj1STgmIEQa8Q68FoV+DUIUK2uauQT tYuvEhuiKk9CaD83sCePkBIF6eVPSzWgog2XYDYiEe/fgt/y6pBc0T+I6pYhjj3MmSyYhpn m+YYnS0XNr2dKcyJBED+awWBKaB4lLzk/sHfAD3rOTU/GRplDbyudJ8u7qOVxktmX0yKJ8o 87uWKnrvOWoK7e5kmB1OrReBvDWdUTd17zghAsNdomfEfotBIlquGI4wOGBA3Ih0b8jYSkq qORUx91Bgs7X1UtbDnLWYJqqaxgdgaLuH7f7KxztBXwzjrHWIL5TANcdEZ01g== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 15848095737819457792 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 10/17] selftests/nolibc: rename euid0 variable to is_root Date: Wed, 21 Jun 2023 21:05:49 +0800 Message-Id: <9547ea8320074269751eb4e54bcbd1395e66c5f5.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org More conditional variables will be added, let's rename them with more meaningful 'has_' or 'is_' prefix. euid0 is converted to is_root to indicate whether or not running as root. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 929d43b95acc..69f59a395746 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -543,7 +543,7 @@ int run_syscall(int min, int max) struct timeval tv; struct timezone tz; struct stat stat_buf; - int euid0; + int is_root; int has_proc; int test; int tmp; @@ -555,7 +555,7 @@ int run_syscall(int min, int max) has_proc = stat("/proc", &stat_buf) == 0; /* this will be used to skip certain tests that can't be run unprivileged */ - euid0 = geteuid() == 0; + is_root = geteuid() == 0; /* from 2.30, glibc provides gettid() */ #if defined(__GLIBC_MINOR__) && defined(__GLIBC__) @@ -585,7 +585,7 @@ int run_syscall(int min, int max) CASE_TEST(chmod_net); EXPECT_SYSZR(has_proc, chmod("/proc/self/net", 0555)); break; CASE_TEST(chmod_self); EXPECT_SYSER(has_proc, chmod("/proc/self", 0555), -1, EPERM); break; CASE_TEST(chown_self); EXPECT_SYSER(has_proc, chown("/proc/self", 0, 0), -1, EPERM); break; - CASE_TEST(chroot_root); EXPECT_SYSZR(euid0, chroot("/")); break; + CASE_TEST(chroot_root); EXPECT_SYSZR(is_root, chroot("/")); break; CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; CASE_TEST(chroot_exe); EXPECT_SYSER(has_proc, chroot("/proc/self/exe"), -1, ENOTDIR); break; CASE_TEST(close_m1); EXPECT_SYSER(1, close(-1), -1, EBADF); break; @@ -607,7 +607,7 @@ int run_syscall(int min, int max) CASE_TEST(ioctl_tiocinq); EXPECT_SYSZR(1, ioctl(0, TIOCINQ, &tmp)); break; CASE_TEST(link_root1); EXPECT_SYSER(1, link("/", "/"), -1, EEXIST); break; CASE_TEST(link_blah); EXPECT_SYSER(1, link("/proc/self/blah", "/blah"), -1, ENOENT); break; - CASE_TEST(link_dir); EXPECT_SYSER(euid0, link("/", "/blah"), -1, EPERM); break; + CASE_TEST(link_dir); EXPECT_SYSER(is_root, link("/", "/blah"), -1, EPERM); break; CASE_TEST(link_cross); EXPECT_SYSER(has_proc, link("/proc/self/net", "/blah"), -1, EXDEV); break; CASE_TEST(lseek_m1); EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break; CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; From patchwork Wed Jun 21 13:07:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287272 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7E513EB64D8 for ; Wed, 21 Jun 2023 13:08:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229986AbjFUNIc (ORCPT ); Wed, 21 Jun 2023 09:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43034 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229888AbjFUNIc (ORCPT ); Wed, 21 Jun 2023 09:08:32 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7A55EE57; Wed, 21 Jun 2023 06:08:30 -0700 (PDT) X-QQ-mid: bizesmtp74t1687352900ty2iclwn Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:08:19 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: vLOCICHxEeC+4y1LTp+BiY9j8PpHb9Dt4Sg+2rc6l1HNUYeypb+ihBW6wVf8X m3rnjZGltsHYRsXmYIEH4Duj+y+zjsGILWk6dG3qMZSHnTR2MZBPXV/uK+QrWjw6JKn3c6e 11uXzBQUetno3Oz5sOQOKjopaXxRuKdOJoJAZpcEi5jB2Ky11wn3+qmKmg0siaHFhdQLrwc kvsgbIYm9WAi2jb3JO6uKkXGfDl9rjnm6KDgT2rmWf15xPyiAeUoVbsdXb4Ct7CeLaD5gi9 ZgyBeXosAzEXjz0dFjGsZowL/nBGYCVTdCmp4yb9c5oINcMKSbIO7XXIdM2rgY3A1lrhQ3s uSk2mU613pLEaVHuJwCBogk6fZv8twRDHJv8MXuaYOPIKziv07HAzterzG6vA== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16746959025053847439 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 11/17] selftests/nolibc: prepare tmpfs and hugetlbfs Date: Wed, 21 Jun 2023 21:07:22 +0800 Message-Id: <604d011aab4b7ec3734685ce9f1a163771a2c9d4.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org Let's make the /tmp and /hugetlb directories and mount tmpfs and hugetlbfs respectively, they will be used to check the existing of tmpfs and hugetlbfs. We will also use tmpfs to let some test cases run without procfs. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 69f59a395746..8b587961e46a 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -935,6 +935,18 @@ int prepare(void) } } + /* try to mount /tmp if not mounted. Silently fail otherwise */ + if (stat("/tmp/.", &stat_buf) == 0 || mkdir("/tmp", 0755) == 0) { + if (mount("none", "/tmp", "tmpfs", 0, 0) != 0) + rmdir("/tmp"); + } + + /* try to mount /hugetlb if not mounted. Silently fail otherwise */ + if (stat("/hugetlb/.", &stat_buf) == 0 || mkdir("/hugetlb", 0755) == 0) { + if (mount("none", "/hugetlb", "hugetlbfs", 0, 0) != 0) + rmdir("/hugetlb"); + } + return 0; } From patchwork Wed Jun 21 13:09:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4DD3CEB64D7 for ; Wed, 21 Jun 2023 13:10:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229789AbjFUNKs (ORCPT ); Wed, 21 Jun 2023 09:10:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232138AbjFUNKr (ORCPT ); Wed, 21 Jun 2023 09:10:47 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8EAEDE57; Wed, 21 Jun 2023 06:10:40 -0700 (PDT) X-QQ-mid: bizesmtp63t1687353031t44bo3k3 Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:10:30 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: LE7C6P2vL8TmJPct4lgjZrwR2r9ifUIlt/ooF/BX9SyZKu13GRvTyl9GsqTST ltdyYZfK1hcYTSw2PtZ2cSsrutXtqrrH3wICe4sQVBMsvsqOyuB7dI4iFpVmLBze724lXru MrCOhErIOZL0iMGraRvDTOwXKXNRwTHqMxbFxAhdcOzLAE6urkKcn7OFGyK5Rr/QQ3Gi+O5 5uVcyN5zxpJheUWjJWBCHlUkqOfvA50eoBqaZecRtTDbFslq8WkE3qHczh1ezZ9Ioa7rK+/ zlHkifVvPodX7TZRCtuN2tansc3KrcXZ2e3GtT/Qg0KVnKjHg2RyqIOXmQVwFyud1pA3NG+ XiNPe3DkQHD4hboBT2grmvA4AP6LZE9fF+QyhfjfFvLMKAG6JLghvxFqZcoZw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 6653536713406143944 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 12/17] selftests/nolibc: rename chmod_net to chmod_good Date: Wed, 21 Jun 2023 21:09:24 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When CONFIG_NET is not enabled, there would be no /proc/self/net, let's use /tmp/blah in such case and rename chmod_net to chmod_good. This allows to test chmod_good with tmpfs even when procfs is not there. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 8b587961e46a..eca0070151b6 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -550,10 +550,22 @@ int run_syscall(int min, int max) int ret = 0; void *p1, *p2; int has_gettid = 1; + int has_tmpdir = 0; + char *tmpdir = NULL; /* indicates whether or not /proc is mounted */ has_proc = stat("/proc", &stat_buf) == 0; + /* indicates whether or not /tmp/blah is there */ + if (stat("/proc/self/net", &stat_buf) == 0) { + tmpdir = "/proc/self/net"; + has_tmpdir = 1; + } else if (stat("/tmp/.", &stat_buf) == 0) { + tmpdir = "/tmp/blah"; + if (mkdir(tmpdir, 0755) == 0) + has_tmpdir = 1; + } + /* this will be used to skip certain tests that can't be run unprivileged */ is_root = geteuid() == 0; @@ -582,7 +594,7 @@ int run_syscall(int min, int max) CASE_TEST(chdir_root); EXPECT_SYSZR(1, chdir("/")); break; CASE_TEST(chdir_dot); EXPECT_SYSZR(1, chdir(".")); break; CASE_TEST(chdir_blah); EXPECT_SYSER(1, chdir("/blah"), -1, ENOENT); break; - CASE_TEST(chmod_net); EXPECT_SYSZR(has_proc, chmod("/proc/self/net", 0555)); break; + CASE_TEST(chmod_good); EXPECT_SYSZR(has_tmpdir, chmod(tmpdir, 0555)); break; CASE_TEST(chmod_self); EXPECT_SYSER(has_proc, chmod("/proc/self", 0555), -1, EPERM); break; CASE_TEST(chown_self); EXPECT_SYSER(has_proc, chown("/proc/self", 0, 0), -1, EPERM); break; CASE_TEST(chroot_root); EXPECT_SYSZR(is_root, chroot("/")); break; From patchwork Wed Jun 21 13:11:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287277 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAC60EB64D7 for ; Wed, 21 Jun 2023 13:12:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230433AbjFUNM2 (ORCPT ); Wed, 21 Jun 2023 09:12:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45982 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230322AbjFUNM1 (ORCPT ); Wed, 21 Jun 2023 09:12:27 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 194EC10FE; Wed, 21 Jun 2023 06:12:25 -0700 (PDT) X-QQ-mid: bizesmtp79t1687353136ti9ply3z Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:12:15 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: ce7j0yCWOO300dz/qw3LjQJFpPjn/M2tGvj15EaaWyGZ7jQ34jzlkDsETFo63 5aHnpY9/cJbGfNm1ErXtDISSMacncgj0SJiF9d599VDJss/siAYVzQNvE8c/KBB5B9696OZ uQDkh8UvcJt3tI+Byg7n6q6jKpcJ+PceHzyEmmp8maSf+ay/khMLvh/Kg6fiuwP0eTmhMd+ 9eEMXT9K5JYtkdvpAYcwNiyn+JYP+fzCSxvYpKtgLwpsmFWPXOPCq9W2FhTO4wYJ6i22/kJ Oo3JK6UiZMbPjwpaQdS+H6I2UgA9QRdKN0GdXzuATVU0yKuDwEfavz21S8hF850ZV6LZwkg 9/sBrKaS2quXoMIQpBz2VrZyn/x19Ho2wkJNXEWjtRIiAqBkLURaIEstt7QVw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 5200152729963748297 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 13/17] selftests/nolibc: link_cross: support tmpfs Date: Wed, 21 Jun 2023 21:11:35 +0800 Message-Id: <575fd573110280bd8fcf39adc87edbcdd7288008.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When CONFIG_NET is not enabled, there would be no /proc/self/net, use /tmp/blah in such case. This allows to test link_cross with tmpfs even when procfs is not there. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index eca0070151b6..c900564219e8 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -620,7 +620,7 @@ int run_syscall(int min, int max) CASE_TEST(link_root1); EXPECT_SYSER(1, link("/", "/"), -1, EEXIST); break; CASE_TEST(link_blah); EXPECT_SYSER(1, link("/proc/self/blah", "/blah"), -1, ENOENT); break; CASE_TEST(link_dir); EXPECT_SYSER(is_root, link("/", "/blah"), -1, EPERM); break; - CASE_TEST(link_cross); EXPECT_SYSER(has_proc, link("/proc/self/net", "/blah"), -1, EXDEV); break; + CASE_TEST(link_cross); EXPECT_SYSER(has_tmpdir, link(tmpdir, "/blah"), -1, EXDEV); break; CASE_TEST(lseek_m1); EXPECT_SYSER(1, lseek(-1, 0, SEEK_SET), -1, EBADF); break; CASE_TEST(lseek_0); EXPECT_SYSER(1, lseek(0, 0, SEEK_SET), -1, ESPIPE); break; CASE_TEST(mkdir_root); EXPECT_SYSER(1, mkdir("/", 0755), -1, EEXIST); break; From patchwork Wed Jun 21 13:13:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287284 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6A156EB64D7 for ; Wed, 21 Jun 2023 13:16:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230122AbjFUNQg (ORCPT ); Wed, 21 Jun 2023 09:16:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48736 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230220AbjFUNQf (ORCPT ); Wed, 21 Jun 2023 09:16:35 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1C3051994; Wed, 21 Jun 2023 06:16:31 -0700 (PDT) X-QQ-mid: bizesmtp64t1687353381tybgz1rn Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:16:20 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: OtIeQkg1QQGRU6D6w1usUxm5UtoUxl8mHkGDNVB6rKGyKV5kvrl1yVbh7EPcT YR7tOU85DSoQ0Z0birjpP0DbP9SyBUaeu8YgRnIl+kX2dhPTaOp2uVTTw2qlzqvirWouum2 T/nPkr61O1qJUrgpGptq7at6lRZndbusEdtbR88mSPvh8BVHOJK+VMdej8eknGixsuHHUtD VDyUxNsgO8ENogsBF8U5GKwnwdqDC6mnohFDX0R45jdvxPDoWfP4iwcXMhAeVSmzIas7VrX o09AxNafPK/tp5+tnsbEfzimFzAFdWRkepC7gPLul6j6YJF5QrjvtwFklYs113Jdzr1N/dB AzokAAND7DPeo8iRsfs/OVUYJ9AnaDMAtGJhXrrESOxbGRtwS9jyBQCFiHewQ== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 1238278600326820981 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 14/17] selftests/nolibc: rename chroot_exe to chroot_file Date: Wed, 21 Jun 2023 21:13:20 +0800 Message-Id: <217a4460a1f4e5fa6fd0312340ea7b7b32ac225f.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When there is no procfs, let's use tmpfs and create a tmp file for chroot_exe test. Since chroot_exe is mainly testing the not directory case (ENOTDIR), so, rename it to chroot_file may be better. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index c900564219e8..19e4ef5ce578 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -547,11 +547,14 @@ int run_syscall(int min, int max) int has_proc; int test; int tmp; + int fd; int ret = 0; void *p1, *p2; int has_gettid = 1; int has_tmpdir = 0; + int has_tmpfile = 0; char *tmpdir = NULL; + char *tmpfile = NULL; /* indicates whether or not /proc is mounted */ has_proc = stat("/proc", &stat_buf) == 0; @@ -560,10 +563,20 @@ int run_syscall(int min, int max) if (stat("/proc/self/net", &stat_buf) == 0) { tmpdir = "/proc/self/net"; has_tmpdir = 1; + + tmpfile = "/proc/self/exe"; + has_tmpfile = 1; } else if (stat("/tmp/.", &stat_buf) == 0) { tmpdir = "/tmp/blah"; if (mkdir(tmpdir, 0755) == 0) has_tmpdir = 1; + + tmpfile = "/tmp/dummy"; + fd = open(tmpfile, O_CREAT); + if (fd != -1) { + has_tmpfile = 1; + close(fd); + } } /* this will be used to skip certain tests that can't be run unprivileged */ @@ -599,7 +612,7 @@ int run_syscall(int min, int max) CASE_TEST(chown_self); EXPECT_SYSER(has_proc, chown("/proc/self", 0, 0), -1, EPERM); break; CASE_TEST(chroot_root); EXPECT_SYSZR(is_root, chroot("/")); break; CASE_TEST(chroot_blah); EXPECT_SYSER(1, chroot("/proc/self/blah"), -1, ENOENT); break; - CASE_TEST(chroot_exe); EXPECT_SYSER(has_proc, chroot("/proc/self/exe"), -1, ENOTDIR); break; + CASE_TEST(chroot_file); EXPECT_SYSER(has_tmpfile, chroot(tmpfile), -1, ENOTDIR); break; CASE_TEST(close_m1); EXPECT_SYSER(1, close(-1), -1, EBADF); break; CASE_TEST(close_dup); EXPECT_SYSZR(1, close(dup(0))); break; CASE_TEST(dup_0); tmp = dup(0); EXPECT_SYSNE(1, tmp, -1); close(tmp); break; From patchwork Wed Jun 21 13:17:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287285 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF699EB64D7 for ; Wed, 21 Jun 2023 13:18:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbjFUNSD (ORCPT ); Wed, 21 Jun 2023 09:18:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231134AbjFUNSC (ORCPT ); Wed, 21 Jun 2023 09:18:02 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 16B7410C1; Wed, 21 Jun 2023 06:17:59 -0700 (PDT) X-QQ-mid: bizesmtp80t1687353470tqb4088x Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:17:48 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: zYANrwvFNEKo4kt9/IM+Z6O3uQ2N0g38rzgWEiNei8PpKKJkVpDPF6pN8KziJ rxg8gGEy4RPWbsvLnscapbN3BkZoCJD/Cs48De4zkxkNJTFGc8YgwxAmotNmeZ7eKpJugoI S8h+nzJTEeXi4Pf93/gi6Y7+xM+uBFltocdJPtDe9lcP7fBCWccTa1Y0z7cHJ7b/dhSCZeU M1STV7DoKWbyJfoSw/WYY/3K5DLEvIYn8MD81UevVeCx/H/RFvKKN/etT3CenPTMa7nwhk/ FlOZhtdQMmcgpOdJ2vqrBO9cJBzjioWyPAozqSvAnQWPB0hvGub0c+hMC3FGISl8hBUbFv3 UKj7bFko031nm2XzD4Bz/SSOZ5i+OwXB4Z/om86KdeJ/JQ8otvgP/tgstXyiw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 16675278491565794052 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 15/17] selftests/nolibc: vfprintf: silence memfd_create() warning Date: Wed, 21 Jun 2023 21:17:25 +0800 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org pass MFD_NOEXEC_SEAL flag to memfd_create() to silence this kernel warning inserted in the middle of the whole test result: memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1 The mixed test result looks this: Running test 'vfprintf' 0 emptymemfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=1 'init' "" = "" [OK] From v6.2, MFD_NOEXEC_SEAL must be passed for the non-executable memfd. Since MFD_NOEXEC_SEAL is a whole new flag, to avoid adding ugly #ifdef macros, let's use magic number here directly. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 19e4ef5ce578..8b1ce9911c5c 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -774,7 +774,17 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char FILE *memfile; va_list args; - fd = memfd_create("vfprintf", 0); + /* silence warning for kernel >= v6.2: + * + * "memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=" + * + * try MFD_NOEXEC_SEAL (0x0008U) flag for kernels >= v6.2, error means + * the kernel is too old and require old flags + */ + fd = memfd_create("vfprintf", 0x0008U); + if (fd == -1) + fd = memfd_create("vfprintf", 0); + if (fd == -1) { pad_spc(llen, 64, "[FAIL]\n"); return 1; From patchwork Wed Jun 21 13:18:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287286 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC66BEB64D7 for ; Wed, 21 Jun 2023 13:20:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230214AbjFUNUY (ORCPT ); Wed, 21 Jun 2023 09:20:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50832 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbjFUNUW (ORCPT ); Wed, 21 Jun 2023 09:20:22 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.154.54.12]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BBAE71994; Wed, 21 Jun 2023 06:20:18 -0700 (PDT) X-QQ-mid: bizesmtp78t1687353609twv2x5yr Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:20:07 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: LE7C6P2vL8QaLL7JPV1s2XMq3xaIhLPj7Fcy7ZasiRCLssjSUm9F+DbEx0p4g 0gPy5kD2TqEixqQZRzFnulPS2AtCpo9yKg2a53LxzOZDf426H2hSW7q9zCjMScUmvL+Gc96 wv3NqZLpC0DEYO20NTyPnywckAS2JgJxhTLDwxla2AKv3sOWObrXEz+Anb8OCHv0wvNFSH9 7zk5zv2vqy36LnH1ewGptn5XZsPVIbcdMlgh4vFMn9w7sIKp+1dkXXbUd75tS/Epfv1rx7x stmMDbj9VDf/181dzxopn0yu4htPyqic7qpxpWmxC4MeYq6/yhx946EDrciP0a1aNvmVlK6 YdFyPLWkPAsOpp9lPx9Jbw3ghg8k90cjaPuFvuU002KpY1c0D0= X-QQ-GoodBg: 0 X-BIZMAIL-ID: 11267784333303017325 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 16/17] selftests/nolibc: vfprintf: skip if neither tmpfs nor hugetlbfs Date: Wed, 21 Jun 2023 21:18:53 +0800 Message-Id: <55a01001987f2795a982755ed2ca8e27efe49249.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org As fs/Kconfig shows, MEMFD_CREATE depends on TMPFS or HUGETLBFS: config MEMFD_CREATE def_bool TMPFS || HUGETLBFS Let's skip vfprintf test if they are not there. The /tmp and /hugetlb directories have been created to mount tmpfs and hugetlbfs respectively, if they are not enabled in kernel configuration, neither /tmp nor /hugetlb will be created. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 8b1ce9911c5c..85fa64746cde 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -769,11 +769,22 @@ int run_stdlib(int min, int max) static int expect_vfprintf(int llen, size_t c, const char *expected, const char *fmt, ...) { + struct stat stat_buf; int ret, fd, w, r; + int tmpfs = 0, hugetlbfs = 0; char buf[100]; FILE *memfile; va_list args; + /* memfd_create depends on tmpfs or hugetlbfs */ + tmpfs = stat("/tmp/.", &stat_buf) == 0; + hugetlbfs = stat("/hugetlb/.", &stat_buf) == 0; + + if (!tmpfs && !hugetlbfs) { + pad_spc(llen, 64, "[SKIPPED]\n"); + return 0; + } + /* silence warning for kernel >= v6.2: * * "memfd_create() without MFD_EXEC nor MFD_NOEXEC_SEAL, pid=" From patchwork Wed Jun 21 13:21:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhangjin Wu X-Patchwork-Id: 13287291 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2FBEEB64D7 for ; Wed, 21 Jun 2023 13:21:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230191AbjFUNVi (ORCPT ); Wed, 21 Jun 2023 09:21:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232502AbjFUNVd (ORCPT ); Wed, 21 Jun 2023 09:21:33 -0400 Received: from bg4.exmail.qq.com (bg4.exmail.qq.com [43.155.65.254]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66201199E; Wed, 21 Jun 2023 06:21:31 -0700 (PDT) X-QQ-mid: bizesmtp72t1687353681to56kz9l Received: from linux-lab-host.localdomain ( [116.30.126.60]) by bizesmtp.qq.com (ESMTP) with id ; Wed, 21 Jun 2023 21:21:20 +0800 (CST) X-QQ-SSF: 01200000000000D0V000000A0000000 X-QQ-FEAT: ILHsT53NKPhKWXRwYjRELOGgofPHYFIsOJGyCC7jLdNWG8dBIPF0UkZrO+pho y+HMLxii13FZiV+9X21Fdhh+KT4s0/ce1scZiy+KV70BQAabF9976m1RObkMDf9DE2uvNIl 7XHKvmnhWhYEWRSY22upbytj1jvM7YY1f/eEIFiZv06k2uEdef6sjG/rQEiUIxNnhX8IX23 tZPj0A0wFA2oQlkyc1atl/ZovWPVo0MumPMBUo/TS16LAWLKHj9X822dIaIVbKGn2EbjN1r LjFr86P/0O5r14qlme75d5HLcG0+QPEozUCVJ5/WIqAjh9juIjY88s6wF2HrGRGNqjcqXTw GZPeoCs+JpS869kMcHRiLSIH3/MAlym9gwmAgrFeTJxkSBhD7EWUc1bn2hiaw== X-QQ-GoodBg: 0 X-BIZMAIL-ID: 3490715069797197203 From: Zhangjin Wu To: w@1wt.eu Cc: thomas@t-8ch.de, arnd@arndb.de, falcon@tinylab.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v1 17/17] selftests/nolibc: vfprintf: support tmpfs and hugetlbfs Date: Wed, 21 Jun 2023 21:21:12 +0800 Message-Id: <52c056a4d319070d2f36b59a8ef0b739ee84fdbc.1687344643.git.falcon@tinylab.org> X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 X-QQ-SENDSIZE: 520 Feedback-ID: bizesmtp:tinylab.org:qybglogicsvrsz:qybglogicsvrsz3a-3 Precedence: bulk List-ID: X-Mailing-List: linux-kselftest@vger.kernel.org When CONFIG_TMPFS not enabled, kernel will use the ramfs based tmpfs instead, but memfd_create doesn't work with such tmpfs, for this type of tmpfs, let's use it instead of memfd_create. At the same time, let's support hugetlbfs too if there is one. Signed-off-by: Zhangjin Wu --- tools/testing/selftests/nolibc/nolibc-test.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tools/testing/selftests/nolibc/nolibc-test.c b/tools/testing/selftests/nolibc/nolibc-test.c index 85fa64746cde..bff72365a158 100644 --- a/tools/testing/selftests/nolibc/nolibc-test.c +++ b/tools/testing/selftests/nolibc/nolibc-test.c @@ -796,6 +796,14 @@ static int expect_vfprintf(int llen, size_t c, const char *expected, const char if (fd == -1) fd = memfd_create("vfprintf", 0); + /* memfd_create not work with ramfs based tmpfs, try tmpfs and hugetlbfs in order instead */ + if (fd == -1) { + if (tmpfs) + fd = open("/tmp/vfprintf", O_CREAT | O_TRUNC | O_RDWR); + else if (hugetlbfs) + fd = open("/hugetlb/vfprintf", O_CREAT | O_TRUNC | O_RDWR); + } + if (fd == -1) { pad_spc(llen, 64, "[FAIL]\n"); return 1;