Skip to content

Commit 20d4e80

Browse files
committed
apparmor: only get a label reference if the fast path check fails
The common fast path check can be done under rcu_read_lock() and doesn't need a reference count on the label. Only take a reference count if entering the slow path. Fixes reported hackbench regression - sha1 79e178a ("Merge tag 'apparmor-pr-2019-12-03' of git://git.kernel.org/pub/scm/linux/kernel/git/jj/linux-apparmor") hackbench -l (256000/#grp) -g #grp 128 groups 19.679 ±0.90% - previous sha1 01d1dff ("Merge tag 's390-5.5-2' of git://git.kernel.org/pub/scm/linux/kernel/git/s390/linux") hackbench -l (256000/#grp) -g #grp 128 groups 3.1689 ±3.04% Reported-by: Vincent Guittot <[email protected]> Tested-by: Vincent Guittot <[email protected]> Tested-by: Sebastian Andrzej Siewior <[email protected]> Fixes: bce4e7e ("apparmor: reduce rcu_read_lock scope for aa_file_perm mediation") Signed-off-by: John Johansen <[email protected]>
1 parent 9c95a27 commit 20d4e80

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

security/apparmor/file.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,8 +618,7 @@ int aa_file_perm(const char *op, struct aa_label *label, struct file *file,
618618
fctx = file_ctx(file);
619619

620620
rcu_read_lock();
621-
flabel = aa_get_newest_label(rcu_dereference(fctx->label));
622-
rcu_read_unlock();
621+
flabel = rcu_dereference(fctx->label);
623622
AA_BUG(!flabel);
624623

625624
/* revalidate access, if task is unconfined, or the cached cred
@@ -631,9 +630,13 @@ int aa_file_perm(const char *op, struct aa_label *label, struct file *file,
631630
*/
632631
denied = request & ~fctx->allow;
633632
if (unconfined(label) || unconfined(flabel) ||
634-
(!denied && aa_label_is_subset(flabel, label)))
633+
(!denied && aa_label_is_subset(flabel, label))) {
634+
rcu_read_unlock();
635635
goto done;
636+
}
636637

638+
flabel = aa_get_newest_label(flabel);
639+
rcu_read_unlock();
637640
/* TODO: label cross check */
638641

639642
if (file->f_path.mnt && path_mediated_fs(file->f_path.dentry))
@@ -643,8 +646,9 @@ int aa_file_perm(const char *op, struct aa_label *label, struct file *file,
643646
else if (S_ISSOCK(file_inode(file)->i_mode))
644647
error = __file_sock_perm(op, label, flabel, file, request,
645648
denied);
646-
done:
647649
aa_put_label(flabel);
650+
651+
done:
648652
return error;
649653
}
650654

0 commit comments

Comments
 (0)