Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp680806imu; Sat, 15 Dec 2018 05:18:29 -0800 (PST) X-Google-Smtp-Source: AFSGD/X2FkxSbVk2iRYLWH7YS248e8kzP7Y9SoyVH03K9uKh9UYBb7TKJB6WYaWoQSXx1WR9hoaE X-Received: by 2002:a65:590b:: with SMTP id f11mr6139279pgu.60.1544879909506; Sat, 15 Dec 2018 05:18:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544879909; cv=none; d=google.com; s=arc-20160816; b=GpR2epOluw5kfhT0M3xngTcemTBU9ojhqVJ/tT5a68nyXWf06ksnRkoaTh5gR84rj6 yOVjEa3S/iAfcu0yk5vTnzZKsjSq6UaGKXIsg28V1V/0mX2LVRitVHHOby4yQtfENPXQ iJIjR0Le9HjayExyQyrnjCWsiznMoxPdLmet52suwmS7RTtQK+3V9NagGhqHyzyuhIuH ndaDSq7nsiDyAdJyHyteYgP+b8IhruF8KSRppNwQUo420NN1ORp3rau7m9UQjvxsreiu 2Mg9WOAE9QtC5mPtqk77LLg0Ws5is1mob5kZhlEmQ21Cffhs8jwAcveoM/p6HnPHv+Sc q/ww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=/MD97g9PNAV4neXgGiTOd3X0HwEpF2SiD7wLdTaDCbs=; b=CjqZfznxlGa4DblIWiA+ZGzN0A8w25xVNy+iNXWwCvpGezct3Bqea3cfralhV5CvJs Ar+uC5JD3CuGF+1imRVFy3TEj8fAnhfjknEsA4R8yz2Sa4CaAp09hqWnbqxdaRLOmTpd ef0laMEiMQgll7jrFiFHax5dHmkdjDDZxCcyjL2RK9v+r12xPkKNJVNq1O51FLJclp6Y AlgPGABmGcxkr/oaJk1IArnN3ipBKNQmst/lNn1dlIRfakq3syU1klYkYo+0EVMNquqd O921niy5bT96xooFXPnLs+/Lw8B56R8Q4LWYiuf73BkhTXechFIdJUoBCQuYFjCdV9NR 9Tfg== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id w12si6154143ply.404.2018.12.15.05.18.12; Sat, 15 Dec 2018 05:18:29 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730119AbeLONRS (ORCPT + 99 others); Sat, 15 Dec 2018 08:17:18 -0500 Received: from szxga06-in.huawei.com ([45.249.212.32]:42201 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1729192AbeLONRS (ORCPT ); Sat, 15 Dec 2018 08:17:18 -0500 Received: from DGGEMS402-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 77A7A3D63F380; Sat, 15 Dec 2018 21:17:15 +0800 (CST) Received: from [127.0.0.1] (10.177.31.14) by DGGEMS402-HUB.china.huawei.com (10.3.19.202) with Microsoft SMTP Server id 14.3.408.0; Sat, 15 Dec 2018 21:17:11 +0800 Subject: Re: [PATCH] jffs2: fix invocations of dbg_xattr() for dead jffs2_xattr_ref To: Richard Weinberger , CC: , David Woodhouse , LKML References: <20181020110753.98407-1-houtao1@huawei.com> <20181209075256.43ca759f@bbrezillon> From: Hou Tao Message-ID: <39d00539-7845-4f1e-d95c-d6f14cde3905@huawei.com> Date: Sat, 15 Dec 2018 21:17:09 +0800 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset="utf-8" Content-Language: en-US Content-Transfer-Encoding: 7bit X-Originating-IP: [10.177.31.14] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2018/12/14 5:53, Richard Weinberger wrote: > On Sun, Dec 9, 2018 at 7:52 AM Boris Brezillon > wrote: >> >> On Sat, 20 Oct 2018 19:07:53 +0800 >> Hou Tao wrote: >> >>> When jffs2_xattr_ref is dead, xref->ic or xref->xd will be invalid >>> because these fields will be reused as xref->ino or xref->xid, >>> so access xref->ic->ino or xref->xd->xid will lead to Oops. >>> >>> Fix the problem by checking whether or not it is a dead xref. >>> >>> Signed-off-by: Hou Tao >>> --- >>> fs/jffs2/xattr.c | 9 +++++++-- >>> 1 file changed, 7 insertions(+), 2 deletions(-) >>> >>> diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c >>> index 3d40fe02b003..0c4c7891556d 100644 >>> --- a/fs/jffs2/xattr.c >>> +++ b/fs/jffs2/xattr.c >>> @@ -550,7 +550,8 @@ static int save_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) >>> ref->xseqno = xseqno; >>> jffs2_add_physical_node_ref(c, phys_ofs | REF_PRISTINE, PAD(sizeof(rr)), (void *)ref); >>> >>> - dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", ref->ic->ino, ref->xd->xid); >>> + dbg_xattr("success on saving xref (ino=%u, xid=%u)\n", >>> + je32_to_cpu(rr.ino), je32_to_cpu(rr.xid)); >> >> Nit: align the second line on the open parens (same applies to the >> other chunk). Thanks for pointing it out, I will fix them. >> Sorry, I can't comment on the actual change. I'll let Richard look >> at it. >> >>> >>> return 0; >>> } >>> @@ -1329,7 +1330,11 @@ int jffs2_garbage_collect_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ >>> rc = save_xattr_ref(c, ref); >>> if (!rc) >>> dbg_xattr("xref (ino=%u, xid=%u) GC'ed from %#08x to %08x\n", >>> - ref->ic->ino, ref->xd->xid, old_ofs, ref_offset(ref->node)); >>> + is_xattr_ref_dead(ref) ? >>> + ref->ino : ref->ic->ino, >>> + is_xattr_ref_dead(ref) ? >>> + ref->xid : ref->xd->xid, >>> + old_ofs, ref_offset(ref->node)); >>> out: >>> if (!rc) >>> jffs2_mark_node_obsolete(c, raw); >> > > Since is_xattr_ref_dead() is cheap, can you please add two macros. > Something like: > static inline uint32_t xattr_ref_ino(struct jffs2_xattr_ref *ref) { > if (is_xattr_ref_dead(ref)) > return ref>ino; > else > return ref->ic->ino; > } > > Same for xid. > Yes, there would be better, will do that. Thanks, Tao