From: NeilBrown <neil@brown.name>
Instead of explicitly locking the parent and performing a look up in
apparmor, use simple_start_creating(), and then simple_done_creating()
to unlock and drop the dentry.
This removes the need to check for an existing entry (as
simple_start_creating() acts like an exclusive create and can return
-EEXIST), simplifies error paths, and keeps dir locking code
centralised.
Signed-off-by: NeilBrown <neil@brown.name>
---
security/apparmor/apparmorfs.c | 38 ++++++++--------------------------
1 file changed, 9 insertions(+), 29 deletions(-)
diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
index 907bd2667e28..7f78c36e6e50 100644
--- a/security/apparmor/apparmorfs.c
+++ b/security/apparmor/apparmorfs.c
@@ -282,32 +282,19 @@ static struct dentry *aafs_create(const char *name, umode_t mode,
dir = d_inode(parent);
- inode_lock(dir);
- dentry = lookup_noperm(&QSTR(name), parent);
+ dentry = simple_start_creating(parent, name);
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
- goto fail_lock;
- }
-
- if (d_really_is_positive(dentry)) {
- error = -EEXIST;
- goto fail_dentry;
+ goto fail;
}
error = __aafs_setup_d_inode(dir, dentry, mode, data, link, fops, iops);
+ simple_done_creating(dentry);
if (error)
- goto fail_dentry;
- inode_unlock(dir);
-
- return dentry;
-
-fail_dentry:
- dput(dentry);
-
-fail_lock:
- inode_unlock(dir);
+ goto fail;
+ return 0;
+fail:
simple_release_fs(&aafs_mnt, &aafs_count);
-
return ERR_PTR(error);
}
@@ -2572,8 +2559,7 @@ static int aa_mk_null_file(struct dentry *parent)
if (error)
return error;
- inode_lock(d_inode(parent));
- dentry = lookup_noperm(&QSTR(NULL_FILE_NAME), parent);
+ dentry = simple_start_creating(parent, NULL_FILE_NAME);
if (IS_ERR(dentry)) {
error = PTR_ERR(dentry);
goto out;
@@ -2581,7 +2567,7 @@ static int aa_mk_null_file(struct dentry *parent)
inode = new_inode(parent->d_inode->i_sb);
if (!inode) {
error = -ENOMEM;
- goto out1;
+ goto out;
}
inode->i_ino = get_next_ino();
@@ -2593,18 +2579,12 @@ static int aa_mk_null_file(struct dentry *parent)
aa_null.dentry = dget(dentry);
aa_null.mnt = mntget(mount);
- error = 0;
-
-out1:
- dput(dentry);
out:
- inode_unlock(d_inode(parent));
+ simple_done_creating(dentry);
simple_release_fs(&mount, &count);
return error;
}
-
-
static const char *policy_get_link(struct dentry *dentry,
struct inode *inode,
struct delayed_call *done)
--
2.50.0.107.gf914562f5916.dirty
On Wed, 2026-02-04 at 15:57 +1100, NeilBrown wrote:
> From: NeilBrown <neil@brown.name>
>
> Instead of explicitly locking the parent and performing a look up in
> apparmor, use simple_start_creating(), and then simple_done_creating()
> to unlock and drop the dentry.
>
> This removes the need to check for an existing entry (as
> simple_start_creating() acts like an exclusive create and can return
> -EEXIST), simplifies error paths, and keeps dir locking code
> centralised.
>
> Signed-off-by: NeilBrown <neil@brown.name>
> ---
> security/apparmor/apparmorfs.c | 38 ++++++++--------------------------
> 1 file changed, 9 insertions(+), 29 deletions(-)
>
> diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
> index 907bd2667e28..7f78c36e6e50 100644
> --- a/security/apparmor/apparmorfs.c
> +++ b/security/apparmor/apparmorfs.c
> @@ -282,32 +282,19 @@ static struct dentry *aafs_create(const char *name, umode_t mode,
>
> dir = d_inode(parent);
>
> - inode_lock(dir);
> - dentry = lookup_noperm(&QSTR(name), parent);
> + dentry = simple_start_creating(parent, name);
> if (IS_ERR(dentry)) {
> error = PTR_ERR(dentry);
> - goto fail_lock;
> - }
> -
> - if (d_really_is_positive(dentry)) {
> - error = -EEXIST;
> - goto fail_dentry;
> + goto fail;
> }
>
> error = __aafs_setup_d_inode(dir, dentry, mode, data, link, fops, iops);
> + simple_done_creating(dentry);
> if (error)
> - goto fail_dentry;
> - inode_unlock(dir);
> -
> - return dentry;
> -
> -fail_dentry:
> - dput(dentry);
> -
> -fail_lock:
> - inode_unlock(dir);
> + goto fail;
> + return 0;
As KTR points out, this should be "return NULL;"
> +fail:
> simple_release_fs(&aafs_mnt, &aafs_count);
> -
> return ERR_PTR(error);
> }
>
> @@ -2572,8 +2559,7 @@ static int aa_mk_null_file(struct dentry *parent)
> if (error)
> return error;
>
> - inode_lock(d_inode(parent));
> - dentry = lookup_noperm(&QSTR(NULL_FILE_NAME), parent);
> + dentry = simple_start_creating(parent, NULL_FILE_NAME);
> if (IS_ERR(dentry)) {
> error = PTR_ERR(dentry);
> goto out;
> @@ -2581,7 +2567,7 @@ static int aa_mk_null_file(struct dentry *parent)
> inode = new_inode(parent->d_inode->i_sb);
> if (!inode) {
> error = -ENOMEM;
> - goto out1;
> + goto out;
> }
>
> inode->i_ino = get_next_ino();
> @@ -2593,18 +2579,12 @@ static int aa_mk_null_file(struct dentry *parent)
> aa_null.dentry = dget(dentry);
> aa_null.mnt = mntget(mount);
>
> - error = 0;
> -
> -out1:
> - dput(dentry);
> out:
> - inode_unlock(d_inode(parent));
> + simple_done_creating(dentry);
> simple_release_fs(&mount, &count);
> return error;
> }
>
> -
> -
> static const char *policy_get_link(struct dentry *dentry,
> struct inode *inode,
> struct delayed_call *done)
Assuming you fix the minor problem above.
Reviewed-by: Jeff Layton <jlayton@kernel.org>
On Thu, 05 Feb 2026, Jeff Layton wrote:
> On Wed, 2026-02-04 at 15:57 +1100, NeilBrown wrote:
> > From: NeilBrown <neil@brown.name>
> >
> > Instead of explicitly locking the parent and performing a look up in
> > apparmor, use simple_start_creating(), and then simple_done_creating()
> > to unlock and drop the dentry.
> >
> > This removes the need to check for an existing entry (as
> > simple_start_creating() acts like an exclusive create and can return
> > -EEXIST), simplifies error paths, and keeps dir locking code
> > centralised.
> >
> > Signed-off-by: NeilBrown <neil@brown.name>
> > ---
> > security/apparmor/apparmorfs.c | 38 ++++++++--------------------------
> > 1 file changed, 9 insertions(+), 29 deletions(-)
> >
> > diff --git a/security/apparmor/apparmorfs.c b/security/apparmor/apparmorfs.c
> > index 907bd2667e28..7f78c36e6e50 100644
> > --- a/security/apparmor/apparmorfs.c
> > +++ b/security/apparmor/apparmorfs.c
> > @@ -282,32 +282,19 @@ static struct dentry *aafs_create(const char *name, umode_t mode,
> >
> > dir = d_inode(parent);
> >
> > - inode_lock(dir);
> > - dentry = lookup_noperm(&QSTR(name), parent);
> > + dentry = simple_start_creating(parent, name);
> > if (IS_ERR(dentry)) {
> > error = PTR_ERR(dentry);
> > - goto fail_lock;
> > - }
> > -
> > - if (d_really_is_positive(dentry)) {
> > - error = -EEXIST;
> > - goto fail_dentry;
> > + goto fail;
> > }
> >
> > error = __aafs_setup_d_inode(dir, dentry, mode, data, link, fops, iops);
> > + simple_done_creating(dentry);
> > if (error)
> > - goto fail_dentry;
> > - inode_unlock(dir);
> > -
> > - return dentry;
> > -
> > -fail_dentry:
> > - dput(dentry);
> > -
> > -fail_lock:
> > - inode_unlock(dir);
> > + goto fail;
> > + return 0;
>
> As KTR points out, this should be "return NULL;"
Actually it should be "return dentry;" which is what the original code
did.
I've no idea how it became 0...
Callers of aafs_create() will silently treat NULL as failure.
>
> > +fail:
> > simple_release_fs(&aafs_mnt, &aafs_count);
> > -
> > return ERR_PTR(error);
> > }
> >
> > @@ -2572,8 +2559,7 @@ static int aa_mk_null_file(struct dentry *parent)
> > if (error)
> > return error;
> >
> > - inode_lock(d_inode(parent));
> > - dentry = lookup_noperm(&QSTR(NULL_FILE_NAME), parent);
> > + dentry = simple_start_creating(parent, NULL_FILE_NAME);
> > if (IS_ERR(dentry)) {
> > error = PTR_ERR(dentry);
> > goto out;
> > @@ -2581,7 +2567,7 @@ static int aa_mk_null_file(struct dentry *parent)
> > inode = new_inode(parent->d_inode->i_sb);
> > if (!inode) {
> > error = -ENOMEM;
> > - goto out1;
> > + goto out;
> > }
> >
> > inode->i_ino = get_next_ino();
> > @@ -2593,18 +2579,12 @@ static int aa_mk_null_file(struct dentry *parent)
> > aa_null.dentry = dget(dentry);
> > aa_null.mnt = mntget(mount);
> >
> > - error = 0;
> > -
> > -out1:
> > - dput(dentry);
> > out:
> > - inode_unlock(d_inode(parent));
> > + simple_done_creating(dentry);
> > simple_release_fs(&mount, &count);
> > return error;
> > }
> >
> > -
> > -
> > static const char *policy_get_link(struct dentry *dentry,
> > struct inode *inode,
> > struct delayed_call *done)
>
> Assuming you fix the minor problem above.
>
> Reviewed-by: Jeff Layton <jlayton@kernel.org>
>
Thanks,
NeilBrown
Hi NeilBrown,
kernel test robot noticed the following build warnings:
[auto build test WARNING on brauner-vfs/vfs.all]
[also build test WARNING on viro-vfs/for-next linus/master v6.19-rc8 next-20260203]
[cannot apply to pcmoore-selinux/next]
[If your patch is applied to the wrong git tree, kindly drop us a note.
And when submitting patch, we suggest to use '--base' as documented in
https://git-scm.com/docs/git-format-patch#_base_tree_information]
url: https://github.com/intel-lab-lkp/linux/commits/NeilBrown/fs-proc-Don-t-lock-root-inode-when-creating-self-and-thread-self/20260204-131659
base: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git vfs.all
patch link: https://lore.kernel.org/r/20260204050726.177283-5-neilb%40ownmail.net
patch subject: [PATCH 04/13] Apparmor: Use simple_start_creating() / simple_done_creating()
config: arm-randconfig-r133-20260204 (https://download.01.org/0day-ci/archive/20260204/202602041851.x2RfFgKO-lkp@intel.com/config)
compiler: arm-linux-gnueabi-gcc (GCC) 11.5.0
reproduce (this is a W=1 build): (https://download.01.org/0day-ci/archive/20260204/202602041851.x2RfFgKO-lkp@intel.com/reproduce)
If you fix the issue in a separate patch/commit (i.e. not just a new version of
the same patch/commit), kindly add following tags
| Reported-by: kernel test robot <lkp@intel.com>
| Closes: https://lore.kernel.org/oe-kbuild-all/202602041851.x2RfFgKO-lkp@intel.com/
sparse warnings: (new ones prefixed by >>)
>> security/apparmor/apparmorfs.c:295:16: sparse: sparse: Using plain integer as NULL pointer
vim +295 security/apparmor/apparmorfs.c
247
248 /**
249 * aafs_create - create a dentry in the apparmorfs filesystem
250 *
251 * @name: name of dentry to create
252 * @mode: permissions the file should have
253 * @parent: parent directory for this dentry
254 * @data: data to store on inode.i_private, available in open()
255 * @link: if symlink, symlink target string
256 * @fops: struct file_operations that should be used for
257 * @iops: struct of inode_operations that should be used
258 *
259 * This is the basic "create a xxx" function for apparmorfs.
260 *
261 * Returns a pointer to a dentry if it succeeds, that must be free with
262 * aafs_remove(). Will return ERR_PTR on failure.
263 */
264 static struct dentry *aafs_create(const char *name, umode_t mode,
265 struct dentry *parent, void *data, void *link,
266 const struct file_operations *fops,
267 const struct inode_operations *iops)
268 {
269 struct dentry *dentry;
270 struct inode *dir;
271 int error;
272
273 AA_BUG(!name);
274 AA_BUG(!parent);
275
276 if (!(mode & S_IFMT))
277 mode = (mode & S_IALLUGO) | S_IFREG;
278
279 error = simple_pin_fs(&aafs_ops, &aafs_mnt, &aafs_count);
280 if (error)
281 return ERR_PTR(error);
282
283 dir = d_inode(parent);
284
285 dentry = simple_start_creating(parent, name);
286 if (IS_ERR(dentry)) {
287 error = PTR_ERR(dentry);
288 goto fail;
289 }
290
291 error = __aafs_setup_d_inode(dir, dentry, mode, data, link, fops, iops);
292 simple_done_creating(dentry);
293 if (error)
294 goto fail;
> 295 return 0;
296 fail:
297 simple_release_fs(&aafs_mnt, &aafs_count);
298 return ERR_PTR(error);
299 }
300
--
0-DAY CI Kernel Test Service
https://github.com/intel/lkp-tests/wiki
© 2016 - 2026 Red Hat, Inc.