Skip to content

Commit d65f5c5

Browse files
committed
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs-2.6: [PATCH] pass struct path * to do_add_mount() [PATCH] switch mtd and dm-table to lookup_bdev() [patch 3/4] vfs: remove unused nameidata argument of may_create() [PATCH] devpts: switch to IDA [PATCH 2/2] proc: switch inode number allocation to IDA [PATCH 1/2] proc: fix inode number bogorithmetic [PATCH] fix bdev leak in block_dev.c do_open() [PATCH] fix races and leaks in vfs_quota_on() users [PATCH] clean dup2() up a bit [PATCH] merge locate_fd() and get_unused_fd() [PATCH] ipv4_static_sysctl_init() should be under CONFIG_SYSCTL Re: BUG at security/selinux/avc.c:883 (was: Re: linux-next: Tree
2 parents a8086ad + 8d66bf5 commit d65f5c5

21 files changed

Lines changed: 203 additions & 268 deletions

File tree

‎drivers/md/dm-table.c‎

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -316,29 +316,12 @@ static inline int check_space(struct dm_table *t)
316316
*/
317317
static int lookup_device(const char *path, dev_t *dev)
318318
{
319-
int r;
320-
struct nameidata nd;
321-
struct inode *inode;
322-
323-
if ((r = path_lookup(path, LOOKUP_FOLLOW, &nd)))
324-
return r;
325-
326-
inode = nd.path.dentry->d_inode;
327-
if (!inode) {
328-
r = -ENOENT;
329-
goto out;
330-
}
331-
332-
if (!S_ISBLK(inode->i_mode)) {
333-
r = -ENOTBLK;
334-
goto out;
335-
}
336-
337-
*dev = inode->i_rdev;
338-
339-
out:
340-
path_put(&nd.path);
341-
return r;
319+
struct block_device *bdev = lookup_bdev(path);
320+
if (IS_ERR(bdev))
321+
return PTR_ERR(bdev);
322+
*dev = bdev->bd_dev;
323+
bdput(bdev);
324+
return 0;
342325
}
343326

344327
/*

‎drivers/mtd/mtdsuper.c‎

Lines changed: 11 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
125125
int (*fill_super)(struct super_block *, void *, int),
126126
struct vfsmount *mnt)
127127
{
128-
struct nameidata nd;
128+
struct block_device *bdev;
129129
int mtdnr, ret;
130130

131131
if (!dev_name)
@@ -181,29 +181,20 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
181181
/* try the old way - the hack where we allowed users to mount
182182
* /dev/mtdblock$(n) but didn't actually _use_ the blockdev
183183
*/
184-
ret = path_lookup(dev_name, LOOKUP_FOLLOW, &nd);
185-
186-
DEBUG(1, "MTDSB: path_lookup() returned %d, inode %p\n",
187-
ret, nd.path.dentry ? nd.path.dentry->d_inode : NULL);
188-
189-
if (ret)
184+
bdev = lookup_bdev(dev_name);
185+
if (IS_ERR(bdev)) {
186+
ret = PTR_ERR(bdev);
187+
DEBUG(1, "MTDSB: lookup_bdev() returned %d\n", ret);
190188
return ret;
191-
192-
ret = -EINVAL;
193-
194-
if (!S_ISBLK(nd.path.dentry->d_inode->i_mode))
195-
goto out;
196-
197-
if (nd.path.mnt->mnt_flags & MNT_NODEV) {
198-
ret = -EACCES;
199-
goto out;
200189
}
190+
DEBUG(1, "MTDSB: lookup_bdev() returned 0\n");
201191

202-
if (imajor(nd.path.dentry->d_inode) != MTD_BLOCK_MAJOR)
192+
ret = -EINVAL;
193+
if (MAJOR(bdev->bd_dev) != MTD_BLOCK_MAJOR)
203194
goto not_an_MTD_device;
204195

205-
mtdnr = iminor(nd.path.dentry->d_inode);
206-
path_put(&nd.path);
196+
mtdnr = MINOR(bdev->bd_dev);
197+
bdput(bdev);
207198

208199
return get_sb_mtd_nr(fs_type, flags, dev_name, data, mtdnr, fill_super,
209200
mnt);
@@ -213,10 +204,8 @@ int get_sb_mtd(struct file_system_type *fs_type, int flags,
213204
printk(KERN_NOTICE
214205
"MTD: Attempt to mount non-MTD device \"%s\"\n",
215206
dev_name);
216-
out:
217-
path_put(&nd.path);
207+
bdput(bdev);
218208
return ret;
219-
220209
}
221210

222211
EXPORT_SYMBOL_GPL(get_sb_mtd);

‎fs/afs/mntpt.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ static void *afs_mntpt_follow_link(struct dentry *dentry, struct nameidata *nd)
232232
}
233233

234234
mntget(newmnt);
235-
err = do_add_mount(newmnt, nd, MNT_SHRINKABLE, &afs_vfsmounts);
235+
err = do_add_mount(newmnt, &nd->path, MNT_SHRINKABLE, &afs_vfsmounts);
236236
switch (err) {
237237
case 0:
238238
path_put(&nd->path);

‎fs/block_dev.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -941,8 +941,10 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part)
941941
* hooks: /n/, see "layering violations".
942942
*/
943943
ret = devcgroup_inode_permission(bdev->bd_inode, perm);
944-
if (ret != 0)
944+
if (ret != 0) {
945+
bdput(bdev);
945946
return ret;
947+
}
946948

947949
ret = -ENXIO;
948950
file->f_mapping = bdev->bd_inode->i_mapping;
@@ -1234,6 +1236,7 @@ struct block_device *lookup_bdev(const char *path)
12341236
bdev = ERR_PTR(error);
12351237
goto out;
12361238
}
1239+
EXPORT_SYMBOL(lookup_bdev);
12371240

12381241
/**
12391242
* open_bdev_excl - open a block device by name and set it up for use

‎fs/cifs/cifs_dfs_ref.c‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ static int add_mount_helper(struct vfsmount *newmnt, struct nameidata *nd,
226226
int err;
227227

228228
mntget(newmnt);
229-
err = do_add_mount(newmnt, nd, nd->path.mnt->mnt_flags, mntlist);
229+
err = do_add_mount(newmnt, &nd->path, nd->path.mnt->mnt_flags, mntlist);
230230
switch (err) {
231231
case 0:
232232
path_put(&nd->path);

‎fs/devpts/inode.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
#define DEVPTS_DEFAULT_MODE 0600
3030

3131
extern int pty_limit; /* Config limit on Unix98 ptys */
32-
static DEFINE_IDR(allocated_ptys);
32+
static DEFINE_IDA(allocated_ptys);
3333
static DEFINE_MUTEX(allocated_ptys_lock);
3434

3535
static struct vfsmount *devpts_mnt;
@@ -180,24 +180,24 @@ static struct dentry *get_node(int num)
180180
int devpts_new_index(void)
181181
{
182182
int index;
183-
int idr_ret;
183+
int ida_ret;
184184

185185
retry:
186-
if (!idr_pre_get(&allocated_ptys, GFP_KERNEL)) {
186+
if (!ida_pre_get(&allocated_ptys, GFP_KERNEL)) {
187187
return -ENOMEM;
188188
}
189189

190190
mutex_lock(&allocated_ptys_lock);
191-
idr_ret = idr_get_new(&allocated_ptys, NULL, &index);
192-
if (idr_ret < 0) {
191+
ida_ret = ida_get_new(&allocated_ptys, &index);
192+
if (ida_ret < 0) {
193193
mutex_unlock(&allocated_ptys_lock);
194-
if (idr_ret == -EAGAIN)
194+
if (ida_ret == -EAGAIN)
195195
goto retry;
196196
return -EIO;
197197
}
198198

199199
if (index >= pty_limit) {
200-
idr_remove(&allocated_ptys, index);
200+
ida_remove(&allocated_ptys, index);
201201
mutex_unlock(&allocated_ptys_lock);
202202
return -EIO;
203203
}
@@ -208,7 +208,7 @@ int devpts_new_index(void)
208208
void devpts_kill_index(int idx)
209209
{
210210
mutex_lock(&allocated_ptys_lock);
211-
idr_remove(&allocated_ptys, idx);
211+
ida_remove(&allocated_ptys, idx);
212212
mutex_unlock(&allocated_ptys_lock);
213213
}
214214

‎fs/dquot.c‎

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1793,6 +1793,21 @@ static int vfs_quota_on_remount(struct super_block *sb, int type)
17931793
return ret;
17941794
}
17951795

1796+
int vfs_quota_on_path(struct super_block *sb, int type, int format_id,
1797+
struct path *path)
1798+
{
1799+
int error = security_quota_on(path->dentry);
1800+
if (error)
1801+
return error;
1802+
/* Quota file not on the same filesystem? */
1803+
if (path->mnt->mnt_sb != sb)
1804+
error = -EXDEV;
1805+
else
1806+
error = vfs_quota_on_inode(path->dentry->d_inode, type,
1807+
format_id);
1808+
return error;
1809+
}
1810+
17961811
/* Actual function called from quotactl() */
17971812
int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path,
17981813
int remount)
@@ -1804,19 +1819,10 @@ int vfs_quota_on(struct super_block *sb, int type, int format_id, char *path,
18041819
return vfs_quota_on_remount(sb, type);
18051820

18061821
error = path_lookup(path, LOOKUP_FOLLOW, &nd);
1807-
if (error < 0)
1808-
return error;
1809-
error = security_quota_on(nd.path.dentry);
1810-
if (error)
1811-
goto out_path;
1812-
/* Quota file not on the same filesystem? */
1813-
if (nd.path.mnt->mnt_sb != sb)
1814-
error = -EXDEV;
1815-
else
1816-
error = vfs_quota_on_inode(nd.path.dentry->d_inode, type,
1817-
format_id);
1818-
out_path:
1819-
path_put(&nd.path);
1822+
if (!error) {
1823+
error = vfs_quota_on_path(sb, type, format_id, &nd.path);
1824+
path_put(&nd.path);
1825+
}
18201826
return error;
18211827
}
18221828

@@ -2185,6 +2191,7 @@ EXPORT_SYMBOL(unregister_quota_format);
21852191
EXPORT_SYMBOL(dqstats);
21862192
EXPORT_SYMBOL(dq_data_lock);
21872193
EXPORT_SYMBOL(vfs_quota_on);
2194+
EXPORT_SYMBOL(vfs_quota_on_path);
21882195
EXPORT_SYMBOL(vfs_quota_on_mount);
21892196
EXPORT_SYMBOL(vfs_quota_off);
21902197
EXPORT_SYMBOL(vfs_quota_sync);

‎fs/ext3/super.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2810,8 +2810,9 @@ static int ext3_quota_on(struct super_block *sb, int type, int format_id,
28102810
journal_unlock_updates(EXT3_SB(sb)->s_journal);
28112811
}
28122812

2813+
err = vfs_quota_on_path(sb, type, format_id, &nd.path);
28132814
path_put(&nd.path);
2814-
return vfs_quota_on(sb, type, format_id, path, remount);
2815+
return err;
28152816
}
28162817

28172818
/* Read data from quotafile - avoid pagecache and such because we cannot afford

‎fs/ext4/super.c‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3352,8 +3352,9 @@ static int ext4_quota_on(struct super_block *sb, int type, int format_id,
33523352
jbd2_journal_unlock_updates(EXT4_SB(sb)->s_journal);
33533353
}
33543354

3355+
err = vfs_quota_on_path(sb, type, format_id, &nd.path);
33553356
path_put(&nd.path);
3356-
return vfs_quota_on(sb, type, format_id, path, remount);
3357+
return err;
33573358
}
33583359

33593360
/* Read data from quotafile - avoid pagecache and such because we cannot afford

0 commit comments

Comments
 (0)