bpf: reject invalid names right in ->lookup()
... and other methods won't see them at all Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
parent
798434bda3
commit
0c93b7d85d
|
@ -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,
|
||||||
{
|
{
|
||||||
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,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue