From: Alan Cox Date: Thu, 26 Jul 2012 21:47:11 +0000 (-0700) Subject: smack: off by one error X-Git-Tag: 2.2.1_release^2~25^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=e6f2e1681f830ef3c206ba8b35f9fd140f77fcf6;p=sdk%2Femulator%2Femulator-kernel.git smack: off by one error commit 3b9fc37280c521b086943f9aedda767f5bf3b2d3 upstream Consider the input case of a rule that consists entirely of non space symbols followed by a \0. Say 64 + \0 In this case strlen(data) = 64 kzalloc of subject and object are 64 byte objects sscanfdata, "%s %s %s", subject, ...) will put 65 bytes into subject. Change-Id: I23f9eddde5747bb1dde6e3fd5a4fbe08fd152ff2 Signed-off-by: Alan Cox Acked-by: Casey Schaufler Cc: stable@vger.kernel.org Signed-off-by: James Morris Signed-off-by: Rafal Krypa Reviewed-on: http://165.213.202.130:8080/53898 Reviewed-by: Kyungmin Park Tested-by: Kyungmin Park --- diff --git a/security/smack/smackfs.c b/security/smack/smackfs.c index eba168687591..dfd9d61eeba3 100644 --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -344,11 +344,11 @@ static int smk_parse_long_rule(const char *data, struct smack_rule *rule, int datalen; int rc = -1; - /* - * This is probably inefficient, but safe. - */ + /* This is inefficient */ datalen = strlen(data); - subject = kzalloc(datalen, GFP_KERNEL); + + /* Our first element can be 64 + \0 with no spaces */ + subject = kzalloc(datalen + 1, GFP_KERNEL); if (subject == NULL) return -1; object = kzalloc(datalen, GFP_KERNEL);