Skip to content

Commit bfdd5aa

Browse files
committed
Merge tag 'Smack-for-5.9' of git://github.com/cschaufler/smack-next
Pull smack updates from Casey Schaufler: "Minor fixes to Smack for the v5.9 release. All were found by automated checkers and have straightforward resolution" * tag 'Smack-for-5.9' of git://github.com/cschaufler/smack-next: Smack: prevent underflow in smk_set_cipso() Smack: fix another vsscanf out of bounds Smack: fix use-after-free in smk_write_relabel_self()
2 parents b62e419 + 42a2df3 commit bfdd5aa

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

security/smack/smackfs.c

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,7 +884,7 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
884884
}
885885

886886
ret = sscanf(rule, "%d", &maplevel);
887-
if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
887+
if (ret != 1 || maplevel < 0 || maplevel > SMACK_CIPSO_MAXLEVEL)
888888
goto out;
889889

890890
rule += SMK_DIGITLEN;
@@ -905,6 +905,10 @@ static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
905905

906906
for (i = 0; i < catlen; i++) {
907907
rule += SMK_DIGITLEN;
908+
if (rule > data + count) {
909+
rc = -EOVERFLOW;
910+
goto out;
911+
}
908912
ret = sscanf(rule, "%u", &cat);
909913
if (ret != 1 || cat > SMACK_CIPSO_MAXCATNUM)
910914
goto out;
@@ -2720,7 +2724,6 @@ static int smk_open_relabel_self(struct inode *inode, struct file *file)
27202724
static ssize_t smk_write_relabel_self(struct file *file, const char __user *buf,
27212725
size_t count, loff_t *ppos)
27222726
{
2723-
struct task_smack *tsp = smack_cred(current_cred());
27242727
char *data;
27252728
int rc;
27262729
LIST_HEAD(list_tmp);
@@ -2745,11 +2748,21 @@ static ssize_t smk_write_relabel_self(struct file *file, const char __user *buf,
27452748
kfree(data);
27462749

27472750
if (!rc || (rc == -EINVAL && list_empty(&list_tmp))) {
2751+
struct cred *new;
2752+
struct task_smack *tsp;
2753+
2754+
new = prepare_creds();
2755+
if (!new) {
2756+
rc = -ENOMEM;
2757+
goto out;
2758+
}
2759+
tsp = smack_cred(new);
27482760
smk_destroy_label_list(&tsp->smk_relabel);
27492761
list_splice(&list_tmp, &tsp->smk_relabel);
2762+
commit_creds(new);
27502763
return count;
27512764
}
2752-
2765+
out:
27532766
smk_destroy_label_list(&list_tmp);
27542767
return rc;
27552768
}

0 commit comments

Comments
 (0)