{"id":816545,"url":"http://patchwork.ozlabs.org/api/patches/816545/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20170920224605.22030-9-ebiggers3@gmail.com/","project":{"id":8,"url":"http://patchwork.ozlabs.org/api/projects/8/?format=json","name":"Linux ext4 filesystem development","link_name":"linux-ext4","list_id":"linux-ext4.vger.kernel.org","list_email":"linux-ext4@vger.kernel.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":true,"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-ext4/patch/20170920224605.22030-9-ebiggers3@gmail.com/mbox/","series":[{"id":4249,"url":"http://patchwork.ozlabs.org/api/series/4249/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/list/?series=4249","date":"2017-09-20T22:45:40","name":"fscrypt: add some higher-level helper functions","version":1,"mbox":"http://patchwork.ozlabs.org/series/4249/mbox/"}],"comments":"http://patchwork.ozlabs.org/api/patches/816545/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816545/checks/","tags":{},"related":[],"headers":{"Return-Path":"<linux-ext4-owner@vger.kernel.org>","X-Original-To":"patchwork-incoming@ozlabs.org","Delivered-To":"patchwork-incoming@ozlabs.org","Authentication-Results":["ozlabs.org;\n\tspf=none (mailfrom) smtp.mailfrom=vger.kernel.org\n\t(client-ip=209.132.180.67; helo=vger.kernel.org;\n\tenvelope-from=linux-ext4-owner@vger.kernel.org;\n\treceiver=<UNKNOWN>)","ozlabs.org; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"GPUdoFZt\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyFHH4LzBz9sPm\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 21 Sep 2017 08:47:07 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751733AbdITWrF (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tWed, 20 Sep 2017 18:47:05 -0400","from mail-pf0-f195.google.com ([209.85.192.195]:36358 \"EHLO\n\tmail-pf0-f195.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751795AbdITWrB (ORCPT\n\t<rfc822; linux-ext4@vger.kernel.org>); Wed, 20 Sep 2017 18:47:01 -0400","by mail-pf0-f195.google.com with SMTP id f84so1721589pfj.3;\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; c=relaxed/relaxed;\n\td=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=uk1hqmwVPmvIoEzZVBIhkV9zCatzEtXNFq8OUrP0O8ycQveHXeaZ6Qr487X0F/PbpX\n\t1P9gltcuWnGohofK8kRGXHGmFH3BTTvX72kezvfxuP7oOOis4sEVYc6iNVCP6Tn3/GsV\n\tHErhVXa7hr13xPzSE8iTcLkVyRcU5E9v+pE6jfKGee6fIqo3z9LxEdg0kP30Cx6HYfoH\n\tGWnjuTDxDyBUyHAw9mhQ8ZoEd9dXbuk9yxw++NEtBUZETeHghTcOCggfgbCymy6qQyVy\n\tFgZvVvlMT8sNilXMQ8zWqk4ZH/JFCq2I+RLlZrpBkW4eIv6ChmKbEEVv5f/Bmsy7pYFM\n\tPZ3w==","X-Gm-Message-State":"AHPjjUhftry4Fq350aDlEY29ku17LC8noaQQ530KTIPifx9ySH9DnZfK\n\tkUcYT2Plvo9FA/R1uyVYABMNLrVCPrY=","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","Cc":"linux-fsdevel@vger.kernel.org, linux-ext4@vger.kernel.org,\n\tlinux-f2fs-devel@lists.sourceforge.net,\n\tlinux-mtd@lists.infradead.org, \"Theodore Y . Ts'o\" <tytso@mit.edu>,\n\tJaegeuk Kim <jaegeuk@kernel.org>, Michael Halcrow <mhalcrow@google.com>,\n\tEric Biggers <ebiggers@google.com>","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>","Sender":"linux-ext4-owner@vger.kernel.org","Precedence":"bulk","List-ID":"<linux-ext4.vger.kernel.org>","X-Mailing-List":"linux-ext4@vger.kernel.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"]}