Skip to contentSkip to conversation

smack:beyond ARRAY_SIZE of data

PATCH In review Roel Kluin 3 participants 6 messages May 20, 2009 – May 22, 2009

Subsystems (2)
lore
Share & tools
lore

Roel Kluin

author
#0 lore raw

PATCH 1/1 smack:beyond ARRAY_SIZE of data

Do not go beyond ARRAY_SIZE of data

---

security/smack/smackfs.c +1 -1
index e03a7e1..7407e5c 100644
@@ -797,7 +797,7 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
 		return -EPERM;
 	if (*ppos != 0)
 		return -EINVAL;
-	if (count < SMK_NETLBLADDRMIN || count > SMK_NETLBLADDRMAX)
+	if (count < SMK_NETLBLADDRMIN || count >= SMK_NETLBLADDRMAX)
 		return -EINVAL;
 	if (copy_from_user(data, buf, count) != 0)
 		return -EFAULT;
maintainer
#1 lore raw
Quoted 9 lines · Roel Kluin

Do not go beyond ARRAY_SIZE of data

---

security/smack/smackfs.c +0 -0
index e03a7e1..7407e5c 100644

security/smack/smackfs.c static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf, · line 801

Quoted 6 lines
security/smack/smackfs.c +1 -1
@@ -797,7 +797,7 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
 		return -EPERM;
 	if (*ppos != 0)
 		return -EINVAL;
-	if (count < SMK_NETLBLADDRMIN || count > SMK_NETLBLADDRMAX)
+	if (count < SMK_NETLBLADDRMIN || count >= SMK_NETLBLADDRMAX)
 

There is a problem here, but this won't fix it. The buffer needs to be allocated bigger than the potential contents (should be SMK_NETLBLADDRMAX + 1 instead of SMK_NETLBLADDRMAX. Your patch will clip the last byte off of a maximum length specification.

Quoted 11 lines
security/smack/smackfs.c +0 -0
 		return -EINVAL;
 	if (copy_from_user(data, buf, count) != 0)

return -EFAULT;

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

author
#2 lore raw

Do not go beyond ARRAY_SIZE of data

---

Quoted 8 lines

Review

Quoted 3 lines
(quoted diff) +1 -1
-	if (count < SMK_NETLBLADDRMIN || count > SMK_NETLBLADDRMAX)
+	if (count < SMK_NETLBLADDRMIN || count >= SMK_NETLBLADDRMAX)

There is a problem here, but this won't fix it. The buffer needs to be allocated bigger than the potential contents (should be SMK_NETLBLADDRMAX + 1 instead of SMK_NETLBLADDRMAX. Your patch will clip the last byte off of a maximum length specification.

Ok, how about this?

security/smack/smackfs.c +1 -1
index e03a7e1..10a4604 100644
@@ -775,7 +775,7 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
 	struct sockaddr_in newname;
 	char smack[SMK_LABELLEN];
 	char *sp;
-	char data[SMK_NETLBLADDRMAX];
+	char data[SMK_NETLBLADDRMAX + 1];
 	char *host = (char *)&newname.sin_addr.s_addr;
 	int rc;
 	struct netlbl_audit audit_info;
maintainer Acked-by
#3 lore raw
Quoted 4 lines · Roel Kluin

Do not go beyond ARRAY_SIZE of data

Thank you. The fix is appreciated.

Quoted 36 lines

---

Quoted 9 lines

Review

Quoted 4 lines
(quoted diff) +1 -1
-	if (count < SMK_NETLBLADDRMIN || count > SMK_NETLBLADDRMAX)
+	if (count < SMK_NETLBLADDRMIN || count >= SMK_NETLBLADDRMAX)

There is a problem here, but this won't fix it. The buffer needs to be allocated bigger than the potential contents (should be SMK_NETLBLADDRMAX + 1 instead of SMK_NETLBLADDRMAX. Your patch will clip the last byte off of a maximum length specification.

Ok, how about this?

security/smack/smackfs.c +1 -2
index e03a7e1..10a4604 100644
@@ -775,7 +775,7 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
 	struct sockaddr_in newname;
 	char smack[SMK_LABELLEN];
 	char *sp;
-	char data[SMK_NETLBLADDRMAX];
+	char data[SMK_NETLBLADDRMAX + 1];
 	char *host = (char *)&newname.sin_addr.s_addr;
 	int rc;
 	struct netlbl_audit audit_info;
 
--

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

maintainer
#4 lore raw
Quoted 10 lines · Casey Schaufler
Quoted 4 lines · Roel Kluin

Do not go beyond ARRAY_SIZE of data

Thank you. The fix is appreciated.

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next

(This needs CAP_MAC_ADMIN to trigger, so I'll assume this is not security-critical, but yell if you disagree).

- James

Signature · 2 lines
James Morris
<[email protected]>
maintainer
#5 lore raw
Quoted 16 lines · James Morris
Quoted 12 lines · Casey Schaufler
Quoted 5 lines · Roel Kluin

Do not go beyond ARRAY_SIZE of data

Thank you. The fix is appreciated.

Quoted 7 lines

Applied to
git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/security-testing-2.6#next

(This needs CAP_MAC_ADMIN to trigger, so I'll assume this is not security-critical, but yell if you disagree).

Not security critical.

Quoted 2 lines

- James