From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3D501C43613 for ; Mon, 24 Jun 2019 09:57:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 0977D2146F for ; Mon, 24 Jun 2019 09:57:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370275; bh=AkT0n44v+S5CAKaSgs/CCFCguX4Ebrotd0gjY3kOFjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=egmV1W/KW92Dr1knY8BQQ0iUME1HzsVTaduDJSbK3zSDcUyMuBhnCcnE7zmn/Se7d 8BL6bGLyO+MK4AxSKh8nMTZ2U/o4Y2Pr5pwOrrN//Xqf/yUhN79d+j9/BYnKFn9RvT xkxdVtSBUY2L9hD5ViTClJn/8my/ihwysB9noKcM= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728329AbfFXJ5x (ORCPT ); Mon, 24 Jun 2019 05:57:53 -0400 Received: from mail.kernel.org ([198.145.29.99]:56072 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728624AbfFXJ5u (ORCPT ); Mon, 24 Jun 2019 05:57:50 -0400 Received: from localhost (f4.8f.5177.ip4.static.sl-reverse.com [119.81.143.244]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 04A6C21530; Mon, 24 Jun 2019 09:57:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1561370269; bh=AkT0n44v+S5CAKaSgs/CCFCguX4Ebrotd0gjY3kOFjY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tM/r5zpWpVEmowhN1JCkLRCqpxEyVUmTRexZge5vrba2nhp9zzQpSWyUcMfdz8yn9 13A/Whk4PZpUsDgNN11wMLgozsZZojYFF8gOZTi1NkGP0ufBITons2ZDdq7CccxFlv Mr6JEPznjPCjEAx4MdYtUmCQs6181PEO0AkCQ+sw= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jann Horn , John Johansen Subject: [PATCH 4.14 11/51] apparmor: enforce nullbyte at end of tag string Date: Mon, 24 Jun 2019 17:56:29 +0800 Message-Id: <20190624092307.714151995@linuxfoundation.org> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190624092305.919204959@linuxfoundation.org> References: <20190624092305.919204959@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Jann Horn commit 8404d7a674c49278607d19726e0acc0cae299357 upstream. A packed AppArmor policy contains null-terminated tag strings that are read by unpack_nameX(). However, unpack_nameX() uses string functions on them without ensuring that they are actually null-terminated, potentially leading to out-of-bounds accesses. Make sure that the tag string is null-terminated before passing it to strcmp(). Cc: stable@vger.kernel.org Fixes: 736ec752d95e ("AppArmor: policy routines for loading and unpacking policy") Signed-off-by: Jann Horn Signed-off-by: John Johansen Signed-off-by: Greg Kroah-Hartman --- security/apparmor/policy_unpack.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/security/apparmor/policy_unpack.c +++ b/security/apparmor/policy_unpack.c @@ -259,7 +259,7 @@ static bool unpack_nameX(struct aa_ext * char *tag = NULL; size_t size = unpack_u16_chunk(e, &tag); /* if a name is specified it must match. otherwise skip tag */ - if (name && (!size || strcmp(name, tag))) + if (name && (!size || tag[size-1] != '\0' || strcmp(name, tag))) goto fail; } else if (name) { /* if a name is specified and there is no name tag fail */