Commit 9e17632c authored by Linus Torvalds's avatar Linus Torvalds

Merge branch 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs

Pull misc vfs cleanups from Al Viro:
 "Assorted cleanups and fixes all over the place"

* 'work.misc' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs:
  coredump: only charge written data against RLIMIT_CORE
  coredump: get rid of coredump_params->written
  ecryptfs_lookup(): try either only encrypted or plaintext name
  ecryptfs: avoid multiple aliases for directories
  bpf: reject invalid names right in ->lookup()
  __d_alloc(): treat NULL name as QSTR("/", 1)
  mtd: switch ubi_open_volume_path() to vfs_stat()
  mtd: switch open_mtd_by_chdev() to use of vfs_stat()
parents 69370471 2c4cb043
...@@ -137,6 +137,7 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i, ...@@ -137,6 +137,7 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i,
char *name; char *name;
char fullname[80], *buf; char fullname[80], *buf;
struct elf_note en; struct elf_note en;
size_t skip;
buf = (void *)get_zeroed_page(GFP_KERNEL); buf = (void *)get_zeroed_page(GFP_KERNEL);
if (!buf) if (!buf)
...@@ -171,8 +172,8 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i, ...@@ -171,8 +172,8 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i,
if (rc < 0) if (rc < 0)
goto out; goto out;
if (!dump_skip(cprm, skip = roundup(cprm->file->f_pos - total + sz, 4) - cprm->file->f_pos;
roundup(cprm->written - total + sz, 4) - cprm->written)) if (!dump_skip(cprm, skip))
goto Eio; goto Eio;
out: out:
free_page((unsigned long)buf); free_page((unsigned long)buf);
......
...@@ -1142,22 +1142,19 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway) ...@@ -1142,22 +1142,19 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
*/ */
static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev) static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
{ {
int err, major, minor, mode; struct kstat stat;
struct path path; int err, minor;
/* Probably this is an MTD character device node path */ /* Probably this is an MTD character device node path */
err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path); err = vfs_stat(mtd_dev, &stat);
if (err) if (err)
return ERR_PTR(err); return ERR_PTR(err);
/* MTD device number is defined by the major / minor numbers */ /* MTD device number is defined by the major / minor numbers */
major = imajor(d_backing_inode(path.dentry)); if (MAJOR(stat.rdev) != MTD_CHAR_MAJOR || !S_ISCHR(stat.mode))
minor = iminor(d_backing_inode(path.dentry));
mode = d_backing_inode(path.dentry)->i_mode;
path_put(&path);
if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
minor = MINOR(stat.rdev);
if (minor & 1) if (minor & 1)
/* /*
* Just do not think the "/dev/mtdrX" devices support is need, * Just do not think the "/dev/mtdrX" devices support is need,
......
...@@ -301,27 +301,24 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm); ...@@ -301,27 +301,24 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
*/ */
struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode) struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
{ {
int error, ubi_num, vol_id, mod; int error, ubi_num, vol_id;
struct inode *inode; struct kstat stat;
struct path path;
dbg_gen("open volume %s, mode %d", pathname, mode); dbg_gen("open volume %s, mode %d", pathname, mode);
if (!pathname || !*pathname) if (!pathname || !*pathname)
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
error = kern_path(pathname, LOOKUP_FOLLOW, &path); error = vfs_stat(pathname, &stat);
if (error) if (error)
return ERR_PTR(error); return ERR_PTR(error);
inode = d_backing_inode(path.dentry); if (!S_ISCHR(stat.mode))
mod = inode->i_mode;
ubi_num = ubi_major2num(imajor(inode));
vol_id = iminor(inode) - 1;
path_put(&path);
if (!S_ISCHR(mod))
return ERR_PTR(-EINVAL); return ERR_PTR(-EINVAL);
ubi_num = ubi_major2num(MAJOR(stat.rdev));
vol_id = MINOR(stat.rdev) - 1;
if (vol_id >= 0 && ubi_num >= 0) if (vol_id >= 0 && ubi_num >= 0)
return ubi_open_volume(ubi_num, vol_id, mode); return ubi_open_volume(ubi_num, vol_id, mode);
return ERR_PTR(-ENODEV); return ERR_PTR(-ENODEV);
......
...@@ -2273,7 +2273,7 @@ static int elf_core_dump(struct coredump_params *cprm) ...@@ -2273,7 +2273,7 @@ static int elf_core_dump(struct coredump_params *cprm)
goto end_coredump; goto end_coredump;
/* Align to page */ /* Align to page */
if (!dump_skip(cprm, dataoff - cprm->written)) if (!dump_skip(cprm, dataoff - cprm->file->f_pos))
goto end_coredump; goto end_coredump;
for (i = 0, vma = first_vma(current, gate_vma); vma != NULL; for (i = 0, vma = first_vma(current, gate_vma); vma != NULL;
......
...@@ -1787,7 +1787,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm) ...@@ -1787,7 +1787,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
goto end_coredump; goto end_coredump;
} }
if (!dump_skip(cprm, dataoff - cprm->written)) if (!dump_skip(cprm, dataoff - cprm->file->f_pos))
goto end_coredump; goto end_coredump;
if (!elf_fdpic_dump_segments(cprm)) if (!elf_fdpic_dump_segments(cprm))
......
...@@ -803,12 +803,9 @@ int dump_skip(struct coredump_params *cprm, size_t nr) ...@@ -803,12 +803,9 @@ int dump_skip(struct coredump_params *cprm, size_t nr)
static char zeroes[PAGE_SIZE]; static char zeroes[PAGE_SIZE];
struct file *file = cprm->file; struct file *file = cprm->file;
if (file->f_op->llseek && file->f_op->llseek != no_llseek) { if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
if (cprm->written + nr > cprm->limit)
return 0;
if (dump_interrupted() || if (dump_interrupted() ||
file->f_op->llseek(file, nr, SEEK_CUR) < 0) file->f_op->llseek(file, nr, SEEK_CUR) < 0)
return 0; return 0;
cprm->written += nr;
return 1; return 1;
} else { } else {
while (nr > PAGE_SIZE) { while (nr > PAGE_SIZE) {
...@@ -823,7 +820,7 @@ EXPORT_SYMBOL(dump_skip); ...@@ -823,7 +820,7 @@ EXPORT_SYMBOL(dump_skip);
int dump_align(struct coredump_params *cprm, int align) int dump_align(struct coredump_params *cprm, int align)
{ {
unsigned mod = cprm->written & (align - 1); unsigned mod = cprm->file->f_pos & (align - 1);
if (align & (align - 1)) if (align & (align - 1))
return 0; return 0;
return mod ? dump_skip(cprm, align - mod) : 1; return mod ? dump_skip(cprm, align - mod) : 1;
......
...@@ -1571,7 +1571,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name) ...@@ -1571,7 +1571,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
* be overwriting an internal NUL character * be overwriting an internal NUL character
*/ */
dentry->d_iname[DNAME_INLINE_LEN-1] = 0; dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
if (name->len > DNAME_INLINE_LEN-1) { if (unlikely(!name)) {
static const struct qstr anon = QSTR_INIT("/", 1);
name = &anon;
dname = dentry->d_iname;
} else if (name->len > DNAME_INLINE_LEN-1) {
size_t size = offsetof(struct external_name, name[1]); size_t size = offsetof(struct external_name, name[1]);
struct external_name *p = kmalloc(size + name->len, struct external_name *p = kmalloc(size + name->len,
GFP_KERNEL_ACCOUNT); GFP_KERNEL_ACCOUNT);
...@@ -1829,9 +1833,7 @@ struct dentry *d_make_root(struct inode *root_inode) ...@@ -1829,9 +1833,7 @@ struct dentry *d_make_root(struct inode *root_inode)
struct dentry *res = NULL; struct dentry *res = NULL;
if (root_inode) { if (root_inode) {
static const struct qstr name = QSTR_INIT("/", 1); res = __d_alloc(root_inode->i_sb, NULL);
res = __d_alloc(root_inode->i_sb, &name);
if (res) if (res)
d_instantiate(res, root_inode); d_instantiate(res, root_inode);
else else
...@@ -1872,7 +1874,6 @@ EXPORT_SYMBOL(d_find_any_alias); ...@@ -1872,7 +1874,6 @@ EXPORT_SYMBOL(d_find_any_alias);
static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected) static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected)
{ {
static const struct qstr anonstring = QSTR_INIT("/", 1);
struct dentry *tmp; struct dentry *tmp;
struct dentry *res; struct dentry *res;
unsigned add_flags; unsigned add_flags;
...@@ -1886,7 +1887,7 @@ static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected) ...@@ -1886,7 +1887,7 @@ static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected)
if (res) if (res)
goto out_iput; goto out_iput;
tmp = __d_alloc(inode->i_sb, &anonstring); tmp = __d_alloc(inode->i_sb, NULL);
if (!tmp) { if (!tmp) {
res = ERR_PTR(-ENOMEM); res = ERR_PTR(-ENOMEM);
goto out_iput; goto out_iput;
......
...@@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode) ...@@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
/** /**
* ecryptfs_lookup_interpose - Dentry interposition for a lookup * ecryptfs_lookup_interpose - Dentry interposition for a lookup
*/ */
static int ecryptfs_lookup_interpose(struct dentry *dentry, static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
struct dentry *lower_dentry, struct dentry *lower_dentry)
struct inode *dir_inode)
{ {
struct inode *inode, *lower_inode = d_inode(lower_dentry); struct inode *inode, *lower_inode = d_inode(lower_dentry);
struct ecryptfs_dentry_info *dentry_info; struct ecryptfs_dentry_info *dentry_info;
...@@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry, ...@@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
"to allocate ecryptfs_dentry_info struct\n", "to allocate ecryptfs_dentry_info struct\n",
__func__); __func__);
dput(lower_dentry); dput(lower_dentry);
return -ENOMEM; return ERR_PTR(-ENOMEM);
} }
lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent)); lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
fsstack_copy_attr_atime(dir_inode, d_inode(lower_dentry->d_parent)); fsstack_copy_attr_atime(d_inode(dentry->d_parent),
d_inode(lower_dentry->d_parent));
BUG_ON(!d_count(lower_dentry)); BUG_ON(!d_count(lower_dentry));
ecryptfs_set_dentry_private(dentry, dentry_info); ecryptfs_set_dentry_private(dentry, dentry_info);
...@@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry, ...@@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
if (d_really_is_negative(lower_dentry)) { if (d_really_is_negative(lower_dentry)) {
/* We want to add because we couldn't find in lower */ /* We want to add because we couldn't find in lower */
d_add(dentry, NULL); d_add(dentry, NULL);
return 0; return NULL;
} }
inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb); inode = __ecryptfs_get_inode(lower_inode, dentry->d_sb);
if (IS_ERR(inode)) { if (IS_ERR(inode)) {
printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n", printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
__func__, PTR_ERR(inode)); __func__, PTR_ERR(inode));
return PTR_ERR(inode); return ERR_CAST(inode);
} }
if (S_ISREG(inode->i_mode)) { if (S_ISREG(inode->i_mode)) {
rc = ecryptfs_i_size_read(dentry, inode); rc = ecryptfs_i_size_read(dentry, inode);
if (rc) { if (rc) {
make_bad_inode(inode); make_bad_inode(inode);
return rc; return ERR_PTR(rc);
} }
} }
if (inode->i_state & I_NEW) if (inode->i_state & I_NEW)
unlock_new_inode(inode); unlock_new_inode(inode);
d_add(dentry, inode); return d_splice_alias(inode, dentry);
return rc;
} }
/** /**
...@@ -390,55 +388,42 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode, ...@@ -390,55 +388,42 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
unsigned int flags) unsigned int flags)
{ {
char *encrypted_and_encoded_name = NULL; char *encrypted_and_encoded_name = NULL;
size_t encrypted_and_encoded_name_size; struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
struct dentry *lower_dir_dentry, *lower_dentry; struct dentry *lower_dir_dentry, *lower_dentry;
const char *name = ecryptfs_dentry->d_name.name;
size_t len = ecryptfs_dentry->d_name.len;
struct dentry *res;
int rc = 0; int rc = 0;
lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent); lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
lower_dentry = lookup_one_len_unlocked(ecryptfs_dentry->d_name.name,
lower_dir_dentry,
ecryptfs_dentry->d_name.len);
if (IS_ERR(lower_dentry)) {
rc = PTR_ERR(lower_dentry);
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
"[%d] on lower_dentry = [%pd]\n", __func__, rc,
ecryptfs_dentry);
goto out;
}
if (d_really_is_positive(lower_dentry))
goto interpose;
mount_crypt_stat = &ecryptfs_superblock_to_private( mount_crypt_stat = &ecryptfs_superblock_to_private(
ecryptfs_dentry->d_sb)->mount_crypt_stat; ecryptfs_dentry->d_sb)->mount_crypt_stat;
if (!(mount_crypt_stat if (mount_crypt_stat
&& (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES))) && (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)) {
goto interpose; rc = ecryptfs_encrypt_and_encode_filename(
dput(lower_dentry); &encrypted_and_encoded_name, &len,
rc = ecryptfs_encrypt_and_encode_filename( mount_crypt_stat, name, len);
&encrypted_and_encoded_name, &encrypted_and_encoded_name_size, if (rc) {
mount_crypt_stat, ecryptfs_dentry->d_name.name, printk(KERN_ERR "%s: Error attempting to encrypt and encode "
ecryptfs_dentry->d_name.len); "filename; rc = [%d]\n", __func__, rc);
if (rc) { return ERR_PTR(rc);
printk(KERN_ERR "%s: Error attempting to encrypt and encode " }
"filename; rc = [%d]\n", __func__, rc); name = encrypted_and_encoded_name;
goto out;
} }
lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name,
lower_dir_dentry, lower_dentry = lookup_one_len_unlocked(name, lower_dir_dentry, len);
encrypted_and_encoded_name_size);
if (IS_ERR(lower_dentry)) { if (IS_ERR(lower_dentry)) {
rc = PTR_ERR(lower_dentry);
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned " ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
"[%d] on lower_dentry = [%s]\n", __func__, rc, "[%ld] on lower_dentry = [%s]\n", __func__,
encrypted_and_encoded_name); PTR_ERR(lower_dentry),
goto out; name);
res = ERR_CAST(lower_dentry);
} else {
res = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry);
} }
interpose:
rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry,
ecryptfs_dir_inode);
out:
kfree(encrypted_and_encoded_name); kfree(encrypted_and_encoded_name);
return ERR_PTR(rc); return res;
} }
static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir, static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,
......
...@@ -119,18 +119,10 @@ static int bpf_inode_type(const struct inode *inode, enum bpf_type *type) ...@@ -119,18 +119,10 @@ static int bpf_inode_type(const struct inode *inode, enum bpf_type *type)
return 0; return 0;
} }
static bool bpf_dname_reserved(const struct dentry *dentry)
{
return strchr(dentry->d_name.name, '.');
}
static int bpf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode) static int bpf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
{ {
struct inode *inode; struct inode *inode;
if (bpf_dname_reserved(dentry))
return -EPERM;
inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFDIR); inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFDIR);
if (IS_ERR(inode)) if (IS_ERR(inode))
return PTR_ERR(inode); return PTR_ERR(inode);
...@@ -152,9 +144,6 @@ static int bpf_mkobj_ops(struct inode *dir, struct dentry *dentry, ...@@ -152,9 +144,6 @@ static int bpf_mkobj_ops(struct inode *dir, struct dentry *dentry,
{ {
struct inode *inode; struct inode *inode;
if (bpf_dname_reserved(dentry))
return -EPERM;
inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFREG); inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFREG);
if (IS_ERR(inode)) if (IS_ERR(inode))
return PTR_ERR(inode); return PTR_ERR(inode);
...@@ -187,31 +176,21 @@ static int bpf_mkobj(struct inode *dir, struct dentry *dentry, umode_t mode, ...@@ -187,31 +176,21 @@ static int bpf_mkobj(struct inode *dir, struct dentry *dentry, umode_t mode,
} }
} }
static int bpf_link(struct dentry *old_dentry, struct inode *dir, static struct dentry *
struct dentry *new_dentry) bpf_lookup(struct inode *dir, struct dentry *dentry, unsigned flags)
{ {
if (bpf_dname_reserved(new_dentry)) if (strchr(dentry->d_name.name, '.'))
return -EPERM; return ERR_PTR(-EPERM);
return simple_lookup(dir, dentry, flags);
return simple_link(old_dentry, dir, new_dentry);
}
static int bpf_rename(struct inode *old_dir, struct dentry *old_dentry,
struct inode *new_dir, struct dentry *new_dentry)
{
if (bpf_dname_reserved(new_dentry))
return -EPERM;
return simple_rename(old_dir, old_dentry, new_dir, new_dentry);
} }
static const struct inode_operations bpf_dir_iops = { static const struct inode_operations bpf_dir_iops = {
.lookup = simple_lookup, .lookup = bpf_lookup,
.mknod = bpf_mkobj, .mknod = bpf_mkobj,
.mkdir = bpf_mkdir, .mkdir = bpf_mkdir,
.rmdir = simple_rmdir, .rmdir = simple_rmdir,
.rename = bpf_rename, .rename = simple_rename,
.link = bpf_link, .link = simple_link,
.unlink = simple_unlink, .unlink = simple_unlink,
}; };
......
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