From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C45AE442371; Fri, 7 Aug 2026 14:59:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786114799; cv=none; b=EQu5Xa/lcM6z/uavwBiPi3woLruwK6f0kcBrNmQ0NH8+1TYUKtw30fkUUjePZZT6VKQTk8Pm2ALxLxQTGsCcRCKZgMwVFCpBIMD/ezoyNx2rgt3APHryy76LE6QQ8iQNxu0+XdVeXdBNHMMt28Nq1OOkRZUTjQuklWJhkW0CUp4= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786114799; c=relaxed/simple; bh=qdjntRtI4U5kuoemzonmF0TJ20vEaoKsJI9eCP3SNWg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=WYbcEnbfO6nJCytKrfIBK6gr73PK0yM6XMkCEGttx69aIrf0pip0VAIMeAYddzVEzz+CK8uLUrY+r6CGDEwXkcl3lnFvTYQlNYyR9VzrtPZlouqbVHEUyjWsV+SWj8q3xdXu0/TgddWmeTDvAGH+57Vpe/g362BHEFX7W0uCetM= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=kibcxtKS; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="kibcxtKS" Received: by smtp.kernel.org (Postfix) with ESMTPSA id DB3411F00A3A; Fri, 7 Aug 2026 14:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1786114798; bh=zymJhRhUYwL2QGanmxCoCDKmu4FFk/+H5zXcb6rtYEk=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=kibcxtKSZa7svevKNNxv9FM4wLfE5hXM/NTqenjZ2OeXE72kOcu92PZsLRgqMNqQx OG2yuz1AHB/uJFXt7hBQDRVeAb/IgB1FhYU+I7lVsiSFlhsY9VjpU2Y9JRhLOCfm6H T38slnQXdco61UhJfGuH0deYJFMQnLr7FFHNe8AQ= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Michael Bommarito , Jarkko Sakkinen , Sasha Levin Subject: [PATCH 6.18 045/396] keys: make keyring key-chunk byte order agree with keyring_diff_objects() Date: Fri, 7 Aug 2026 16:33:25 +0200 Message-ID: <20260807143425.239538231@linuxfoundation.org> X-Mailer: git-send-email 2.55.0 In-Reply-To: <20260807143424.272339768@linuxfoundation.org> References: <20260807143424.272339768@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: patches@lists.linux.dev List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael Bommarito [ Upstream commit 58565eef0f8d861aae92abfb7658458d661cee17 ] keyring_get_key_chunk() loads description bytes into the index chunk low address first, while keyring_diff_objects() numbers the first differing bit from the low end and folds the absolute byte index into the level without removing the inline-prefix offset the level already carries. The two disagree on byte order and bit position, so the array can be told two keys first differ at a bit that does not differ in the chunk the walker uses, letting crafted descriptions collide into one node. Load the chunk in the order keyring_diff_objects() assumes and drop the inline-prefix length when folding the byte index into the level. This only changes the in-memory ordering used to place keys within a keyring; add, search and read of non-colliding keys are unaffected. Fixes: f771fde82051 ("keys: Simplify key description management") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito Reviewed-by: Jarkko Sakkinen Tested-by: Jarkko Sakkinen Link: https://lore.kernel.org/r/20260719161505.2423935-3-michael.bommarito@gmail.com Signed-off-by: Jarkko Sakkinen Signed-off-by: Sasha Levin --- security/keys/keyring.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/security/keys/keyring.c b/security/keys/keyring.c index b9ca9dc9b0c3f..fd95a0eb7a466 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c @@ -293,9 +293,10 @@ static unsigned long keyring_get_key_chunk(const void *data, int level) desc_len -= offset; if (desc_len > n) desc_len = n; + d += desc_len; do { chunk <<= 8; - chunk |= *d++; + chunk |= *--d; } while (--desc_len > 0); return chunk; } @@ -376,7 +377,7 @@ static int keyring_diff_objects(const void *object, const void *data) return -1; differ_plus_i: - level += i; + level += i - (int)sizeof(a->desc); differ: i = level * 8 + __ffs(seg_a ^ seg_b); return i; -- 2.53.0