]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
Apparmor: Use simple_start_creating() / simple_done_creating()
authorNeilBrown <neil@brown.name>
Tue, 24 Feb 2026 22:16:50 +0000 (09:16 +1100)
committerChristian Brauner <brauner@kernel.org>
Fri, 6 Mar 2026 09:24:11 +0000 (10:24 +0100)
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.

Reviewed-by: Jeff Layton <jlayton@kernel.org>
Signed-off-by: NeilBrown <neil@brown.name>
Link: https://patch.msgid.link/20260224222542.3458677-6-neilb@ownmail.net
Signed-off-by: Christian Brauner <brauner@kernel.org>
security/apparmor/apparmorfs.c

index 2f84bd23edb69e7e69cb097e554091df0132816d..f93c4f31d02aee22e5251f395c9bca51d169c9b4 100644 (file)
@@ -282,32 +282,20 @@ 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);
-
+               goto fail;
        return dentry;
 
-fail_dentry:
-       dput(dentry);
-
-fail_lock:
-       inode_unlock(dir);
+fail:
        simple_release_fs(&aafs_mnt, &aafs_count);
-
        return ERR_PTR(error);
 }
 
@@ -2585,8 +2573,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;
@@ -2594,7 +2581,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();
@@ -2606,18 +2593,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)