From 00488aa21150053a568343df2aca10a33559d7d8 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:13:58 -0500 Subject: [PATCH 01/17] zonefs: d_splice_alias() will do the right thing on ERR_PTR() inode Acked-by: Damien Le Moal Signed-off-by: Al Viro --- fs/zonefs/super.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/zonefs/super.c b/fs/zonefs/super.c index e6a75401677d..93971742613a 100644 --- a/fs/zonefs/super.c +++ b/fs/zonefs/super.c @@ -747,8 +747,6 @@ static struct dentry *zonefs_lookup(struct inode *dir, struct dentry *dentry, inode = zonefs_get_dir_inode(dir, dentry); else inode = zonefs_get_file_inode(dir, dentry); - if (IS_ERR(inode)) - return ERR_CAST(inode); return d_splice_alias(inode, dentry); } From 96931dfe437cbd480fcfa72bd05b41b9ef15522e Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:55:03 -0500 Subject: [PATCH 02/17] nilfs2: d_obtain_alias(ERR_PTR(...)) will do the right thing... Acked-by: Ryusuke Konishi Signed-off-by: Al Viro --- fs/nilfs2/namei.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/nilfs2/namei.c b/fs/nilfs2/namei.c index 2a4e7f4a8102..8e8c7c981a7a 100644 --- a/fs/nilfs2/namei.c +++ b/fs/nilfs2/namei.c @@ -439,7 +439,6 @@ out: static struct dentry *nilfs_get_parent(struct dentry *child) { unsigned long ino; - struct inode *inode; struct nilfs_root *root; ino = nilfs_inode_by_name(d_inode(child), &dotdot_name); @@ -448,11 +447,7 @@ static struct dentry *nilfs_get_parent(struct dentry *child) root = NILFS_I(d_inode(child))->i_root; - inode = nilfs_iget(child->d_sb, root, ino); - if (IS_ERR(inode)) - return ERR_CAST(inode); - - return d_obtain_alias(inode); + return d_obtain_alias(nilfs_iget(child->d_sb, root, ino)); } static struct dentry *nilfs_get_dentry(struct super_block *sb, u64 cno, From 743cde7419bc9580a71a7e6f15eda66d6d8e71c2 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 12 Nov 2023 16:56:19 -0500 Subject: [PATCH 03/17] bfs_add_entry(): get rid of pointless ->d_name.len checks First of all, any dentry getting here would have passed bfs_lookup(), so it it passed ENAMETOOLONG check there, there's no need to repeat it. And we are not going to get dentries with zero name length - that check ultimately comes from ext2 and it's as pointless here as it used to be there. Acked-by: Tigran Aivazian Signed-off-by: Al Viro --- fs/bfs/dir.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/fs/bfs/dir.c b/fs/bfs/dir.c index fbc4ae80a4b2..c375e22c4c0c 100644 --- a/fs/bfs/dir.c +++ b/fs/bfs/dir.c @@ -275,11 +275,6 @@ static int bfs_add_entry(struct inode *dir, const struct qstr *child, int ino) dprintf("name=%s, namelen=%d\n", name, namelen); - if (!namelen) - return -ENOENT; - if (namelen > BFS_NAMELEN) - return -ENAMETOOLONG; - sblock = BFS_I(dir)->i_sblock; eblock = BFS_I(dir)->i_eblock; for (block = sblock; block <= eblock; block++) { From 28403c09e36c84233db46ee29fdfc7124a8f576d Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 19:27:17 -0500 Subject: [PATCH 04/17] nfsd: kill stale comment about simple_fill_super() requirements That went into the tree back in 2005; the comment used to be true for predecessor of simple_fill_super() that happened to live in nfsd; that one didn't take care to skip the array entries with NULL ->name, so it could not tolerate any gaps. That had been fixed in 2003 when nfsd_fill_super() had been abstracted into simple_fill_super(); if Neil's patch lived out of tree during that time, he probably replaced the name of function when rebasing it and didn't notice that restriction in question was no longer there. Acked-by: Chuck Lever Signed-off-by: Al Viro --- fs/nfsd/nfsctl.c | 4 ---- 1 file changed, 4 deletions(-) diff --git a/fs/nfsd/nfsctl.c b/fs/nfsd/nfsctl.c index 3e15b72f421d..26a25e40c451 100644 --- a/fs/nfsd/nfsctl.c +++ b/fs/nfsd/nfsctl.c @@ -48,10 +48,6 @@ enum { NFSD_MaxBlkSize, NFSD_MaxConnections, NFSD_Filecache, - /* - * The below MUST come last. Otherwise we leave a hole in nfsd_files[] - * with !CONFIG_NFSD_V4 and simple_fill_super() goes oops - */ #ifdef CONFIG_NFSD_V4 NFSD_Leasetime, NFSD_Gracetime, From 32328a73e0ad4a1babebf798c309c64ee3b97400 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:14:38 -0500 Subject: [PATCH 05/17] udf: d_splice_alias() will do the right thing on ERR_PTR() inode Acked-by: Jan Kara Signed-off-by: Al Viro --- fs/udf/namei.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 3508ac484da3..92f25e540430 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -125,8 +125,6 @@ static struct dentry *udf_lookup(struct inode *dir, struct dentry *dentry, udf_fiiter_release(&iter); inode = udf_iget(dir->i_sb, &loc); - if (IS_ERR(inode)) - return ERR_CAST(inode); } return d_splice_alias(inode, dentry); From f58b8c3ef7b25582448c262e56f0414c48424952 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:55:30 -0500 Subject: [PATCH 06/17] udf: d_obtain_alias(ERR_PTR(...)) will do the right thing... Acked-by: Jan Kara Signed-off-by: Al Viro --- fs/udf/namei.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index 92f25e540430..a64102d63781 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -897,7 +897,6 @@ out_oiter: static struct dentry *udf_get_parent(struct dentry *child) { struct kernel_lb_addr tloc; - struct inode *inode = NULL; struct udf_fileident_iter iter; int err; @@ -907,11 +906,7 @@ static struct dentry *udf_get_parent(struct dentry *child) tloc = lelb_to_cpu(iter.fi.icb.extLocation); udf_fiiter_release(&iter); - inode = udf_iget(child->d_sb, &tloc); - if (IS_ERR(inode)) - return ERR_CAST(inode); - - return d_obtain_alias(inode); + return d_obtain_alias(udf_iget(child->d_sb, &tloc)); } From 5e7582f6e3a89d2fecf0a08e44ee02780c4cb4cf Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 12 Nov 2023 17:12:26 -0500 Subject: [PATCH 07/17] udf_fiiter_add_entry(): check for zero ->d_name.len is bogus... Acked-by: Jan Kara Signed-off-by: Al Viro --- fs/udf/namei.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/udf/namei.c b/fs/udf/namei.c index a64102d63781..b1674e07d5a5 100644 --- a/fs/udf/namei.c +++ b/fs/udf/namei.c @@ -228,8 +228,6 @@ static int udf_fiiter_add_entry(struct inode *dir, struct dentry *dentry, char name[UDF_NAME_LEN_CS0]; if (dentry) { - if (!dentry->d_name.len) - return -EINVAL; namelen = udf_put_filename(dir->i_sb, dentry->d_name.name, dentry->d_name.len, name, UDF_NAME_LEN_CS0); From 6f36230e235da4f34a831d20c51f0472e1a36f48 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:11:47 -0500 Subject: [PATCH 08/17] hostfs: use d_splice_alias() calling conventions to simplify failure exits Signed-off-by: Al Viro --- fs/hostfs/hostfs_kern.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index ea87f24c6c3f..a73d27c4dd58 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c @@ -637,12 +637,8 @@ static struct dentry *hostfs_lookup(struct inode *ino, struct dentry *dentry, inode = hostfs_iget(ino->i_sb, name); __putname(name); - if (IS_ERR(inode)) { - if (PTR_ERR(inode) == -ENOENT) - inode = NULL; - else - return ERR_CAST(inode); - } + if (inode == ERR_PTR(-ENOENT)) + inode = NULL; return d_splice_alias(inode, dentry); } From 1eae9a47835ed4703055afbb3c52fef6d07a8a4c Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:13:08 -0500 Subject: [PATCH 09/17] /proc/sys: use d_splice_alias() calling conventions to simplify failure exits Signed-off-by: Al Viro --- fs/proc/proc_sysctl.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c index 8064ea76f80b..1ae6486dc7d4 100644 --- a/fs/proc/proc_sysctl.c +++ b/fs/proc/proc_sysctl.c @@ -534,13 +534,8 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry, goto out; } - inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); - if (IS_ERR(inode)) { - err = ERR_CAST(inode); - goto out; - } - d_set_d_op(dentry, &proc_sys_dentry_operations); + inode = proc_sys_make_inode(dir->i_sb, h ? h : head, p); err = d_splice_alias(inode, dentry); out: @@ -698,13 +693,8 @@ static bool proc_sys_fill_cache(struct file *file, return false; if (d_in_lookup(child)) { struct dentry *res; - inode = proc_sys_make_inode(dir->d_sb, head, table); - if (IS_ERR(inode)) { - d_lookup_done(child); - dput(child); - return false; - } d_set_d_op(child, &proc_sys_dentry_operations); + inode = proc_sys_make_inode(dir->d_sb, head, table); res = d_splice_alias(inode, child); d_lookup_done(child); if (unlikely(res)) { From 155d46beea3dd1c26564856cbabf7f654ad094e6 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:51:48 -0500 Subject: [PATCH 10/17] affs: d_obtain_alias(ERR_PTR(...)) will do the right thing Signed-off-by: Al Viro --- fs/affs/namei.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/affs/namei.c b/fs/affs/namei.c index d6b9758ee23d..8c154490a2d6 100644 --- a/fs/affs/namei.c +++ b/fs/affs/namei.c @@ -532,9 +532,6 @@ static struct dentry *affs_get_parent(struct dentry *child) parent = affs_iget(child->d_sb, be32_to_cpu(AFFS_TAIL(child->d_sb, bh)->parent)); brelse(bh); - if (IS_ERR(parent)) - return ERR_CAST(parent); - return d_obtain_alias(parent); } From f6c8bfcf951feeab716bd051e4c1d767fe82df0f Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 11 Nov 2023 01:52:25 -0500 Subject: [PATCH 11/17] befs: d_obtain_alias(ERR_PTR(...)) will do the right thing Signed-off-by: Al Viro --- fs/befs/linuxvfs.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c index a93d76df8ed8..2b4dda047450 100644 --- a/fs/befs/linuxvfs.c +++ b/fs/befs/linuxvfs.c @@ -671,9 +671,6 @@ static struct dentry *befs_get_parent(struct dentry *child) parent = befs_iget(child->d_sb, (unsigned long)befs_ino->i_parent.start); - if (IS_ERR(parent)) - return ERR_CAST(parent); - return d_obtain_alias(parent); } From 556f38bf457fee5d9f3ede65b67fd91dd2ea2ca1 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 12 Nov 2023 16:25:46 -0500 Subject: [PATCH 12/17] ext4_add_entry(): ->d_name.len is never 0 That bogosity goes back to the initial merge of ext3. Once upon a time ext2 used to have a similar check; that got taken out during the switch to page cache (June 2001). ext3 got merged into mainline 5 months later, still using buffer cache for directories; removal of the pointless check in ext2 should've been done as a separate patch, but it hadn't been, so that thing got missed... Signed-off-by: Al Viro --- fs/ext4/namei.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/fs/ext4/namei.c b/fs/ext4/namei.c index d252935f9c8a..fa8b8dd841b5 100644 --- a/fs/ext4/namei.c +++ b/fs/ext4/namei.c @@ -2388,8 +2388,6 @@ static int ext4_add_entry(handle_t *handle, struct dentry *dentry, sb = dir->i_sb; blocksize = sb->s_blocksize; - if (!dentry->d_name.len) - return -EINVAL; if (fscrypt_is_nokey_name(dentry)) return -ENOKEY; From b64b0732c3eec11783dd6bb12757dc04395a73e1 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 12 Nov 2023 17:03:14 -0500 Subject: [PATCH 13/17] __ocfs2_add_entry(), ocfs2_prepare_dir_for_insert(): namelen checks namelen can't be zero; neither when it's coming from dentry name, nor when dealing with orphans (in ocfs2_orphan_add() and __ocfs2_prepare_orphan_dir()). Rudiment of old ext2 pointless check, long gone in ext2 itself... Signed-off-by: Al Viro --- fs/ocfs2/dir.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/fs/ocfs2/dir.c b/fs/ocfs2/dir.c index a14c8fee6ee5..d620d4c53c6f 100644 --- a/fs/ocfs2/dir.c +++ b/fs/ocfs2/dir.c @@ -1593,9 +1593,6 @@ int __ocfs2_add_entry(handle_t *handle, struct buffer_head *insert_bh = lookup->dl_leaf_bh; char *data_start = insert_bh->b_data; - if (!namelen) - return -EINVAL; - if (ocfs2_dir_indexed(dir)) { struct buffer_head *bh; @@ -4245,12 +4242,6 @@ int ocfs2_prepare_dir_for_insert(struct ocfs2_super *osb, trace_ocfs2_prepare_dir_for_insert( (unsigned long long)OCFS2_I(dir)->ip_blkno, namelen); - if (!namelen) { - ret = -EINVAL; - mlog_errno(ret); - goto out; - } - /* * Do this up front to reduce confusion. * From 3a1613672e859b85cf87bbe7569552b55612a0f5 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 12 Nov 2023 17:08:50 -0500 Subject: [PATCH 14/17] reiserfs_add_entry(): get rid of pointless namelen checks In all cases namelen is ->d_name.len of some dentry; moreover, a dentry that has passed ->lookup() without triggering ENAMETOOLONG check there. The comment next to these checks is either a rudiment of some other check that used to be there once upon a time, or an attempt to come up with the possible reason for that check (well, more like "why does ext3 do it?") Signed-off-by: Al Viro --- fs/reiserfs/namei.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/reiserfs/namei.c b/fs/reiserfs/namei.c index 994d6e6995ab..c5f233b4a27f 100644 --- a/fs/reiserfs/namei.c +++ b/fs/reiserfs/namei.c @@ -451,13 +451,6 @@ static int reiserfs_add_entry(struct reiserfs_transaction_handle *th, BUG_ON(!th->t_trans_id); - /* cannot allow items to be added into a busy deleted directory */ - if (!namelen) - return -EINVAL; - - if (namelen > REISERFS_MAX_NAME(dir->i_sb->s_blocksize)) - return -ENAMETOOLONG; - /* each entry has unique key. compose it */ make_cpu_key(&entry_key, dir, get_third_component(dir->i_sb, name, namelen), From fda43691041c7ee685da903641402a0f913fe9e9 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Tue, 14 Nov 2023 12:20:22 -0500 Subject: [PATCH 15/17] ocfs2_find_match(): there's no such thing as NULL or negative ->d_parent Signed-off-by: Al Viro --- fs/ocfs2/dcache.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/fs/ocfs2/dcache.c b/fs/ocfs2/dcache.c index 04fc8344063a..a9b8688aaf30 100644 --- a/fs/ocfs2/dcache.c +++ b/fs/ocfs2/dcache.c @@ -124,17 +124,10 @@ static int ocfs2_match_dentry(struct dentry *dentry, if (!dentry->d_fsdata) return 0; - if (!dentry->d_parent) - return 0; - if (skip_unhashed && d_unhashed(dentry)) return 0; parent = d_inode(dentry->d_parent); - /* Negative parent dentry? */ - if (!parent) - return 0; - /* Name is in a different directory. */ if (OCFS2_I(parent)->ip_blkno != parent_blkno) return 0; From 12c0c3a65a0f399e9bb582350314d59960e62919 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Thu, 20 Apr 2023 15:36:12 -0400 Subject: [PATCH 16/17] orangefs: saner arguments passing in readdir guts orangefs_dir_fill() doesn't use oi and dentry arguments at all do_readdir() gets dentry, uses only dentry->d_inode; it also gets oi, which is ORANGEFS_I(dentry->d_inode) (i.e. ->d_inode - constant offset). orangefs_dir_mode() gets dentry and oi, uses only to pass those to do_readdir(). orangefs_dir_iterate() uses dentry and oi only to pass those to orangefs_dir_fill() and orangefs_dir_more(). The only thing it really needs is ->d_inode; moreover, that's better expressed as file_inode(file) - no need to go through ->f_path.dentry->d_inode. Signed-off-by: Al Viro --- fs/orangefs/dir.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/fs/orangefs/dir.c b/fs/orangefs/dir.c index 9cacce5d55c1..6d1fbeca9d81 100644 --- a/fs/orangefs/dir.c +++ b/fs/orangefs/dir.c @@ -58,10 +58,10 @@ struct orangefs_dir { * first part of the part list. */ -static int do_readdir(struct orangefs_inode_s *oi, - struct orangefs_dir *od, struct dentry *dentry, +static int do_readdir(struct orangefs_dir *od, struct inode *inode, struct orangefs_kernel_op_s *op) { + struct orangefs_inode_s *oi = ORANGEFS_I(inode); struct orangefs_readdir_response_s *resp; int bufi, r; @@ -87,7 +87,7 @@ again: op->upcall.req.readdir.buf_index = bufi; r = service_operation(op, "orangefs_readdir", - get_interruptible_flag(dentry->d_inode)); + get_interruptible_flag(inode)); orangefs_readdir_index_put(bufi); @@ -158,8 +158,7 @@ static int parse_readdir(struct orangefs_dir *od, return 0; } -static int orangefs_dir_more(struct orangefs_inode_s *oi, - struct orangefs_dir *od, struct dentry *dentry) +static int orangefs_dir_more(struct orangefs_dir *od, struct inode *inode) { struct orangefs_kernel_op_s *op; int r; @@ -169,7 +168,7 @@ static int orangefs_dir_more(struct orangefs_inode_s *oi, od->error = -ENOMEM; return -ENOMEM; } - r = do_readdir(oi, od, dentry, op); + r = do_readdir(od, inode, op); if (r) { od->error = r; goto out; @@ -238,9 +237,7 @@ next: return 1; } -static int orangefs_dir_fill(struct orangefs_inode_s *oi, - struct orangefs_dir *od, struct dentry *dentry, - struct dir_context *ctx) +static int orangefs_dir_fill(struct orangefs_dir *od, struct dir_context *ctx) { struct orangefs_dir_part *part; size_t count; @@ -304,15 +301,10 @@ static loff_t orangefs_dir_llseek(struct file *file, loff_t offset, static int orangefs_dir_iterate(struct file *file, struct dir_context *ctx) { - struct orangefs_inode_s *oi; - struct orangefs_dir *od; - struct dentry *dentry; + struct orangefs_dir *od = file->private_data; + struct inode *inode = file_inode(file); int r; - dentry = file->f_path.dentry; - oi = ORANGEFS_I(dentry->d_inode); - od = file->private_data; - if (od->error) return od->error; @@ -342,7 +334,7 @@ static int orangefs_dir_iterate(struct file *file, */ while (od->token != ORANGEFS_ITERATE_END && ctx->pos > od->end) { - r = orangefs_dir_more(oi, od, dentry); + r = orangefs_dir_more(od, inode); if (r) return r; } @@ -351,17 +343,17 @@ static int orangefs_dir_iterate(struct file *file, /* Then try to fill if there's any left in the buffer. */ if (ctx->pos < od->end) { - r = orangefs_dir_fill(oi, od, dentry, ctx); + r = orangefs_dir_fill(od, ctx); if (r) return r; } /* Finally get some more and try to fill. */ if (od->token != ORANGEFS_ITERATE_END) { - r = orangefs_dir_more(oi, od, dentry); + r = orangefs_dir_more(od, inode); if (r) return r; - r = orangefs_dir_fill(oi, od, dentry, ctx); + r = orangefs_dir_fill(od, ctx); } return r; From c5f3fd21789cff8fa1120e802dd1390d34e3eec0 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sat, 16 Sep 2023 12:49:26 -0400 Subject: [PATCH 17/17] apparmorfs: don't duplicate kfree_link() rawdata_link_cb() is identical to it Signed-off-by: Al Viro --- security/apparmor/apparmorfs.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c index 38650e52ef57..63ca77103de9 100644 --- a/security/apparmor/apparmorfs.c +++ b/security/apparmor/apparmorfs.c @@ -1615,11 +1615,6 @@ static char *gen_symlink_name(int depth, const char *dirname, const char *fname) return buffer; } -static void rawdata_link_cb(void *arg) -{ - kfree(arg); -} - static const char *rawdata_get_link_base(struct dentry *dentry, struct inode *inode, struct delayed_call *done, @@ -1643,7 +1638,7 @@ static const char *rawdata_get_link_base(struct dentry *dentry, if (IS_ERR(target)) return target; - set_delayed_call(done, rawdata_link_cb, target); + set_delayed_call(done, kfree_link, target); return target; }