Skip to content

Commit 2749749

Browse files
pandayeahcschaufler
authored andcommitted
smackfs: Use rcu_assign_pointer() to ensure safe assignment in smk_set_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]>
1 parent eabc10e commit 2749749

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

security/smack/smackfs.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -932,7 +932,7 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
932932
}
933933
if (rc >= 0) {
934934
old_cat = skp->smk_netlabel.attr.mls.cat;
935-
skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
935+
rcu_assign_pointer(skp->smk_netlabel.attr.mls.cat, ncats.attr.mls.cat);
936936
skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
937937
synchronize_rcu();
938938
netlbl_catmap_free(old_cat);

0 commit comments

Comments
 (0)