Skip to content

Commit

Permalink
apparmor: use per file locks for transactional queries
Browse files Browse the repository at this point in the history
As made mention of in commit 1dea3b4 ("apparmor: speed up
transactional queries"), a single lock is currently used to synchronize
transactional queries. We can, use the lock allocated for each file by
VFS instead.

Signed-off-by: Hamza Mahfooz <someguy@effective-light.com>
Signed-off-by: John Johansen <john.johansen@canonical.com>
  • Loading branch information
Hamza Mahfooz authored and John Johansen committed Nov 3, 2021
1 parent aa4ceed commit d0d845a
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions security/apparmor/apparmorfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -811,8 +811,6 @@ struct multi_transaction {
};

#define MULTI_TRANSACTION_LIMIT (PAGE_SIZE - sizeof(struct multi_transaction))
/* TODO: replace with per file lock */
static DEFINE_SPINLOCK(multi_transaction_lock);

static void multi_transaction_kref(struct kref *kref)
{
Expand Down Expand Up @@ -846,10 +844,10 @@ static void multi_transaction_set(struct file *file,
AA_BUG(n > MULTI_TRANSACTION_LIMIT);

new->size = n;
spin_lock(&multi_transaction_lock);
spin_lock(&file->f_lock);
old = (struct multi_transaction *) file->private_data;
file->private_data = new;
spin_unlock(&multi_transaction_lock);
spin_unlock(&file->f_lock);
put_multi_transaction(old);
}

Expand Down Expand Up @@ -878,9 +876,10 @@ static ssize_t multi_transaction_read(struct file *file, char __user *buf,
struct multi_transaction *t;
ssize_t ret;

spin_lock(&multi_transaction_lock);
spin_lock(&file->f_lock);
t = get_multi_transaction(file->private_data);
spin_unlock(&multi_transaction_lock);
spin_unlock(&file->f_lock);

if (!t)
return 0;

Expand Down

0 comments on commit d0d845a

Please sign in to comment.