Commit 076e4ab3 authored by Al Viro's avatar Al Viro Committed by Greg Kroah-Hartman

don't put symlink bodies in pagecache into highmem

commit 21fc61c7 upstream.

kmap() in page_follow_link_light() needed to go - allowing to hold
an arbitrary number of kmaps for long is a great way to deadlocking
the system.

new helper (inode_nohighmem(inode)) needs to be used for pagecache
symlinks inodes; done for all in-tree cases.  page_follow_link_light()
instrumented to yell about anything missed.
Signed-off-by: default avatarAl Viro <viro@zeniv.linux.org.uk>
Signed-off-by: default avatarJin Qian <jinqian@google.com>
Signed-off-by: default avatarJin Qian <jinqian@android.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 33813d43
...@@ -4417,6 +4417,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino) ...@@ -4417,6 +4417,7 @@ struct inode *ext4_iget(struct super_block *sb, unsigned long ino)
inode->i_op = &ext4_symlink_inode_operations; inode->i_op = &ext4_symlink_inode_operations;
ext4_set_aops(inode); ext4_set_aops(inode);
} }
inode_nohighmem(inode);
} else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
inode->i_op = &ext4_special_inode_operations; inode->i_op = &ext4_special_inode_operations;
......
...@@ -3151,6 +3151,7 @@ static int ext4_symlink(struct inode *dir, ...@@ -3151,6 +3151,7 @@ static int ext4_symlink(struct inode *dir,
if ((disk_link.len > EXT4_N_BLOCKS * 4)) { if ((disk_link.len > EXT4_N_BLOCKS * 4)) {
if (!encryption_required) if (!encryption_required)
inode->i_op = &ext4_symlink_inode_operations; inode->i_op = &ext4_symlink_inode_operations;
inode_nohighmem(inode);
ext4_set_aops(inode); ext4_set_aops(inode);
/* /*
* We cannot call page_symlink() with transaction started * We cannot call page_symlink() with transaction started
......
...@@ -45,7 +45,7 @@ static const char *ext4_encrypted_follow_link(struct dentry *dentry, void **cook ...@@ -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); cpage = read_mapping_page(inode->i_mapping, 0, NULL);
if (IS_ERR(cpage)) if (IS_ERR(cpage))
return ERR_CAST(cpage); return ERR_CAST(cpage);
caddr = kmap(cpage); caddr = page_address(cpage);
caddr[size] = 0; caddr[size] = 0;
} }
...@@ -75,16 +75,12 @@ static const char *ext4_encrypted_follow_link(struct dentry *dentry, void **cook ...@@ -75,16 +75,12 @@ static const char *ext4_encrypted_follow_link(struct dentry *dentry, void **cook
/* Null-terminate the name */ /* Null-terminate the name */
if (res <= plen) if (res <= plen)
paddr[res] = '\0'; paddr[res] = '\0';
if (cpage) { if (cpage)
kunmap(cpage);
page_cache_release(cpage); page_cache_release(cpage);
}
return *cookie = paddr; return *cookie = paddr;
errout: errout:
if (cpage) { if (cpage)
kunmap(cpage);
page_cache_release(cpage); page_cache_release(cpage);
}
kfree(paddr); kfree(paddr);
return ERR_PTR(res); return ERR_PTR(res);
} }
......
...@@ -202,6 +202,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino) ...@@ -202,6 +202,7 @@ struct inode *f2fs_iget(struct super_block *sb, unsigned long ino)
inode->i_op = &f2fs_encrypted_symlink_inode_operations; inode->i_op = &f2fs_encrypted_symlink_inode_operations;
else else
inode->i_op = &f2fs_symlink_inode_operations; inode->i_op = &f2fs_symlink_inode_operations;
inode_nohighmem(inode);
inode->i_mapping->a_ops = &f2fs_dblock_aops; inode->i_mapping->a_ops = &f2fs_dblock_aops;
} else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) || } else if (S_ISCHR(inode->i_mode) || S_ISBLK(inode->i_mode) ||
S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) { S_ISFIFO(inode->i_mode) || S_ISSOCK(inode->i_mode)) {
......
...@@ -351,6 +351,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry, ...@@ -351,6 +351,7 @@ static int f2fs_symlink(struct inode *dir, struct dentry *dentry,
inode->i_op = &f2fs_encrypted_symlink_inode_operations; inode->i_op = &f2fs_encrypted_symlink_inode_operations;
else else
inode->i_op = &f2fs_symlink_inode_operations; inode->i_op = &f2fs_symlink_inode_operations;
inode_nohighmem(inode);
inode->i_mapping->a_ops = &f2fs_dblock_aops; inode->i_mapping->a_ops = &f2fs_dblock_aops;
f2fs_lock_op(sbi); f2fs_lock_op(sbi);
...@@ -942,7 +943,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook ...@@ -942,7 +943,7 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
cpage = read_mapping_page(inode->i_mapping, 0, NULL); cpage = read_mapping_page(inode->i_mapping, 0, NULL);
if (IS_ERR(cpage)) if (IS_ERR(cpage))
return ERR_CAST(cpage); return ERR_CAST(cpage);
caddr = kmap(cpage); caddr = page_address(cpage);
caddr[size] = 0; caddr[size] = 0;
/* Symlink is encrypted */ /* Symlink is encrypted */
...@@ -982,13 +983,11 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook ...@@ -982,13 +983,11 @@ static const char *f2fs_encrypted_follow_link(struct dentry *dentry, void **cook
/* Null-terminate the name */ /* Null-terminate the name */
paddr[res] = '\0'; paddr[res] = '\0';
kunmap(cpage);
page_cache_release(cpage); page_cache_release(cpage);
return *cookie = paddr; return *cookie = paddr;
errout: errout:
kfree(cstr.name); kfree(cstr.name);
f2fs_fname_crypto_free_buffer(&pstr); f2fs_fname_crypto_free_buffer(&pstr);
kunmap(cpage);
page_cache_release(cpage); page_cache_release(cpage);
return ERR_PTR(res); return ERR_PTR(res);
} }
......
...@@ -2028,3 +2028,9 @@ void inode_set_flags(struct inode *inode, unsigned int flags, ...@@ -2028,3 +2028,9 @@ void inode_set_flags(struct inode *inode, unsigned int flags,
new_flags) != old_flags)); new_flags) != old_flags));
} }
EXPORT_SYMBOL(inode_set_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);
...@@ -3066,5 +3066,6 @@ static inline bool dir_relax(struct inode *inode) ...@@ -3066,5 +3066,6 @@ static inline bool dir_relax(struct inode *inode)
} }
extern bool path_noexec(const struct path *path); extern bool path_noexec(const struct path *path);
extern void inode_nohighmem(struct inode *inode);
#endif /* _LINUX_FS_H */ #endif /* _LINUX_FS_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment