From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388136; b=N1/P15ExkAiPRIE+TAtslRdhBqE10kdFnBZ2SxTYsH4FDimVrB8i/edOadXf5+xMAWeA dmh/aFbviaSuVgIcvT3ZA/Hk1H0Ggz/7oLpuiYzgH2rAfAdSWKc8rDhFrOvP4YIw22I+L aC2Y9piAJ9g6Mjbg5gLTYG56cdEsr58yLZPhbaUFzBbDRuGjyQuK72X0AZTCphVhcMKvK 1XJZlXVSETTTWYzkP1DH+kkpkaHUEDitNAQsMyZ/VxhGj6FSrVseJBQ+iCRGHh41sPA18 +GKpC+MrY7aWILgRhxXyhspeHwEbkrlKvYF4m+9O2Ur49j4yQtyBiCeJBgX2BkU7Y/Q== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388136; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Type:Content-Transfer-Encoding; bh=+7RoT15mnSaJYU0LpcLCCTckAdLnBL4kAL2XSfrr8Lo=; b=QZ2sN8huuTOfQMJeBo3PcM0MvFfr75FFYwTbsDQXhNcavTe//LLHXQRy6NE6ErGOtHDG qn8cgGWlohc/K3OmxWJd9N2NAaZu1dO5yAsKjTNmshfBgKscGRucFWKJfekwlG8Jw4Amr Ml6Kqf0G0jFDgCXnVQ86jeaUXhaTxIqf9eIxKX6/89BsKEbuu8aSnqdwT2W/XtFXRl2sA zO8QZLymixQuSMnX2gFbRTJo6SKnUUHlCGSGajIpGBSYTdd6SzBfYAi/GS8Gf7aAsB56m v3QkJH/rCmygdBufFHCo2xzvzWHGEKj4scWJa4yE5FcQ2nKKJislhvxjF6E8e0EGddw== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XkjrFVHv; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EBC3A606A322; Fri, 4 Dec 2026 12:42:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XkjrFVHv Received: by smtp.kernel.org (Postfix) with ESMTPSA id 687EA1F000CE; Fri, 4 Dec 2026 12:42:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388135; bh=+7RoT15mnSaJYU0LpcLCCTckAdLnBL4kAL2XSfrr8Lo=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XkjrFVHviFkCpx71MV2QCUmJ30fdWgh6KwcT9NxAMHv+veA+w5t78CUEKuIFApSok jglRbCNsDE273jJSPYubCCWyMMBiTx3wJC39op+GoKXPx8Mv6B5FCYtaoOfaIbdIAP ypfZ9XuBs5eKDg1InWCMtEQNMjsGB6/l0kySni9E= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, =?UTF-8?q?Maxime=20B=C3=A9lair?= , John Johansen , Sasha Levin Subject: [PATCH 6.1 0456/1059] apparmor: convert duplicated dfa transitions to match_char() Date: Fri, 4 Dec 2026 18:59:47 +0900 Message-ID: <20261204100656.095963219@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Maxime Bélair [ Upstream commit e667fc72f7f4a54674962c324048ca2cc58bc703 ] For historical reasons several matchers duplicate the dfa character transition instead of using match_char(). This is because aa_dfa_match_until() and aa_dfa_matchn_until() were written on a branch that did not yet have match_char(), and copied code from aa_dfa_match(). leftmatch_fb() used the same pattern. When match_char() added support for diff-encoded states, the change was never ported to these copies. match_char() resolves a diff encoded state by using def[state] and retrying the same character, until it reaches a state with a valid transition. The copies instead do a simple `state = def[state];` after the character is consumed, so on a diff encoded state one byte is dropped and the walk continues from the diff parent in the wrong state. This makes an unnamed px/Px/cx/Cx transition resolve to no profile, and exec fails with apparmor="DENIED" operation="exec" info="profile transition not found" Convert the three copies to match_char(). For a dfa with no diff encoded state this is a no-op. This bug is latent until the kernel advertises policy/diff-encode. Closes: https://gitlab.com/apparmor/apparmor/-/work_items/663 Fixes: 21f606610502 ("apparmor: improve overlapping domain attachment resolution") Fixes: 031dcc8f4e84f ("apparmor: dfa add support for state differential encoding") Signed-off-by: Maxime Bélair Signed-off-by: John Johansen [ sashal: Kept the tree's older types (unsigned int state, u16 tables, non-const dfa) in the three function declarations and only dropped the unused pos variable. ] Signed-off-by: Sasha Levin --- security/apparmor/match.c | 52 ++++++++++++++------------------------- 1 file changed, 19 insertions(+), 33 deletions(-) diff --git a/security/apparmor/match.c b/security/apparmor/match.c index adcf27ac94600..77947afd85463 100644 --- a/security/apparmor/match.c +++ b/security/apparmor/match.c @@ -598,7 +598,7 @@ unsigned int aa_dfa_match_until(struct aa_dfa *dfa, unsigned int start, u16 *next = NEXT_TABLE(dfa); u16 *check = CHECK_TABLE(dfa); u32 *accept = ACCEPT_TABLE(dfa); - unsigned int state = start, pos; + unsigned int state = start; if (state == 0) return 0; @@ -609,22 +609,18 @@ unsigned int aa_dfa_match_until(struct aa_dfa *dfa, unsigned int start, u8 *equiv = EQUIV_TABLE(dfa); /* default is direct to next state */ while (*str) { - pos = base_idx(base[state]) + equiv[(u8) *str++]; - if (check[pos] == state) - state = next[pos]; - else - state = def[state]; + u8 c = equiv[(u8) *str++]; + + match_char(state, def, base, next, check, c); if (accept[state]) break; } } else { /* default is direct to next state */ while (*str) { - pos = base_idx(base[state]) + (u8) *str++; - if (check[pos] == state) - state = next[pos]; - else - state = def[state]; + u8 c = (u8) *str++; + + match_char(state, def, base, next, check, c); if (accept[state]) break; } @@ -659,7 +655,7 @@ unsigned int aa_dfa_matchn_until(struct aa_dfa *dfa, unsigned int start, u16 *next = NEXT_TABLE(dfa); u16 *check = CHECK_TABLE(dfa); u32 *accept = ACCEPT_TABLE(dfa); - unsigned int state = start, pos; + unsigned int state = start; *retpos = NULL; if (state == 0) @@ -671,22 +667,18 @@ unsigned int aa_dfa_matchn_until(struct aa_dfa *dfa, unsigned int start, u8 *equiv = EQUIV_TABLE(dfa); /* default is direct to next state */ for (; n; n--) { - pos = base_idx(base[state]) + equiv[(u8) *str++]; - if (check[pos] == state) - state = next[pos]; - else - state = def[state]; + u8 c = equiv[(u8) *str++]; + + match_char(state, def, base, next, check, c); if (accept[state]) break; } } else { /* default is direct to next state */ for (; n; n--) { - pos = base_idx(base[state]) + (u8) *str++; - if (check[pos] == state) - state = next[pos]; - else - state = def[state]; + u8 c = (u8) *str++; + + match_char(state, def, base, next, check, c); if (accept[state]) break; } @@ -735,7 +727,7 @@ static unsigned int leftmatch_fb(struct aa_dfa *dfa, unsigned int start, u32 *base = BASE_TABLE(dfa); u16 *next = NEXT_TABLE(dfa); u16 *check = CHECK_TABLE(dfa); - unsigned int state = start, pos; + unsigned int state = start; AA_BUG(!dfa); AA_BUG(!str); @@ -753,13 +745,10 @@ static unsigned int leftmatch_fb(struct aa_dfa *dfa, unsigned int start, /* default is direct to next state */ while (*str) { unsigned int adjust; + u8 c = equiv[(u8) *str++]; wb->history[wb->pos] = state; - pos = base_idx(base[state]) + equiv[(u8) *str++]; - if (check[pos] == state) - state = next[pos]; - else - state = def[state]; + match_char(state, def, base, next, check, c); if (is_loop(wb, state, &adjust)) { state = aa_dfa_match(dfa, state, str); *count -= adjust; @@ -772,13 +761,10 @@ static unsigned int leftmatch_fb(struct aa_dfa *dfa, unsigned int start, /* default is direct to next state */ while (*str) { unsigned int adjust; + u8 c = (u8) *str++; wb->history[wb->pos] = state; - pos = base_idx(base[state]) + (u8) *str++; - if (check[pos] == state) - state = next[pos]; - else - state = def[state]; + match_char(state, def, base, next, check, c); if (is_loop(wb, state, &adjust)) { state = aa_dfa_match(dfa, state, str); *count -= adjust; -- 2.53.0