aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Arefev <arefev@swemel.ru>2023-01-24 13:50:37 +0300
committerCasey Schaufler <casey@schaufler-ca.com>2023-02-21 11:22:02 -0800
commitccfd889acb06eab10b98deb4b5eef0ec74157ea0 (patch)
tree675f4bb4232d8fb1129d4fb326678da286e71401
parent2241ab53cbb5cdb08a6b2d4688feb13971058f65 (diff)
downloadlinux-ccfd889acb06eab10b98deb4b5eef0ec74157ea0.tar.gz
smackfs: Added check catlen
If the catlen is 0, the memory for the netlbl_lsm_catmap structure must be allocated anyway, otherwise the check of such rules is not completed correctly. Signed-off-by: Denis Arefev <arefev@swemel.ru> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
-rw-r--r--security/smack/smackfs.c17
1 files changed, 14 insertions, 3 deletions
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 4b58526450d492..5590eaad241bbc 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -830,7 +830,7 @@ static int smk_open_cipso(struct inode *inode, struct file *file)
static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
size_t count, loff_t *ppos, int format)
{
- struct netlbl_lsm_catmap *old_cat;
+ struct netlbl_lsm_catmap *old_cat, *new_cat = NULL;
struct smack_known *skp;
struct netlbl_lsm_secattr ncats;
char mapcatset[SMK_CIPSOLEN];
@@ -917,8 +917,19 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
smack_catset_bit(cat, mapcatset);
}
-
- rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
+ ncats.flags = 0;
+ if (catlen == 0) {
+ ncats.attr.mls.cat = NULL;
+ ncats.attr.mls.lvl = maplevel;
+ new_cat = netlbl_catmap_alloc(GFP_ATOMIC);
+ if (new_cat)
+ new_cat->next = ncats.attr.mls.cat;
+ ncats.attr.mls.cat = new_cat;
+ skp->smk_netlabel.flags &= ~(1U << 3);
+ rc = 0;
+ } else {
+ rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
+ }
if (rc >= 0) {
old_cat = skp->smk_netlabel.attr.mls.cat;
skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;