Skip to content

Commit 5997aab

Browse files
committed
Merge branch 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
Pull vfs fixes from Al Viro: "Assorted fixes all over the place" * 'fixes' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs: aio: fix io_destroy(2) vs. lookup_ioctx() race ext2: fix a block leak nfsd: vfs_mkdir() might succeed leaving dentry negative unhashed cachefiles: vfs_mkdir() might succeed leaving dentry negative unhashed unfuck sysfs_mount() kernfs: deal with kernfs_fill_super() failures cramfs: Fix IS_ENABLED typo befs_lookup(): use d_splice_alias() affs_lookup: switch to d_splice_alias() affs_lookup(): close a race with affs_remove_link() fix breakage caused by d_find_alias() semantics change fs: don't scan the inode cache before SB_BORN is set do d_instantiate/unlock_new_inode combinations safely iov_iter: fix memory leak in pipe_get_pages_alloc() iov_iter: fix return type of __pipe_get_pages()
2 parents 3b78ce4 + baf1056 commit 5997aab

26 files changed

Lines changed: 152 additions & 118 deletions

File tree

‎fs/affs/namei.c‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -201,14 +201,16 @@ affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
201201
struct super_block *sb = dir->i_sb;
202202
struct buffer_head *bh;
203203
struct inode *inode = NULL;
204+
struct dentry *res;
204205

205206
pr_debug("%s(\"%pd\")\n", __func__, dentry);
206207

207208
affs_lock_dir(dir);
208209
bh = affs_find_entry(dir, dentry);
209-
affs_unlock_dir(dir);
210-
if (IS_ERR(bh))
210+
if (IS_ERR(bh)) {
211+
affs_unlock_dir(dir);
211212
return ERR_CAST(bh);
213+
}
212214
if (bh) {
213215
u32 ino = bh->b_blocknr;
214216

@@ -222,11 +224,12 @@ affs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
222224
}
223225
affs_brelse(bh);
224226
inode = affs_iget(sb, ino);
225-
if (IS_ERR(inode))
226-
return ERR_CAST(inode);
227227
}
228-
d_add(dentry, inode);
229-
return NULL;
228+
res = d_splice_alias(inode, dentry);
229+
if (!IS_ERR_OR_NULL(res))
230+
res->d_fsdata = dentry->d_fsdata;
231+
affs_unlock_dir(dir);
232+
return res;
230233
}
231234

232235
int

‎fs/aio.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,8 +1078,8 @@ static struct kioctx *lookup_ioctx(unsigned long ctx_id)
10781078

10791079
ctx = rcu_dereference(table->table[id]);
10801080
if (ctx && ctx->user_id == ctx_id) {
1081-
percpu_ref_get(&ctx->users);
1082-
ret = ctx;
1081+
if (percpu_ref_tryget_live(&ctx->users))
1082+
ret = ctx;
10831083
}
10841084
out:
10851085
rcu_read_unlock();

‎fs/befs/linuxvfs.c‎

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -198,23 +198,16 @@ befs_lookup(struct inode *dir, struct dentry *dentry, unsigned int flags)
198198

199199
if (ret == BEFS_BT_NOT_FOUND) {
200200
befs_debug(sb, "<--- %s %pd not found", __func__, dentry);
201-
d_add(dentry, NULL);
202-
return ERR_PTR(-ENOENT);
203-
201+
inode = NULL;
204202
} else if (ret != BEFS_OK || offset == 0) {
205203
befs_error(sb, "<--- %s Error", __func__);
206-
return ERR_PTR(-ENODATA);
204+
inode = ERR_PTR(-ENODATA);
205+
} else {
206+
inode = befs_iget(dir->i_sb, (ino_t) offset);
207207
}
208-
209-
inode = befs_iget(dir->i_sb, (ino_t) offset);
210-
if (IS_ERR(inode))
211-
return ERR_CAST(inode);
212-
213-
d_add(dentry, inode);
214-
215208
befs_debug(sb, "<--- %s", __func__);
216209

217-
return NULL;
210+
return d_splice_alias(inode, dentry);
218211
}
219212

220213
static int

‎fs/btrfs/inode.c‎

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6586,8 +6586,7 @@ static int btrfs_mknod(struct inode *dir, struct dentry *dentry,
65866586
goto out_unlock_inode;
65876587
} else {
65886588
btrfs_update_inode(trans, root, inode);
6589-
unlock_new_inode(inode);
6590-
d_instantiate(dentry, inode);
6589+
d_instantiate_new(dentry, inode);
65916590
}
65926591

65936592
out_unlock:
@@ -6663,8 +6662,7 @@ static int btrfs_create(struct inode *dir, struct dentry *dentry,
66636662
goto out_unlock_inode;
66646663

66656664
BTRFS_I(inode)->io_tree.ops = &btrfs_extent_io_ops;
6666-
unlock_new_inode(inode);
6667-
d_instantiate(dentry, inode);
6665+
d_instantiate_new(dentry, inode);
66686666

66696667
out_unlock:
66706668
btrfs_end_transaction(trans);
@@ -6809,12 +6807,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, umode_t mode)
68096807
if (err)
68106808
goto out_fail_inode;
68116809

6812-
d_instantiate(dentry, inode);
6813-
/*
6814-
* mkdir is special. We're unlocking after we call d_instantiate
6815-
* to avoid a race with nfsd calling d_instantiate.
6816-
*/
6817-
unlock_new_inode(inode);
6810+
d_instantiate_new(dentry, inode);
68186811
drop_on_err = 0;
68196812

68206813
out_fail:
@@ -10257,8 +10250,7 @@ static int btrfs_symlink(struct inode *dir, struct dentry *dentry,
1025710250
goto out_unlock_inode;
1025810251
}
1025910252

10260-
unlock_new_inode(inode);
10261-
d_instantiate(dentry, inode);
10253+
d_instantiate_new(dentry, inode);
1026210254

1026310255
out_unlock:
1026410256
btrfs_end_transaction(trans);

‎fs/cachefiles/namei.c‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,6 +572,11 @@ int cachefiles_walk_to_object(struct cachefiles_object *parent,
572572
if (ret < 0)
573573
goto create_error;
574574

575+
if (unlikely(d_unhashed(next))) {
576+
dput(next);
577+
inode_unlock(d_inode(dir));
578+
goto lookup_again;
579+
}
575580
ASSERT(d_backing_inode(next));
576581

577582
_debug("mkdir -> %p{%p{ino=%lu}}",
@@ -764,6 +769,7 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
764769
/* search the current directory for the element name */
765770
inode_lock(d_inode(dir));
766771

772+
retry:
767773
start = jiffies;
768774
subdir = lookup_one_len(dirname, dir, strlen(dirname));
769775
cachefiles_hist(cachefiles_lookup_histogram, start);
@@ -793,6 +799,10 @@ struct dentry *cachefiles_get_directory(struct cachefiles_cache *cache,
793799
if (ret < 0)
794800
goto mkdir_error;
795801

802+
if (unlikely(d_unhashed(subdir))) {
803+
dput(subdir);
804+
goto retry;
805+
}
796806
ASSERT(d_backing_inode(subdir));
797807

798808
_debug("mkdir -> %p{%p{ino=%lu}}",

‎fs/cramfs/inode.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ static void cramfs_kill_sb(struct super_block *sb)
492492
{
493493
struct cramfs_sb_info *sbi = CRAMFS_SB(sb);
494494

495-
if (IS_ENABLED(CCONFIG_CRAMFS_MTD) && sb->s_mtd) {
495+
if (IS_ENABLED(CONFIG_CRAMFS_MTD) && sb->s_mtd) {
496496
if (sbi && sbi->mtd_point_size)
497497
mtd_unpoint(sb->s_mtd, 0, sbi->mtd_point_size);
498498
kill_mtd_super(sb);

‎fs/dcache.c‎

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1899,6 +1899,28 @@ void d_instantiate(struct dentry *entry, struct inode * inode)
18991899
}
19001900
EXPORT_SYMBOL(d_instantiate);
19011901

1902+
/*
1903+
* This should be equivalent to d_instantiate() + unlock_new_inode(),
1904+
* with lockdep-related part of unlock_new_inode() done before
1905+
* anything else. Use that instead of open-coding d_instantiate()/
1906+
* unlock_new_inode() combinations.
1907+
*/
1908+
void d_instantiate_new(struct dentry *entry, struct inode *inode)
1909+
{
1910+
BUG_ON(!hlist_unhashed(&entry->d_u.d_alias));
1911+
BUG_ON(!inode);
1912+
lockdep_annotate_inode_mutex_key(inode);
1913+
security_d_instantiate(entry, inode);
1914+
spin_lock(&inode->i_lock);
1915+
__d_instantiate(entry, inode);
1916+
WARN_ON(!(inode->i_state & I_NEW));
1917+
inode->i_state &= ~I_NEW;
1918+
smp_mb();
1919+
wake_up_bit(&inode->i_state, __I_NEW);
1920+
spin_unlock(&inode->i_lock);
1921+
}
1922+
EXPORT_SYMBOL(d_instantiate_new);
1923+
19021924
/**
19031925
* d_instantiate_no_diralias - instantiate a non-aliased dentry
19041926
* @entry: dentry to complete

‎fs/ecryptfs/inode.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,8 +283,7 @@ ecryptfs_create(struct inode *directory_inode, struct dentry *ecryptfs_dentry,
283283
iget_failed(ecryptfs_inode);
284284
goto out;
285285
}
286-
unlock_new_inode(ecryptfs_inode);
287-
d_instantiate(ecryptfs_dentry, ecryptfs_inode);
286+
d_instantiate_new(ecryptfs_dentry, ecryptfs_inode);
288287
out:
289288
return rc;
290289
}

‎fs/ext2/inode.c‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,21 +1264,11 @@ static void __ext2_truncate_blocks(struct inode *inode, loff_t offset)
12641264

12651265
static void ext2_truncate_blocks(struct inode *inode, loff_t offset)
12661266
{
1267-
/*
1268-
* XXX: it seems like a bug here that we don't allow
1269-
* IS_APPEND inode to have blocks-past-i_size trimmed off.
1270-
* review and fix this.
1271-
*
1272-
* Also would be nice to be able to handle IO errors and such,
1273-
* but that's probably too much to ask.
1274-
*/
12751267
if (!(S_ISREG(inode->i_mode) || S_ISDIR(inode->i_mode) ||
12761268
S_ISLNK(inode->i_mode)))
12771269
return;
12781270
if (ext2_inode_is_fast_symlink(inode))
12791271
return;
1280-
if (IS_APPEND(inode) || IS_IMMUTABLE(inode))
1281-
return;
12821272

12831273
dax_sem_down_write(EXT2_I(inode));
12841274
__ext2_truncate_blocks(inode, offset);

‎fs/ext2/namei.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ static inline int ext2_add_nondir(struct dentry *dentry, struct inode *inode)
4141
{
4242
int err = ext2_add_link(dentry, inode);
4343
if (!err) {
44-
unlock_new_inode(inode);
45-
d_instantiate(dentry, inode);
44+
d_instantiate_new(dentry, inode);
4645
return 0;
4746
}
4847
inode_dec_link_count(inode);
@@ -255,8 +254,7 @@ static int ext2_mkdir(struct inode * dir, struct dentry * dentry, umode_t mode)
255254
if (err)
256255
goto out_fail;
257256

258-
unlock_new_inode(inode);
259-
d_instantiate(dentry, inode);
257+
d_instantiate_new(dentry, inode);
260258
out:
261259
return err;
262260

0 commit comments

Comments
 (0)