From mboxrd@z Thu Jan 1 00:00:00 1970 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 E1FB2C00144 for ; Fri, 29 Jul 2022 06:30:19 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7E9376B0071; Fri, 29 Jul 2022 02:30:19 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 798768E0001; Fri, 29 Jul 2022 02:30:19 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 65FE76B0073; Fri, 29 Jul 2022 02:30:19 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 53FD76B0071 for ; Fri, 29 Jul 2022 02:30:19 -0400 (EDT) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id E06BBABFCC for ; Fri, 29 Jul 2022 06:30:18 +0000 (UTC) X-FDA: 79739162916.29.D9EA28F Received: from mail-pj1-f44.google.com (mail-pj1-f44.google.com [209.85.216.44]) by imf04.hostedemail.com (Postfix) with ESMTP id 582FB400AD for ; Fri, 29 Jul 2022 06:30:18 +0000 (UTC) Received: by mail-pj1-f44.google.com with SMTP id e1so4003273pjl.1 for ; Thu, 28 Jul 2022 23:30:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ANvlGc2tcOj/ARFqImFQ7yhjDB+jN4jIvGcrZLLwcsQ=; b=aPKEHipM7DtWpVKB58Rt3XGgq25g2noB1E3l7y0ngybKMOHr/cl17p9ZQ4Y1yuuVWZ apvQwO/m1Dmk3w1elRpGKCyovPMyuVzKF3bxDk+ujXS87fkCAt8vjjHTimb2STrlMka6 Soo7XFEvstbvxJ5Swy+xQtPgRegNCUzSUzsNTYXTGbSqG33ZbtAtv06KMmfgxTSOk6Zi vzdwZ0C/MfVLva9v/5k7oSY/q0omGHrBzifiGMkPRV8/Ld+oOhqHPrmF2SADWY1I4cdW w/gu2nVBzyQPZv72y6IhxyWR7ok09QCeErDsEoIJ6REpD/SX4Xkx33xuwdZqHTNtVXFw Rp5A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ANvlGc2tcOj/ARFqImFQ7yhjDB+jN4jIvGcrZLLwcsQ=; b=2FbhbhM3MZIzFtKBTMAvNuuYL/PkF1Z0vVHjBUHnCqw2+73rPHDlgoAz7KHBI/JMaS tnBEIvKml4TivOPeZtPqZ2Jjaa8OZJV9++vBZV+/LHKmvZ5zUCLgXMWc2uXaP13lRqFG xpHgR+A5hPAtvdr7lL0V+IzjtMxNK36FoG7/+67ZTK9tTej2JiEshxF2HAAD+9xNW2n2 kv6x0xnDZVWJ8haGtjAZ3vyEM4Y06P9B4aR51ZRgjsKw5eJ3NzaS2XVhQxq2xEEjJO8+ H9BGLu3aVVR0j2f3TiY+KaaqirYMxiDF0z/tZVxqnR+XwmQAzELbTl1D8Ey4vq264eEW pmiA== X-Gm-Message-State: ACgBeo0VljO9jXMY02vJwbdy8afdbPNaM+ODtPZqIe+qfJ01Bopv2s4x 2t2QyIjzHJd1YCan1Gu9wxWHfqFoER2kYP6Q9bpPvg== X-Google-Smtp-Source: AA6agR4qr7ol8vLKsJJGTkBvZ/GDFcU29Uy3w2bTmKEQI6ogifuBJE6+Cx5lCQRBjHyPEKDkjU0vDVnYKILAqpCizoE= X-Received: by 2002:a17:903:32c6:b0:16d:328f:898d with SMTP id i6-20020a17090332c600b0016d328f898dmr2323434plr.143.1659076216913; Thu, 28 Jul 2022 23:30:16 -0700 (PDT) MIME-Version: 1.0 References: <6f71a4f3-8f8e-926b-883c-1df630cfc1a0@linuxfoundation.org> <20220729061504.744140-1-jeffxu@google.com> <20220729061504.744140-2-jeffxu@google.com> In-Reply-To: <20220729061504.744140-2-jeffxu@google.com> From: Jeff Xu Date: Thu, 28 Jul 2022 23:29:40 -0700 Message-ID: Subject: Re: [PATCH 4/4] selftests/memfd: add tests for MFD_NOEXEC To: skhan@linuxfoundation.org Cc: akpm@linux-foundation.org, dmitry.torokhov@gmail.com, dverkamp@chromium.org, hughd@google.com, jorgelo@chromium.org, keescook@chromium.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, mnissler@chromium.org Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1659076218; a=rsa-sha256; cv=none; b=ZDRFEYoeWfZdI435XagpZTuC5AiwrKntYCqNG6X2hJNtMPLoQ9D06F1KzzLISLEclCs79M KALYARuS8cCfAdefHpOJuAsnLgSYEll0YvSXABGRvXbkYw1GkM4xH+49fd3f9cY6zNt71t Zk+n8J1RPn2mj9uRBAYayVNsJb/jcv0= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aPKEHipM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of jeffxu@google.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=jeffxu@google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1659076218; 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-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=ANvlGc2tcOj/ARFqImFQ7yhjDB+jN4jIvGcrZLLwcsQ=; b=T5VeqCj5y2H1hMKQlZiFyN2qeNmB/qULW+ty3yGo3TSuLmwxX+w8FXLMa7GeKLvq9K4Xjg i2BuRDAyUTxYhBYXicbavNO9/CGS8meS46bkyQRW6w64hBvL9SYIBZqvAweYFtKuusCN+Z AmLxo1EW062r5SEyF7rsLYYVeW3zFhc= X-Rspamd-Queue-Id: 582FB400AD X-Rspam-User: Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=aPKEHipM; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf04.hostedemail.com: domain of jeffxu@google.com designates 209.85.216.44 as permitted sender) smtp.mailfrom=jeffxu@google.com X-Rspamd-Server: rspam09 X-Stat-Signature: 7n5jothg88dc6yww3eic7nriaheekttp X-HE-Tag: 1659076218-794312 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: > > + /* Create with NOEXEC and ALLOW_SEALING */ > > + fd = mfd_assert_new("kern_memfd_noexec", > > + mfd_def_size, > > + MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_NOEXEC); > Don't we need to check fd here? mfd_assert_new will abort() if fd is not valid, so we don't check fd here. Jeff On Thu, Jul 28, 2022 at 11:15 PM Jeff Xu wrote: > > From: Daniel Verkamp > > Tests that ensure MFD_NOEXEC memfds have the appropriate mode bits and > cannot be chmod-ed into being executable. > > Co-developed-by: Jeff Xu > Signed-off-by: Jeff Xu > Signed-off-by: Daniel Verkamp > --- > tools/testing/selftests/memfd/memfd_test.c | 34 ++++++++++++++++++++++ > 1 file changed, 34 insertions(+) > > diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c > index 1d7e7b36bbdd..4906f778564e 100644 > --- a/tools/testing/selftests/memfd/memfd_test.c > +++ b/tools/testing/selftests/memfd/memfd_test.c > @@ -36,6 +36,10 @@ > #define MAX_PATH 256 > #endif > > +#ifndef MFD_NOEXEC > +#define MFD_NOEXEC 0x0008U > +#endif > + > /* > * Default is not to test hugetlbfs > */ > @@ -1006,6 +1010,35 @@ static void test_seal_exec(void) > close(fd); > } > > +/* > + * Test memfd_create with MFD_NOEXEC flag > + * Test that MFD_NOEXEC applies F_SEAL_EXEC and prevents change of exec bits > + */ > +static void test_noexec(void) > +{ > + int fd; > + > + printf("%s NOEXEC\n", memfd_str); > + > + /* Create with NOEXEC and ALLOW_SEALING */ > + fd = mfd_assert_new("kern_memfd_noexec", > + mfd_def_size, > + MFD_CLOEXEC | MFD_ALLOW_SEALING | MFD_NOEXEC); > + mfd_assert_mode(fd, 0666); > + mfd_assert_has_seals(fd, F_SEAL_EXEC); > + mfd_fail_chmod(fd, 0777); > + close(fd); > + > + /* Create with NOEXEC but without ALLOW_SEALING */ > + fd = mfd_assert_new("kern_memfd_noexec", > + mfd_def_size, > + MFD_CLOEXEC | MFD_NOEXEC); > + mfd_assert_mode(fd, 0666); > + mfd_assert_has_seals(fd, F_SEAL_EXEC | F_SEAL_SEAL); > + mfd_fail_chmod(fd, 0777); > + close(fd); > +} > + > /* > * Test sharing via dup() > * Test that seals are shared between dupped FDs and they're all equal. > @@ -1179,6 +1212,7 @@ int main(int argc, char **argv) > > test_create(); > test_basic(); > + test_noexec(); > > test_seal_write(); > test_seal_future_write(); > -- > 2.37.1.455.g008518b4e5-goog >