From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (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 7090524C06A for ; Mon, 4 May 2026 23:27:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777937268; cv=none; b=B5eZRGyqSrVkHJx+Mw9FFVrO3yMMztmcdFNZyOdzfd/ZMSmegOH0iCKZRrQQe7A3QK0e4utWu9VqaqEgzMGxrA8ElncFXQ6UT8i5PdtyKjhJYFkIPwfR0AWn7aiYB6cloxlr8yzDVZckd95IEKs+zIiqljhVwpm096Mycxjpu3Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777937268; c=relaxed/simple; bh=X/Ts6FB29sipVCHkAJKOzqHUgYArmLo5X/jhFL+PcWk=; h=Message-ID:Subject:From:To:Cc:Date:In-Reply-To:References: Content-Type:MIME-Version; b=J56gPa6RQ3cfOUV8WOmZEQw5ZM4/QHsRADIzzoC4rkc3wkZeCH8m1ZLp1VZyU0x8LxhpecwShAzug/HPk3ykHvidiabkpPWcRSRWTcfut+1UGOqEsJfOQ48ASabYRf/K7VkfU08xeE0+AnHUhHkE3Fkf2CtO+RUoiQ0LmNhlN+8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=CB+1t2Tv; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=Ojji7bUe; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="CB+1t2Tv"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="Ojji7bUe" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1777937265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yeaz/dAuRpUt7GzZUrHflLMUXhh07epuZ/gDSiDt6lQ=; b=CB+1t2Tv11YqWjUH/ZkoYDYempOsrl5jurjfghj7HsV+GVq2u6eglfV20lIwxuS5TQ0BhO 2PwKmG6QLiCDoXEo9RiXT5RRNPidbJbZsiq9lfAaNfbA2A5U6eapkrmAIVIKIXvYnd2aKQ uCV56aVK6knkgxHzwzwIHVNyG9cZDls= Received: from mail-yw1-f200.google.com (mail-yw1-f200.google.com [209.85.128.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-595-zoBvqrLxPei7lDeoE_ZVAQ-1; Mon, 04 May 2026 19:27:44 -0400 X-MC-Unique: zoBvqrLxPei7lDeoE_ZVAQ-1 X-Mimecast-MFC-AGG-ID: zoBvqrLxPei7lDeoE_ZVAQ_1777937263 Received: by mail-yw1-f200.google.com with SMTP id 00721157ae682-7bd5c267082so68638467b3.0 for ; Mon, 04 May 2026 16:27:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1777937263; x=1778542063; darn=vger.kernel.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:from:to:cc:subject :date:message-id:reply-to; bh=yeaz/dAuRpUt7GzZUrHflLMUXhh07epuZ/gDSiDt6lQ=; b=Ojji7bUePPVSPBfvDnMUirWa6/C7s2ioCP9taSRHZ8avF93GgLTPKeBOMZEQqTaEeT DMFKUy2I0u0Fb8IRz8fMY6WWBJgpRGPLWxild76F6fAjwiaOCYZdByvq10sB3VsJzeON nKS5Uuc1kxVruG0OH/L+9Tm5tCcfaLxrxr1ITGYGIU5vEXE2U0NKrvwbPc3ZvB5sZWHm MP7+Fr7TuC9kP0nmAVN9Hvng/fuR9f0s6p3HkYch3GtlTpmg6aAMRGfm3G+YS0Aqxbo+ nQxpcx2gU/eXXtu8gf7eymLn1HYI7WJJ75iX1qTlfu/cK6i5tXxrA0M3EozoCOos2V4n y7TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1777937263; x=1778542063; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:cc:to:from:subject:message-id:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yeaz/dAuRpUt7GzZUrHflLMUXhh07epuZ/gDSiDt6lQ=; b=E9VjIVTuLmUBsIPij3mWGRSy/iuIFb7zvqYphj9h28Yp9M3roGSs7AAtVdS/9hcwXC Q38+J6/dY8JnXmZi8llUPPzdggNwutmj/3YcL793ldyDPsu3Yp+izCrUK1LYI7z4hlFb hfu3mdTmld3OSv4Tff+DiDAu+BUgByfPxhvFGItVeRJ7jhXPUH69IYmPaeGe6NOm4oFA cUPM5Heb0ubrtqKBvnD4jdD7ebQFBu5XBsXU3ps+2rtwYd9gUvK4YEU5a8wSXbRAd64l cqaUanyFvOBaHPkHQ+lTM8+VwqPGKR5BY36S35FMSR313AiOHRzlLNIE3kBW5DztDfwf aj6w== X-Forwarded-Encrypted: i=1; AFNElJ+PI/ejwTV7+oUGi6qDTC0WNtxLMSAP2AN9Vkq9B5ZrDdLIxm0z74z2AlxJ3xj1R/fPvZIIDtvqOxWnw9o=@vger.kernel.org X-Gm-Message-State: AOJu0YzxxMQCWE4EsMJRsjBuutpO32LkRPO5KVLMG01doKqTpi+gCZHL 89aK82dpxI8EDrbpBYdYcPTQmnE9KCjvZdib2lpIWm3i4AOhP1b4fJe9GTjUmJwwgwcFGlUAqpH gnwzulF0PKJSJeVbYiWC2PluyftQVH/Jv/9GEFVsMJB4dcAiUPh13BopHc83F2w1t6A== X-Gm-Gg: AeBDievw0cvDcakyOUoKWkWNu7cK6qvrNe0ZsM5y4StyKlH7zMQyHnANgTaWjSXwGl2 g6Qheh1vgHDsWjQY5sfgRXXNpLLh+AYx8hkJc/+lyNtOYorSXFZhMU2/G5dNJPaZkj+OuJP89tn 1aN+Ux4LZ89m5jXFMPbqCe52g3RJ7rL0DBncad4fFd9xUFcrLMV9kk9H2635ON/EZO7u2/oTwb1 ZKp0mN4ZAQoGcQhGemidRzqQqyYasxgBhRI6FL0gYaDP5pclL1QsbGUCiLQ4ltZ9JDlHHMP0ghV 86DvJYyG37l4JJ4WhPKyTQ5lFjXKtuqt8EZgW1ZKOrayRK9xnwfWZrrRgFLdmm2YfECvlzWmvSf xJOUI+yKwb2yoFqrSdEsR9Y31IimtqqBNgnhOC+4uTs8fHQo7LSo/Gza7VvbVoQs= X-Received: by 2002:a05:690c:dd5:b0:7bd:882a:43e0 with SMTP id 00721157ae682-7bdac599075mr9047057b3.27.1777937263352; Mon, 04 May 2026 16:27:43 -0700 (PDT) X-Received: by 2002:a05:690c:dd5:b0:7bd:882a:43e0 with SMTP id 00721157ae682-7bdac599075mr9046887b3.27.1777937262923; Mon, 04 May 2026 16:27:42 -0700 (PDT) Received: from li-4c4c4544-0032-4210-804c-c3c04f423534.ibm.com ([2600:1700:6476:1430::29]) by smtp.gmail.com with ESMTPSA id 00721157ae682-7bd6652dae3sm55907087b3.8.2026.05.04.16.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 May 2026 16:27:42 -0700 (PDT) Message-ID: <2a12f80d489dbf0a5a128294a95e9181e607a5db.camel@redhat.com> Subject: Re: [PATCH 1/3] hfs/hfsplus: fix u32 overflow in check_and_correct_requested_length From: Viacheslav Dubeyko To: Tristan Madani , Viacheslav Dubeyko , John Paul Adrian Glaubitz , Yangtao Li Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org, Tristan Madani , syzbot+6df204b70bf3261691c5@syzkaller.appspotmail.com, syzbot+e76bf3d19b85350571ac@syzkaller.appspotmail.com Date: Mon, 04 May 2026 16:27:40 -0700 In-Reply-To: <20260501110218.29906-1-tristmd@gmail.com> References: <20260501110218.29906-1-tristmd@gmail.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.60.0 (3.60.0-1.fc44app2) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 On Fri, 2026-05-01 at 11:02 +0000, Tristan Madani wrote: > From: Tristan Madani >=20 > check_and_correct_requested_length() compares (off + len) against > node_size using u32 arithmetic. When the caller passes a large len > value (e.g. from an underflowed subtraction in hfs_brec_remove()), > off + len can wrap past 2^32 and produce a small result, causing the > bounds check to pass when it should fail. >=20 > For example, with off=3D14 and len=3D0xFFFFFFF2 (underflowed from > data_off - keyoffset - size in hfs_brec_remove), off + len wraps to 6, > which is less than a typical node_size of 512, so the check passes and > the subsequent memmove reads ~4GB past the node buffer. >=20 > Fix this by comparing len against (node_size - off) instead. Since > is_bnode_offset_valid() already guarantees off < node_size before this > point, the subtraction cannot underflow. >=20 > Reported-by: syzbot+6df204b70bf3261691c5@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=3D6df204b70bf3261691c5 > Tested-by: syzbot+6df204b70bf3261691c5@syzkaller.appspotmail.com > Reported-by: syzbot+e76bf3d19b85350571ac@syzkaller.appspotmail.com > Closes: https://syzkaller.appspot.com/bug?extid=3De76bf3d19b85350571ac > Tested-by: syzbot+e76bf3d19b85350571ac@syzkaller.appspotmail.com > Fixes: a431930c9bac ("hfs: fix slab-out-of-bounds in hfs_bnode_read()") > Cc: stable@vger.kernel.org > Signed-off-by: Tristan Madani > --- > fs/hfs/bnode.c | 2 +- > fs/hfsplus/hfsplus_fs.h | 2 +- > 2 files changed, 2 insertions(+), 2 deletions(-) >=20 > diff --git a/fs/hfs/bnode.c b/fs/hfs/bnode.c > index 13d58c51fc46b..c00645a4a5733 100644 > --- a/fs/hfs/bnode.c > +++ b/fs/hfs/bnode.c > @@ -41,7 +41,7 @@ u32 check_and_correct_requested_length(struct hfs_bnode= *node, u32 off, u32 len) > =20 > node_size =3D node->tree->node_size; > =20 > - if ((off + len) > node_size) { > + if (len > node_size - off) { I don't agree with likewise change. Probably, we need to have: (u64)off + len Thanks, Slava. > u32 new_len =3D node_size - off; > =20 > pr_err("requested length has been corrected: " > diff --git a/fs/hfsplus/hfsplus_fs.h b/fs/hfsplus/hfsplus_fs.h > index 3545b8dbf11c5..10b2dda3f8044 100644 > --- a/fs/hfsplus/hfsplus_fs.h > +++ b/fs/hfsplus/hfsplus_fs.h > @@ -600,7 +600,7 @@ u32 check_and_correct_requested_length(struct hfs_bno= de *node, u32 off, u32 len) > =20 > node_size =3D node->tree->node_size; > =20 > - if ((off + len) > node_size) { > + if (len > node_size - off) { > u32 new_len =3D node_size - off; > =20 > pr_err("requested length has been corrected: "