Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp727107rwb; Tue, 4 Oct 2022 09:48:12 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6WTzPvOYhW759IRI08YYq8fFVerT6gmqFQ90OOHfuSyiDaiHNGA4jAgD8A7uoQHfaPznw2 X-Received: by 2002:a17:902:b70c:b0:179:eb79:cf9a with SMTP id d12-20020a170902b70c00b00179eb79cf9amr27714185pls.130.1664902091863; Tue, 04 Oct 2022 09:48:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664902091; cv=none; d=google.com; s=arc-20160816; b=B1yhejwOg2zJ1l+MFuoBU/zPF6SIrjubwj/rJdY46vw0qlY25I61ChC9rtgdD563JI uesNJgE4/TE7Kv+PX/zvHHXoLiXaBjl1F8ZLWZzzPBaj1huNcArh67IEQthsx1+s+cK3 l21waTF0Hc78K97vXOeyjn7vP887iEM9di1lxmggsQiZ6neDcKBy9E7Et9GmX9GYPD0d VsYcIbZFVQ1lB08ZhkbAQSm/GzVyj9jRdtJdtCU7Gx9MlNdyDUH5lQmxrNptu6erTpEm AO1AqYT+olJAYRUQ+6ItTvGFAC90AccBaEtJ/Wx5crweGh9QbeeM5joOMxm41+e9mHrT ORfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:mail-followup-to:message-id:subject:cc:to:from:date :dkim-signature; bh=EHOaEWtpls80u0hoY+6rbk4sNUcWRWnCaG2DHaDvy7U=; b=gIJ8uGrBWHkhQjdB8jceDkuKDQ4EAA708oU3qzAuERqtb9ZpxL/nJ5OY0Evt7B3sXP Cn5QSUlMc1q0aHBv164m5yS8rFyLp4VmGkvPKp2GzuTR6fvl6JtET3TNLM7G1Ade476v zbudvNIqPAYmFkTBnewvqShMw//mcZ9lSPfZMDA681RHSKdBEW+6biw/+2w1jPAHEEA4 MTUPatwzQx73Pb4JhxeCeNTpi7JiONU9G3PyCumOy40DoXbFNDL7V6E/7V+Ia/7QPtj9 xyAKx/PIyR0S4bhLU7C5iH8cYEXvHl6wfKxE6MTV5zZKh6odSZMaaIgwinRIkjUNXZU+ POvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HFN/1mY+"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f73-20020a62384c000000b0052e57ed915asi12998300pfa.233.2022.10.04.09.47.33; Tue, 04 Oct 2022 09:48:11 -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; dkim=pass header.i=@kernel.org header.s=k20201202 header.b="HFN/1mY+"; 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=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229851AbiJDQIc (ORCPT + 99 others); Tue, 4 Oct 2022 12:08:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbiJDQI2 (ORCPT ); Tue, 4 Oct 2022 12:08:28 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1E980543C9 for ; Tue, 4 Oct 2022 09:08:27 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 865D1613E9 for ; Tue, 4 Oct 2022 16:08:26 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 9DD6EC433C1; Tue, 4 Oct 2022 16:08:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1664899705; bh=uFMwOLP3RUhCOk0dtvA+jQ3MjGUaf7MqATOqt3PVaOE=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=HFN/1mY+sFwQiffx3YtSM4uJXf8ssrhi8l7C/bwLZfTtbMfDtwmVX/U93UJkuyfhf tul7ZEdJ8N2YykR2wp5/2sG/S+N99dDIlM1mHOk9+Gq4SP/i9BvZwDdmcJkpMWPoau ViCBwEKLUYNHgorUHZAv89jgPRlmBtKt309BhlwpF7h880R1zcaTr/NPBvTzcKVS0m nQIeXAPPf8R/+umcG71x2/pdW+QOSIWIYS86pvrjSFkequhR+3wMZjedLLLshiJwmX UDAJzlyit5UJVJfqZTCQRoLrHcKF4HquMvjprz55Y+uRr4fiOPKOV52dsO5IjPFJDc WVdplxud/jGuw== Date: Wed, 5 Oct 2022 00:08:21 +0800 From: Gao Xiang To: Yue Hu Cc: chao@kernel.org, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, zhangwen@coolpad.com, Yue Hu Subject: Re: [PATCH] erofs: fix the unmapped access in z_erofs_fill_inode_lazy() Message-ID: Mail-Followup-To: Yue Hu , chao@kernel.org, linux-erofs@lists.ozlabs.org, linux-kernel@vger.kernel.org, zhangwen@coolpad.com, Yue Hu References: <20221004144951.31075-1-zbestahu@163.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20221004144951.31075-1-zbestahu@163.com> X-Spam-Status: No, score=-7.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 Tue, Oct 04, 2022 at 10:49:51PM +0800, Yue Hu wrote: > From: Yue Hu > > Note that we are still accessing 'h_idata_size' and 'h_fragmentoff' > after calling erofs_put_metabuf(), that is not correct. Fix it. > > Fixes: ab92184ff8f1 ("add on-disk compressed tail-packing inline support") > Fixes: b15b2e307c3a ("support on-disk compressed fragments data") > Signed-off-by: Yue Hu > --- > fs/erofs/zmap.c | 15 +++++++-------- > 1 file changed, 7 insertions(+), 8 deletions(-) > erofs: fix invalid unmapped accesses in z_erofs_fill_inode_lazy() > diff --git a/fs/erofs/zmap.c b/fs/erofs/zmap.c > index 44c27ef39c43..1a15bbf18ba3 100644 > --- a/fs/erofs/zmap.c > +++ b/fs/erofs/zmap.c > @@ -58,7 +58,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) > pos = ALIGN(iloc(EROFS_SB(sb), vi->nid) + vi->inode_isize + > vi->xattr_isize, 8); > kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), > - EROFS_KMAP_ATOMIC); > + EROFS_KMAP); kaddr = erofs_read_metabuf(&buf, sb, erofs_blknr(pos), EROFS_KMAP); ? Also I will use kmap_local later to replace kmap and kmap_atomic if possible. > if (IS_ERR(kaddr)) { > err = PTR_ERR(kaddr); > goto out_unlock; > @@ -73,7 +73,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) > vi->z_advise = Z_EROFS_ADVISE_FRAGMENT_PCLUSTER; > vi->z_fragmentoff = le64_to_cpu(*(__le64 *)h) ^ (1ULL << 63); > vi->z_tailextent_headlcn = 0; > - goto unmap_done; > + goto init_done; > } > vi->z_advise = le16_to_cpu(h->h_advise); > vi->z_algorithmtype[0] = h->h_algorithmtype & 15; > @@ -105,10 +105,6 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) > err = -EFSCORRUPTED; > goto unmap_done; > } > -unmap_done: > - erofs_put_metabuf(&buf); > - if (err) > - goto out_unlock; > > if (vi->z_advise & Z_EROFS_ADVISE_INLINE_PCLUSTER) { > struct erofs_map_blocks map = { > @@ -127,7 +123,7 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) > err = -EFSCORRUPTED; > } > if (err < 0) > - goto out_unlock; > + goto unmap_done; > } > > if (vi->z_advise & Z_EROFS_ADVISE_FRAGMENT_PCLUSTER && > @@ -141,11 +137,14 @@ static int z_erofs_fill_inode_lazy(struct inode *inode) > EROFS_GET_BLOCKS_FINDTAIL); > erofs_put_metabuf(&map.buf); > if (err < 0) > - goto out_unlock; > + goto unmap_done; > } > +init_done: done: > /* paired with smp_mb() at the beginning of the function */ > smp_mb(); > set_bit(EROFS_I_Z_INITED_BIT, &vi->flags); > +unmap_done: out_put_metabuf: Thanks, Gao Xiang > + erofs_put_metabuf(&buf); > out_unlock: > clear_and_wake_up_bit(EROFS_I_BL_Z_BIT, &vi->flags); > return err; > -- > 2.25.1 >