History

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

Linus Torvalds committed 12 years ago

Commit 7e05b802 parents 4cb8c35 9f2f7d49 files · +50 −58Browse files

Unified · Split

9 files
  1. drivers/char/raw.c +1 −1
  2. drivers/staging/android/logger.c +8 −5
  3. fs/block_dev.c +2 −1
  4. fs/isofs/inode.c +2 −22
  5. fs/isofs/namei.c +4 −18
  6. fs/namei.c +1 −1
  7. fs/overlayfs/readdir.c +10 −7
  8. include/linux/fs.h +7 −3
  9. include/linux/rcupdate.h +15 −0
drivers/char/raw.c+1−1
@@ -285,7 +285,7 @@ static long raw_ctl_compat_ioctl(struct file *file, unsigned int cmd, · 284 unmodified lines
285 285
286static const struct file_operations raw_fops = {286static const struct file_operations raw_fops = {
287 .read = new_sync_read,287 .read = new_sync_read,
288 .read_iter = generic_file_read_iter,288 .read_iter = blkdev_read_iter,
289 .write = new_sync_write,289 .write = new_sync_write,
290 .write_iter = blkdev_write_iter,290 .write_iter = blkdev_write_iter,
291 .fsync = blkdev_fsync,291 .fsync = blkdev_fsync,
drivers/staging/android/logger.c+8−5
@@ -420,7 +420,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) · 419 unmodified lines
420 struct logger_log *log = file_get_log(iocb->ki_filp);420 struct logger_log *log = file_get_log(iocb->ki_filp);
421 struct logger_entry header;421 struct logger_entry header;
422 struct timespec now;422 struct timespec now;
423 size_t len, count;423 size_t len, count, w_off;
424 424
425 count = min_t(size_t, iocb->ki_nbytes, LOGGER_ENTRY_MAX_PAYLOAD);425 count = min_t(size_t, iocb->ki_nbytes, LOGGER_ENTRY_MAX_PAYLOAD);
426 426
@@ -452,11 +452,14 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) · 25 unmodified lines
452 memcpy(log->buffer + log->w_off, &header, len);452 memcpy(log->buffer + log->w_off, &header, len);
453 memcpy(log->buffer, (char *)&header + len, sizeof(header) - len);453 memcpy(log->buffer, (char *)&header + len, sizeof(header) - len);
454 454
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));
456 457
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) {
458 /*461 /*
459 * Note that by not updating w_off, this abandons the462 * Note that by not updating log->w_off, this abandons the
460 * portion of the new entry that *was* successfully463 * portion of the new entry that *was* successfully
461 * copied, just above. This is intentional to avoid464 * copied, just above. This is intentional to avoid
462 * message corruption from missing fragments.465 * message corruption from missing fragments.
@@ -470,7 +473,7 @@ static ssize_t logger_write_iter(struct kiocb *iocb, struct iov_iter *from) · 7 unmodified lines
470 return -EFAULT;473 return -EFAULT;
471 }474 }
472 475
473 log->w_off = logger_offset(log, log->w_off + count);476 log->w_off = logger_offset(log, w_off + count);
474 mutex_unlock(&log->mutex);477 mutex_unlock(&log->mutex);
475 478
476 /* wake up any blocked readers */479 /* wake up any blocked readers */
fs/block_dev.c+2−1
@@ -1585,7 +1585,7 @@ ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from) · 1584 unmodified lines
1585}1585}
1586EXPORT_SYMBOL_GPL(blkdev_write_iter);1586EXPORT_SYMBOL_GPL(blkdev_write_iter);
1587 1587
1588static ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)1588ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to)
1589{1589{
1590 struct file *file = iocb->ki_filp;1590 struct file *file = iocb->ki_filp;
1591 struct inode *bd_inode = file->f_mapping->host;1591 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) · 7 unmodified lines
1599 iov_iter_truncate(to, size);1599 iov_iter_truncate(to, size);
1600 return generic_file_read_iter(iocb, to);1600 return generic_file_read_iter(iocb, to);
1601}1601}
1602EXPORT_SYMBOL_GPL(blkdev_read_iter);
1602 1603
1603/*1604/*
1604 * Try to release a page associated with block device when the system1605 * Try to release a page associated with block device when the system
fs/isofs/inode.c+2−22
@@ -29,13 +29,9 @@ · 28 unmodified lines
29#define BEQUIET29#define BEQUIET
30 30
31static int isofs_hashi(const struct dentry *parent, struct qstr *qstr);31static int isofs_hashi(const struct dentry *parent, struct qstr *qstr);
32static int isofs_hash(const struct dentry *parent, struct qstr *qstr);
33static int isofs_dentry_cmpi(const struct dentry *parent,32static int isofs_dentry_cmpi(const struct dentry *parent,
34 const struct dentry *dentry,33 const struct dentry *dentry,
35 unsigned int len, const char *str, const struct qstr *name);34 unsigned int len, const char *str, const struct qstr *name);
36static int isofs_dentry_cmp(const struct dentry *parent,
37 const struct dentry *dentry,
38 unsigned int len, const char *str, const struct qstr *name);
39 35
40#ifdef CONFIG_JOLIET36#ifdef CONFIG_JOLIET
41static int isofs_hashi_ms(const struct dentry *parent, struct qstr *qstr);37static int isofs_hashi_ms(const struct dentry *parent, struct qstr *qstr);
@@ -134,10 +130,6 @@ static const struct super_operations isofs_sops = { · 92 unmodified lines
134 130
135 131
136static const struct dentry_operations isofs_dentry_ops[] = {132static const struct dentry_operations isofs_dentry_ops[] = {
137 {
138 .d_hash = isofs_hash,
139 .d_compare = isofs_dentry_cmp,
140 },
141 {133 {
142 .d_hash = isofs_hashi,134 .d_hash = isofs_hashi,
143 .d_compare = isofs_dentry_cmpi,135 .d_compare = isofs_dentry_cmpi,
@@ -257,25 +249,12 @@ static int isofs_dentry_cmp_common( · 113 unmodified lines
257 return 1;249 return 1;
258}250}
259 251
260static int
261isofs_hash(const struct dentry *dentry, struct qstr *qstr)
262{
263 return isofs_hash_common(qstr, 0);
264}
265
266static int252static int
267isofs_hashi(const struct dentry *dentry, struct qstr *qstr)253isofs_hashi(const struct dentry *dentry, struct qstr *qstr)
268{254{
269 return isofs_hashi_common(qstr, 0);255 return isofs_hashi_common(qstr, 0);
270}256}
271 257
272static int
273isofs_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
279static int258static int
280isofs_dentry_cmpi(const struct dentry *parent, const struct dentry *dentry,259isofs_dentry_cmpi(const struct dentry *parent, const struct dentry *dentry,
281 unsigned int len, const char *str, const struct qstr *name)260 unsigned int len, const char *str, const struct qstr *name)
@@ -930,7 +909,8 @@ root_found: · 648 unmodified lines
930 if (opt.check == 'r')909 if (opt.check == 'r')
931 table++;910 table++;
932 911
933 s->s_d_op = &isofs_dentry_ops[table];912 if (table)
913 s->s_d_op = &isofs_dentry_ops[table - 1];
934 914
935 /* get the root dentry */915 /* get the root dentry */
936 s->s_root = d_make_root(inode);916 s->s_root = d_make_root(inode);
fs/isofs/namei.c+4−18
@@ -18,25 +18,10 @@ static int · 17 unmodified lines
18isofs_cmp(struct dentry *dentry, const char *compare, int dlen)18isofs_cmp(struct dentry *dentry, const char *compare, int dlen)
19{19{
20 struct qstr qstr;20 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
38 qstr.name = compare;21 qstr.name = compare;
39 qstr.len = dlen;22 qstr.len = dlen;
23 if (likely(!dentry->d_op))
24 return dentry->d_name.len != dlen || memcmp(dentry->d_name.name, compare, dlen);
40 return dentry->d_op->d_compare(NULL, NULL, dentry->d_name.len, dentry->d_name.name, &qstr);25 return dentry->d_op->d_compare(NULL, NULL, dentry->d_name.len, dentry->d_name.name, &qstr);
41}26}
42 27
@@ -146,7 +131,8 @@ isofs_find_entry(struct inode *dir, struct dentry *dentry, · 103 unmodified lines
146 (!(de->flags[-sbi->s_high_sierra] & 1))) &&131 (!(de->flags[-sbi->s_high_sierra] & 1))) &&
147 (sbi->s_showassoc ||132 (sbi->s_showassoc ||
148 (!(de->flags[-sbi->s_high_sierra] & 4)))) {133 (!(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);
150 }136 }
151 if (match) {137 if (match) {
152 isofs_normalize_block_and_offset(de,138 isofs_normalize_block_and_offset(de,
fs/namei.c+1−1
@@ -2497,7 +2497,7 @@ struct dentry *lock_rename(struct dentry *p1, struct dentry *p2) · 2496 unmodified lines
2497 }2497 }
2498 2498
2499 mutex_lock_nested(&p1->d_inode->i_mutex, I_MUTEX_PARENT);2499 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);
2501 return NULL;2501 return NULL;
2502}2502}
2503EXPORT_SYMBOL(lock_rename);2503EXPORT_SYMBOL(lock_rename);
fs/overlayfs/readdir.c+10−7
@@ -21,9 +21,10 @@ struct ovl_cache_entry { · 20 unmodified lines
21 unsigned int len;21 unsigned int len;
22 unsigned int type;22 unsigned int type;
23 u64 ino;23 u64 ino;
24 bool is_whiteout;
25 struct list_head l_node;24 struct list_head l_node;
26 struct rb_node node;25 struct rb_node node;
26 bool is_whiteout;
27 bool is_cursor;
27 char name[];28 char name[];
28};29};
29 30
@@ -92,6 +93,7 @@ static struct ovl_cache_entry *ovl_cache_entry_new(const char *name, int len, · 62 unmodified lines
92 p->type = d_type;93 p->type = d_type;
93 p->ino = ino;94 p->ino = ino;
94 p->is_whiteout = false;95 p->is_whiteout = false;
96 p->is_cursor = false;
95 }97 }
96 98
97 return p;99 return p;
@@ -251,7 +253,7 @@ static int ovl_dir_mark_whiteouts(struct dentry *dir, · 153 unmodified lines
251 253
252 mutex_lock(&dir->d_inode->i_mutex);254 mutex_lock(&dir->d_inode->i_mutex);
253 list_for_each_entry(p, rdd->list, l_node) {255 list_for_each_entry(p, rdd->list, l_node) {
254 if (!p->name)256 if (p->is_cursor)
255 continue;257 continue;
256 258
257 if (p->type != DT_CHR)259 if (p->type != DT_CHR)
@@ -307,7 +309,6 @@ static inline int ovl_dir_read_merged(struct path *upperpath, · 49 unmodified lines
307 }309 }
308out:310out:
309 return err;311 return err;
310
311}312}
312 313
313static void ovl_seek_cursor(struct ovl_dir_file *od, loff_t pos)314static 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) · 2 unmodified lines
316 loff_t off = 0;317 loff_t off = 0;
317 318
318 list_for_each_entry(p, &od->cache->entries, l_node) {319 list_for_each_entry(p, &od->cache->entries, l_node) {
319 if (!p->name)320 if (p->is_cursor)
320 continue;321 continue;
321 if (off >= pos)322 if (off >= pos)
322 break;323 break;
@@ -389,7 +390,7 @@ static int ovl_iterate(struct file *file, struct dir_context *ctx) · 66 unmodified lines
389 390
390 p = list_entry(od->cursor.l_node.next, struct ovl_cache_entry, l_node);391 p = list_entry(od->cursor.l_node.next, struct ovl_cache_entry, l_node);
391 /* Skip cursors */392 /* Skip cursors */
392 if (p->name) {393 if (!p->is_cursor) {
393 if (!p->is_whiteout) {394 if (!p->is_whiteout) {
394 if (!dir_emit(ctx, p->name, p->len, p->ino, p->type))395 if (!dir_emit(ctx, p->name, p->len, p->ino, p->type))
395 break;396 break;
@@ -454,12 +455,13 @@ static int ovl_dir_fsync(struct file *file, loff_t start, loff_t end, · 58 unmodified lines
454 if (!od->is_upper && ovl_path_type(dentry) == OVL_PATH_MERGE) {455 if (!od->is_upper && ovl_path_type(dentry) == OVL_PATH_MERGE) {
455 struct inode *inode = file_inode(file);456 struct inode *inode = file_inode(file);
456 457
457 realfile = od->upperfile;458 realfile =lockless_dereference(od->upperfile);
458 if (!realfile) {459 if (!realfile) {
459 struct path upperpath;460 struct path upperpath;
460 461
461 ovl_path_upper(dentry, &upperpath);462 ovl_path_upper(dentry, &upperpath);
462 realfile = ovl_path_open(&upperpath, O_RDONLY);463 realfile = ovl_path_open(&upperpath, O_RDONLY);
464 smp_mb__before_spinlock();
463 mutex_lock(&inode->i_mutex);465 mutex_lock(&inode->i_mutex);
464 if (!od->upperfile) {466 if (!od->upperfile) {
465 if (IS_ERR(realfile)) {467 if (IS_ERR(realfile)) {
@@ -518,6 +520,7 @@ static int ovl_dir_open(struct inode *inode, struct file *file) · 52 unmodified lines
518 od->realfile = realfile;520 od->realfile = realfile;
519 od->is_real = (type != OVL_PATH_MERGE);521 od->is_real = (type != OVL_PATH_MERGE);
520 od->is_upper = (type != OVL_PATH_LOWER);522 od->is_upper = (type != OVL_PATH_LOWER);
523 od->cursor.is_cursor = true;
521 file->private_data = od;524 file->private_data = od;
522 525
523 return 0;526 return 0;
@@ -569,7 +572,7 @@ void ovl_cleanup_whiteouts(struct dentry *upper, struct list_head *list) · 45 unmodified lines
569{572{
570 struct ovl_cache_entry *p;573 struct ovl_cache_entry *p;
571 574
572 mutex_lock_nested(&upper->d_inode->i_mutex, I_MUTEX_PARENT);575 mutex_lock_nested(&upper->d_inode->i_mutex, I_MUTEX_CHILD);
573 list_for_each_entry(p, list, l_node) {576 list_for_each_entry(p, list, l_node) {
574 struct dentry *dentry;577 struct dentry *dentry;
575 578
include/linux/fs.h+7−3
@@ -639,11 +639,13 @@ static inline int inode_unhashed(struct inode *inode) · 638 unmodified lines
639 * 2: child/target639 * 2: child/target
640 * 3: xattr640 * 3: xattr
641 * 4: second non-directory641 * 4: second non-directory
642 * The last is for certain operations (such as rename) which lock two642 * 5: second parent (when locking independent directories in rename)
643 *
644 * I_MUTEX_NONDIR2 is for certain operations (such as rename) which lock two
643 * non-directories at once.645 * non-directories at once.
644 *646 *
645 * The locking order between these classes is647 * The locking order between these classes is
646 * parent -> child -> normal -> xattr -> second non-directory648 * parent[2] -> child -> grandchild -> normal -> xattr -> second non-directory
647 */649 */
648enum inode_i_mutex_lock_class650enum inode_i_mutex_lock_class
649{651{
@@ -651,7 +653,8 @@ enum inode_i_mutex_lock_class · 1 unmodified line
651 I_MUTEX_PARENT,653 I_MUTEX_PARENT,
652 I_MUTEX_CHILD,654 I_MUTEX_CHILD,
653 I_MUTEX_XATTR,655 I_MUTEX_XATTR,
654 I_MUTEX_NONDIR2656 I_MUTEX_NONDIR2,
657 I_MUTEX_PARENT2,
655};658};
656 659
657void lock_two_nondirectories(struct inode *, struct inode*);660void 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 · 1808 unmodified lines
2466extern ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);2469extern ssize_t new_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos);
2467 2470
2468/* fs/block_dev.c */2471/* fs/block_dev.c */
2472extern ssize_t blkdev_read_iter(struct kiocb *iocb, struct iov_iter *to);
2469extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from);2473extern ssize_t blkdev_write_iter(struct kiocb *iocb, struct iov_iter *from);
2470extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end,2474extern int blkdev_fsync(struct file *filp, loff_t start, loff_t end,
2471 int datasync);2475 int datasync);
include/linux/rcupdate.h+15−0
@@ -616,6 +616,21 @@ static inline void rcu_preempt_sleep_check(void) · 615 unmodified lines
616 */616 */
617#define RCU_INITIALIZER(v) (typeof(*(v)) __force __rcu *)(v)617#define RCU_INITIALIZER(v) (typeof(*(v)) __force __rcu *)(v)
618 618
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
619/**634/**
620 * rcu_assign_pointer() - assign to RCU-protected pointer635 * rcu_assign_pointer() - assign to RCU-protected pointer
621 * @p: pointer to assign to636 * @p: pointer to assign to