{"id":816569,"url":"http://patchwork.ozlabs.org/api/patches/816569/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20170920224605.22030-9-ebiggers3@gmail.com/","project":{"id":3,"url":"http://patchwork.ozlabs.org/api/projects/3/?format=json","name":"Linux MTD development","link_name":"linux-mtd","list_id":"linux-mtd.lists.infradead.org","list_email":"linux-mtd@lists.infradead.org","web_url":null,"scm_url":null,"webscm_url":null,"list_archive_url":"","list_archive_url_format":"","commit_url_format":""},"msgid":"<20170920224605.22030-9-ebiggers3@gmail.com>","list_archive_url":null,"date":"2017-09-20T22:45:48","name":"[08/25] fscrypt: new helper function - fscrypt_prepare_rename()","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":false,"hash":"b1dfd487fd5ae79aa23958651217b277df991769","submitter":{"id":65202,"url":"http://patchwork.ozlabs.org/api/people/65202/?format=json","name":"Eric Biggers","email":"ebiggers3@gmail.com"},"delegate":null,"mbox":"http://patchwork.ozlabs.org/project/linux-mtd/patch/20170920224605.22030-9-ebiggers3@gmail.com/mbox/","series":[{"id":4250,"url":"http://patchwork.ozlabs.org/api/series/4250/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-mtd/list/?series=4250","date":"2017-09-20T22:45:45","name":"fscrypt: add some higher-level helper functions","version":1,"mbox":"http://patchwork.ozlabs.org/series/4250/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816569/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816569/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org>","X-Original-To":"incoming@patchwork.ozlabs.org","Delivered-To":"patchwork-incoming@bilbo.ozlabs.org","Authentication-Results":["ozlabs.org; spf=none (mailfrom)\n\tsmtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133;\n\thelo=bombadil.infradead.org;\n\tenvelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=lists.infradead.org\n\theader.i=@lists.infradead.org header.b=\"sEqm5sSM\"; \n\tdkim=fail reason=\"signature verification failed\" (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"GPUdoFZt\"; dkim-atps=neutral"],"Received":["from bombadil.infradead.org (bombadil.infradead.org\n\t[65.50.211.133])\n\t(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256\n\tbits)) (No client certificate requested)\n\tby ozlabs.org (Postfix) with ESMTPS id 3xyFLV5wv9z9sPk\n\tfor <incoming@patchwork.ozlabs.org>;\n\tThu, 21 Sep 2017 08:49:54 +1000 (AEST)","from localhost ([127.0.0.1] helo=bombadil.infradead.org)\n\tby bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dunoO-0006pP-TY; Wed, 20 Sep 2017 22:49:44 +0000","from mail-pf0-x241.google.com ([2607:f8b0:400e:c00::241])\n\tby bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux))\n\tid 1dunm1-0004xc-IW\n\tfor linux-mtd@lists.infradead.org; Wed, 20 Sep 2017 22:47:28 +0000","by mail-pf0-x241.google.com with SMTP id g65so1725710pfe.1\n\tfor <linux-mtd@lists.infradead.org>;\n\tWed, 20 Sep 2017 15:47:00 -0700 (PDT)","from ebiggers-linuxstation.kir.corp.google.com ([100.66.174.81])\n\tby smtp.gmail.com with ESMTPSA id j2sm6249pgn.26.2017.09.20.15.46.59\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tWed, 20 Sep 2017 15:46:59 -0700 (PDT)"],"DKIM-Signature":["v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed;\n\td=lists.infradead.org; s=bombadil.20170209; h=Sender:\n\tContent-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe:\n\tList-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References:\n\tIn-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID:\n\tContent-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc\n\t:Resent-Message-ID:List-Owner;\n\tbh=/cu6C924WjDhcGqCT3ql+pJnRF9ahW+7+KK7MX/MtVY=;\n\tb=sEqm5sSM6FAk56wnjMxoWr2GrR\n\ttilkcVU2aa/ayTxX/aoItq+BGlForyT84DJVxiwkugRwy3D3pUyqCmeStPMS65QL1WbrdzjO7y/ts\n\tcJJFtWD5lhFSClkNCToxGEtdldmobRBP9g20a6oFSg5Fo4PtrROtkKuHupMKMUgGwwF+TnfffICvG\n\twP59w5f9usyq/AWJWc/50WwtC75fE+9NhpfBBn6tb5Av46su0YFBM26Ra8pyzBK+DCALEDzqJmUUS\n\tek0ZcpvHaurEGgyFNLpfPaTwHWRmf8dNCRqy55aWfm9Ud4gQc+Le/OC/I7LCLEknhThoSBYW0WzD3\n\tQlKi9eTw==;","v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025;\n\th=from:to:cc:subject:date:message-id:in-reply-to:references;\n\tbh=LIzTb5n2r4dfk1Ti+uU565uMFd5VD5WWvUSIFbLU2EE=;\n\tb=GPUdoFZtIZ8WcYf+/qY+QVnNkcLjP1n38O5ryAYfXBQO/GT2e9fepYu12dNwMF8VO2\n\t1kXx8y4d8npeZAhrBDt5sRbY3rIsZUi9imvZ+PEgOALjGfhIXEZzGNc9e0e8mIyaJqMp\n\tgxVxSyiDkI6Lij2mEyVfKvb/icwT9qtceUcveVOrT5fs7q3f30DTTCKKUlZHi/LKM+qr\n\tOPbUA9zpiD1NFdg6lnqE7jMwrQj0V43hhhUP4vS96+S1rKa+4aTTANZxorJM+M+kXGjN\n\tSngY5csccM8cUzGFE/UZE20BQ7v2YMlP06GsIMunTwzIpIRoa8ILk+O5rHV7f41MPwvx\n\t/oAg=="],"X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20161025;\n\th=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to\n\t:references;\n\tbh=LIzTb5n2r4dfk1Ti+uU565uMFd5VD5WWvUSIFbLU2EE=;\n\tb=ArSddQs4qfyFB5L5mN/HbLG6AWFTSfw16aN5gZxGDTLZAlPUOSBDyPx4qdkozQfu1B\n\tOVKFHoxCBKGJwhi0SSMMguBXUx53aStPNtLnrCZl/uE8BA2UldvIXZw19CdE1iJ/zO3i\n\tbhvOsLvgNFDvQw2YP/kfNvdpYNme08BQ35xK/HRxVJfzQzRY1DF9sgCiJI45viYwi0LK\n\t82ZLH3+DeE5shpvLNnxgif8tmmeVnfQQ4zKC0ebZI6CFFBhXq0Z6aeOSFbIqN9Ijzzh9\n\t2IaqY/mM8D4OAyxVNs6qbv6SYUVUU5WcwHLtC4ciq59RV/E9X66S2+MaWc9LHCcqGZuy\n\tmqaQ==","X-Gm-Message-State":"AHPjjUh5TGpWvNjOoxdRjwraiMgXkSNxTy1ne4GNBe9J1c50j/sjyqzA\n\tpoYYp2xipXQeK76h5uYiUHQ=","X-Google-Smtp-Source":"AOwi7QC83S6eS4o6GgU7jjtBLG6dRcHNS4E4tYs8rki2TrXkC7F5HVyPo7SlsQoFUULiKUR584BWmQ==","X-Received":"by 10.84.130.35 with SMTP id 32mr3481695plc.368.1505947620333;\n\tWed, 20 Sep 2017 15:47:00 -0700 (PDT)","From":"Eric Biggers <ebiggers3@gmail.com>","To":"linux-fscrypt@vger.kernel.org","Subject":"[PATCH 08/25] fscrypt: new helper function -\n\tfscrypt_prepare_rename()","Date":"Wed, 20 Sep 2017 15:45:48 -0700","Message-Id":"<20170920224605.22030-9-ebiggers3@gmail.com>","X-Mailer":"git-send-email 2.14.1.821.g8fa685d3b7-goog","In-Reply-To":"<20170920224605.22030-1-ebiggers3@gmail.com>","References":"<20170920224605.22030-1-ebiggers3@gmail.com>","X-CRM114-Version":"20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 ","X-CRM114-CacheID":"sfid-20170920_154717_783597_5FE04918 ","X-CRM114-Status":"GOOD (  14.72  )","X-Spam-Score":"-1.8 (-)","X-Spam-Report":"SpamAssassin version 3.4.1 on bombadil.infradead.org summary:\n\tContent analysis details:   (-1.8 points)\n\tpts rule name              description\n\t---- ----------------------\n\t--------------------------------------------------\n\t-0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/,\n\tno\n\ttrust [2607:f8b0:400e:c00:0:0:0:241 listed in] [list.dnswl.org]\n\t-0.0 SPF_PASS               SPF: sender matches SPF record\n\t0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends\n\tin digit (ebiggers3[at]gmail.com)\n\t0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail\n\tprovider (ebiggers3[at]gmail.com)\n\t-1.9 BAYES_00               BODY: Bayes spam probability is 0 to 1%\n\t[score: 0.0000]\n\t-0.1 DKIM_VALID Message has at least one valid DKIM or DK signature\n\t0.1 DKIM_SIGNED            Message has a DKIM or DK signature,\n\tnot necessarily valid\n\t-0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from\n\tauthor's domain","X-BeenThere":"linux-mtd@lists.infradead.org","X-Mailman-Version":"2.1.21","Precedence":"list","List-Id":"Linux MTD discussion mailing list <linux-mtd.lists.infradead.org>","List-Unsubscribe":"<http://lists.infradead.org/mailman/options/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=unsubscribe>","List-Archive":"<http://lists.infradead.org/pipermail/linux-mtd/>","List-Post":"<mailto:linux-mtd@lists.infradead.org>","List-Help":"<mailto:linux-mtd-request@lists.infradead.org?subject=help>","List-Subscribe":"<http://lists.infradead.org/mailman/listinfo/linux-mtd>,\n\t<mailto:linux-mtd-request@lists.infradead.org?subject=subscribe>","Cc":"\"Theodore Y . Ts'o\" <tytso@mit.edu>, Eric Biggers <ebiggers@google.com>, \n\tMichael Halcrow <mhalcrow@google.com>,\n\tlinux-f2fs-devel@lists.sourceforge.net, \n\tlinux-mtd@lists.infradead.org, linux-fsdevel@vger.kernel.org,\n\tJaegeuk Kim <jaegeuk@kernel.org>, linux-ext4@vger.kernel.org","MIME-Version":"1.0","Content-Type":"text/plain; charset=\"us-ascii\"","Content-Transfer-Encoding":"7bit","Sender":"\"linux-mtd\" <linux-mtd-bounces@lists.infradead.org>","Errors-To":"linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org"},"content":"From: Eric Biggers <ebiggers@google.com>\n\nIntroduce a helper function which prepares to rename a file into a\npossibly encrypted directory.  It handles loading the encryption keys\nfor the source and target directories if needed, and it handles\nenforcing that if the target directory (and the source directory for a\ncross-rename) is encrypted, then the file being moved into the directory\nhas the same encryption policy as its containing directory.\n\nSigned-off-by: Eric Biggers <ebiggers@google.com>\n---\n fs/crypto/hooks.c               | 30 ++++++++++++++++++++++++++++++\n include/linux/fscrypt_notsupp.h | 11 +++++++++++\n include/linux/fscrypt_supp.h    | 39 +++++++++++++++++++++++++++++++++++++++\n 3 files changed, 80 insertions(+)","diff":"diff --git a/fs/crypto/hooks.c b/fs/crypto/hooks.c\nindex 8b90217320dd..822cb78f9b45 100644\n--- a/fs/crypto/hooks.c\n+++ b/fs/crypto/hooks.c\n@@ -62,3 +62,33 @@ int __fscrypt_prepare_link(struct inode *inode, struct inode *dir)\n \treturn 0;\n }\n EXPORT_SYMBOL_GPL(__fscrypt_prepare_link);\n+\n+int __fscrypt_prepare_rename(struct inode *old_dir, struct dentry *old_dentry,\n+\t\t\t     struct inode *new_dir, struct dentry *new_dentry,\n+\t\t\t     unsigned int flags)\n+{\n+\tint err;\n+\n+\terr = fscrypt_require_key(old_dir);\n+\tif (err)\n+\t\treturn err;\n+\n+\terr = fscrypt_require_key(new_dir);\n+\tif (err)\n+\t\treturn err;\n+\n+\tif (old_dir != new_dir) {\n+\t\tif (IS_ENCRYPTED(new_dir) &&\n+\t\t    !fscrypt_has_permitted_context(new_dir,\n+\t\t\t\t\t\t   d_inode(old_dentry)))\n+\t\t\treturn -EPERM;\n+\n+\t\tif ((flags & RENAME_EXCHANGE) &&\n+\t\t    IS_ENCRYPTED(old_dir) &&\n+\t\t    !fscrypt_has_permitted_context(old_dir,\n+\t\t\t\t\t\t   d_inode(new_dentry)))\n+\t\t\treturn -EPERM;\n+\t}\n+\treturn 0;\n+}\n+EXPORT_SYMBOL_GPL(__fscrypt_prepare_rename);\ndiff --git a/include/linux/fscrypt_notsupp.h b/include/linux/fscrypt_notsupp.h\nindex 2cb400440be3..a88a2959cd8c 100644\n--- a/include/linux/fscrypt_notsupp.h\n+++ b/include/linux/fscrypt_notsupp.h\n@@ -198,4 +198,15 @@ static inline int fscrypt_prepare_link(struct dentry *old_dentry,\n \treturn 0;\n }\n \n+static inline int fscrypt_prepare_rename(struct inode *old_dir,\n+\t\t\t\t\t struct dentry *old_dentry,\n+\t\t\t\t\t struct inode *new_dir,\n+\t\t\t\t\t struct dentry *new_dentry,\n+\t\t\t\t\t unsigned int flags)\n+{\n+\tif (IS_ENCRYPTED(old_dir) || IS_ENCRYPTED(new_dir))\n+\t\treturn -EOPNOTSUPP;\n+\treturn 0;\n+}\n+\n #endif\t/* _LINUX_FSCRYPT_NOTSUPP_H */\ndiff --git a/include/linux/fscrypt_supp.h b/include/linux/fscrypt_supp.h\nindex ebc0cc41aaf9..fa062d41b39a 100644\n--- a/include/linux/fscrypt_supp.h\n+++ b/include/linux/fscrypt_supp.h\n@@ -201,4 +201,43 @@ static inline int fscrypt_prepare_link(struct dentry *old_dentry,\n \treturn 0;\n }\n \n+extern int __fscrypt_prepare_rename(struct inode *old_dir,\n+\t\t\t\t    struct dentry *old_dentry,\n+\t\t\t\t    struct inode *new_dir,\n+\t\t\t\t    struct dentry *new_dentry,\n+\t\t\t\t    unsigned int flags);\n+\n+/**\n+ * fscrypt_prepare_rename - prepare for a rename between possibly-encrypted directories\n+ * @old_dir: source directory\n+ * @old_dentry: dentry for source file\n+ * @new_dir: target directory\n+ * @new_dentry: dentry for target location (may be negative unless exchanging)\n+ * @flags: rename flags (we care at least about %RENAME_EXCHANGE)\n+ *\n+ * Prepare for ->rename() where the source and/or target directories may be\n+ * encrypted.  A new link can only be added to an encrypted directory if the\n+ * directory's encryption key is available --- since otherwise we'd have no way\n+ * to encrypt the filename.  A rename to an existing name, on the other hand,\n+ * *is* cryptographically possible without the key.  However, we take the more\n+ * conservative approach and just forbid all no-key renames.\n+ *\n+ * We also verify that the rename will not violate the constraint that all files\n+ * in an encrypted directory tree use the same encryption policy.\n+ *\n+ * Return: 0 on success, -ENOKEY if an encryption key is missing, -EPERM if the\n+ * rename would cause inconsistent encryption policies, or another -errno code.\n+ */\n+static inline int fscrypt_prepare_rename(struct inode *old_dir,\n+\t\t\t\t\t struct dentry *old_dentry,\n+\t\t\t\t\t struct inode *new_dir,\n+\t\t\t\t\t struct dentry *new_dentry,\n+\t\t\t\t\t unsigned int flags)\n+{\n+\tif (IS_ENCRYPTED(old_dir) || IS_ENCRYPTED(new_dir))\n+\t\treturn __fscrypt_prepare_rename(old_dir, old_dentry,\n+\t\t\t\t\t\tnew_dir, new_dentry, flags);\n+\treturn 0;\n+}\n+\n #endif\t/* _LINUX_FSCRYPT_SUPP_H */\n","prefixes":["08/25"]}