Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Apparmor: Use simple_start_creating() / simple_done_creating()

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>

authored by

NeilBrown and committed by
Christian Brauner
5c6c7ae9 1948172b

+8 -27
+8 -27
security/apparmor/apparmorfs.c
··· 282 282 283 283 dir = d_inode(parent); 284 284 285 - inode_lock(dir); 286 - dentry = lookup_noperm(&QSTR(name), parent); 285 + dentry = simple_start_creating(parent, name); 287 286 if (IS_ERR(dentry)) { 288 287 error = PTR_ERR(dentry); 289 - goto fail_lock; 290 - } 291 - 292 - if (d_really_is_positive(dentry)) { 293 - error = -EEXIST; 294 - goto fail_dentry; 288 + goto fail; 295 289 } 296 290 297 291 error = __aafs_setup_d_inode(dir, dentry, mode, data, link, fops, iops); 292 + simple_done_creating(dentry); 298 293 if (error) 299 - goto fail_dentry; 300 - inode_unlock(dir); 301 - 294 + goto fail; 302 295 return dentry; 303 296 304 - fail_dentry: 305 - dput(dentry); 306 - 307 - fail_lock: 308 - inode_unlock(dir); 297 + fail: 309 298 simple_release_fs(&aafs_mnt, &aafs_count); 310 - 311 299 return ERR_PTR(error); 312 300 } 313 301 ··· 2573 2585 if (error) 2574 2586 return error; 2575 2587 2576 - inode_lock(d_inode(parent)); 2577 - dentry = lookup_noperm(&QSTR(NULL_FILE_NAME), parent); 2588 + dentry = simple_start_creating(parent, NULL_FILE_NAME); 2578 2589 if (IS_ERR(dentry)) { 2579 2590 error = PTR_ERR(dentry); 2580 2591 goto out; ··· 2581 2594 inode = new_inode(parent->d_inode->i_sb); 2582 2595 if (!inode) { 2583 2596 error = -ENOMEM; 2584 - goto out1; 2597 + goto out; 2585 2598 } 2586 2599 2587 2600 inode->i_ino = get_next_ino(); ··· 2593 2606 aa_null.dentry = dget(dentry); 2594 2607 aa_null.mnt = mntget(mount); 2595 2608 2596 - error = 0; 2597 - 2598 - out1: 2599 - dput(dentry); 2600 2609 out: 2601 - inode_unlock(d_inode(parent)); 2610 + simple_done_creating(dentry); 2602 2611 simple_release_fs(&mount, &count); 2603 2612 return error; 2604 2613 } 2605 - 2606 - 2607 2614 2608 2615 static const char *policy_get_link(struct dentry *dentry, 2609 2616 struct inode *inode,