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: 13210869 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 kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1DE3CC77B6E for ; Fri, 14 Apr 2023 02:28:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D643900002; Thu, 13 Apr 2023 22:28:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 386FA6B0075; Thu, 13 Apr 2023 22:28:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 24F38900002; Thu, 13 Apr 2023 22:28:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 137A56B0072 for ; Thu, 13 Apr 2023 22:28:08 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D1C2EAB69F for ; Fri, 14 Apr 2023 02:28:07 +0000 (UTC) X-FDA: 80678411814.19.2473E4B Received: from mail-pl1-f169.google.com (mail-pl1-f169.google.com [209.85.214.169]) by imf13.hostedemail.com (Postfix) with ESMTP id 0FCFC20007 for ; Fri, 14 Apr 2023 02:28:05 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LNh11wT4; spf=pass (imf13.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.214.169 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1681439286; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=wV0ORfeXv57jdNTZ94hzyydSs04V0lY4z8KcxEzlrGU=; b=cNCGiXTAmFbD2tP8MG2zSZ+89ToJqAc8pPFWHzFPkK9Qs1APHXPwf7RCKsCqiL2v6qM91L IL5AwIlY9/aOdx/+C9tB2W4Ih9q5cupQ7JR0lbi7djMaT6gmuockxTx3gw8NW6qQhRw49+ TfwPhy8wNvGs3d4uvlfrePVEyqdRpQY= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=pass header.d=chromium.org header.s=google header.b=LNh11wT4; spf=pass (imf13.hostedemail.com: domain of jeffxu@chromium.org designates 209.85.214.169 as permitted sender) smtp.mailfrom=jeffxu@chromium.org; dmarc=pass (policy=none) header.from=chromium.org ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1681439286; a=rsa-sha256; cv=none; b=vibyxnoUPQft18SHPrEqMjdhC27E6LEIM6nBm0P/TgPOIQ6vOETq8PZRp+UBDIOq3oDnGP aNiJwh8iOOniOPKTl66m+Aikxnh5NxK3R53OcJUd/YEC3B+lIFOKtPCH9/gJ3tXqNrD9YW eBqGs/mBG+A6937LKi1EoZsHT+PU3xQ= Received: by mail-pl1-f169.google.com with SMTP id kc3so43832plb.6 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=FZ3uA2VANl8xMiQU1I9MhoiFaD1q1TT9Qk6cCxfVHiBVIj/SR4bVNyR5X88nb81fTK QVrJ7wE7WzOJ7OkywjJJOrqmO50hSJPHoNtl8NTCgLpKSzAZmOiQa8tEe0qq8jvj9exI KnsHC2deO+QGq6T3xKqbK8bJ9ZHYvW/jRI9RweeBxZ2/llWWjR6pmWldOPXyXfilpnmK 9u51i8QuS2GukONp92vCOP6vp11JQF4nNVgFEGCz+iMltJ9J45Atm0xmlrsaVS30Eq6i wEkgGKwYeY6TiIgTmjEsT8bThJOI9BTx+FvzX7A0REEOujO0R4aHXWTD10B7SfKXgyUK bD1g== X-Gm-Message-State: AAQBX9deE9YyvxMgq/UQiCvrsZg9fLPWctA8h3t3osyk9M8aQJ/5mP3L VA3fFe9b56qxp4bpEzfQDZmuog== X-Google-Smtp-Source: AKy350YAYoawfrxXQq9o1RU60KWyzyS6aXgZpnvHFLuSmoSnnEGsr+nci58MA60iAQlgbFwQQ9A5RA== 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 0FCFC20007 X-Stat-Signature: s674xupw9rfn1dd8awrup6cj17iy74xz X-HE-Tag: 1681439285-418265 X-HE-Meta: U2FsdGVkX19kV+WmTLFd03aY6mMdr4belGrwCOPqpkAJC/QZHLavR9NIq+bkB9kYQDMBtek745Lv4xvDNuPBfc2yBDMbXjcQqo60hDbFtLB/xsk5aOTbDr4y+Pcru7dXeMgUKq60iu02e6h2x3AbqaTFZjBbFM6nH9+ef6jOCxyDWZSZ6bAppUtWzSpAnndUXzSF1XS4X3MyzS2sB5UY8jqJKZFxd9SjHqqy4hS/bib8YpmvapzZZJpV1RIoZ0H4r78sMn+KEnBNejXvA8faFHqP8XPL5+JLfLyNjHdV+fizkjyL3fsBkucG+NJly38Yob/Fzphaig9bVV5P2M5q6TQ/RJ43Jy4Jgt+ThDMb5dm7dtdwGbrIv3LRxdb6pxwYTNzkyjJd799uSFl4Ah3TD2tNMrWqnQASPVKNvG4M/Ry5z4r/+JqiQaiyOVtTZOcu5b1HskoGxAb8aoFu7dYk80U6bGgJBuKxkq/vxCrb3/dr6OUoZxB6zP+pmUgnlh/y16HCEfjVu35ixF4FYluvVP0G6J6vGp/nvsbUt+Hjlf2BTwPK8jBe2VHlpKLpUZaHgXXS5GdjfMdPzajZW1afLLotLR6S2ClKmo1mZm3+lHQEIOvVdjaQ9TV8INmq3rV0JxbctL6s9q/QSEwe23cF1vPtxkrFNgFz7Lcg5NPFD9UF0RtPhX1GOliKj0lRNwkAVA+O5oUSwH5vyXX1CH/E0T1ckJkzPTVhB6cjYxvSPlp6U+s5AXghuYU/ZUQN2hwk+fwIclhsQ5sJ+a7PxWHiqcArk/f3vCXcZjSqXZaorylgFgY8sGpDe09L7pm/JifwUZd0fYd6O4vNG6M0lBOOYtE+PPRvR0fxbhW+P+IHAwahzDHSDW9ggm7c49uJhU08pjUj/HXIRDW3gJ1oZpvw+HvYOrA5ZL9cfGfhliXfoqB4Fjpb1V7HHBglYAgppK77CR/UIBc/hzSY6Ca2Qzj PaAGe/SH 2I/ok7qjFfkR+sTXUtqAJUDRRpIxGRgJ4gsXqNsh2HkJsK3CgczlHyK7XnAP5DFB04jauvWeTGcobMCPutaN/xYOkSQU0CTBP6XWJoPIgv/hBI7A5R/Fl5wrrH2cTuTueK7HPi4z0yOfMPung3jKQsUJMqoTAM9wpFaRzqfHs1BCqRTLj0NK+Cht28C9uHGqi6XWVwEjtFKKqOUGD6r+aBehoq17jGaU97wAnDMjkhTzq2EWPGcPfTrxUqu1PPwJbLAHyVDIC8gbdlAQXXv7ulYyxPEGtCU2Rfg2pIG3c+tqCXtL7+oH9QnNR9hfbETXKRJlOye05EMc3iKMN05UQceoZrwVZZFWyXx5+PIyoum9XanAHQcVGqA/qoqAwTMQ0XrZyJWc89Ji16ZWZnQZJm3uh2L3Y/vqRfXQjBoV+NZtsM6c7cViNiVc2lwZfyhHjJpi0Wlbez27n4Fb3RJFggLfK1o0Nhq6ip95oc2Zlak+CRKpSsJ6DZfyFug== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: 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); } /*