From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qv1-f50.google.com (mail-qv1-f50.google.com [209.85.219.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B4F673876C6 for ; Tue, 14 Jul 2026 11:54:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.219.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784030100; cv=none; b=rBOZU5sQJes3NXU0YAQKF7mq1kZOXONNYw6a6aoKnckHnEGugjv0iVcpBi4aCC1gW0M6hOC3PPClF7QXh+0BxOb9uLHeYeZOLLZAMiHYyIRfYov5ZOipS64hU+QImV85/y9Y/CT/rofNjNy/vvUDGEfXYgG7UeNPBarReomkke8= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784030100; c=relaxed/simple; bh=9RRZcFgrtBWsMm88TekPA+n+ES8ipoI28R2xVaJ1owk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=YtOgphM0K6LAcaYqJcxlCTxFaKkbfzGBljxQG+dgZehslLTVIgQHQXVjPOCxV9wBUShFrcwKuZ2EaCdWYRIzIhgpNsZ+n2wi4tHrOhoQ1X2ln+dfMciGaElaV9EyoqQGRN06R118CDsdKPwyJ7RNRoE696rpPYmfRruLQlLxb7U= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=gpClXGEf; arc=none smtp.client-ip=209.85.219.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="gpClXGEf" Received: by mail-qv1-f50.google.com with SMTP id 6a1803df08f44-8f29ec73064so36830016d6.1 for ; Tue, 14 Jul 2026 04:54:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784030097; x=1784634897; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=qTYC4WZ/uNDWSHxkWtJkYAaxtQ+BheOgFcuFhfNnJxk=; b=gpClXGEfxfL7j2nFBXqFrw0r99d9aHViGFW9h2OF+0ObBXOMJrajp0tORuZ34Q2iJq l6/G99oDTrxrphhEYPQm5kFN8odf8T/9xttT7kjhrqbLqbL/sIQZaK/+gLbYCnCpaQRg 209Di8tAmiouJhVJBhMzDNGgyaHsXapJ/tuThpLX3QpjJTYZew1vAImSNuyKC9iqf7Ok lZt2zoHLiWmZ8YDKbZ8AohszsxwSybYtQQXVVNfeGYUNfOBhXPz9ZGvNhRztkuij5k0U y86KLuMhrutMFql276OFQ50pssoM7SLeZG9ndO6TFFQ/qITo7WzPLTHdeSywor7W7n88 AGLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784030097; x=1784634897; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=qTYC4WZ/uNDWSHxkWtJkYAaxtQ+BheOgFcuFhfNnJxk=; b=ZqFT9f0uKnr/peFJ3hd20Iz1zyuLaDL5PeyJPSjXae7QGP89rjV6qzC+BQiOS6gXES N9lXr/ZdugI+pfIDhRWUGDLSXKneb5zVG5M43t2/oeTDNmp/EfM2fqV6UfqTsG2CE1hq tmwQ9RaydTe6D8E5tcgkgFszUmYmZ8/Hpn2KC6OYNLSwc8PqHlZOZEbG544HPYRmFPP5 rqDJttwUy/Fr7bbPYVq0bi5iAtCYR6LywZsXT92T1h76nn0W/Ie1q2zgQCodiEtIrLB6 NYz4A75+TjdgIzQlq3snx1FL7H3n5zRJKycjlzTEMPF+eDQNXCz0WITSdXX8A4BejuCz x1Nw== X-Forwarded-Encrypted: i=1; AHgh+RpuUQ2rhrSsJPU8ryax1OA6DNNQbDkU3Pe4lJ9QIBg4X8Ghjc7DP72TZjIC7FLvmfuFRygfy6aEhuPu4Ro=@vger.kernel.org X-Gm-Message-State: AOJu0YxxJS1yYjCb/Fl4kB99lYWpXw4crS5fKphqUaFiomRHZg2GVjl6 J9qesvlrgp3yiW73dofxSf5izHTDcz6sxyE2/5q2PUX2IcY+CVfUzP76 X-Gm-Gg: AfdE7cm8LRVZN/MEAPLeiBUXn+xs+pgjdillRUVXTu8Uc8D1ugDQe6J4WCk1FBINGKf RnoKM6KTr0y485VZg8hPMClekGc/PXn1ri+PJytbuO/xkJIgvGdJApts5LM+UL83X8SryUZ/5Tq qqHKoHKdyVG3qrdSzPboYGZSiWzEGrZvqD9AOj7U2Uf0N1QTH79RQVCjp1TvmGBOZlL56I1uvLZ zYu7U253yx7uRxuI1PaRKO5vWVSXe22YIBV5YUFuIkchRT9Ah7wUtC1L/4kaaD7US+xLoytQMhL oSlXHf9nr6t2SeaLEmXhmQdoaHNN7HIIc+wWhKPdP1skvEa3YJIAIGlC85vnJZKN2yQit394JuB G3NlBzab//RSAzHd8AP9YvAkZpKx9JPXwCoQJxz1uEoyxd4bW6nGKa5kZqvw8aansqzq95DgSwp H99V7QmfBStY12I81J4pi5au+YATkB2mcmqM96QCGEsfS6lpRhfQQkRzFipvmNpMXacM0SHWBmS U/Oz96HyQ== X-Received: by 2002:a05:6214:21e7:b0:8fd:6de3:dd7d with SMTP id 6a1803df08f44-9074c8b3fbdmr17351196d6.63.1784030097559; Tue, 14 Jul 2026 04:54:57 -0700 (PDT) Received: from server0 (c-68-48-65-54.hsd1.mi.comcast.net. [68.48.65.54]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-8ffd80fd492sm185100576d6.34.2026.07.14.04.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 04:54:57 -0700 (PDT) From: Michael Bommarito To: David Howells , Jarkko Sakkinen Cc: Andrew Morton , Paul Moore , James Morris , "Serge E . Hallyn" , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 2/3] keys: make keyring key-chunk byte order agree with keyring_diff_objects() Date: Tue, 14 Jul 2026 07:54:50 -0400 Message-ID: <20260714115451.3773164-3-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260714115451.3773164-1-michael.bommarito@gmail.com> References: <20260714115451.3773164-1-michael.bommarito@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 --- 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 1739373172ad5..e7066893e6ffc 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c @@ -292,9 +292,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; } @@ -375,7 +376,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