Skip to content

Commit 0c93b7d

Browse files
author
Al Viro
committed
bpf: reject invalid names right in ->lookup()
... and other methods won't see them at all Signed-off-by: Al Viro <[email protected]>
1 parent 798434b commit 0c93b7d

File tree

1 file changed

+8
-29
lines changed

1 file changed

+8
-29
lines changed

kernel/bpf/inode.c

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -119,18 +119,10 @@ static int bpf_inode_type(const struct inode *inode, enum bpf_type *type)
119119
return 0;
120120
}
121121

122-
static bool bpf_dname_reserved(const struct dentry *dentry)
123-
{
124-
return strchr(dentry->d_name.name, '.');
125-
}
126-
127122
static int bpf_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
128123
{
129124
struct inode *inode;
130125

131-
if (bpf_dname_reserved(dentry))
132-
return -EPERM;
133-
134126
inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFDIR);
135127
if (IS_ERR(inode))
136128
return PTR_ERR(inode);
@@ -152,9 +144,6 @@ static int bpf_mkobj_ops(struct inode *dir, struct dentry *dentry,
152144
{
153145
struct inode *inode;
154146

155-
if (bpf_dname_reserved(dentry))
156-
return -EPERM;
157-
158147
inode = bpf_get_inode(dir->i_sb, dir, mode | S_IFREG);
159148
if (IS_ERR(inode))
160149
return PTR_ERR(inode);
@@ -187,31 +176,21 @@ static int bpf_mkobj(struct inode *dir, struct dentry *dentry, umode_t mode,
187176
}
188177
}
189178

190-
static int bpf_link(struct dentry *old_dentry, struct inode *dir,
191-
struct dentry *new_dentry)
179+
static struct dentry *
180+
bpf_lookup(struct inode *dir, struct dentry *dentry, unsigned flags)
192181
{
193-
if (bpf_dname_reserved(new_dentry))
194-
return -EPERM;
195-
196-
return simple_link(old_dentry, dir, new_dentry);
197-
}
198-
199-
static int bpf_rename(struct inode *old_dir, struct dentry *old_dentry,
200-
struct inode *new_dir, struct dentry *new_dentry)
201-
{
202-
if (bpf_dname_reserved(new_dentry))
203-
return -EPERM;
204-
205-
return simple_rename(old_dir, old_dentry, new_dir, new_dentry);
182+
if (strchr(dentry->d_name.name, '.'))
183+
return ERR_PTR(-EPERM);
184+
return simple_lookup(dir, dentry, flags);
206185
}
207186

208187
static const struct inode_operations bpf_dir_iops = {
209-
.lookup = simple_lookup,
188+
.lookup = bpf_lookup,
210189
.mknod = bpf_mkobj,
211190
.mkdir = bpf_mkdir,
212191
.rmdir = simple_rmdir,
213-
.rename = bpf_rename,
214-
.link = bpf_link,
192+
.rename = simple_rename,
193+
.link = simple_link,
215194
.unlink = simple_unlink,
216195
};
217196

0 commit comments

Comments
 (0)