Skip to content

Commit

Permalink
smackfs: Use rcu_assign_pointer() to ensure safe assignment in smk_se…
Browse files Browse the repository at this point in the history
…t_cipso

In the `smk_set_cipso` function, the `skp->smk_netlabel.attr.mls.cat`
field is directly assigned to a new value without using the appropriate
RCU pointer assignment functions. According to RCU usage rules, this is
illegal and can lead to unpredictable behavior, including data
inconsistencies and impossible-to-diagnose memory corruption issues.

This possible bug was identified using a static analysis tool developed
by myself, specifically designed to detect RCU-related issues.

To address this, the assignment is now done using rcu_assign_pointer(),
which ensures that the pointer assignment is done safely, with the
necessary memory barriers and synchronization. This change prevents
potential RCU dereference issues by ensuring that the `cat` field is
safely updated while still adhering to RCU's requirements.

Fixes: 0817534 ("smackfs: Fix use-after-free in netlbl_catmap_walk()")
Signed-off-by: Jiawei Ye <[email protected]>
Signed-off-by: Casey Schaufler <[email protected]>
  • Loading branch information
pandayeah authored and cschaufler committed Sep 3, 2024
1 parent eabc10e commit 2749749
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion security/smack/smackfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
}
if (rc >= 0) {
old_cat = skp->smk_netlabel.attr.mls.cat;
skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
rcu_assign_pointer(skp->smk_netlabel.attr.mls.cat, ncats.attr.mls.cat);
skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
synchronize_rcu();
netlbl_catmap_free(old_cat);
Expand Down

0 comments on commit 2749749

Please sign in to comment.