Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2494600rwb; Fri, 9 Dec 2022 02:53:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf7tP6taZiNWbvXIF9FjJaXT51OeAdlDPasyFj1vJlnefZ7ThFOa01yfVOKHcr4CHjvho8RS X-Received: by 2002:a17:907:2ace:b0:7c1:eb:b2a7 with SMTP id fm14-20020a1709072ace00b007c100ebb2a7mr3677782ejc.13.1670583198287; Fri, 09 Dec 2022 02:53:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1670583198; cv=pass; d=google.com; s=arc-20160816; b=uNlLN4IN4853riYjXiP39RrxITrsOchoMUwbmeC5fHrJ9pNa1uae/jtdejEY3buhd/ LdeNBkDksGyIrGoGBx7I+5p9qq25/TqNz+HDfKPjvK91iiwxt21NHYIqHOjdQWBuWfr2 c+qWVlTd/RNs+TmnkywdSiHiFUWqlPcJ9HMRQRb3TYREU5fZo8Wi2Y8jlyQQDb0QTeLq EF9DJlaAVlH6HZrUe1CG2UO92f8oICYtPIoNYA0gso8ZgQ9+lz45pj60LPTtEVJnv+Vk aaWyf7kzwAGxiV1+CkVkXbm/6c1F01lvkAcZl+f0oeBGG/ypfS1zhbSpC/8lQgepedPa zxIg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version:date :subject:message-id:cc:to:from:dkim-signature; bh=JUZ1nbgPyt696GphUrYZhsJZC+42uCS/7nfOQ2ALbBw=; b=hvtSf76DKCkAOdR8JaRYWfdpCpf1iPx6woG+02Rzqz3aUWlMVV7v5FCz2YROQP32ZM rhZlnTLdHNhb+j4aGu20Yc8VmYuVA3Sz1vUNXCnK2iXUrxr7rpu9/37lZjOiByoGjbnt Qmpzsu/mXuWxF7B1sb4kIBYxHFPecWnUyd4rJNGgQkNhvq/lxydxh64iJzaJquQ8pIPL PRpOsRbCTFYI1IBFZ5geBMicbLT0B26IWgTx7GSSiytJHy3LNDkvv1TClFAqKsGeGiD6 qU+0obxA9j+0OSotkvssdaQZBKXn+01pQwNhSeWCl7tIwPob01rW5g0kWEH60NKJZ9DE RoBg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@siddh.me header.s=zmail header.b=PnHtyBfH; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siddh.me Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ht20-20020a170907609400b007c0db55679esi1014957ejc.361.2022.12.09.02.53.00; Fri, 09 Dec 2022 02:53:18 -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=@siddh.me header.s=zmail header.b=PnHtyBfH; arc=pass (i=1 spf=pass spfdomain=siddh.me dkim=pass dkdomain=siddh.me dmarc=pass fromdomain=siddh.me>); 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=siddh.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbiLIKWm (ORCPT + 74 others); Fri, 9 Dec 2022 05:22:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229558AbiLIKWk (ORCPT ); Fri, 9 Dec 2022 05:22:40 -0500 Received: from sender-of-o50.zoho.in (sender-of-o50.zoho.in [103.117.158.50]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAF7A28B for ; Fri, 9 Dec 2022 02:22:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670581320; cv=none; d=zohomail.in; s=zohoarc; b=JKZvFEQC0s+u8mPgmbSg+4UnMydSwUlXT7fqoEejG0SsstB2FdiD4GRHE7PDef5NucFMzmuyqfZUZ4XSG5LtfL/xGPS42BG6JJvUDLUoVbEg70I+2I+3PBGnTt1xWLJuUk5xyuANF9q+XYCUQLcA2xRfJZYl5SXwME+3pdUEhik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.in; s=zohoarc; t=1670581320; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:MIME-Version:Message-ID:Subject:To; bh=JUZ1nbgPyt696GphUrYZhsJZC+42uCS/7nfOQ2ALbBw=; b=M1BKZrHabNPzWfYVHg9Yse+zEUwQV4k89Js9gDG2v79E0BICX7ASemKskTNQJDIY88VAdPfwtFMQY7AwuOpJcawS3JW/wd9GhgLo9tGbrIOaM1+taio25LZj+iTR6PZgH9qKO9mhPA9ZjuXJ48cwZAuHggaOOmoun8XxN+szwVY= ARC-Authentication-Results: i=1; mx.zohomail.in; dkim=pass header.i=siddh.me; spf=pass smtp.mailfrom=code@siddh.me; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1670581320; s=zmail; d=siddh.me; i=code@siddh.me; h=From:From:To:To:Cc:Cc:Message-ID:Subject:Subject:Date:Date:MIME-Version:Content-Transfer-Encoding:Content-Type:Message-Id:Reply-To; bh=JUZ1nbgPyt696GphUrYZhsJZC+42uCS/7nfOQ2ALbBw=; b=PnHtyBfHVkuau6YA04pqos05PXgOlGNy0VcBY3he0rTBjMNJyRAW6qaPXmsza0HO 0VyxwpcH6xfOsYolR5JBbzsSWq4/mesBZ7YWeS5Zc25X5ThW3sZDN58KDTnrZrYz5P5 tD6X1rPuj58lK671Zf7j3cbU8LvLzDt1TxsffB1k= Received: from kampyooter.. (110.226.31.37 [110.226.31.37]) by mx.zoho.in with SMTPS id 1670581318019810.3770917612286; Fri, 9 Dec 2022 15:51:58 +0530 (IST) From: Siddh Raman Pant To: Gao Xiang , Chao Yu , Yue Hu , Jeffle Xu Cc: linux-erofs , linux-kernel , syzbot+a8e049cd3abd342936b6@syzkaller.appspotmail.com Message-ID: <20221209102151.311049-1-code@siddh.me> Subject: [PATCH v2] erofs/zmap.c: Fix incorrect offset calculation Date: Fri, 9 Dec 2022 15:51:51 +0530 X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMailClient: External Content-Type: text/plain; charset=utf8 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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 Effective offset to add to length was being incorrectly calculated, which resulted in iomap->length being set to 0, triggering a WARN_ON in iomap_iter_done(). Fix that, and describe it in comments. This was reported as a crash by syzbot under an issue about a warning encountered in iomap_iter_done(), but unrelated to erofs. C reproducer: https://syzkaller.appspot.com/text?tag=3DReproC&x=3D1037a6b28= 80000 Kernel config: https://syzkaller.appspot.com/text?tag=3DKernelConfig&x=3De2= 021a61197ebe02 Dashboard link: https://syzkaller.appspot.com/bug?extid=3Da8e049cd3abd34293= 6b6 Reported-by: syzbot+a8e049cd3abd342936b6@syzkaller.appspotmail.com Suggested-by: Gao Xiang Signed-off-by: Siddh Raman Pant --- Changes since v2: - Fix the calculation instead of bailing out. fs/erofs/zmap.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c index 0bb66927e3d0..a171e4caba3c 100644 --- a/fs/erofs/zmap.c +++ b/fs/erofs/zmap.c @@ -790,12 +790,16 @@ static int z_erofs_iomap_begin_report(struct inode *i= node, loff_t offset, =09=09iomap->type =3D IOMAP_HOLE; =09=09iomap->addr =3D IOMAP_NULL_ADDR; =09=09/* -=09=09 * No strict rule how to describe extents for post EOF, yet -=09=09 * we need do like below. Otherwise, iomap itself will get +=09=09 * No strict rule on how to describe extents for post EOF, yet +=09=09 * we need to do like below. Otherwise, iomap itself will get =09=09 * into an endless loop on post EOF. +=09=09 * +=09=09 * Calculate the effective offset by subtracting extent start +=09=09 * (map.m_la) from the requested offset, and add it to length. +=09=09 * (NB: offset >=3D map.m_la always) =09=09 */ =09=09if (iomap->offset >=3D inode->i_size) -=09=09=09iomap->length =3D length + map.m_la - offset; +=09=09=09iomap->length =3D length + offset - map.m_la; =09} =09iomap->flags =3D 0; =09return 0; --=20 2.35.1