Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3318158rwa; Tue, 23 Aug 2022 02:43:11 -0700 (PDT) X-Google-Smtp-Source: AA6agR5pPjGCT+5LT+W5ZhF/1R+zxjcl3mZdXvNjaxs5baT39d2zhkgOdwhzkoPM7N//kZi1dioX X-Received: by 2002:a17:907:3d89:b0:73d:6a08:b03b with SMTP id he9-20020a1709073d8900b0073d6a08b03bmr9073995ejc.458.1661247791095; Tue, 23 Aug 2022 02:43:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661247791; cv=none; d=google.com; s=arc-20160816; b=U2x8fR4fFKxjl5seAGbiQo99f1LeXRRAmxpRwEdnnO5FzQXnIhhAMjtPw88J8rfbWs XDNZXGGNf6EURKPlb9EpSdbZC0GtQbp9IravcGS/KJhLJ8ldoWBHbC/Ugy6SKaxgabBJ Vec1t8dJhA+Opc8+qoIn2kjnaiDPv7cmtwHtvPvH08XB7OT4srCX1hRlL8Ik2ou+2lle Z13Lp4O7FHMrTsrEc8lGVc8KmVvUIbHH2owEvyjctpwvFW/u6WuhMdI3gt4aQLup6dsV LkvOD/1TcUfs9isH2Fi+6G/Pjib/g1c+136jPTOoHFEMCg3mlZtMNVlCfwItkFOm1+QA J8+w== 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=y+tJfNiEW9X5xuWgrQ9+dfWrYpSM8kCBDHaOQZgSAL0=; b=hcUzs15/U15oXoh3J5D0ieOB3ADk7WA6RyUv1uz6OAUkVZktCkIX2DG4xC81U6H1ur fywr5Gn+h0a3XCUXAQBp17YhH7HbhU0RdpKYosjy7xyhqB4n/ocT0Glm8iyhKpqjp7Mm zkUkp7qXpH0JZHky5w9uXEgUw1S1zqyFNSx4LgVgT7mJ12DzGceSy/4FGTyLrr80UVoV UQwuACr1EegUHN1n5wicfd+YLuyBrulflINyu2cnwHRouudCyPp+vs1wdblKDmgyDoCq DH40vtxFmiiDqNbZ37ksJBUUhlMqNYrD5nApWFsbdQuBrbiMh255If9UKcKvG9hZFm3b wgMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=OjqIUux0; 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 sc3-20020a1709078a0300b0073da40f26b9si763995ejc.156.2022.08.23.02.42.44; Tue, 23 Aug 2022 02:43:11 -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=OjqIUux0; 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 S242281AbiHWINl (ORCPT + 99 others); Tue, 23 Aug 2022 04:13:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58048 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242011AbiHWIK1 (ORCPT ); Tue, 23 Aug 2022 04:10:27 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 64C27F22; Tue, 23 Aug 2022 01:06:59 -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 dfw.source.kernel.org (Postfix) with ESMTPS id 00731611DD; Tue, 23 Aug 2022 08:06:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 06A2FC433D6; Tue, 23 Aug 2022 08:06:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661242018; bh=Avg86YgDdyu2v0jtz82RqyS8CWRkcNshlaeC/O9+9Gc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=OjqIUux0NPxSwsj6qY2ajFXkfflhYrGik6rVUHJTpzhxMzA/Cu09blkkz2LBjbEeI W0QXGhVG3cehT4eCtelUxR8CBAMQjNoMKLGIE+RQGD09hM9IbFZhRLymCFE8KYo9gW DGAhlshLOyLATdtGwcNGz7TsTsGmZ10UwhehdisQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Johansen Subject: [PATCH 5.19 046/365] apparmor: fix overlapping attachment computation Date: Tue, 23 Aug 2022 09:59:07 +0200 Message-Id: <20220823080120.110374303@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080118.128342613@linuxfoundation.org> References: <20220823080118.128342613@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 @@ -466,7 +466,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;