Received: by 2002:a05:6358:11c7:b0:104:8066:f915 with SMTP id i7csp3384rwl; Thu, 13 Apr 2023 19:37:24 -0700 (PDT) X-Google-Smtp-Source: AKy350aTaP++RS0ri1C+Fw9OY+Lz8FSR/xcNdtd2aWTd8RjJNeBj8LvJ7sEZ/4MAF29iDRwpEzuc X-Received: by 2002:a17:90a:3fc8:b0:23d:15d8:1bc3 with SMTP id u8-20020a17090a3fc800b0023d15d81bc3mr4045787pjm.39.1681439844505; Thu, 13 Apr 2023 19:37:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681439844; cv=none; d=google.com; s=arc-20160816; b=tQP5gFfwhbo3ntfd7tiducuhMIqz38l8TCZ1KWEi7iUy0H32lXc6vP2Dtk1lCIMpy6 XdMg9d3TxSCQJGnGnc/+OmGg9Jgf/YMW9uvVaAB3/IgLYSWvRyliFTYQ9nQ9e/nZNgi6 e5vOlxRJxjihr/ua4htdYHcADpEkwM1qzx9Yzy66s1VfdYN2OZRwZfdxbrqREgr2uzvi AsTD431yx7GeLyCoP4k1H2VGakBtyXg0H9lYEsUepmNH+sxXSPi3Gr2Hknbxdjm3Tq6L BVtVzJDJaRyQ9x2a6uwMlnXeMpQRnxSs1rKS28YVz9gKI1RLX9WNnDzGYE6I2sRUfJgZ I1tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=wV0ORfeXv57jdNTZ94hzyydSs04V0lY4z8KcxEzlrGU=; b=xzs+8PuR5uucgO5K9KmrScx+47hk/nW5G/97NNKNn+FYhhdiFT6S1GmoDo7YMJ/1kI Uc0EgdhD2YwoMQoszNHMZriNOY3JglAxFMI2apuz0OiuDr5++v6g4aqp70vroym9Cf+6 sniChBbd8ss3ez9fAflFxX6QOD6eEcc9iuQ1OPYgHBbx5IpJY96YEjrdqB+HpQZnY6xM t9C68L2w88wVu+AIGcHZww7RFA/8Tn9quvONjgyD59NUTBfJryuvWb1u/4l/v9//FuCs LbxaFRNmsronjk2t3rJw7oy920sbDTn+/MPLYThBEfcV07d/NY4hSAWRRK+2OwUxj26s YWJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LNh11wT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t24-20020a6564d8000000b0051b313bdebesi2550251pgv.1.2023.04.13.19.37.10; Thu, 13 Apr 2023 19:37:24 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=LNh11wT4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229598AbjDNC2Q (ORCPT + 99 others); Thu, 13 Apr 2023 22:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53858 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229845AbjDNC2P (ORCPT ); Thu, 13 Apr 2023 22:28:15 -0400 Received: from mail-pl1-x62d.google.com (mail-pl1-x62d.google.com [IPv6:2607:f8b0:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CF341525A for ; Thu, 13 Apr 2023 19:28:05 -0700 (PDT) Received: by mail-pl1-x62d.google.com with SMTP id q2so21915559pll.7 for ; Thu, 13 Apr 2023 19:28:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1681439285; x=1684031285; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=wV0ORfeXv57jdNTZ94hzyydSs04V0lY4z8KcxEzlrGU=; b=LNh11wT4EHIzhimZwEgXV9BDMf7nHy+oBl6lf8qtqMoNiEz6OoQG9N1T2bGlwiCoe7 izBspUiGU1sLSEskgQCVo7NLelLl2Ec5Fsqg+nqpkAkfvZRlAPfALKIxZsDh5hB5bByW Jd+YhfV2XTBYasK3IDCGRuYOotcdq44GCS8nw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681439285; x=1684031285; 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=wV0ORfeXv57jdNTZ94hzyydSs04V0lY4z8KcxEzlrGU=; b=WyaIURg7NW5kl5iScfkSNQMJW0Rgf/jqIoNC7X4ZuSRNpe5sHmRH6SUSZr6J0NbQdW /6TS78eEA+uI3c+RWdvQI6YZx5FPoDc7ewnk+V7F1J3HFX5c/8qAfW5U9KK+X4W3vePZ /D7Ih1y/Cm6EXSyvjyLiLdTLLXSmMo+2GbnnOvcx/N3FX9reLWtpOSlYRNdxCpmzJXLy ytsXGbzCKnRh63F8wvF1GF71TuWJeKC5XIXpzO2cFUq/fXble2tX6Qlm7xtMIeVeGduW RkF+SYhU80//hUEZVZ+Ibx3K7UnzPATlPvHcUPjDfvfV+fbENnz+y3TXRDWU3ei7CTm1 otaQ== X-Gm-Message-State: AAQBX9cYccXfUY4AATpiN/+cGtEfvqvTrF4NdJ97TkRWZipUiQY/OyVF F6mnYCZjV8QXSooRPLASlqpkcA== X-Received: by 2002:a17:90a:7c0f:b0:23f:83de:7e4a with SMTP id v15-20020a17090a7c0f00b0023f83de7e4amr4082251pjf.7.1681439284753; Thu, 13 Apr 2023 19:28:04 -0700 (PDT) Received: from localhost (183.43.230.35.bc.googleusercontent.com. [35.230.43.183]) by smtp.gmail.com with UTF8SMTPSA id m2-20020a17090aab0200b0024677263e36sm1972982pjq.43.2023.04.13.19.28.04 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 13 Apr 2023 19:28:04 -0700 (PDT) From: jeffxu@chromium.org To: skhan@linuxfoundation.org, keescook@chromium.org Cc: akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jeffxu@google.com, jorgelo@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, jannh@google.com, linux-hardening@vger.kernel.org, linux-security-module@vger.kernel.org, kernel test robot Subject: [PATCH] selftests/memfd: fix test_sysctl Date: Fri, 14 Apr 2023 02:28:01 +0000 Message-ID: <20230414022801.2545257-1-jeffxu@google.com> X-Mailer: git-send-email 2.40.0.634.g4ca3ef3211-goog MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jeff Xu sysctl memfd_noexec is pid-namespaced, non-reservable, and inherent to the child process. Moving the inherence test from init ns to child ns, so init ns can keep the default value. Signed-off-by: Jeff Xu Reported-by: kernel test robot Link: https://lore.kernel.org/oe-lkp/202303312259.441e35db-yujie.liu@intel.com --- tools/testing/selftests/memfd/memfd_test.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c index ae71f15f790d..dba0e8ba002f 100644 --- a/tools/testing/selftests/memfd/memfd_test.c +++ b/tools/testing/selftests/memfd/memfd_test.c @@ -43,6 +43,9 @@ */ static size_t mfd_def_size = MFD_DEF_SIZE; static const char *memfd_str = MEMFD_STR; +static pid_t spawn_newpid_thread(unsigned int flags, int (*fn)(void *)); +static int newpid_thread_fn2(void *arg); +static void join_newpid_thread(pid_t pid); static ssize_t fd2name(int fd, char *buf, size_t bufsize) { @@ -1111,6 +1114,7 @@ static void test_noexec_seal(void) static void test_sysctl_child(void) { int fd; + int pid; printf("%s sysctl 0\n", memfd_str); sysctl_assert_write("0"); @@ -1129,6 +1133,10 @@ static void test_sysctl_child(void) mfd_def_size, MFD_CLOEXEC | MFD_ALLOW_SEALING); + printf("%s child ns\n", memfd_str); + pid = spawn_newpid_thread(CLONE_NEWPID, newpid_thread_fn2); + join_newpid_thread(pid); + mfd_assert_mode(fd, 0666); mfd_assert_has_seals(fd, F_SEAL_EXEC); mfd_fail_chmod(fd, 0777); @@ -1206,12 +1214,6 @@ static void test_sysctl(void) int pid = spawn_newpid_thread(CLONE_NEWPID, newpid_thread_fn); join_newpid_thread(pid); - - printf("%s child ns\n", memfd_str); - sysctl_assert_write("1"); - - pid = spawn_newpid_thread(CLONE_NEWPID, newpid_thread_fn2); - join_newpid_thread(pid); } /* -- 2.40.0.577.gac1e443424-goog