Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.179 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1794630939; b=kftjWE+wT7wezxwkmqxwbLPa+nPqCh+LvqPqboMF8/ifA/N9Fl1Fe10AJrr+mCYatD9l MWwhPQSMFnz13tQh+bBQsQ7pVSCZrx+CU5gXklLjvSD1ybST7EiT4ePwqSxxssYKbtBLN M/o3/oO22dgIfX1kIX9a1sehrcw4zQaw/qe71n7KPz+ui0prygOuFfjYBWM5ZPGthAGR2 j72ImxehDZfqwzcHBrFwvWtOSrlKNFL4/LKTiksQzp+tWq4Bex6E6YGGPZq/7FdNULgJd 8nDaO0ojCtleTWy3p9s+DcFU9T8v4CspTquNC5ePxK7V/abOgz79k/kJqzPjU9FfVng== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794630939; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Gm-Message-State:X-Gm-Gg:X-Received:Received:From:To:Cc:Subject: Date:Message-ID:X-Mailer:MIME-Version:Content-Transfer-Encoding; bh=qiW5EsyMhvM/T+7WTNOJmmFgLaE+Y6fQGJrEN+loHe4=; b=z85fQSRrGH0W+frgYjXsI5Rib6crNKY+9X50BiN4OvDNDw4DgcvGJh/LkP/vb4uNak/b thJ723rvYLEa8FSqbEhXZUHlM0Y8SByt4Eh+OnUIMexs5FJOokflFAYeuyPamtmxZ2Xkw CrrI7ddrzffC7QOrYdh23+NgOaSQUvvNRht4DDG9v0iUaS811LUt1rBYdiUl93ZmI/H14 mL+I+Ouq4kmNZljiK+XzeQpfSrPYDTOqTv/+LmDy6AjlLi0LHIyRXmBPtnAFN8OBFdRlk 2POSgmeme7TounkzTQRriSuiDNY2eOwnAXyiEtt9BXHmHnAsGGfbliL1hPEj93rW65g== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b=UMda+HX2; arc=none smtp.remote-ip=74.125.82.179 Received: from mail-dy1-f179.google.com (mail-dy1-f179.google.com [74.125.82.179]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 52EA5606A32E for ; Sat, 14 Nov 2026 04:35:39 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 52EA5606A32E 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.a=rsa-sha256 header.s=20260707 header.b=UMda+HX2 Received: by mail-dy1-f179.google.com with SMTP id 5a478bee46e88-37000e7234bso2765198eec.1 for ; Fri, 13 Nov 2026 20:35:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1794630938; x=1795235738; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to:content-type; bh=qiW5EsyMhvM/T+7WTNOJmmFgLaE+Y6fQGJrEN+loHe4=; b=UMda+HX2vxyRAAv2yaCE6FBNtDKdZdeEhlTP7g2fj4RCAL9KonoCdNMRaKLFBxgtcL eXncfrWmrpOc2roZBgQapI3R6QldTXOvDPX5UYwBlWuNlQovmMmxhJQ27l3/4Gx2zMy2 va6DmpFg56tISWeWhS85DkDxJcu9pD/Uxr9PozhIM3EDFB1m4D0IlvBoA3l3holrURuu l0RSY22dzkui603y44pPamNYsCrXwF2cxuQcAuraE9wqbdZdfGxYl6DT/8POLU4uLNpT xmci5NpOQgJGjKIPdITpcql+WR0RCYvrACR0ITk54U5OhOtuf1GaSusadFUalrZNzSqQ 0XJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1794630938; x=1795235738; h=content-transfer-encoding:mime-version: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=qiW5EsyMhvM/T+7WTNOJmmFgLaE+Y6fQGJrEN+loHe4=; b=PqwGskuQtIZgk/0mJknuGhQjmve8WAZfvd7q0jeRJs5cGz1deDBdR9JOw82wQWWQdd TRpwdQiS2+uVSGGYF/zuawzZENrETEbf3xwL+dH8+dMtk/6fOLXv2qWe6ZSsPGME2Ua/ zarxG/nj3GBzcLscS5CJQEpWuFECLeTMhvZ/JYg+UwOZzpQ5pRYP3Dpd08foXpI73O7d AyUuou4D33IbO4aoja1HBwyrpxXKfkE/YQfaXyVtns5XrURNksK1y1kOZ5xz6OsMbl+e 0LUXWHXbzJ15iUgIfQ6tLiRwyTqTHzqCpb9aqrHHAb7VJDKKt0N4j7dRFPcgEBQIKbz2 kYtw== X-Gm-Message-State: APuU4Z89U1y7R9umhZwUdpdrulCpAVen8KCr0wkKP1TsJ1O9LIHzW2xP iUCGN9H6Ruw1OdtzpvEcJz4+mWeiCH3MLDN2TRBCm8v7GgQfyz4hIMiS X-Gm-Gg: AYBFou0fNhomy/qGFbNliK7lZCdimKdcwbK9AxeXaitG6Y909Re3TO+Fy8fflqU4uxq Z/GhBDH9xOKVwe4rfHpJK7elPWp5eiTnKTVHDQAeyd4GKvf7GEMgS/7wsciJTBIEdJwSwh2u9ud pKTbhKoUwFgtgv7WXV0FjXHTVJLg9LUUvj2Irytk/67P5kt2Rll0aTdKtSthEDsm8aARzTbxqOJ 0kXTryqJl93cDoMhtlNr9ugtem7KY3rZnZQv2edh6UmxZsoLNnKTr65IYv0KMQl7OlVCJEXaT2C y6+CnSQd8gRQK/kbRZLLlyJuY50UCY0jyiKbVtPkdUI/Rf0D4mZDIp4SfYZ0F8muVi3STRHcWF3 dsP4pXpzoK9e5lObVGmGxGFKO0hBduUSBv2qS0a5lLhypQrcVXEOpfABdwBXb4/hYPTaArxHeeo sW/KtVByg8XX7NOessIse9UZmvw1/dJzgOnVWRgzyEEUIqaSyBYj35gS4bl+QzOeznqjWDhDowu vuTGcdwUIIUvUG3t5FTrDa7KRE5IIJ6k3WmzTXUOJjcTMPpU2xWgMyGXvn7XFLZKb25U9EEn/2A uXHeOvz6Lh8bI7Dq5QpDTzw21qdruwpU43mWsussVsoKhdqQbsrVLxkNzlB6IC63rk7NW2SpnuT 1n+urceBtIKlSDb0WXEAWjMfDk0Q= X-Received: by 2002:a05:7301:4287:b0:36e:53bc:4681 with SMTP id 5a478bee46e88-3796731594bmr3469347eec.37.1794630938255; Fri, 13 Nov 2026 20:35:38 -0800 (PST) Received: from localhost.localdomain ([2601:646:4300:d042:796f:2855:533:1bb3]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-37955f02ff0sm11744106eec.16.2026.11.13.20.35.36 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 13 Nov 2026 20:35:37 -0800 (PST) From: ozgun kultekin To: slava@dubeyko.com, glaubitz@physik.fu-berlin.de, frank.li@vivo.com Cc: linux-fsdevel@vger.kernel.org, ozgun kultekin , Guikun Yang , stable@vger.kernel.org Subject: [PATCH 1/2] hfsplus: bound btree keys by the tree's max_key_len in hfs_bnode_read_key() Date: Fri, 13 Nov 2026 20:35:21 -0800 Message-ID: <20261114043522.48764-1-ozgunkultekin@gmail.com> X-Mailer: git-send-email 2.56.0 X-Mailing-List: linux-fsdevel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit hfs_bnode_read_key() reads the key length of leaf records (and of all records of variable-key and attributes trees) from disk and only checks it against sizeof(hfsplus_btree_key), 518 bytes. The destination is always one of the two key buffers hfs_find_init() allocates, each tree->max_key_len + 2 bytes long. For the extents tree max_key_len is fixed at 10, so the whole allocation is 24 bytes and a crafted leaf key writes up to 516 attacker-controlled bytes into kmalloc-32. The error path has the same problem: it clears 518 bytes of the 24-byte buffer. hfs_brec_insert() reaches this with an unvalidated key: when the tree root is 0 it reads the key of record 0 of the leaf it inserts into, and after a split it reads the first key of the new node. A read-write mount that extends the catalog (creating the private data directory), or an append to a file whose extents spill into the extents tree, is enough; no other file operation is needed. The 518-byte bound was added by commit bb5e07cb9277 ("hfs/hfsplus: fix slab-out-of-bounds in hfs_bnode_read_key"); it covers the catalog and attributes buffers but not the extents buffer. Bound the key length by the tree's own maximum, which btree.c already validates per tree, and only clear the bytes the buffer actually has. Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2") Fixes: bb5e07cb9277 ("hfs/hfsplus: fix slab-out-of-bounds in hfs_bnode_read_key") Reported-by: Guikun Yang Closes: https://lore.kernel.org/all/tencent_F85118A9AFDF9B230D4E8FA672510A3E2F08@qq.com/ Cc: stable@vger.kernel.org Signed-off-by: ozgun kultekin --- diff --git a/fs/hfsplus/bnode.c b/fs/hfsplus/bnode.c index 3a1a1fa..f414020 100644 --- a/fs/hfsplus/bnode.c +++ b/fs/hfsplus/bnode.c @@ -84,8 +84,13 @@ void hfs_bnode_read_key(struct hfs_bnode *node, void *key, u32 off) else key_len = tree->max_key_len + 2; - if (key_len > sizeof(hfsplus_btree_key) || key_len < 1) { - memset(key, 0, sizeof(hfsplus_btree_key)); + /* + * The key buffers come from hfs_find_init() and hold + * tree->max_key_len + 2 bytes each, which is far less than + * sizeof(hfsplus_btree_key) for the extents tree. + */ + if (key_len > tree->max_key_len + 2 || key_len < 1) { + memset(key, 0, tree->max_key_len + 2); pr_err("hfsplus: Invalid key length: %u\n", key_len); return; } -- 2.47.0