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=1796388133; b=jfKDhC6fLMvscMP9Qkojn4E70aMG4VWlE1NBqWY9fwMUdESvZ6qhZAljC3tcEocPLd1G cThrKeY7ncfxxeLWomjIBnxBxlzC3sQfsx0bIx3EdeZvo7eQdRK+zFGBn34F7iKee/iJk 9/igZmND6cIKRV3c2niFKHg2Fprep5dY8yILTkAOvlRDjCKyx8DVvk43j2soez6obzWnY AY9TOWs2VPIGzs8YYCun7hgqEUPKpbzqlWne13iIVduZ6U1Nln0jqHMZJKXKt5nmYcYfz vgeIRXNL9mjI3QUso0Ym6h8LIYlfPjIonGASa37jUONbQhtOqpRmo/8BLGjieEqysNA== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388133; 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=54D0Yp3AwHysesdE0nY6EwIhKsPqp5xeTD8OggbIUSc=; b=Y7+fiS6oD0b1pLH6CDiPfuOfK8FxvR6zL/+GFBlvGEp0h2KayLQfk4x0IwS6OBQXKssc zxR2kmiuGXCRoaMDoC0K6StU3FntENQJd7c2et8CouyUtd3OMGZL9a3y6tSnnWY1YBwwh 0EGjVzRrlmMxcXtVrgg8uB+Ni5xD0pqnHSIdOfuFtmO+L3ll33qyCE6yLRI3DQQ68Y6Gl 66mTlO7umQIq/BlalZjn1yV1bG9iTca7pKiL6qOyxxz71wW7Ap6kD4vzSlo7Q3SUl8Tat kB8AQA0nMbBrvyMhn6+I0dmJi67MLfIljWFPl6XFQnymsGcSG6ZN8gpNEqsKnL64Syw== 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=zAw4jkEI; 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 B04CB606A322; Fri, 4 Dec 2026 12:42:13 +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=zAw4jkEI Received: by smtp.kernel.org (Postfix) with ESMTPSA id 233D21F000CE; Fri, 4 Dec 2026 12:42:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388133; bh=54D0Yp3AwHysesdE0nY6EwIhKsPqp5xeTD8OggbIUSc=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=zAw4jkEIUs1bIhHwW2dAiSGvqSHUl/jSkySaiY19g6Yq4scYU4MxXdT8qvW5eP4mB /8F6vgVLISlW6ckWX2efFfzGDYK8xspYP86qBMFscnmJM8Eu9ko0WBfABo9giZL8bX +nmNZqbvUXf9IjjIdKfNdt/WKGhnQmT8n+mXBuCM= 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 0455/1059] apparmor: fix table_size() integer overflow on 32 bit Date: Fri, 4 Dec 2026 18:59:46 +0900 Message-ID: <20261204100656.070976255@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 449195a4bb7d9c456c02b871eec6905edb449bd2 ] table_size() checks ALIGN(sizeof(struct table_header) + len * el_size, 8) in size_t, where @len is td_lolen, a u32 user-provided value from the policy blob. On 32 bit kernels both operations can overflow. Triggering this bug allows to: - overflow a 16 byte allocation with up to 4GiB of policy data - store the table header at address ZERO_SIZE_PTR (kvzalloc(0)) However, this bug requires CAP_MAC_ADMIN, only affects 32 bit kernels, and the copy runs until the machine is destroyed, so it gives no controllable primitive and is therefore not a security issue. Compute the size with the checked helpers and return 0 when the result is not representable, so the callers can reject the table. A valid table is never 0 bytes, the header alone is 12. 64 bit kernels cannot overflow (these structs are 32 bit), and are hence not affected. Fixes: e06f75a6a2b4 ("AppArmor: dfa match engine") Signed-off-by: Maxime Bélair Signed-off-by: John Johansen [ sashal: Dropped the remap_data16_to_data32() and unpack_pdb() caller hunks since those functions don't exist here, keeping only the table_size() overflow check and the unpack_table() zero check. ] Signed-off-by: Sasha Levin --- security/apparmor/include/match.h | 11 ++++++++++- security/apparmor/match.c | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/security/apparmor/include/match.h b/security/apparmor/include/match.h index 72562aaab9aea..b0215ab950e79 100644 --- a/security/apparmor/include/match.h +++ b/security/apparmor/include/match.h @@ -12,6 +12,7 @@ #define __AA_MATCH_H #include +#include #define DFA_NOMATCH 0 #define DFA_START 1 @@ -121,7 +122,15 @@ extern struct aa_dfa *stacksplitdfa; static inline size_t table_size(size_t len, size_t el_size) { - return ALIGN(sizeof(struct table_header) + len * el_size, 8); + size_t size; + + /* Need check_*_overflow for 32 bit machines */ + if (check_mul_overflow(len, el_size, &size) || + check_add_overflow(size, sizeof(struct table_header), &size) || + size > SIZE_MAX - 7) + return 0; + + return ALIGN(size, 8); } int aa_setup_dfa_engine(void); diff --git a/security/apparmor/match.c b/security/apparmor/match.c index c284614dc0286..adcf27ac94600 100644 --- a/security/apparmor/match.c +++ b/security/apparmor/match.c @@ -102,7 +102,7 @@ static struct table_header *unpack_table(char *blob, size_t bsize) if (th.td_lolen == 0) goto out; tsize = table_size(th.td_lolen, th.td_flags); - if (bsize < tsize) + if (!tsize || bsize < tsize) goto out; table = kvzalloc(tsize, GFP_KERNEL); -- 2.53.0