Received: by 2002:a05:6358:7058:b0:131:369:b2a3 with SMTP id 24csp7814339rwp; Wed, 19 Jul 2023 00:09:34 -0700 (PDT) X-Google-Smtp-Source: APBJJlFq9saCqA102chiPlpgx5ALSfdrelAhRnnI3fTqXYMR2W/WiEpHs41MjCm+MquooZBokLk4 X-Received: by 2002:a92:c64e:0:b0:346:5e1c:f01e with SMTP id 14-20020a92c64e000000b003465e1cf01emr1405781ill.5.1689750573706; Wed, 19 Jul 2023 00:09:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689750573; cv=none; d=google.com; s=arc-20160816; b=mvX4S40R76bQammRQgyMoM5AO7J3XDfdHBUe7QwmaQQJe4RGqddH6YanGIUa/SEupB B3Y2nTfWSGjVpVx6yfCB7eYr+y4m7MdhNFocluWbCp7n17gg1wgLXmVHxvDwKe/UF16k 3+MHx3oofPFX7A9+1gTMsEx89EtRWa/9X7FCMiYtjRPFNE8eUkSM7bJAduoE3tEUe7P5 ouQMPQoigP9VnM9sWDU525jqNstKa8hX9xtw14du7KkZ9IUnldA4GpixzXn/5iJR6A4P 2CBtbJfz4n4tXlbM1JIhKGtXY8fARNkcu7GBYeSCHkwVgBwQ4fu5ZtoBblLsy2VxCr5z 0Vpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from; bh=zFj3qOYbdoEzV/7Ujma/NB8x+JG2bWeFKxjOMsqDpn8=; fh=vDNCtZfonx9omdPo5qwADj/ZvTphBKnKtHtK5q954Ds=; b=NTCRjbxPFH+lMaRK3LpLN3BYz44kTZPxBjKgffo3kYJMaJjGjaeIPd2U4AQ3XEiKXu vyMtKHhUeFtKLkvSCgu6GPy/H8bbKyR7MO9KarcLU6dAhYdXd4qkI6cNSyax4KgMag9R mko6vO9uqxiXkOb1WWTPsC+qbY6Q4wJvMo59eXsi4TuUkR6DV55NuscJQh0jVaWxOURO wsx/ix7rx1VowYbYeDInxNNxY2/T8kyaBcqwEbevDv+LhmJrHlXwEzI7oaP2K6VpQjck uPKrMu55O/J/5d172cObTrzSQe1/a354d0Srwfd8364MoFVC25kVST5jxc1xr7zl7KEz sz3g== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h14-20020a17090aa88e00b00262e650abadsi888872pjq.117.2023.07.19.00.09.21; Wed, 19 Jul 2023 00:09:33 -0700 (PDT) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=alibaba.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230502AbjGSGzN (ORCPT + 99 others); Wed, 19 Jul 2023 02:55:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38592 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229590AbjGSGzK (ORCPT ); Wed, 19 Jul 2023 02:55:10 -0400 Received: from out30-132.freemail.mail.aliyun.com (out30-132.freemail.mail.aliyun.com [115.124.30.132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 105B61BFC for ; Tue, 18 Jul 2023 23:55:08 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R121e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018045170;MF=hsiangkao@linux.alibaba.com;NM=1;PH=DS;RN=4;SR=0;TI=SMTPD_---0Vnkhvgd_1689749700; Received: from e18g06460.et15sqa.tbsite.net(mailfrom:hsiangkao@linux.alibaba.com fp:SMTPD_---0Vnkhvgd_1689749700) by smtp.aliyun-inc.com; Wed, 19 Jul 2023 14:55:06 +0800 From: Gao Xiang To: linux-erofs@lists.ozlabs.org Cc: LKML , Gao Xiang , Shijie Sun Subject: [PATCH] erofs: fix wrong primary bvec selection on deduplicated extents Date: Wed, 19 Jul 2023 14:54:59 +0800 Message-Id: <20230719065459.60083-1-hsiangkao@linux.alibaba.com> X-Mailer: git-send-email 2.24.4 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-9.9 required=5.0 tests=BAYES_00, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY,USER_IN_DEF_SPF_WL 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 When handling deduplicated compressed data, there can be multiple decompressed extents pointing to the same compressed data in one shot. In such cases, the bvecs which belong to the longest extent will be selected as the primary bvecs for real decompressors to decode and the other duplicated bvecs will be directly copied from the primary bvecs. Previously, only relative offsets of the longest extent was checked to decompress the primary bvecs. On rare occasions, it can be incorrect if there are several extents with the same start relative offset. As a result, some short bvecs could be selected for decompression and then cause data corruption. For example, as Shijie Sun reported off-list, considering the following extents of a file: 117: 903345.. 915250 | 11905 : 385024.. 389120 | 4096 ... 119: 919729.. 930323 | 10594 : 385024.. 389120 | 4096 ... 124: 968881.. 980786 | 11905 : 385024.. 389120 | 4096 The start relative offset is the same: 2225, but extent 119 (919729.. 930323) is shorter than the others. Let's restrict the bvec length in addition to the start offset if bvecs are not full. Reported-by: Shijie Sun Fixes: 5c2a64252c5d ("erofs: introduce partial-referenced pclusters") Signed-off-by: Gao Xiang --- fs/erofs/zdata.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fs/erofs/zdata.c b/fs/erofs/zdata.c index b69d89a11dd0..de4f12152b62 100644 --- a/fs/erofs/zdata.c +++ b/fs/erofs/zdata.c @@ -1144,10 +1144,11 @@ static void z_erofs_do_decompressed_bvec(struct z_erofs_decompress_backend *be, struct z_erofs_bvec *bvec) { struct z_erofs_bvec_item *item; + unsigned int pgnr; - if (!((bvec->offset + be->pcl->pageofs_out) & ~PAGE_MASK)) { - unsigned int pgnr; - + if (!((bvec->offset + be->pcl->pageofs_out) & ~PAGE_MASK) && + (bvec->end == PAGE_SIZE || + bvec->offset + bvec->end == be->pcl->length)) { pgnr = (bvec->offset + be->pcl->pageofs_out) >> PAGE_SHIFT; DBG_BUGON(pgnr >= be->nr_pages); if (!be->decompressed_pages[pgnr]) { -- 2.24.4