Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp1289782rwb; Thu, 1 Dec 2022 15:20:05 -0800 (PST) X-Google-Smtp-Source: AA0mqf42ZEjgfxMjKoqWHeYLTDGYejKjdhZkPg+UgjkJHunuksI5tZD12bDUWfGludx1plfsqU9T X-Received: by 2002:aa7:c78b:0:b0:467:97e4:6339 with SMTP id n11-20020aa7c78b000000b0046797e46339mr61807811eds.381.1669936805634; Thu, 01 Dec 2022 15:20:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669936805; cv=none; d=google.com; s=arc-20160816; b=XsP3Jmo4MSp207PC5se5uAJBoRVB8dMB/TRRxrlRMjDfwm/Ryj6o07LkBuoTfa1wKw UO9QNBWfJDpoTCWBGMKkL3FSVVOH/W0qiKSV1YV+PMuoHL/BZ6MuyaDG5Is7UMgI7dnb 3sX5/0igHvfGzbfOdaR0TPxTNiBdJqJPB2yb3wsC79Aau93ZvYF5vWKknJwnjuXkgfLq QsPAhCXko/4UHu+53J6CSLzAc2fQGQZeZLQA0IPfLUDrmgb9zOJ32E3POT2awvIU8OjG faRZzjxjvLRiBFamheBEmEOORuhM/Z87E7gE+kidUY9QRrAI9yAFbKSBvwp7XNEpGffE vtXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version:dkim-signature; bh=8r55NhVr723cwq0xc0lLRrnya0twXWY3CzmxTQ/dZkI=; b=z+GzolgyRuX6D3n805DUpMnKSRbu+VWKrjSWl9he7HCT6rsL8VlnzKO0Y3aPMwxZwK QVaKcFloBV9C/AiOyA5XB5cdBTtsWmqdgnCvBzqD78MPuHjfWgpVQEotsLS9ONI71Iea j5/bHbi9hH+K95aMPfSTCq0fr3ik2LzdtIRx8fLmd+jNxmGyReDoSc3Nl+dLdkCe2HW9 K9f7POVN1L+qr/NB1FpsigHGLqRSrkJFum0uJ1MgCItJoAkVM8WJXqBc6h6tDiugr+Dk FNPSU0WGUxwTLiBy4wWuwSOQqvBw0im0j92wNxFRK3OR1VBToryHCZfhtOJc92WqKwuw pdqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@dubeyko-com.20210112.gappssmtp.com header.s=20210112 header.b="dLEd/+Zm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ne16-20020a1709077b9000b007bf7bb4702asi5220100ejc.804.2022.12.01.15.19.46; Thu, 01 Dec 2022 15:20:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@dubeyko-com.20210112.gappssmtp.com header.s=20210112 header.b="dLEd/+Zm"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231724AbiLAXKf (ORCPT + 81 others); Thu, 1 Dec 2022 18:10:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231295AbiLAXKW (ORCPT ); Thu, 1 Dec 2022 18:10:22 -0500 Received: from mail-qt1-x832.google.com (mail-qt1-x832.google.com [IPv6:2607:f8b0:4864:20::832]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE51FC3FF1 for ; Thu, 1 Dec 2022 15:09:35 -0800 (PST) Received: by mail-qt1-x832.google.com with SMTP id h16so3009843qtu.2 for ; Thu, 01 Dec 2022 15:09:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=dubeyko-com.20210112.gappssmtp.com; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=8r55NhVr723cwq0xc0lLRrnya0twXWY3CzmxTQ/dZkI=; b=dLEd/+ZmyTUCV4O9y9TMSltJmihMtv9UXsNn0xX/Q968beeCQDCwHJi5pPHXVTR78O 7qeKTHd/S19uxhBD+8OH4MNNWg8+UR/rfukSPVBb4KHSTm/7gX/u5vhXETibNpCSOrwp xZ25CEfHMqwJkdU2iKMXAEIduAAyNECuDJY2CQkWK2gIVU105XWuXU2Bbq7tg4wN/7td /5QuwrSerATX7eI1xdLjGI4GireFJdMa/ovBXLHaS+uPHDuvsWLknxj/FCxDfdUVY5Rr vkRASZNdaPLrGg6PYBQE4GKTk8agTtdgxKkzdauMId1H1aWDduJIlV7XAZc5aQgMCKOk oIdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8r55NhVr723cwq0xc0lLRrnya0twXWY3CzmxTQ/dZkI=; b=Pb77dswEhFxEYREcjXlW33ElryV1AJX7BJpvl5L+DCZe9/9iVo0hzsb52b2e7SKEpn n/Pg3CFM3m3tpRrT0IFptC+ZDg6gBnAo4EzqArnenFNxhd/Dpfi7eW0GwaTQGqM5+4ay Q4j/YQlio/PDjZ6RRbqCJmBuU/CnMK4OZcJtm6V35zwb7w+mb42uAKuM1uaCabFk8gRr EIEHTMAfLefOgU2sSNE28IGDj1P7lza0TozE7dstVShTeFtxc3WYLGyh+zMUY5MO6/r7 cVpwdNsDwRLnTpPz1MyQtAkjYiznClIPF+yJJ8tXjaS9dnV5/v74C5xtRoVGLDUpc1AR kgSw== X-Gm-Message-State: ANoB5plIxgIh3fCdHYS/Rq12VOki4nL/9wpR/nL31g7Efo/ishZBi22Y +SLrDZapOY+hjWTxgFyQaAQE/A== X-Received: by 2002:ac8:6897:0:b0:3a6:964c:c638 with SMTP id m23-20020ac86897000000b003a6964cc638mr2355191qtq.52.1669936174809; Thu, 01 Dec 2022 15:09:34 -0800 (PST) Received: from smtpclient.apple (172-125-78-211.lightspeed.sntcca.sbcglobal.net. [172.125.78.211]) by smtp.gmail.com with ESMTPSA id r12-20020a05620a298c00b006e16dcf99c8sm4384142qkp.71.2022.12.01.15.09.31 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Thu, 01 Dec 2022 15:09:34 -0800 (PST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3696.120.41.1.1\)) Subject: Re: [PATCH] hfs: Fix OOB Write in hfs_asc2mac From: Viacheslav Dubeyko In-Reply-To: <2ca8a20b-047d-bae1-5a01-0892be4d7e7d@huawei.com> Date: Thu, 1 Dec 2022 15:09:22 -0800 Cc: zippel@linux-m68k.org, akpm@osdl.org, Linux FS Devel , LKML , sunnanyong@huawei.com, wangkefeng.wang@huawei.com, syzbot+dc3b1cf9111ab5fe98e7@syzkaller.appspotmail.com Content-Transfer-Encoding: quoted-printable Message-Id: <7E14DFDD-CA11-46A7-8140-C4A0F9AD069D@dubeyko.com> References: <20221126043612.853428-1-zhangpeng362@huawei.com> <9F97B7A6-9E20-4D70-BA79-8301D80DF9DB@dubeyko.com> <8e298cc0-27b9-a61a-48cc-64a9186048c8@huawei.com> <481BF13E-8CEA-48B4-A29B-0BDE4CAABAF9@dubeyko.com> <2ca8a20b-047d-bae1-5a01-0892be4d7e7d@huawei.com> To: "zhangpeng (AS)" X-Mailer: Apple Mail (2.3696.120.41.1.1) X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Nov 30, 2022, at 5:53 PM, zhangpeng (AS) = wrote: >=20 >=20 > On 2022/11/30 3:08, Viacheslav Dubeyko wrote: >>> On Nov 28, 2022, at 6:23 PM, zhangpeng (AS) = wrote: >>>=20 >>> On 2022/11/29 3:29, Viacheslav Dubeyko wrote: >>>>> On Nov 25, 2022, at 8:36 PM, Peng Zhang = wrote: >>>>>=20 >>>>> From: ZhangPeng >>>>>=20 >>>>> Syzbot reported a OOB Write bug: >>>>>=20 >>>>> loop0: detected capacity change from 0 to 64 >>>>> =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D >>>>> BUG: KASAN: slab-out-of-bounds in hfs_asc2mac+0x467/0x9a0 >>>>> fs/hfs/trans.c:133 >>>>> Write of size 1 at addr ffff88801848314e by task = syz-executor391/3632 >>>>>=20 >>>>> Call Trace: >>>>> >>>>> __dump_stack lib/dump_stack.c:88 [inline] >>>>> dump_stack_lvl+0x1b1/0x28e lib/dump_stack.c:106 >>>>> print_address_description+0x74/0x340 mm/kasan/report.c:284 >>>>> print_report+0x107/0x1f0 mm/kasan/report.c:395 >>>>> kasan_report+0xcd/0x100 mm/kasan/report.c:495 >>>>> hfs_asc2mac+0x467/0x9a0 fs/hfs/trans.c:133 >>>>> hfs_cat_build_key+0x92/0x170 fs/hfs/catalog.c:28 >>>>> hfs_lookup+0x1ab/0x2c0 fs/hfs/dir.c:31 >>>>> lookup_open fs/namei.c:3391 [inline] >>>>> open_last_lookups fs/namei.c:3481 [inline] >>>>> path_openat+0x10e6/0x2df0 fs/namei.c:3710 >>>>> do_filp_open+0x264/0x4f0 fs/namei.c:3740 >>>>>=20 >>>>> If in->len is much larger than HFS_NAMELEN(31) which is the = maximum >>>>> length of an HFS filename, a OOB Write could occur in = hfs_asc2mac(). In >>>>> that case, when the dst reaches the boundary, the srclen is still >>>>> greater than 0, which causes a OOB Write. >>>>> Fix this by adding a Check on dstlen before Writing to dst = address. >>>>>=20 >>>>> Fixes: 328b92278650 ("[PATCH] hfs: NLS support") >>>>> Reported-by: syzbot+dc3b1cf9111ab5fe98e7@syzkaller.appspotmail.com >>>>> Signed-off-by: ZhangPeng >>>>> --- >>>>> fs/hfs/trans.c | 2 ++ >>>>> 1 file changed, 2 insertions(+) >>>>>=20 >>>>> diff --git a/fs/hfs/trans.c b/fs/hfs/trans.c >>>>> index 39f5e343bf4d..886158db07b3 100644 >>>>> --- a/fs/hfs/trans.c >>>>> +++ b/fs/hfs/trans.c >>>>> @@ -130,6 +130,8 @@ void hfs_asc2mac(struct super_block *sb, = struct hfs_name *out, const struct qstr >>>>> dst +=3D size; >>>>> dstlen -=3D size; >>>>> } else { >>>>> + if (dstlen =3D=3D 0) >>>>> + goto out; >>>> Maybe, it makes sense to use dstlen instead of srclen in while()? >>>>=20 >>>> We have now: >>>>=20 >>>> while (srclen > 0) { >>>> >>>> } else { >>>> >>>> } >>>>=20 >>>> We can use instead: >>>>=20 >>>> while (dstlen > 0) { >>>> >>>> } else { >>>> >>>> } >>>>=20 >>>> Will it fix the issue? >>>>=20 >>>> Thanks, >>>> Slava. >>> Thank you for your help. >>>=20 >>> After testing, it fix the issue. >>> Would it be better to add dstlen > 0 instead of replacing srclen > 0 = with dstlen > 0? >>> Because there may be dstlen > 0 and srclen <=3D 0. >>>=20 >>> we can use: >>>=20 >>> while (srclen > 0 && dstlen > 0) { >>> >>> } else { >>> >>> } >>>=20 >> Looks good to me. >=20 > Can I put you down as a Reviewed-by or Suggested-by? Sure. I hope to see the second version of the patch. Reviewed-by: Viacheslav Dubeyko Thanks, Slava. >=20 > Thanks, > Zhang Peng >=20 >> Thanks, >> Slava. >>=20 >>> Thanks, >>> Zhang Peng >>>=20 >>>>> *dst++ =3D ch > 0xff ? '?' : ch; >>>>> dstlen--; >>>>> } >>>>> --=20 >>>>> 2.25.1