Skip to content

Commit 19c013e

Browse files
goongascschaufler
authored andcommitted
smack: /smack/doi must be > 0
/smack/doi allows writing and keeping negative doi values. Correct values are 0 < doi <= (max 32-bit positive integer) (2008-02-04, Casey Schaufler) Fixes: e114e47 ("Smack: Simplified Mandatory Access Control Kernel") Signed-off-by: Konstantin Andreev <andreev@swemel.ru> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
1 parent e877cbb commit 19c013e

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

security/smack/smackfs.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ struct smack_parsed_rule {
141141
int smk_access2;
142142
};
143143

144-
static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
144+
static u32 smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
145145

146146
/*
147147
* Values for parsing cipso rules
@@ -1562,7 +1562,7 @@ static ssize_t smk_read_doi(struct file *filp, char __user *buf,
15621562
if (*ppos != 0)
15631563
return 0;
15641564

1565-
sprintf(temp, "%d", smk_cipso_doi_value);
1565+
sprintf(temp, "%lu", (unsigned long)smk_cipso_doi_value);
15661566
rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
15671567

15681568
return rc;
@@ -1581,7 +1581,7 @@ static ssize_t smk_write_doi(struct file *file, const char __user *buf,
15811581
size_t count, loff_t *ppos)
15821582
{
15831583
char temp[80];
1584-
int i;
1584+
unsigned long u;
15851585

15861586
if (!smack_privileged(CAP_MAC_ADMIN))
15871587
return -EPERM;
@@ -1594,10 +1594,12 @@ static ssize_t smk_write_doi(struct file *file, const char __user *buf,
15941594

15951595
temp[count] = '\0';
15961596

1597-
if (sscanf(temp, "%d", &i) != 1)
1597+
if (kstrtoul(temp, 10, &u))
15981598
return -EINVAL;
15991599

1600-
smk_cipso_doi_value = i;
1600+
if (u == CIPSO_V4_DOI_UNKNOWN || u > U32_MAX)
1601+
return -EINVAL;
1602+
smk_cipso_doi_value = u;
16011603

16021604
smk_cipso_doi();
16031605

0 commit comments

Comments
 (0)