Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp3412014rwa; Tue, 23 Aug 2022 04:28:10 -0700 (PDT) X-Google-Smtp-Source: AA6agR4j7E4p6qeVCUVwHhEALKB/A7eXGXLkEucH/MhprffVwVyHOeQcOSEyFtCmJh27k8segqN8 X-Received: by 2002:a17:907:3f0a:b0:730:994f:8d57 with SMTP id hq10-20020a1709073f0a00b00730994f8d57mr15979901ejc.538.1661254090200; Tue, 23 Aug 2022 04:28:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661254090; cv=none; d=google.com; s=arc-20160816; b=x/g+2hd48IFWM66eI20iZyayha5poqXPWuP/lp3+ToyjwHYyVRlNCDsW+FG44zQBsQ C6iKcPZ2FMFd8tdNBSHcw0m91Als2AA3opBicbtjvuYN9yNTqvhkaQXs5OSYge9Z8Ovb wGa3F3bJ0SEVmRR1bvNkgiMBHO8ccQEtSN3pkxCQmSnv+Og+7eE9UaMsV/8LFnT9pZ5F Pud+tjPMUiG+freK65hDF5H1oWPk/mRmujE0MvMlyMt2xA/hArUV3q4SLSU5wMdrvo68 8v08JvQ6ecLfxS4mxkx//IkPARr1LoFBAnSsTxwxZ9VPp4tRzv1V5WaY9FSqY/LVaMiM bRKA== 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=ZwDntQq3SDYElBqAUn0BcLueDZpaMh0ORluGooUqDuQ=; b=lBkwyQvVHEko4ZEg2d4TMJEe0xcxZw7Ig/NCZ7Rnj1R5kSSfbhEXB8ZdETs+ItqxZZ yY2UC5k//ABz0iJjO9G/+EeczmPL8V5KfPnmEjbYl7RN79r1gO4R3VRikqk/Iybc0UGG aaFLrPdLOYY2kJy+D5jWhJpMID+bHvDDwDv4Gpwk8MK7ALRbYRxKkjbgFzGprXzbhh0Y +pRqRvYr7nxD/TSD07jcFYsA8Q/AU1+mhj9TMLz+N+zUg2qBBbFWPiRQBrirfVNiSuYM YlGeuIk3jkfJFYpQapt4XCfHvkmot69Jzafv4ByOMc25qWZGCNPPAnqGC8dLnULZwamj UlyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=FDbeEpxL; 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 hc39-20020a17090716a700b0073cfa9b42a2si10405032ejc.445.2022.08.23.04.27.43; Tue, 23 Aug 2022 04:28:10 -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=FDbeEpxL; 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 S1356354AbiHWKyd (ORCPT + 99 others); Tue, 23 Aug 2022 06:54:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40340 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356346AbiHWKrD (ORCPT ); Tue, 23 Aug 2022 06:47:03 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B573586B59; Tue, 23 Aug 2022 02:11: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 dfw.source.kernel.org (Postfix) with ESMTPS id 40EEF60F50; Tue, 23 Aug 2022 09:11:47 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4D115C433D6; Tue, 23 Aug 2022 09:11:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1661245906; bh=J1OQH30u8/si5yEbyQ4z0MiHnttBlN//30HHIi/nk44=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=FDbeEpxLkeWmCqIgXdsTp2QH7sDiFmRyumSPTU0vyOhwl2Bs90u3Eqz4RH5Pb/vI4 T1ozImuRKw5XFmiFeQFzjLioWY8QMdalgbpUA/vhgiTP6sdKu14F1oSHMGHfPigjz6 E6rHqPnfBefVAYau43wwL7QYkPlCA7dtFSHm1aXM= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, John Johansen Subject: [PATCH 4.19 227/287] apparmor: fix overlapping attachment computation Date: Tue, 23 Aug 2022 10:26:36 +0200 Message-Id: <20220823080108.649059844@linuxfoundation.org> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20220823080100.268827165@linuxfoundation.org> References: <20220823080100.268827165@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 @@ -464,7 +464,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 @@ -139,7 +139,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;