From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 996E92737F8 for ; Sun, 12 Jul 2026 01:45:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783820721; cv=none; b=H2JH0UNfsnYu9NLVGyqELvI5HbWkznol5e6t5Zv3f2izVM3yfflJxp9/RKWcZgdFpnmmi+d4Ie82muD+TwAhozxfgsHVejXy3Fyyq9s24fhcKia5fTcBK3nkgKODccztlfh/asISsq+lpEen1ZrcYq42oi2a4qtsL4x9q8lDR/w= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783820721; c=relaxed/simple; bh=8zs0bohkqz5AHgWLOAdTFJ4eY64BQy7weh3GYB3lFvs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=admfxjNQ9GDd3b93PNEtKmEiRgD0tN76p8tHBWuXHFQPk+EJBbKbj9Zc3zoZZNMXg/ZiWUsDCjwossKH9DUojAVqjo7o5dgHIS/s/+HdNOqw86+P5Sc/Dx4BnIm3GsAqFjPj/Psn0lA/Pi8fzN1TdVfVIQ9uLK31gKOV3/GEXtY= 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=U3H94r7v; arc=none smtp.client-ip=209.85.222.172 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="U3H94r7v" Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-92e53581361so119423185a.1 for ; Sat, 11 Jul 2026 18:45:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783820718; x=1784425518; 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=suF5ptZtpi7RCzW0/i+xzlbJ6znA4LVm3BIxn07HFo4=; b=U3H94r7vnEmaKwLo1R4SbOPWfwT7K8s1QX79QW9iMTUGT33vLdoYWQS8iMT8uJPKmC wI77md2l6uRBFI7+e2F4xEeBnffxSrdDWwe1neRp0MmG1/bJboBVXl7m+fO/8QJmEbIl o9YtTqdL8/fnzJReH5xgV2IpEFPx72MFT4ROAs21VOUgJkFOadaVUxxs8IktSWcEepVE +bMxJLYY7Sy0G/5sZW2iS1QlF7aEbav494PnoNVkgISiZQnKhSGkWN7t3SoaomQU3lgT pHqJ31Nt1fm5H1B/SPclzNf8sZxRpTADI4AztcMi5GhpmjMG3dZEbmazso97S5A/qG1w FNGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783820718; x=1784425518; 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=suF5ptZtpi7RCzW0/i+xzlbJ6znA4LVm3BIxn07HFo4=; b=qjLtHlMq05eF3ukSZxVjQFMwohqO96igBYtbzI/JAow2jDy30gtF+arf+w69WCubq3 +MUDiSkf09CgT4QFaHEMlKiBgpAaBoOW+Q0FLYcRy/dRsOheixvlhaXnn2fqna5DuFx8 oMgIC4Y2vn0YOZkOE6wiz4MatdFpJ1hmDJxNdR9pI1NcyJsny1P0nBlAZvHODxhdP834 FF1CEd2v6/kxQTSH38cz4y/F2lKVzyA3Icts/oZcLEx1Nn1sIN9PHBFNJA2n9tkXOEva rH5bh0yDpCyuHW1x9s8n4mH3qwDZ8qZj8jSJBJXPiGzloHV65Heum+GjU0KxrPDB3MUd maOg== X-Forwarded-Encrypted: i=1; AHgh+Rq271Xq+Hp5HqnbXIyB0Onr7YDfvP4frVcklLNCAqrpDErzwhCy0qM9IdPikP9OUZSY6y+LQzLD2K0pXYU=@vger.kernel.org X-Gm-Message-State: AOJu0YxmJa95vKwBRNWDvVeeo2HMFe/+kTZi+cMaWLyvuz9uhJerhRI3 g0j+nYyl3hedlwMD8GCfLSpWBpOAa9eZXoRHqOvfIsGq0tbNp7bcYapJ X-Gm-Gg: AfdE7cnDsXE1sW8jXytfyYHEnrk4FiigUVhMHDndh+bLIhnRjaWJ7Cy6qrQCM7xSUjW sw+g9Gp4lrym0Xg3hj7NeIokqZdQgWndyc/TTL62J8yQlwVUAFZtmHtN3fQ5+aXwC+HffX6B++7 pxxAiC7s6sAJhvicxK10UO5AOD2TxfUdjDHuZ1LrTlwSh9MPndXHxpobYB3qnlt5D8CAbmCRxze wpClaJ0eFPNCFPcizpGR4Mx0rJo+baqXrRmYGiGnvM0aU67ojppaoUxd5LrnmVPGiuIdZDavBnM NLihvDa2zwhN47uCEhAeVf+9EpkrFwja5L0e9X/jd8wZoM8XxRhPUBDA+4QCjwJNUiX/5j9b4Os rOWPcpq1mWYsOlsM2HkuUf62rSbhnFrRfB5llWmm1z4Tk8/87qD2NHv1ImBnpY1RGxnkq2hLe4N 6fkt/+smVgsBvoezJIXeHDIaYWSb3lj143zkDvVhjI4YQjM5W1KXztoIs7lDTa2xzErLFJ1NNPv vR7TePIKQ== X-Received: by 2002:a05:620a:6ccd:b0:92b:980b:e0a9 with SMTP id af79cd13be357-92ef29d2cc4mr535620885a.0.1783820718342; Sat, 11 Jul 2026 18:45:18 -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 af79cd13be357-92ee5b492ebsm624902185a.9.2026.07.11.18.45.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 11 Jul 2026 18:45:17 -0700 (PDT) From: Michael Bommarito To: David Howells , Jarkko Sakkinen Cc: Paul Moore , James Morris , "Serge E . Hallyn" , Andrew Morton , keyrings@vger.kernel.org, linux-security-module@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] keys: fix out-of-bounds read in keyring_get_key_chunk() Date: Sat, 11 Jul 2026 21:44:58 -0400 Message-ID: <20260712014500.480410-2-michael.bommarito@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260712014500.480410-1-michael.bommarito@gmail.com> References: <20260712014500.480410-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 For description-level chunks keyring_get_key_chunk() advances the read pointer by level * sizeof(long) past the inline prefix but only bounds-checks the prefix, so a long enough key description is read past its kmemdup(desc, desc_len + 1) allocation. Compute the full byte offset and bounds-check the description against it before reading. The walk only reaches a description-level chunk when two keys collide through the hash, x, type and domain_tag chunks, so this is reached from an unprivileged add_key(2) with a crafted pair of same-type keys whose index hashes collide; KASAN reports a slab-out-of-bounds read. Fixes: f771fde82051 ("keys: Simplify key description management") Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Michael Bommarito --- security/keys/keyring.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) KASAN, x86_64: add_key(2) of a crafted hash-colliding "user"-key pair (~63-byte descriptions) reports BUG: KASAN: slab-out-of-bounds in keyring_get_key_chunk keyring_get_key_chunk <- assoc_array_insert <- __key_link_begin <- __do_sys_add_key reading one byte past the description allocation; the same trigger is KASAN-clean with this patch. On a kernel built without init-on-alloc, reading the colliding keyring back with KEYCTL_READ returns uninitialized slab until patches 2 and 3 are applied too. Trigger available off-list. diff --git a/security/keys/keyring.c b/security/keys/keyring.c index 7a2ee0ded7c93..1739373172ad5 100644 --- a/security/keys/keyring.c +++ b/security/keys/keyring.c @@ -270,7 +270,7 @@ static unsigned long keyring_get_key_chunk(const void *data, int level) const struct keyring_index_key *index_key = data; unsigned long chunk = 0; const u8 *d; - int desc_len = index_key->desc_len, n = sizeof(chunk); + int desc_len = index_key->desc_len, n = sizeof(chunk), offset; level /= ASSOC_ARRAY_KEY_CHUNK_SIZE; switch (level) { @@ -284,12 +284,12 @@ static unsigned long keyring_get_key_chunk(const void *data, int level) return (unsigned long)index_key->domain_tag; default: level -= 4; - if (desc_len <= sizeof(index_key->desc)) + offset = sizeof(index_key->desc) + level * sizeof(long); + if (desc_len <= offset) return 0; - d = index_key->description + sizeof(index_key->desc); - d += level * sizeof(long); - desc_len -= sizeof(index_key->desc); + d = index_key->description + offset; + desc_len -= offset; if (desc_len > n) desc_len = n; do { -- 2.53.0