{"id":816542,"url":"http://patchwork.ozlabs.org/api/patches/816542/?format=json","web_url":"http://patchwork.ozlabs.org/project/linux-ext4/patch/20170920224605.22030-2-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-2-ebiggers3@gmail.com>","list_archive_url":null,"date":"2017-09-20T22:45:41","name":"[01/25] fs, fscrypt: add an S_ENCRYPTED inode flag","commit_ref":null,"pull_url":null,"state":"not-applicable","archived":true,"hash":"6261577311368e476735b8db1a3fa55e7fc8047b","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-2-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/816542/comments/","check":"pending","checks":"http://patchwork.ozlabs.org/api/patches/816542/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=\"Xa+VKYqR\"; dkim-atps=neutral"],"Received":["from vger.kernel.org (vger.kernel.org [209.132.180.67])\n\tby ozlabs.org (Postfix) with ESMTP id 3xyFH33x5xz9sPk\n\tfor <patchwork-incoming@ozlabs.org>;\n\tThu, 21 Sep 2017 08:46:55 +1000 (AEST)","(majordomo@vger.kernel.org) by vger.kernel.org via listexpand\n\tid S1751854AbdITWqy (ORCPT <rfc822;patchwork-incoming@ozlabs.org>);\n\tWed, 20 Sep 2017 18:46:54 -0400","from mail-pf0-f195.google.com ([209.85.192.195]:36325 \"EHLO\n\tmail-pf0-f195.google.com\" rhost-flags-OK-OK-OK-OK) by vger.kernel.org\n\twith ESMTP id S1751743AbdITWqw (ORCPT\n\t<rfc822; linux-ext4@vger.kernel.org>); Wed, 20 Sep 2017 18:46:52 -0400","by mail-pf0-f195.google.com with SMTP id f84so1721477pfj.3;\n\tWed, 20 Sep 2017 15:46:52 -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.51\n\t(version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128);\n\tWed, 20 Sep 2017 15:46:51 -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=wARWDprN0k35/Sd7s8XV8xzgOqaKGxpXF6yLyf3yyrw=;\n\tb=Xa+VKYqRS2FgWA4AvVbp/NAUSyEKBZG4AjdI4e/A8MMP56ywYkq7d7oAwwvVZEp2Tk\n\thw3bfARbjK1NdDS8Zk3Ia2i3up8Ncc87P99jH+f5/9lkTPGhp4QK4beLbINGCeDflDtQ\n\tfJZ35YdR6PuE8BBguaELXzzi2ezjsuTJTfg3OjLKfDqvDeGmMmqsrVWZPOQW+VCCJdEE\n\tc3g9Sy84NT+i5QXRUvSCULVe4UL5kZMWs967gfFXfH2rcpJueeGV5TwgtUFz/WwAlWsX\n\tqZc8UJMN+nEG0bQsnf4W1kIVm25DGOkrDM9grf5kc80pMCTClROilpyoYoI4vRMx3NO2\n\tjz7g==","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=wARWDprN0k35/Sd7s8XV8xzgOqaKGxpXF6yLyf3yyrw=;\n\tb=cE8ApguCOKz3+xhi2mwiH8wpzjUMkPM9lTIHObSJ0RTkMG9UmCCAJicJJ/fG6wzvYm\n\tFgl56Eo4e/Ez2b+bR9kNeSzh5V7ofk9I1Pzi5y3C3zGOWswcjo1WqyqJ/s8OrgdlOUoM\n\tzVJ2rr3cfRoIf7Dkz6mGyJ3lgovhSxSmA4d6c5U+gqUjRjQezkAfcWHBgB2ePnrKpBah\n\tJdyMtStDa/LNmfpTM1hZfgG2530sdeMuFoXc0zpOASRuGCLvkkLVcHSPq4xpsCnZ5K6E\n\ttgqtw27KcG6yUzVZfNeow2W/VTu2y2mmOBkqGxoNcdwXYmpR00S3MUb5qrjwwqv+Ryva\n\tijDA==","X-Gm-Message-State":"AHPjjUgkaKJQs6hu7MO+vk6anJDoqjnLlB/wwduPBy035qf8b2lzUfAl\n\tivZRwReE+1cnidFMa5qwwAbx3DD2rWk=","X-Google-Smtp-Source":"AOwi7QDEYFPyapqGQ2nhbKXYP+AjJ3BfoLK2WVVdflpsSz/P3AozwctMH74c5ZQZ00QtUPTGgJxpAg==","X-Received":"by 10.84.143.165 with SMTP id 34mr3392176plz.91.1505947612023;\n\tWed, 20 Sep 2017 15:46:52 -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 01/25] fs, fscrypt: add an S_ENCRYPTED inode flag","Date":"Wed, 20 Sep 2017 15:45:41 -0700","Message-Id":"<20170920224605.22030-2-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 flag S_ENCRYPTED which can be set in ->i_flags to indicate\nthat the inode is encrypted using the fscrypt (fs/crypto/) mechanism.\n\nChecking this flag will give the same information that\ninode->i_sb->s_cop->is_encrypted(inode) currently does, but will be more\nefficient.  This will be useful for adding higher-level helper functions\nfor filesystems to use.  For example we'll be able to replace this:\n\n\tif (ext4_encrypted_inode(inode)) {\n\t\tret = fscrypt_get_encryption_info(inode);\n\t\tif (ret)\n\t\t\treturn ret;\n\t\tif (!fscrypt_has_encryption_key(inode))\n\t\t\treturn -ENOKEY;\n\t}\n\nwith this:\n\n\tret = fscrypt_require_key(inode);\n\tif (ret)\n\t\treturn ret;\n\n... since we'll be able to retain the fast path for unencrypted files as\na single flag check, using an inline function.  This wasn't possible\nbefore because we'd have had to frequently call through the\n->i_sb->s_cop->is_encrypted function pointer, even when the encryption\nsupport was disabled or not being used.\n\nNote: we don't define S_ENCRYPTED to 0 if CONFIG_FS_ENCRYPTION is\ndisabled because we want to continue to return an error if an encrypted\nfile is accessed without encryption support, rather than pretending that\nit is unencrypted.\n\nSigned-off-by: Eric Biggers <ebiggers@google.com>\n---\n fs/ext4/inode.c    | 7 +++++--\n fs/ext4/super.c    | 8 ++++++--\n fs/f2fs/f2fs.h     | 1 +\n fs/f2fs/inode.c    | 5 ++++-\n fs/ubifs/ioctl.c   | 5 ++++-\n fs/ubifs/xattr.c   | 1 +\n include/linux/fs.h | 2 ++\n 7 files changed, 23 insertions(+), 6 deletions(-)","diff":"diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c\nindex 31db875bc7a1..d5a471939fbc 100644\n--- a/fs/ext4/inode.c\n+++ b/fs/ext4/inode.c\n@@ -4589,10 +4589,13 @@ void ext4_set_inode_flags(struct inode *inode)\n \t\tnew_fl |= S_DIRSYNC;\n \tif (test_opt(inode->i_sb, DAX) && S_ISREG(inode->i_mode) &&\n \t    !ext4_should_journal_data(inode) && !ext4_has_inline_data(inode) &&\n-\t    !ext4_encrypted_inode(inode))\n+\t    !(flags & EXT4_ENCRYPT_FL))\n \t\tnew_fl |= S_DAX;\n+\tif (flags & EXT4_ENCRYPT_FL)\n+\t\tnew_fl |= S_ENCRYPTED;\n \tinode_set_flags(inode, new_fl,\n-\t\t\tS_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX);\n+\t\t\tS_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|S_DAX|\n+\t\t\tS_ENCRYPTED);\n }\n \n static blkcnt_t ext4_inode_blocks(struct ext4_inode *raw_inode,\ndiff --git a/fs/ext4/super.c b/fs/ext4/super.c\nindex b104096fce9e..dcfb19539871 100644\n--- a/fs/ext4/super.c\n+++ b/fs/ext4/super.c\n@@ -1181,7 +1181,8 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,\n \t\t\text4_clear_inode_state(inode,\n \t\t\t\t\tEXT4_STATE_MAY_INLINE_DATA);\n \t\t\t/*\n-\t\t\t * Update inode->i_flags - e.g. S_DAX may get disabled\n+\t\t\t * Update inode->i_flags - S_ENCRYPTED will be enabled,\n+\t\t\t * S_DAX may be disabled\n \t\t\t */\n \t\t\text4_set_inode_flags(inode);\n \t\t}\n@@ -1206,7 +1207,10 @@ static int ext4_set_context(struct inode *inode, const void *ctx, size_t len,\n \t\t\t\t    ctx, len, 0);\n \tif (!res) {\n \t\text4_set_inode_flag(inode, EXT4_INODE_ENCRYPT);\n-\t\t/* Update inode->i_flags - e.g. S_DAX may get disabled */\n+\t\t/*\n+\t\t * Update inode->i_flags - S_ENCRYPTED will be enabled,\n+\t\t * S_DAX may be disabled\n+\t\t */\n \t\text4_set_inode_flags(inode);\n \t\tres = ext4_mark_inode_dirty(handle, inode);\n \t\tif (res)\ndiff --git a/fs/f2fs/f2fs.h b/fs/f2fs/f2fs.h\nindex 9a7c90386947..beaefddf2ff8 100644\n--- a/fs/f2fs/f2fs.h\n+++ b/fs/f2fs/f2fs.h\n@@ -2949,6 +2949,7 @@ static inline void f2fs_set_encrypted_inode(struct inode *inode)\n {\n #ifdef CONFIG_F2FS_FS_ENCRYPTION\n \tfile_set_encrypt(inode);\n+\tinode->i_flags |= S_ENCRYPTED;\n #endif\n }\n \ndiff --git a/fs/f2fs/inode.c b/fs/f2fs/inode.c\nindex 50c88e37ed66..53fb08810ee9 100644\n--- a/fs/f2fs/inode.c\n+++ b/fs/f2fs/inode.c\n@@ -43,8 +43,11 @@ void f2fs_set_inode_flags(struct inode *inode)\n \t\tnew_fl |= S_NOATIME;\n \tif (flags & FS_DIRSYNC_FL)\n \t\tnew_fl |= S_DIRSYNC;\n+\tif (f2fs_encrypted_inode(inode))\n+\t\tnew_fl |= S_ENCRYPTED;\n \tinode_set_flags(inode, new_fl,\n-\t\t\tS_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC);\n+\t\t\tS_SYNC|S_APPEND|S_IMMUTABLE|S_NOATIME|S_DIRSYNC|\n+\t\t\tS_ENCRYPTED);\n }\n \n static void __get_inode_rdev(struct inode *inode, struct f2fs_inode *ri)\ndiff --git a/fs/ubifs/ioctl.c b/fs/ubifs/ioctl.c\nindex fdc311246807..0164bcc827f8 100644\n--- a/fs/ubifs/ioctl.c\n+++ b/fs/ubifs/ioctl.c\n@@ -38,7 +38,8 @@ void ubifs_set_inode_flags(struct inode *inode)\n {\n \tunsigned int flags = ubifs_inode(inode)->flags;\n \n-\tinode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_DIRSYNC);\n+\tinode->i_flags &= ~(S_SYNC | S_APPEND | S_IMMUTABLE | S_DIRSYNC |\n+\t\t\t    S_ENCRYPTED);\n \tif (flags & UBIFS_SYNC_FL)\n \t\tinode->i_flags |= S_SYNC;\n \tif (flags & UBIFS_APPEND_FL)\n@@ -47,6 +48,8 @@ void ubifs_set_inode_flags(struct inode *inode)\n \t\tinode->i_flags |= S_IMMUTABLE;\n \tif (flags & UBIFS_DIRSYNC_FL)\n \t\tinode->i_flags |= S_DIRSYNC;\n+\tif (flags & UBIFS_CRYPT_FL)\n+\t\tinode->i_flags |= S_ENCRYPTED;\n }\n \n /*\ndiff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c\nindex c13eae819cbc..5ddc89d564fd 100644\n--- a/fs/ubifs/xattr.c\n+++ b/fs/ubifs/xattr.c\n@@ -170,6 +170,7 @@ static int create_xattr(struct ubifs_info *c, struct inode *host,\n \terr = ubifs_jnl_update(c, host, nm, inode, 0, 1);\n \tif (err)\n \t\tgoto out_cancel;\n+\tubifs_set_inode_flags(host);\n \tmutex_unlock(&host_ui->ui_mutex);\n \n \tubifs_release_budget(c, &req);\ndiff --git a/include/linux/fs.h b/include/linux/fs.h\nindex 339e73742e73..055d2fbf8eca 100644\n--- a/include/linux/fs.h\n+++ b/include/linux/fs.h\n@@ -1853,6 +1853,7 @@ struct super_operations {\n #else\n #define S_DAX\t\t0\t/* Make all the DAX code disappear */\n #endif\n+#define S_ENCRYPTED\t16384\t/* Encrypted file (using fs/crypto/) */\n \n /*\n  * Note that nosuid etc flags are inode-specific: setting some file-system\n@@ -1892,6 +1893,7 @@ static inline bool sb_rdonly(const struct super_block *sb) { return sb->s_flags\n #define IS_AUTOMOUNT(inode)\t((inode)->i_flags & S_AUTOMOUNT)\n #define IS_NOSEC(inode)\t\t((inode)->i_flags & S_NOSEC)\n #define IS_DAX(inode)\t\t((inode)->i_flags & S_DAX)\n+#define IS_ENCRYPTED(inode)\t((inode)->i_flags & S_ENCRYPTED)\n \n #define IS_WHITEOUT(inode)\t(S_ISCHR(inode->i_mode) && \\\n \t\t\t\t (inode)->i_rdev == WHITEOUT_DEV)\n","prefixes":["01/25"]}