Skip to content

Commit 9e17632

Browse files
committed
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()
2 parents 6937047 + 2c4cb04 commit 9e17632

9 files changed

Lines changed: 69 additions & 112 deletions

File tree

‎arch/powerpc/platforms/cell/spufs/coredump.c‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i,
137137
char *name;
138138
char fullname[80], *buf;
139139
struct elf_note en;
140+
size_t skip;
140141

141142
buf = (void *)get_zeroed_page(GFP_KERNEL);
142143
if (!buf)
@@ -171,8 +172,8 @@ static int spufs_arch_write_note(struct spu_context *ctx, int i,
171172
if (rc < 0)
172173
goto out;
173174

174-
if (!dump_skip(cprm,
175-
roundup(cprm->written - total + sz, 4) - cprm->written))
175+
skip = roundup(cprm->file->f_pos - total + sz, 4) - cprm->file->f_pos;
176+
if (!dump_skip(cprm, skip))
176177
goto Eio;
177178
out:
178179
free_page((unsigned long)buf);

‎drivers/mtd/ubi/build.c‎

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1142,22 +1142,19 @@ int ubi_detach_mtd_dev(int ubi_num, int anyway)
11421142
*/
11431143
static struct mtd_info * __init open_mtd_by_chdev(const char *mtd_dev)
11441144
{
1145-
int err, major, minor, mode;
1146-
struct path path;
1145+
struct kstat stat;
1146+
int err, minor;
11471147

11481148
/* Probably this is an MTD character device node path */
1149-
err = kern_path(mtd_dev, LOOKUP_FOLLOW, &path);
1149+
err = vfs_stat(mtd_dev, &stat);
11501150
if (err)
11511151
return ERR_PTR(err);
11521152

11531153
/* MTD device number is defined by the major / minor numbers */
1154-
major = imajor(d_backing_inode(path.dentry));
1155-
minor = iminor(d_backing_inode(path.dentry));
1156-
mode = d_backing_inode(path.dentry)->i_mode;
1157-
path_put(&path);
1158-
if (major != MTD_CHAR_MAJOR || !S_ISCHR(mode))
1154+
if (MAJOR(stat.rdev) != MTD_CHAR_MAJOR || !S_ISCHR(stat.mode))
11591155
return ERR_PTR(-EINVAL);
11601156

1157+
minor = MINOR(stat.rdev);
11611158
if (minor & 1)
11621159
/*
11631160
* Just do not think the "/dev/mtdrX" devices support is need,

‎drivers/mtd/ubi/kapi.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -301,27 +301,24 @@ EXPORT_SYMBOL_GPL(ubi_open_volume_nm);
301301
*/
302302
struct ubi_volume_desc *ubi_open_volume_path(const char *pathname, int mode)
303303
{
304-
int error, ubi_num, vol_id, mod;
305-
struct inode *inode;
306-
struct path path;
304+
int error, ubi_num, vol_id;
305+
struct kstat stat;
307306

308307
dbg_gen("open volume %s, mode %d", pathname, mode);
309308

310309
if (!pathname || !*pathname)
311310
return ERR_PTR(-EINVAL);
312311

313-
error = kern_path(pathname, LOOKUP_FOLLOW, &path);
312+
error = vfs_stat(pathname, &stat);
314313
if (error)
315314
return ERR_PTR(error);
316315

317-
inode = d_backing_inode(path.dentry);
318-
mod = inode->i_mode;
319-
ubi_num = ubi_major2num(imajor(inode));
320-
vol_id = iminor(inode) - 1;
321-
path_put(&path);
322-
323-
if (!S_ISCHR(mod))
316+
if (!S_ISCHR(stat.mode))
324317
return ERR_PTR(-EINVAL);
318+
319+
ubi_num = ubi_major2num(MAJOR(stat.rdev));
320+
vol_id = MINOR(stat.rdev) - 1;
321+
325322
if (vol_id >= 0 && ubi_num >= 0)
326323
return ubi_open_volume(ubi_num, vol_id, mode);
327324
return ERR_PTR(-ENODEV);

‎fs/binfmt_elf.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2273,7 +2273,7 @@ static int elf_core_dump(struct coredump_params *cprm)
22732273
goto end_coredump;
22742274

22752275
/* Align to page */
2276-
if (!dump_skip(cprm, dataoff - cprm->written))
2276+
if (!dump_skip(cprm, dataoff - cprm->file->f_pos))
22772277
goto end_coredump;
22782278

22792279
for (i = 0, vma = first_vma(current, gate_vma); vma != NULL;

‎fs/binfmt_elf_fdpic.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1787,7 +1787,7 @@ static int elf_fdpic_core_dump(struct coredump_params *cprm)
17871787
goto end_coredump;
17881788
}
17891789

1790-
if (!dump_skip(cprm, dataoff - cprm->written))
1790+
if (!dump_skip(cprm, dataoff - cprm->file->f_pos))
17911791
goto end_coredump;
17921792

17931793
if (!elf_fdpic_dump_segments(cprm))

‎fs/coredump.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -803,12 +803,9 @@ int dump_skip(struct coredump_params *cprm, size_t nr)
803803
static char zeroes[PAGE_SIZE];
804804
struct file *file = cprm->file;
805805
if (file->f_op->llseek && file->f_op->llseek != no_llseek) {
806-
if (cprm->written + nr > cprm->limit)
807-
return 0;
808806
if (dump_interrupted() ||
809807
file->f_op->llseek(file, nr, SEEK_CUR) < 0)
810808
return 0;
811-
cprm->written += nr;
812809
return 1;
813810
} else {
814811
while (nr > PAGE_SIZE) {
@@ -823,7 +820,7 @@ EXPORT_SYMBOL(dump_skip);
823820

824821
int dump_align(struct coredump_params *cprm, int align)
825822
{
826-
unsigned mod = cprm->written & (align - 1);
823+
unsigned mod = cprm->file->f_pos & (align - 1);
827824
if (align & (align - 1))
828825
return 0;
829826
return mod ? dump_skip(cprm, align - mod) : 1;

‎fs/dcache.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1571,7 +1571,11 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
15711571
* be overwriting an internal NUL character
15721572
*/
15731573
dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
1574-
if (name->len > DNAME_INLINE_LEN-1) {
1574+
if (unlikely(!name)) {
1575+
static const struct qstr anon = QSTR_INIT("/", 1);
1576+
name = &anon;
1577+
dname = dentry->d_iname;
1578+
} else if (name->len > DNAME_INLINE_LEN-1) {
15751579
size_t size = offsetof(struct external_name, name[1]);
15761580
struct external_name *p = kmalloc(size + name->len,
15771581
GFP_KERNEL_ACCOUNT);
@@ -1829,9 +1833,7 @@ struct dentry *d_make_root(struct inode *root_inode)
18291833
struct dentry *res = NULL;
18301834

18311835
if (root_inode) {
1832-
static const struct qstr name = QSTR_INIT("/", 1);
1833-
1834-
res = __d_alloc(root_inode->i_sb, &name);
1836+
res = __d_alloc(root_inode->i_sb, NULL);
18351837
if (res)
18361838
d_instantiate(res, root_inode);
18371839
else
@@ -1872,7 +1874,6 @@ EXPORT_SYMBOL(d_find_any_alias);
18721874

18731875
static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected)
18741876
{
1875-
static const struct qstr anonstring = QSTR_INIT("/", 1);
18761877
struct dentry *tmp;
18771878
struct dentry *res;
18781879
unsigned add_flags;
@@ -1886,7 +1887,7 @@ static struct dentry *__d_obtain_alias(struct inode *inode, int disconnected)
18861887
if (res)
18871888
goto out_iput;
18881889

1889-
tmp = __d_alloc(inode->i_sb, &anonstring);
1890+
tmp = __d_alloc(inode->i_sb, NULL);
18901891
if (!tmp) {
18911892
res = ERR_PTR(-ENOMEM);
18921893
goto out_iput;

‎fs/ecryptfs/inode.c‎

Lines changed: 35 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -324,9 +324,8 @@ static int ecryptfs_i_size_read(struct dentry *dentry, struct inode *inode)
324324
/**
325325
* ecryptfs_lookup_interpose - Dentry interposition for a lookup
326326
*/
327-
static int ecryptfs_lookup_interpose(struct dentry *dentry,
328-
struct dentry *lower_dentry,
329-
struct inode *dir_inode)
327+
static struct dentry *ecryptfs_lookup_interpose(struct dentry *dentry,
328+
struct dentry *lower_dentry)
330329
{
331330
struct inode *inode, *lower_inode = d_inode(lower_dentry);
332331
struct ecryptfs_dentry_info *dentry_info;
@@ -339,11 +338,12 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
339338
"to allocate ecryptfs_dentry_info struct\n",
340339
__func__);
341340
dput(lower_dentry);
342-
return -ENOMEM;
341+
return ERR_PTR(-ENOMEM);
343342
}
344343

345344
lower_mnt = mntget(ecryptfs_dentry_to_lower_mnt(dentry->d_parent));
346-
fsstack_copy_attr_atime(dir_inode, d_inode(lower_dentry->d_parent));
345+
fsstack_copy_attr_atime(d_inode(dentry->d_parent),
346+
d_inode(lower_dentry->d_parent));
347347
BUG_ON(!d_count(lower_dentry));
348348

349349
ecryptfs_set_dentry_private(dentry, dentry_info);
@@ -353,27 +353,25 @@ static int ecryptfs_lookup_interpose(struct dentry *dentry,
353353
if (d_really_is_negative(lower_dentry)) {
354354
/* We want to add because we couldn't find in lower */
355355
d_add(dentry, NULL);
356-
return 0;
356+
return NULL;
357357
}
358-
inode = __ecryptfs_get_inode(lower_inode, dir_inode->i_sb);
358+
inode = __ecryptfs_get_inode(lower_inode, dentry->d_sb);
359359
if (IS_ERR(inode)) {
360360
printk(KERN_ERR "%s: Error interposing; rc = [%ld]\n",
361361
__func__, PTR_ERR(inode));
362-
return PTR_ERR(inode);
362+
return ERR_CAST(inode);
363363
}
364364
if (S_ISREG(inode->i_mode)) {
365365
rc = ecryptfs_i_size_read(dentry, inode);
366366
if (rc) {
367367
make_bad_inode(inode);
368-
return rc;
368+
return ERR_PTR(rc);
369369
}
370370
}
371371

372372
if (inode->i_state & I_NEW)
373373
unlock_new_inode(inode);
374-
d_add(dentry, inode);
375-
376-
return rc;
374+
return d_splice_alias(inode, dentry);
377375
}
378376

379377
/**
@@ -390,55 +388,42 @@ static struct dentry *ecryptfs_lookup(struct inode *ecryptfs_dir_inode,
390388
unsigned int flags)
391389
{
392390
char *encrypted_and_encoded_name = NULL;
393-
size_t encrypted_and_encoded_name_size;
394-
struct ecryptfs_mount_crypt_stat *mount_crypt_stat = NULL;
391+
struct ecryptfs_mount_crypt_stat *mount_crypt_stat;
395392
struct dentry *lower_dir_dentry, *lower_dentry;
393+
const char *name = ecryptfs_dentry->d_name.name;
394+
size_t len = ecryptfs_dentry->d_name.len;
395+
struct dentry *res;
396396
int rc = 0;
397397

398398
lower_dir_dentry = ecryptfs_dentry_to_lower(ecryptfs_dentry->d_parent);
399-
lower_dentry = lookup_one_len_unlocked(ecryptfs_dentry->d_name.name,
400-
lower_dir_dentry,
401-
ecryptfs_dentry->d_name.len);
402-
if (IS_ERR(lower_dentry)) {
403-
rc = PTR_ERR(lower_dentry);
404-
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
405-
"[%d] on lower_dentry = [%pd]\n", __func__, rc,
406-
ecryptfs_dentry);
407-
goto out;
408-
}
409-
if (d_really_is_positive(lower_dentry))
410-
goto interpose;
399+
411400
mount_crypt_stat = &ecryptfs_superblock_to_private(
412401
ecryptfs_dentry->d_sb)->mount_crypt_stat;
413-
if (!(mount_crypt_stat
414-
&& (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)))
415-
goto interpose;
416-
dput(lower_dentry);
417-
rc = ecryptfs_encrypt_and_encode_filename(
418-
&encrypted_and_encoded_name, &encrypted_and_encoded_name_size,
419-
mount_crypt_stat, ecryptfs_dentry->d_name.name,
420-
ecryptfs_dentry->d_name.len);
421-
if (rc) {
422-
printk(KERN_ERR "%s: Error attempting to encrypt and encode "
423-
"filename; rc = [%d]\n", __func__, rc);
424-
goto out;
402+
if (mount_crypt_stat
403+
&& (mount_crypt_stat->flags & ECRYPTFS_GLOBAL_ENCRYPT_FILENAMES)) {
404+
rc = ecryptfs_encrypt_and_encode_filename(
405+
&encrypted_and_encoded_name, &len,
406+
mount_crypt_stat, name, len);
407+
if (rc) {
408+
printk(KERN_ERR "%s: Error attempting to encrypt and encode "
409+
"filename; rc = [%d]\n", __func__, rc);
410+
return ERR_PTR(rc);
411+
}
412+
name = encrypted_and_encoded_name;
425413
}
426-
lower_dentry = lookup_one_len_unlocked(encrypted_and_encoded_name,
427-
lower_dir_dentry,
428-
encrypted_and_encoded_name_size);
414+
415+
lower_dentry = lookup_one_len_unlocked(name, lower_dir_dentry, len);
429416
if (IS_ERR(lower_dentry)) {
430-
rc = PTR_ERR(lower_dentry);
431417
ecryptfs_printk(KERN_DEBUG, "%s: lookup_one_len() returned "
432-
"[%d] on lower_dentry = [%s]\n", __func__, rc,
433-
encrypted_and_encoded_name);
434-
goto out;
418+
"[%ld] on lower_dentry = [%s]\n", __func__,
419+
PTR_ERR(lower_dentry),
420+
name);
421+
res = ERR_CAST(lower_dentry);
422+
} else {
423+
res = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry);
435424
}
436-
interpose:
437-
rc = ecryptfs_lookup_interpose(ecryptfs_dentry, lower_dentry,
438-
ecryptfs_dir_inode);
439-
out:
440425
kfree(encrypted_and_encoded_name);
441-
return ERR_PTR(rc);
426+
return res;
442427
}
443428

444429
static int ecryptfs_link(struct dentry *old_dentry, struct inode *dir,

‎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)