From patchwork Tue Feb 6 19:09:37 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jin Qian X-Patchwork-Id: 10203819 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id C9E4860247 for ; Tue, 6 Feb 2018 19:10:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CEDCD28B8B for ; Tue, 6 Feb 2018 19:10:30 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C386828BF3; Tue, 6 Feb 2018 19:10:30 +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=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6DBCC28B8B for ; Tue, 6 Feb 2018 19:10:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753296AbeBFTKT (ORCPT ); Tue, 6 Feb 2018 14:10:19 -0500 Received: from mail-pg0-f68.google.com ([74.125.83.68]:41838 "EHLO mail-pg0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753174AbeBFTKK (ORCPT ); Tue, 6 Feb 2018 14:10:10 -0500 Received: by mail-pg0-f68.google.com with SMTP id 141so1471876pgd.8 for ; Tue, 06 Feb 2018 11:10:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=android.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=/caUWH55Y+w54z4PzZ4UVlaVApxGqdUQM/AOh34qZmQ=; b=kuE/4/OLDFXT+OXbosebqdBNNSQ8296BwvDXpMgi8rNbvjnUk13A90Di55TLy8NmnI FP5g2Ll6YNIM1IMNgKb7DYpZ0Z2onX1zlKf1iuq/Hv1pk01vKr9Hj4FDWF9DH8CncUhb UPvFbL/acJP/L4slLO5S0KQ/NvKKM+sNZ7wfdRO2ntWDZHjp+Vxpv/EsqaC6HsiKadx2 9OHdvcwtBphHoViv4yZNelwLjhzuMo5KpEM65HJG1gvEDXYC4ePoQxUcj+To8SoQb1qJ lTY7p6pK9KlX1xVVo2ahP6u0cJOIaIfwKrGdtdvDVKtU5aEPQHoQTFpXWMSl4O3vb5YG 7uQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=/caUWH55Y+w54z4PzZ4UVlaVApxGqdUQM/AOh34qZmQ=; b=sLAf3PInjFgz2e+DWany0KO7HSFtXDS7bqOHI68YNVozQ2hJtDa7tW1P/+bQ2l01TX em8PbAq1UfA1oJgiV6nkz7s+4Sm/9NhqMRlB9QLhG0HOYUtKUwEM1c1EGUFcOOX6Y91r BFrc2LoB+P5iH31TFlHarIiCS0lhIYzUKjlsHu0zzoawkMOEkHPlz3p5XyHCDw8Aa3el GQTVtZ3r8ooHS+B7o0kdO2zVIXNe9NEIP6rMtUsGCc143vs/RNSSsyPSOzoMDhRkJJmG mk07VMiMIN4mCy8ki5qT1a9UXpfCgZSSQzjmNg0IwHRe9BTTT1kNPOh5Sy/DLT7IHlLo Quzw== X-Gm-Message-State: APf1xPBqOWVmH/bmoUqNNWBhOJ+D/2OLqg+4+ZFs7nVB9xqq9IGX1MVW joMPlRnqFsi2aLouV6DE8lzESw== X-Google-Smtp-Source: AH8x225IjWBMXHm6HfehB0lmwhViANsWQI0xqeZiRMDFO38TEbCeXOdNBtSZ01d0EHh7H8hBIyD4hQ== X-Received: by 10.99.174.7 with SMTP id q7mr2740822pgf.170.1517944209588; Tue, 06 Feb 2018 11:10:09 -0800 (PST) Received: from jinqian2.mtv.corp.google.com ([2620:0:1000:1601:756c:3217:2035:e37b]) by smtp.gmail.com with ESMTPSA id o135sm23162169pfg.161.2018.02.06.11.10.07 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 06 Feb 2018 11:10:08 -0800 (PST) From: Jin Qian To: "Theodore Ts'o" , Andreas Dilger , Alexander Viro , Jeff Layton , "J. Bruce Fields" , linux-ext4@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: Jin Qian , stable@vger.kernel.org, Jin Qian Subject: [PATCHv2 1/1] ext4: don't put symlink in pagecache into highmem Date: Tue, 6 Feb 2018 11:09:37 -0800 Message-Id: <20180206190938.172792-1-jinqian@android.com> X-Mailer: git-send-email 2.16.0.rc1.238.g530d649a79-goog Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Jin Qian partial backport from 21fc61c73c3903c4c312d0802da01ec2b323d174 upstream to v4.4 to prevent virt_to_page on highmem. ext4_encrypted_follow_link uses kmap() for cpage caddr = kmap(cpage); _ext4_fname_disk_to_usr calls virt_to_page on the kmapped address. _ext4_fname_disk_to_usr() ext4_fname_decrypt() sg_init_one() sg_init_one(&src_sg, iname->name, iname->len); sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf)); Cc: stable@vger.kernel.org Signed-off-by: Al Viro Signed-off-by: Jin Qian Signed-off-by: Jin Qian --- fs/ext4/inode.c | 1 + fs/ext4/namei.c | 1 + fs/ext4/symlink.c | 10 +++------- fs/inode.c | 6 ++++++ include/linux/fs.h | 1 + 5 files changed, 12 insertions(+), 7 deletions(-) diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 4df1cb19a243..f0cabc8c96cb 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c @@ -4417,6 +4417,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) inode->i_op = &ext4_symlink_inode_operations; ext4_set_aops(inode); } + inode_nohighmem(inode); } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { inode->i_op = &ext4_special_inode_operations; diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index 4c36dca486cc..32960b3ecd4f 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -3151,6 +3151,7 @@ static int ext4_symlink(struct inode *dir, if ((disk_link.len > EXT4_N_BLOCKS * 4)) { if (!encryption_required) inode->i_op = &ext4_symlink_inode_operations; + inode_nohighmem(inode); ext4_set_aops(inode); /* * We cannot call page_symlink() with transaction started diff --git a/fs/ext4/symlink.c b/fs/ext4/symlink.c index e8e7af62ac95..287c3980fa0b 100644 --- a/fs/ext4/symlink.c +++ b/fs/ext4/symlink.c @@ -45,7 +45,7 @@ static const char *ext4_encrypted_follow_link(struct dentry *dentry, void **cook cpage = read_mapping_page(inode->i_mapping, 0, NULL); if (IS_ERR(cpage)) return ERR_CAST(cpage); - caddr = kmap(cpage); + caddr = page_address(cpage); caddr[size] = 0; } @@ -75,16 +75,12 @@ static const char *ext4_encrypted_follow_link(struct dentry *dentry, void **cook /* Null-terminate the name */ if (res <= plen) paddr[res] = '\0'; - if (cpage) { - kunmap(cpage); + if (cpage) page_cache_release(cpage); - } return *cookie = paddr; errout: - if (cpage) { - kunmap(cpage); + if (cpage) page_cache_release(cpage); - } kfree(paddr); return ERR_PTR(res); } diff --git a/fs/inode.c b/fs/inode.c index b0edef500590..b95615f3fc50 100644 --- a/fs/inode.c +++ b/fs/inode.c @@ -2028,3 +2028,9 @@ void inode_set_flags(struct inode *inode, unsigned int flags, new_flags) != old_flags)); } EXPORT_SYMBOL(inode_set_flags); + +void inode_nohighmem(struct inode *inode) +{ + mapping_set_gfp_mask(inode->i_mapping, GFP_USER); +} +EXPORT_SYMBOL(inode_nohighmem); diff --git a/include/linux/fs.h b/include/linux/fs.h index c8decb7075d6..f746a59fcc88 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -3066,5 +3066,6 @@ static inline bool dir_relax(struct inode *inode) } extern bool path_noexec(const struct path *path); +extern void inode_nohighmem(struct inode *inode); #endif /* _LINUX_FS_H */