From patchwork Fri Apr 14 02:28:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jeff Xu X-Patchwork-Id: 83194 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp85061vqo; Thu, 13 Apr 2023 19:43:22 -0700 (PDT) X-Google-Smtp-Source: AKy350ZvcAnDkK9QFNsmBtcsQXKJDaLXkiMcNneWn2tpT/BRIsurkby6bXQ+O03imm4nqGptfq86 X-Received: by 2002:a05:6a00:2ea7:b0:63b:158d:ca4 with SMTP id fd39-20020a056a002ea700b0063b158d0ca4mr6357592pfb.5.1681440201727; Thu, 13 Apr 2023 19:43:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1681440201; cv=none; d=google.com; s=arc-20160816; b=W1YJjFVYLw9FniUYySlM+JLgGq8CZWkJEx1ybueztTWMUa/QzUCS0hSt6CDkapv/Qk 4G2NOzgHpsaCm8rYp8uVLjn5AzQZkGmI1GOOwTORMBqq8EUGwBMUS83Ugbg0obzIEoSB EWiKKMxjCBPLOgGAW0f/AZgSbMDMHNV9tpk+AHLzkbcx91iuHHDdCdwoZI57Y3ebFNT5 2xE1ZqRz+iufGgjVeYqBOhza8S035n7GG8f9iPnlaNOuGfQbRFBfNfSaGBlwTWl51hW2 yb8iWjtOgVh8X1L6ZRPrbIkhcW7VpJshewHmxsY1WnnIOOk04SkqZc8V1eDG/0txyKlC h2yg== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 1-20020a630201000000b00513973864fcsi3497819pgc.782.2023.04.13.19.43.07; Thu, 13 Apr 2023 19:43:21 -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 S229876AbjDNC2R (ORCPT + 99 others); Thu, 13 Apr 2023 22:28:17 -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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763117840670098557?= X-GMAIL-MSGID: =?utf-8?q?1763117840670098557?= 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 Tested-by: Yujie Liu --- 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); } /*