Skip to content

Commit 7e05b80

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull VFS fixes from Al Viro: "A bunch of assorted fixes, most of them followups to overlayfs merge" * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: ovl: initialize ->is_cursor Return short read or 0 at end of a raw device, not EIO isofs: don't bother with ->d_op for normal case isofs_cmp(): we'll never see a dentry for . or .. overlayfs: fix lockdep misannotation ovl: fix check for cursor overlayfs: barriers for opening upper-layer directory rcu: Provide counterpart to rcu_dereference() for non-RCU situations staging: android: logger: Fix log corruption regression
2 parents 4cb8c35 + 9f2f7d4 commit 7e05b80

9 files changed

Lines changed: 50 additions & 58 deletions

File tree

‎drivers/char/raw.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ static long raw_ctl_compat_ioctl(struct file *file, unsigned int cmd,
285285

286286
static const struct file_operations raw_fops = {
287287
.read = new_sync_read,
288-
.read_iter = generic_file_read_iter,
288+
.read_iter = blkdev_read_iter,
289289
.write = new_sync_write,
290290
.write_iter = blkdev_write_iter,
291291
.fsync = blkdev_fsync,

‎drivers/staging/android/logger.c‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
420420
struct logger_log *log = file_get_log(iocb->ki_filp);
421421
struct logger_entry header;
422422
struct timespec now;
423-
size_t len, count;
423+
size_t len, count, w_off;
424424

425425
count = min_t(size_t, iocb->ki_nbytes, LOGGER_ENTRY_MAX_PAYLOAD);
426426

@@ -452,11 +452,14 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
452452
memcpy(log->buffer + log->w_off, &header, len);
453453
memcpy(log->buffer, (char *)&header + len, sizeof(header) - len);
454454

455-
len = min(count, log->size - log->w_off);
455+
/* Work with a copy until we are ready to commit the whole entry */
456+
w_off = logger_offset(log, log->w_off + sizeof(struct logger_entry));
456457

457-
if (copy_from_iter(log->buffer + log->w_off, len, from) != len) {
458+
len = min(count, log->size - w_off);
459+
460+
if (copy_from_iter(log->buffer + w_off, len, from) != len) {
458461
/*
459-
* Note that by not updating w_off, this abandons the
462+
* Note that by not updating log->w_off, this abandons the
460463
* portion of the new entry that *was* successfully
461464
* copied, just above. This is intentional to avoid
462465
* message corruption from missing fragments.
@@ -470,7 +473,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from)
470473
return -EFAULT;
471474
}
472475

473-
log->w_off = logger_offset(log, log->w_off + count);
476+
log->w_off = logger_offset(log, w_off + count);
474477
mutex_unlock(&log->mutex);
475478

476479
/* wake up any blocked readers */

‎fs/block_dev.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1585,7 +1585,7 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from)
15851585
}
15861586
EXPORT_SYMBOL_GPL(blkdev_write_iter);
15871587

1588-
static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
1588+
ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
15891589
{
15901590
struct file *file = iocb->ki_filp;
15911591
struct inode *bd_inode = file->f_mapping->host;
@@ -1599,6 +1599,7 @@ static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
15991599
iov_iter_truncate(to, size);
16001600
return generic_file_read_iter(iocb, to);
16011601
}
1602+
EXPORT_SYMBOL_GPL(blkdev_read_iter);
16021603

16031604
/*
16041605
* Try to release a page associated with block device when the system

‎fs/isofs/inode.c‎

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,9 @@
2929
#define BEQUIET
3030

3131
static int isofs_hashi(const struct dentry *parent, struct qstr *qstr);
32-
static int isofs_hash(const struct dentry *parent, struct qstr *qstr);
3332
static int isofs_dentry_cmpi(const struct dentry *parent,
3433
const struct dentry *dentry,
3534
unsigned int len, const char *str, const struct qstr *name);
36-
static int isofs_dentry_cmp(const struct dentry *parent,
37-
const struct dentry *dentry,
38-
unsigned int len, const char *str, const struct qstr *name);
3935

4036
#ifdef CONFIG_JOLIET
4137
static int isofs_hashi_ms(const struct dentry *parent, struct qstr *qstr);
@@ -134,10 +130,6 @@ static const struct super_operations isofs_sops = {
134130

135131

136132
static const struct dentry_operations isofs_dentry_ops[] = {
137-
{
138-
.d_hash = isofs_hash,
139-
.d_compare = isofs_dentry_cmp,
140-
},
141133
{
142134
.d_hash = isofs_hashi,
143135
.d_compare = isofs_dentry_cmpi,
@@ -257,25 +249,12 @@ static int isofs_dentry_cmp_common(
257249
return 1;
258250
}
259251

260-
static int
261-
isofs_hash(const struct dentry *dentry, struct qstr *qstr)
262-
{
263-
return isofs_hash_common(qstr, 0);
264-
}
265-
266252
static int
267253
isofs_hashi(const struct dentry *dentry, struct qstr *qstr)
268254
{
269255
return isofs_hashi_common(qstr, 0);
270256
}
271257

272-
static int
273-
isofs_dentry_cmp(const struct dentry *parent, const struct dentry *dentry,
274-
unsigned int len, const char *str, const struct qstr *name)
275-
{
276-
return isofs_dentry_cmp_common(len, str, name, 0, 0);
277-
}
278-
279258
static int
280259
isofs_dentry_cmpi(const struct dentry *parent, const struct dentry *dentry,
281260
unsigned int len, const char *str, const struct qstr *name)
@@ -930,7 +909,8 @@ static int isofs_fill_super(struct super_block *s, void *data, int silent)
930909
if (opt.check == 'r')
931910
table++;
932911

933-
s->s_d_op = &isofs_dentry_ops[table];
912+
if (table)
913+
s->s_d_op = &isofs_dentry_ops[table - 1];
934914

935915
/* get the root dentry */
936916
s->s_root = d_make_root(inode);

‎fs/isofs/namei.c‎

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,25 +18,10 @@ static int
1818
isofs_cmp(struct dentry *dentry, const char *compare, int dlen)
1919
{
2020
struct qstr qstr;
21-
22-
if (!compare)
23-
return 1;
24-
25-
/* check special "." and ".." files */
26-
if (dlen == 1) {
27-
/* "." */
28-
if (compare[0] == 0) {
29-
if (!dentry->d_name.len)
30-
return 0;
31-
compare = ".";
32-
} else if (compare[0] == 1) {
33-
compare = "..";
34-
dlen = 2;
35-
}
36-
}
37-
3821
qstr.name = compare;
3922
qstr.len = dlen;
23+
if (likely(!dentry->d_op))
24+
return dentry->d_name.len != dlen || memcmp(dentry->d_name.name, compare, dlen);
4025
return dentry->d_op->d_compare(NULL, NULL, dentry->d_name.len, dentry->d_name.name, &qstr);
4126
}
4227

@@ -146,7 +131,8 @@ isofs_find_entry(struct inode *dir, struct dentry *dentry,
146131
(!(de->flags[-sbi->s_high_sierra] & 1))) &&
147132
(sbi->s_showassoc ||
148133
(!(de->flags[-sbi->s_high_sierra] & 4)))) {
149-
match = (isofs_cmp(dentry, dpnt, dlen) == 0);
134+
if (dpnt && (dlen > 1 || dpnt[0] > 1))
135+
match = (isofs_cmp(dentry, dpnt, dlen) == 0);
150136
}
151137
if (match) {
152138
isofs_normalize_block_and_offset(de,

‎fs/namei.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2497,7 +2497,7 @@ struct dentry *lock_rename(struct dentry *p1, struct dentry *p2)
24972497
}
24982498

24992499
mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);
2500-
mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_CHILD);
2500+
mutex_lock_nested(&p2->d_inode->i_mutex, I_MUTEX_PARENT2);
25012501
return NULL;
25022502
}
25032503
EXPORT_SYMBOL(lock_rename);

‎fs/overlayfs/readdir.c‎

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,10 @@ struct ovl_cache_entry {
2121
unsigned int len;
2222
unsigned int type;
2323
u64 ino;
24-
bool is_whiteout;
2524
struct list_head l_node;
2625
struct rb_node node;
26+
bool is_whiteout;
27+
bool is_cursor;
2728
char name[];
2829
};
2930

@@ -92,6 +93,7 @@ static struct ovl_cache_entry *ovl_cache_entry_new(const char *name, int len,
9293
p->type = d_type;
9394
p->ino = ino;
9495
p->is_whiteout = false;
96+
p->is_cursor = false;
9597
}
9698

9799
return p;
@@ -251,7 +253,7 @@ static int ovl_dir_mark_whiteouts(struct dentry *dir,
251253

252254
mutex_lock(&dir->d_inode->i_mutex);
253255
list_for_each_entry(p, rdd->list, l_node) {
254-
if (!p->name)
256+
if (p->is_cursor)
255257
continue;
256258

257259
if (p->type != DT_CHR)
@@ -307,7 +309,6 @@ static inline int ovl_dir_read_merged(struct path *upperpath,
307309
}
308310
out:
309311
return err;
310-
311312
}
312313

313314
static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos)
@@ -316,7 +317,7 @@ static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos)
316317
loff_t off = 0;
317318

318319
list_for_each_entry(p, &od->cache->entries, l_node) {
319-
if (!p->name)
320+
if (p->is_cursor)
320321
continue;
321322
if (off >= pos)
322323
break;
@@ -389,7 +390,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx)
389390

390391
p = list_entry(od->cursor.l_node.next, struct ovl_cache_entry, l_node);
391392
/* Skip cursors */
392-
if (p->name) {
393+
if (!p->is_cursor) {
393394
if (!p->is_whiteout) {
394395
if (!dir_emit(ctx, p->name, p->len, p->ino, p->type))
395396
break;
@@ -454,12 +455,13 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end,
454455
if (!od->is_upper && ovl_path_type(dentry) == OVL_PATH_MERGE) {
455456
struct inode *inode = file_inode(file);
456457

457-
realfile = od->upperfile;
458+
realfile =lockless_dereference(od->upperfile);
458459
if (!realfile) {
459460
struct path upperpath;
460461

461462
ovl_path_upper(dentry, &upperpath);
462463
realfile = ovl_path_open(&upperpath, O_RDONLY);
464+
smp_mb__before_spinlock();
463465
mutex_lock(&inode->i_mutex);
464466
if (!od->upperfile) {
465467
if (IS_ERR(realfile)) {
@@ -518,6 +520,7 @@ static int ovl_dir_open(struct inode *inode, struct file *file)
518520
od->realfile = realfile;
519521
od->is_real = (type != OVL_PATH_MERGE);
520522
od->is_upper = (type != OVL_PATH_LOWER);
523+
od->cursor.is_cursor = true;
521524
file->private_data = od;
522525

523526
return 0;
@@ -569,7 +572,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list)
569572
{
570573
struct ovl_cache_entry *p;
571574

572-
mutex_lock_nested(&upper->d_inode->i_mutex, I_MUTEX_PARENT);
575+
mutex_lock_nested(&upper->d_inode->i_mutex, I_MUTEX_CHILD);
573576
list_for_each_entry(p, list, l_node) {
574577
struct dentry *dentry;
575578

‎include/linux/fs.h‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -639,19 +639,22 @@ static inline int inode_unhashed(struct inode *inode)
639639
* 2: child/target
640640
* 3: xattr
641641
* 4: second non-directory
642-
* The last is for certain operations (such as rename) which lock two
642+
* 5: second parent (when locking independent directories in rename)
643+
*
644+
* I_MUTEX_NONDIR2 is for certain operations (such as rename) which lock two
643645
* non-directories at once.
644646
*
645647
* The locking order between these classes is
646-
* parent -> child -> normal -> xattr -> second non-directory
648+
* parent[2] -> child -> grandchild -> normal -> xattr -> second non-directory
647649
*/
648650
enum inode_i_mutex_lock_class
649651
{
650652
I_MUTEX_NORMAL,
651653
I_MUTEX_PARENT,
652654
I_MUTEX_CHILD,
653655
I_MUTEX_XATTR,
654-
I_MUTEX_NONDIR2
656+
I_MUTEX_NONDIR2,
657+
I_MUTEX_PARENT2,
655658
};
656659

657660
void lock_two_nondirectories(struct inode *, struct inode*);
@@ -2466,6 +2469,7 @@ extern ssize_t new_sync_read(struct file *filp, char __user *buf, size_t len, lo
24662469
extern ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
24672470

24682471
/* fs/block_dev.c */
2472+
extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to);
24692473
extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from);
24702474
extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
24712475
int datasync);

‎include/linux/rcupdate.h‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,21 @@ static inline void rcu_preempt_sleep_check(void)
616616
*/
617617
#define RCU_INITIALIZER(v) (typeof(*(v)) __force __rcu *)(v)
618618

619+
/**
620+
* lockless_dereference() - safely load a pointer for later dereference
621+
* @p: The pointer to load
622+
*
623+
* Similar to rcu_dereference(), but for situations where the pointed-to
624+
* object's lifetime is managed by something other than RCU. That
625+
* "something other" might be reference counting or simple immortality.
626+
*/
627+
#define lockless_dereference(p) \
628+
({ \
629+
typeof(p) _________p1 = ACCESS_ONCE(p); \
630+
smp_read_barrier_depends(); /* Dependency order vs. p above. */ \
631+
(_________p1); \
632+
})
633+
619634
/**
620635
* rcu_assign_pointer() - assign to RCU-protected pointer
621636
* @p: pointer to assign to

0 commit comments

Comments
 (0)