From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757773Ab2HGXnE (ORCPT ); Tue, 7 Aug 2012 19:43:04 -0400 Received: from mail-pb0-f46.google.com ([209.85.160.46]:54583 "EHLO mail-pb0-f46.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756997Ab2HGW11 (ORCPT ); Tue, 7 Aug 2012 18:27:27 -0400 From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Greg KH , torvalds@linux-foundation.org, akpm@linux-foundation.org, alan@lxorguk.ukuu.org.uk, Alan Cox , Casey Schaufler , James Morris Subject: [ 010/122] smack: off by one error Date: Tue, 7 Aug 2012 15:24:58 -0700 Message-Id: <20120807221949.167564072@linuxfoundation.org> X-Mailer: git-send-email 1.7.10.1.362.g242cab3 In-Reply-To: <20120807221948.220495155@linuxfoundation.org> References: <20120807221948.220495155@linuxfoundation.org> User-Agent: quilt/0.60-20.4 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg KH 3.5-stable review patch. If anyone has any objections, please let me know. ------------------ From: Alan Cox 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. Signed-off-by: Alan Cox Acked-by: Casey Schaufler Signed-off-by: James Morris Signed-off-by: Greg Kroah-Hartman --- security/smack/smackfs.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) --- a/security/smack/smackfs.c +++ b/security/smack/smackfs.c @@ -325,11 +325,11 @@ static int smk_parse_long_rule(const cha 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);