From patchwork Tue Jan 25 14:33:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Christian_G=C3=B6ttsche?= X-Patchwork-Id: 12723884 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 A3A9BC433EF for ; Tue, 25 Jan 2022 14:33:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F7D76B0081; Tue, 25 Jan 2022 09:33:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A83B6B0083; Tue, 25 Jan 2022 09:33:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 047876B0085; Tue, 25 Jan 2022 09:33:27 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0121.hostedemail.com [216.40.44.121]) by kanga.kvack.org (Postfix) with ESMTP id E6FE46B0081 for ; Tue, 25 Jan 2022 09:33:27 -0500 (EST) Received: from smtpin15.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9A0B08249980 for ; Tue, 25 Jan 2022 14:33:27 +0000 (UTC) X-FDA: 79069052454.15.3B18F4B Received: from mail-ed1-f54.google.com (mail-ed1-f54.google.com [209.85.208.54]) by imf22.hostedemail.com (Postfix) with ESMTP id 34824C0007 for ; Tue, 25 Jan 2022 14:33:27 +0000 (UTC) Received: by mail-ed1-f54.google.com with SMTP id u24so17411776eds.11 for ; Tue, 25 Jan 2022 06:33:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bLGRSDBqt3CI9o30EqMaKBgi/Og7jvCpHq0R8ShXmFM=; b=Mn4PK6g/oizWyfQ/FlsNpx8KUGy4lvZNH4Q44yveFyG6XwfO4vkxu5X4ytfU6J68Jp t/Ep8y+dU+4NrFLJMNh5dhoE3ITMKtr8o4VcdBESKAXHbnpqb0CjYOyMH+JgwlHcFxUg SdYu2BojdjheT8JGAjkEWzq6FCuwKY1y7yWHJguJTGz1GcYRHYZkH++kWEoZ0Pvrl0EM TNidQED+LEGzAweI2o8TceH5KTyp97FCGQZyfp44hk6hrSdAJIzr1V/CxQJtFyfq8bnP oy9Avv4wKRXUE6cJtJrAk60hQGmhsPB+EiNE1/cwxu7YTSuMAE9EwA6e/ZhT9IOo9xYz OTkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=bLGRSDBqt3CI9o30EqMaKBgi/Og7jvCpHq0R8ShXmFM=; b=U9SdJnFXshiNmGytCFMCK7yOUl8H4wggkddd7yTKh82/JMVrH2Qvd7XyeBhbtXz6vW iTL9LDw6a+zTGyIbXVe7d+nHrk6jDszfhJUkhi90vW/VlwekH+q4YuS++H26sxfxZPha GooGqnYEZoJaUjdsJcunCmuyiLV+IJAlE4Zs3iaEWVrFzfn+vwhKevIZ4LQleEY/lu0s rhiOZE1xqRoBE9H72WAITRWvFovkvJLRUraKkXUP0wwA1IRWtiLJbOf10gPVBmHpWKCi 4IqCnHbBPAjVOYlqqi0QEajwnQXJxGOX8bZIN+0vQmXQO88aXLkSdXbHtbdQtuRPz7v/ nnEg== X-Gm-Message-State: AOAM531SagLThNwwrjVx6VzAKYTm9VQIM6+alow0ap2bm+9WdrCmO2jy k2c7f5HIrWt+KS5xXlms6+0= X-Google-Smtp-Source: ABdhPJw2WjOewfY30kV7zrgPQ4uGjfJlfejcSiIazlBcEOdPGrjUrMOyvy+xfpRlBK6bRy0afqR1Uw== X-Received: by 2002:a17:906:7306:: with SMTP id di6mr16139066ejc.93.1643121205668; Tue, 25 Jan 2022 06:33:25 -0800 (PST) Received: from debianHome.localdomain (dynamic-077-010-144-044.77.10.pool.telefonica.de. [77.10.144.44]) by smtp.gmail.com with ESMTPSA id gz12sm6291530ejc.124.2022.01.25.06.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 25 Jan 2022 06:33:25 -0800 (PST) From: =?utf-8?q?Christian_G=C3=B6ttsche?= To: selinux@vger.kernel.org, James Morris , "Serge E. Hallyn" , linux-security-module@vger.kernel.org, Paul Moore , Stephen Smalley , Eric Paris Cc: Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH] mm: create security context for memfd_secret inodes Date: Tue, 25 Jan 2022 15:33:04 +0100 Message-Id: <20220125143304.34628-1-cgzones@googlemail.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 X-Rspam-User: nil X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: 34824C0007 X-Stat-Signature: 51u8pbuk7upcpgwi1u6jio5yba9m9fkm Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=googlemail.com header.s=20210112 header.b="Mn4PK6g/"; spf=pass (imf22.hostedemail.com: domain of cgzones@googlemail.com designates 209.85.208.54 as permitted sender) smtp.mailfrom=cgzones@googlemail.com; dmarc=pass (policy=quarantine) header.from=googlemail.com X-HE-Tag: 1643121207-982945 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 a security context for the inodes created by memfd_secret(2) via the LSM hook inode_init_security_anon to allow a fine grained control. As secret memory areas can affect hibernation and have a global shared limit access control might be desirable. Signed-off-by: Christian Göttsche --- An alternative way of checking memfd_secret(2) is to create a new LSM hook and e.g. for SELinux check via a new process class permission. --- mm/secretmem.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/mm/secretmem.c b/mm/secretmem.c index 22b310adb53d..b61cd2f661bc 100644 --- a/mm/secretmem.c +++ b/mm/secretmem.c @@ -164,11 +164,20 @@ static struct file *secretmem_file_create(unsigned long flags) { struct file *file = ERR_PTR(-ENOMEM); struct inode *inode; + const char *anon_name = "[secretmem]"; + const struct qstr qname = QSTR_INIT(anon_name, strlen(anon_name)); + int err; inode = alloc_anon_inode(secretmem_mnt->mnt_sb); if (IS_ERR(inode)) return ERR_CAST(inode); + err = security_inode_init_security_anon(inode, &qname, NULL); + if (err) { + file = ERR_PTR(err); + goto err_free_inode; + } + file = alloc_file_pseudo(inode, secretmem_mnt, "secretmem", O_RDWR, &secretmem_fops); if (IS_ERR(file))