[PATCH] SMACK smacklabel : apply &MASK to IP inserted in /smack/netlabel

From: etienne
Date: Tue Feb 17 2009 - 15:32:28 EST


hello,

with current code it is possible to insert inconsistent IP/mask in /smack/netlabel

before patch :
==============

root@etienne-desktop:/home/etienne/linux-2.6# cat /smack/netlabel
12.67.3.2/15 @
12.67.3.1/15 @
12.67.2.1/15 @
12.67.2.1/16 @
12.67.1.1/16 @
0.0.0.0/0 @

the solution is to apply the mask to the IP inserted in /smack/netlabel

after the patch:
================
root@etienne-desktop:/home/etienne/linux-2.6# echo 12.67.3.2/15 @ > /smack/netlabel
root@etienne-desktop:/home/etienne/linux-2.6# cat /smack/netlabel
12.67.0.0/15 @
root@etienne-desktop:/home/etienne/linux-2.6# echo 12.67.3.1/15 @ > /smack/netlabel
root@etienne-desktop:/home/etienne/linux-2.6# cat /smack/netlabel
12.67.0.0/15 @
root@etienne-desktop:/home/etienne/linux-2.6# echo 12.67.3.3/15 @ > /smack/netlabel
root@etienne-desktop:/home/etienne/linux-2.6# cat /smack/netlabel
12.67.0.0/15 @

regards,
Etienne

Signed-off-by: <etienen.basset@xxxxxxxxxxxxxx>
----
diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c
index 8e42800..5717150 100644
--- a/security/smack/smackfs.c
+++ b/security/smack/smackfs.c
@@ -765,6 +765,7 @@ static ssize_t smk_write_netlbladdr(struct file *file, const char __user *buf,
mask.s_addr |= bebits;
bebits <<= 1;
}
+ newname.sin_addr.s_addr &= mask.s_addr;
/*
* Only allow one writer at a time. Writes should be
* quite rare and small in any case.


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