Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3329215rwa; Tue, 23 Aug 2022 02:59:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR7rd3jWEFs4swQxxJ6NJ3R/Qrfd4Rz3aQatvdhv3LkErLUWXmOm3Zpm0PxA67mdDO7B7FR6 X-Received: by 2002:a05:6402:400d:b0:446:6fe1:7663 with SMTP id d13-20020a056402400d00b004466fe17663mr2958711eda.376.1661248744158; Tue, 23 Aug 2022 02:59:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661248744; cv=none; d=google.com; s=arc-20160816; b=SFBhciO4T9Ki6UAE0xn6OfX3AKiObn1IRC0D2onoIAIW3fVFfNifjYkRPeSFnc5VV5 5R/lL4OEiAVxh87Tfa0pMpvaiI6p5dxEU4HSzLM1kEPeNfTpF4ZmhV87R1TJPARxj/2q GGXS0m1FfNw5XVWsvoc06CBPZoLbPPydJtJVG6xJ3KmTOZPUM8ADSKivcyvYUaj+gPbn pmoHf4KlOudt3/K8Rg3MEy9caPFDZEHgTBTkc8o5MbtViQPBha7x1PDxdH+bZBbs+SBO Ave6k8u4Fjs5kyhZY4KZASjN697Bq6JEGTshyrz6XzIv41r3Rs9WuVFbw37SmAr5hg0z TkcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mTVmTdevZrIGmw5OPkK+kc89JbYe8S/DaSSUeVY3l7k=; b=MNw+FN95XbVKL4G3LkmhVZsvmkktFp69e3E74gS9B++hLWauA6qgvRECPKy7YLpg9t IW4MyXES8eL3IuoStKkewKkRDlQ5AycmXsHafiHOBu27IkbEbIII4HOOeib44X/rf/Sc BaWvPCnaEmTXMDwdwPnxijGUC5MR0e0xw+9bxoPjZswvuMVvIk3utfHjEB+kUvMc95pG Huw8w7N00krZh6gU/0qita5VF2gckGC9w4Zl2OjkJRL+ufve8lKflhc5swBigJvMFS8U eKiwET6Ioq++43Z1mZXiiqfvZeteLYN2DeyqgawigPjAVeWImFX6tyxZ5usdwNDaVvNa k62g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q90JOrQj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b20-20020a056402279400b0043c8997b44dsi2175766ede.384.2022.08.23.02.58.37; Tue, 23 Aug 2022 02:59:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Q90JOrQj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238650AbiHWJnr (ORCPT + 99 others); Tue, 23 Aug 2022 05:43:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53402 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352083AbiHWJkz (ORCPT ); Tue, 23 Aug 2022 05:40:55 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 725F7402FA; Tue, 23 Aug 2022 01:41:47 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 06255B81C5A; Tue, 23 Aug 2022 08:41:19 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 348B1C433D6; Tue, 23 Aug 2022 08:41:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661244077; bh=sZHTj6NlHV1gKfCIF3Oh0sM2abCOlzPAapitMOgNRbQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Q90JOrQjI8UnHtAuofmA7pUS2lPDoiZUwYDqzW/nQa+1hWul4F99opK1wzePonrMq +6leH7VJfRGzumAOply8RBwXUkpEDejtYzwsAURd1ZkEYnMzUUznhvS+nP2S1dOmYN v7r8Vjmud67TVGvMOiPMDQ5IetaInfNHvlFmM5MQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Johansen Subject: [PATCH 5.15 033/244] apparmor: fix overlapping attachment computation Date: Tue, 23 Aug 2022 10:23:12 +0200 Message-Id: <20220823080100.171767098@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080059.091088642@linuxfoundation.org> References: <20220823080059.091088642@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: John Johansen commit 2504db207146543736e877241f3b3de005cbe056 upstream. When finding the profile via patterned attachments, the longest left match is being set to the static compile time value and not using the runtime computed value. Fix this by setting the candidate value to the greater of the precomputed value or runtime computed value. Fixes: 21f606610502 ("apparmor: improve overlapping domain attachment resolution") Signed-off-by: John Johansen Signed-off-by: Greg Kroah-Hartman --- security/apparmor/domain.c | 2 +- security/apparmor/include/policy.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) --- a/security/apparmor/domain.c +++ b/security/apparmor/domain.c @@ -467,7 +467,7 @@ restart: * xattrs, or a longer match */ candidate = profile; - candidate_len = profile->xmatch_len; + candidate_len = max(count, profile->xmatch_len); candidate_xattrs = ret; conflict = false; } --- a/security/apparmor/include/policy.h +++ b/security/apparmor/include/policy.h @@ -135,7 +135,7 @@ struct aa_profile { const char *attach; struct aa_dfa *xmatch; - int xmatch_len; + unsigned int xmatch_len; enum audit_mode audit; long mode; u32 path_flags;