From patchwork Tue Oct 9 22:20:42 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10633327 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E846F3CF1 for ; Tue, 9 Oct 2018 22:21:10 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D77F929B58 for ; Tue, 9 Oct 2018 22:21:10 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5BB329B74; Tue, 9 Oct 2018 22:21:10 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 61A5B29B58 for ; Tue, 9 Oct 2018 22:21:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 19FB96B026C; Tue, 9 Oct 2018 18:21:08 -0400 (EDT) Delivered-To: linux-mm-outgoing@kvack.org Received: by kanga.kvack.org (Postfix, from userid 40) id 0FCA66B026E; Tue, 9 Oct 2018 18:21:08 -0400 (EDT) X-Original-To: int-list-linux-mm@kvack.org X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB7D56B026F; Tue, 9 Oct 2018 18:21:07 -0400 (EDT) X-Original-To: linux-mm@kvack.org X-Delivered-To: linux-mm@kvack.org Received: from mail-pf1-f198.google.com (mail-pf1-f198.google.com [209.85.210.198]) by kanga.kvack.org (Postfix) with ESMTP id AB1816B026C for ; Tue, 9 Oct 2018 18:21:07 -0400 (EDT) Received: by mail-pf1-f198.google.com with SMTP id r81-v6so3031826pfk.11 for ; Tue, 09 Oct 2018 15:21:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:dkim-signature:from:to:cc:subject:date :message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=mSCp3IjXtO6KaCWkQ2EwPMcxQAzHpqecCP58DFd+0XQ=; b=uReKB4mLq6W2DNT9R98bf0JhDKMhz1+7ExwKP/Zll70f+2hIsMvmK3foqWMjCVaL4F ASuGOzQePIz+E8/38HP1kEZH0e6dZWG6P+6/bEMg9AQIEp0IraLaGIEvIM+/s8k1Hx04 S31FaQnpgTyttJ9yNx8CVaAvto6EiCmHh0uBSRY0197VacHCAFp0+Klk/iCMb8cxYR/k caok6Bo0Vlebo1WNc5iTVDTcGCXzPP8bONI0WY9oA4wNeKC/79DX58WyhPNnBPP0V49K SaEpkyGa9L6+BercvOhOltqz32MThA9yR7MttBHunp/8p/gWtw+j/elBdiP3IUzrHEES V35Q== X-Gm-Message-State: ABuFfoiOl7SS9uFrmYTY7rZI0kZ5JslTRVlp+ahcrf0ZgsPaAcLbQq22 +Ln5yil9lsjkn3mNruGZFIwPTS66Ke1wXSjFRZKRWww73uPc74QZxooBGs17cyo0ZdT4XSXPla6 hURVAUPThM4WLljxUZPyP8n8/Uv+8RVMjNHrV5nCPtJSyXm510DLKlaTVpr5nq+4ROooTVWjYEd a1nMsac07nmAM7YaLeXLguuuwE7PZ8Oo/1ob3Tqpn2bQueMs360RpqyyqQbM22U/DpA6tL0eCGH nLu/t0ESSarbCj1mpq8rjmBtUwrf38VGzjEI8ygitzsROt+jgbol34xy84fpGrOSKneZ+KZJNg7 Z8oPtTxcXaaMiLPv1Gyi5ed4YLsctvHMfQ2dHVE3EkCzPZFAxEevlEDeQK0xvI/20ZQiQdKpUQU W X-Received: by 2002:a17:902:7d86:: with SMTP id a6-v6mr30512594plm.314.1539123667374; Tue, 09 Oct 2018 15:21:07 -0700 (PDT) X-Received: by 2002:a17:902:7d86:: with SMTP id a6-v6mr30512566plm.314.1539123666547; Tue, 09 Oct 2018 15:21:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1539123666; cv=none; d=google.com; s=arc-20160816; b=ZAKa407xmMHvd5JDZ2PlSgtIPoLxmm9puosg9qV8fxb5mWagrBA+I45pv/HJV9no5Y r9cxu9O1LfBN1U8BySogaKzAfGDys/2G33RqTZHFSPAOHut2Nc5XfQzSXctxOu84KGTR iNox4I9wvExwpGY+WEn0+UQiWJjmcNdLpFeCDTYI/6kJbuPdAwlMR+AMRbIyiK6Py/Ew 6E0n6pFNTx91bNG+njPSkUOsx+ReyNSo+qbYaAyQah8QrAXKe6+NJWpwyX4DFky/Lazh QHg72NEYOWT5TOOUq3c+5LWSVvUc/cXEVGasyzPUiEtt9WUjbSa4N0Kc7n1H8IxHY6Cx bNnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:dkim-signature; bh=mSCp3IjXtO6KaCWkQ2EwPMcxQAzHpqecCP58DFd+0XQ=; b=Y5akGahISjwgc80pZgkOBZDNeUMFVGIX+NpgqY30TRsVr8nKSTItPoYZInNsHGfJDU g2oFJq61UEe4L3nzz8twX6eJAXwXQmY50adojTW5x6e2T3QO1ly7A2bPB0tLogxRC08t ay8C7Z5ELbQssUHUgMguvFs8CfnlZI7FpmBCA7V+lTI5QML/H8NlB1wxFAguLkclDWxQ HjTC5IdFnIIIwI7cV/DJlFY4u+KE5sAUNzVqHtPKZqxfrN1+uyghtcH3A5MGaJxFaxcA gHCzXYQgs0Ri7PAu1qwIACKNXbyukt245kjF1Cxlm8zyo3kAXlcy5/JtyXJ9tCAz/Qrt q9/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Vdy6DvZH; spf=pass (google.com: domain of joel@joelfernandes.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=joel@joelfernandes.org Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 93-v6sor13357854plf.23.2018.10.09.15.21.06 for (Google Transport Security); Tue, 09 Oct 2018 15:21:06 -0700 (PDT) Received-SPF: pass (google.com: domain of joel@joelfernandes.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@joelfernandes.org header.s=google header.b=Vdy6DvZH; spf=pass (google.com: domain of joel@joelfernandes.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=joel@joelfernandes.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mSCp3IjXtO6KaCWkQ2EwPMcxQAzHpqecCP58DFd+0XQ=; b=Vdy6DvZH2nbFshP8qYD/ks+zBdEI8OFH1w8BCeB0V47R1wL2lOsyrVi+HOJ66+onyF oJCPdDRjWMRXav9ZvB6GF/UUM9BeNCA+kPT3sDnJiJY22C0+5n++fxUqp7iB2g8CvgfX mJ15DCGbAWj08HnKQVNkhTSIPdSz5T/Nf5Xb8= X-Google-Smtp-Source: ACcGV60yixQ7WkKtFoVo0a2iIypyOXeolvn18ZMkAH0fdyE9vdp77xXrrlRgW8IxyrNqeVzlUSyXbQ== X-Received: by 2002:a17:902:15a8:: with SMTP id m37-v6mr23489770pla.132.1539123665951; Tue, 09 Oct 2018 15:21:05 -0700 (PDT) Received: from joelaf.mtv.corp.google.com ([2620:0:1000:1601:3aef:314f:b9ea:889f]) by smtp.gmail.com with ESMTPSA id z15-v6sm26900856pfn.170.2018.10.09.15.21.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Oct 2018 15:21:04 -0700 (PDT) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: kernel-team@android.com, "Joel Fernandes (Google)" , dancol@google.com, minchan@google.com, Andrew Morton , gregkh@linuxfoundation.org, "J. Bruce Fields" , Jeff Layton , john.stultz@linaro.org, jreck@google.com, Khalid Aziz , linux-fsdevel@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-mm@kvack.org, Mike Kravetz , Shuah Khan , tkjos@google.com Subject: [PATCH v2 2/2] selftests/memfd: Add tests for F_SEAL_FS_WRITE seal Date: Tue, 9 Oct 2018 15:20:42 -0700 Message-Id: <20181009222042.9781-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.19.0.605.g01d371f741-goog In-Reply-To: <20181009222042.9781-1-joel@joelfernandes.org> References: <20181009222042.9781-1-joel@joelfernandes.org> MIME-Version: 1.0 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: X-Virus-Scanned: ClamAV using ClamSMTP Add tests to verify sealing memfds with the F_SEAL_FS_WRITE works as expected. Cc: dancol@google.com Cc: minchan@google.com Signed-off-by: Joel Fernandes (Google) Signed-off-by: Joel Fernandes (Google) --- tools/testing/selftests/memfd/memfd_test.c | 51 +++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/memfd/memfd_test.c b/tools/testing/selftests/memfd/memfd_test.c index 10baa1652fc2..4bd2b6c87bb4 100644 --- a/tools/testing/selftests/memfd/memfd_test.c +++ b/tools/testing/selftests/memfd/memfd_test.c @@ -27,7 +27,7 @@ #define MFD_DEF_SIZE 8192 #define STACK_SIZE 65536 - +#define F_SEAL_FS_WRITE 0x0010 /* * Default is not to test hugetlbfs */ @@ -170,6 +170,24 @@ static void *mfd_assert_mmap_shared(int fd) return p; } +static void *mfd_fail_mmap_shared(int fd) +{ + void *p; + + p = mmap(NULL, + mfd_def_size, + PROT_READ | PROT_WRITE, + MAP_SHARED, + fd, + 0); + if (p != MAP_FAILED) { + printf("mmap() didn't fail as expected\n"); + abort(); + } + + return p; +} + static void *mfd_assert_mmap_private(int fd) { void *p; @@ -692,6 +710,36 @@ static void test_seal_write(void) close(fd); } +/* + * Test SEAL_WRITE + * Test whether SEAL_WRITE actually prevents modifications. + */ +static void test_seal_fs_write(void) +{ + int fd; + void *p; + + printf("%s SEAL-FS-WRITE\n", memfd_str); + + fd = mfd_assert_new("kern_memfd_seal_fs_write", + mfd_def_size, + MFD_CLOEXEC | MFD_ALLOW_SEALING); + + p = mfd_assert_mmap_shared(fd); + + /* FS_WRITE seal can be added even with existing + * writeable mappings */ + mfd_assert_has_seals(fd, 0); + mfd_assert_add_seals(fd, F_SEAL_FS_WRITE); + mfd_assert_has_seals(fd, F_SEAL_FS_WRITE); + + mfd_assert_read(fd); + mfd_fail_write(fd); + + munmap(p, mfd_def_size); + close(fd); +} + /* * Test SEAL_SHRINK * Test whether SEAL_SHRINK actually prevents shrinking @@ -945,6 +993,7 @@ int main(int argc, char **argv) test_basic(); test_seal_write(); + test_seal_fs_write(); test_seal_shrink(); test_seal_grow(); test_seal_resize();