From patchwork Fri Dec 9 10:21:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Siddh Raman Pant X-Patchwork-Id: 31710 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp690946wrr; Fri, 9 Dec 2022 02:26:49 -0800 (PST) X-Google-Smtp-Source: AA0mqf5oOHcj6GjmdMDy2RHrAK/JqCtuDDwyzHCkxwy0EVxRCaR4Yp6PGGQLWA1YSnA+F3v+mZs3 X-Received: by 2002:a05:6a20:180a:b0:ab:e8a7:6137 with SMTP id bk10-20020a056a20180a00b000abe8a76137mr5327462pzb.3.1670581609036; Fri, 09 Dec 2022 02:26:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1670581609; cv=pass; d=google.com; s=arc-20160816; b=AmwBGvI2aeHqA6MSkgFrMD9qEIhWHjm+ixrJ8UBSvCtHOeBfSOm0PfNYvwLISMf6Op oLKENizP0dB5qnB8/QncmhzZj/DU9r39bUwjuOk4zxWD/MS+u3c/Z4oGMCMp91VM8E0n ocMrqynFofrvSQwFbLRTwVhZ/Z7Y7chqxEHewXCkrIPgGPvfidperHwYCTWfNuCkUgow HsYfJUgLsZ//e29YiZABkRAEGxzNEBV3wygroMJLeYNQeeBPf0wqyIApu3Q+nhEPcdYI uX3XySJTz/fpj97yuBXAyQup3ZcOEUTyf9i7s/MzQ+gh9gt1b3F5nlnwFLRE0yt9sk8F Epgw== 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f68-20020a636a47000000b0047853fba938si1145860pgc.390.2022.12.09.02.26.35; Fri, 09 Dec 2022 02:26:49 -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 + 99 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 X-ZohoMailClient: External 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751731781579762504?= X-GMAIL-MSGID: =?utf-8?q?1751731781579762504?= 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=ReproC&x=1037a6b2880000 Kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=e2021a61197ebe02 Dashboard link: https://syzkaller.appspot.com/bug?extid=a8e049cd3abd342936b6 Reported-by: syzbot+a8e049cd3abd342936b6@syzkaller.appspotmail.com Suggested-by: Gao Xiang Signed-off-by: Siddh Raman Pant Reviewed-by: Gao Xiang Reviewed-by: Chao Yu --- 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 *inode, loff_t offset, iomap->type = IOMAP_HOLE; iomap->addr = IOMAP_NULL_ADDR; /* - * No strict rule how to describe extents for post EOF, yet - * we need do like below. Otherwise, iomap itself will get + * No strict rule on how to describe extents for post EOF, yet + * we need to do like below. Otherwise, iomap itself will get * into an endless loop on post EOF. + * + * Calculate the effective offset by subtracting extent start + * (map.m_la) from the requested offset, and add it to length. + * (NB: offset >= map.m_la always) */ if (iomap->offset >= inode->i_size) - iomap->length = length + map.m_la - offset; + iomap->length = length + offset - map.m_la; } iomap->flags = 0; return 0;