Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp2339857imu; Sat, 8 Dec 2018 22:20:34 -0800 (PST) X-Google-Smtp-Source: AFSGD/WWpqaFFORXfn8KBYCL4QaGgS6m1M8Yx1Z8t5pZWoePGAASJBu8iOMDeuQA03lUjF9o/P+8 X-Received: by 2002:a63:6445:: with SMTP id y66mr7236429pgb.250.1544336434688; Sat, 08 Dec 2018 22:20:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544336434; cv=none; d=google.com; s=arc-20160816; b=RoDDQ2wrjaI/zS3p6ggvHh8ctQbZpXAueah87KJdMjwOXBCfero6xC/QX0RaosoxKA XhrdlXUB0yQ8AS2Y0gixa/4K2CI1OCBUyePFdsBNy/8AU5igH7VJivRgRhtBNYm48HH3 mzQ1DVI8VYYJrqMj1t5NFdKIg7c19G+t6n6t55ffg+RPQVyPfDZkkaS+HIbmiVbPNq0t 2ogVq7yGkU0yEujH2s4MInyyS7Fp4AJJU8YEnmcDhjSEfRjs72r61AmXFz76qjlfoWeA uwmJxA9RpTbOsbc/sw352Yj813ogJtJ3GK5S5NcvpCm6QF4pXNu8H/hg55m6BNRIT/af 2RbQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:message-id:date:subject:cc :to:from; bh=pRUN1rupj8rgbMD9fodTwFicK4npXIBqPpbP6u7rBxg=; b=YB09KRqzcxrq+yeKie4Ms0FWlvnffE6Bu4BE7URmTH3vE6uIBmmdx0dpYmgf67//0t 1WkCMpKqiZK/5LVRNAPaOjTU/Q4XoHavBxtPkionzMrRh7Q/Fd600Z95tQo8L4Or3TjC dKskNDMvlQozRbNsnlK+MGEpM3iphZpDR/+ZwarU8V8uecDfeySHcOFbpsyC0V92EQDP +jVBAeL1PBf/AowzhKyJccToB9cuhWyc5zyapDEUpQ2Dvp+Or9oxrSKx7xMJoaSmjbTS sJyJlHDrAKVJq/SpRLzzFOiWbciE6uRE5xL1nO3QsFZCsU7CHJGVApdiL5O6COgZzpX/ oxdQ== 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 3si7384910plo.102.2018.12.08.22.20.19; Sat, 08 Dec 2018 22:20:34 -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 S1726157AbeLIGS3 (ORCPT + 99 others); Sun, 9 Dec 2018 01:18:29 -0500 Received: from szxga05-in.huawei.com ([45.249.212.191]:15665 "EHLO huawei.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726066AbeLIGS3 (ORCPT ); Sun, 9 Dec 2018 01:18:29 -0500 Received: from DGGEMS413-HUB.china.huawei.com (unknown [172.30.72.60]) by Forcepoint Email with ESMTP id 55313EA0C9F0B; Sun, 9 Dec 2018 14:18:25 +0800 (CST) Received: from huawei.com (10.90.53.225) by DGGEMS413-HUB.china.huawei.com (10.3.19.213) with Microsoft SMTP Server id 14.3.408.0; Sun, 9 Dec 2018 14:18:24 +0800 From: Hou Tao To: , CC: , , Subject: [PATCH] jffs2: make the overwritten xattr invisible after remount Date: Sun, 9 Dec 2018 14:21:33 +0800 Message-ID: <20181209062133.106781-1-houtao1@huawei.com> X-Mailer: git-send-email 2.16.2.dirty MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.90.53.225] X-CFilter-Loop: Reflected Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org For xattr modification, we do not write a new jffs2_raw_xref with delete marker into flash, so if a xattr is modified then removed, and the old xref & xdatum are not erased by GC, after reboot or remount, the new xattr xref will be dead but the old xattr xref will be alive, and we will get the overwritten xattr instead of non-existent error when reading the removed xattr. Fix it by writing the deletion mark for xattr overwrite. Fixes: 8a13695cbe4e ("[JFFS2][XATTR] rid unnecessary writing of delete marker.") Signed-off-by: Hou Tao --- fs/jffs2/xattr.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 49 insertions(+), 6 deletions(-) diff --git a/fs/jffs2/xattr.c b/fs/jffs2/xattr.c index da3e18503c65..b2d6072f34af 100644 --- a/fs/jffs2/xattr.c +++ b/fs/jffs2/xattr.c @@ -573,6 +573,15 @@ static struct jffs2_xattr_ref *create_xattr_ref(struct jffs2_sb_info *c, struct return ref; /* success */ } +static void move_xattr_ref_to_dead_list(struct jffs2_sb_info *c, + struct jffs2_xattr_ref *ref) +{ + spin_lock(&c->erase_completion_lock); + ref->next = c->xref_dead_list; + c->xref_dead_list = ref; + spin_unlock(&c->erase_completion_lock); +} + static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *ref) { /* must be called under down_write(xattr_sem) */ @@ -582,10 +591,7 @@ static void delete_xattr_ref(struct jffs2_sb_info *c, struct jffs2_xattr_ref *re ref->xseqno |= XREF_DELETE_MARKER; ref->ino = ref->ic->ino; ref->xid = ref->xd->xid; - spin_lock(&c->erase_completion_lock); - ref->next = c->xref_dead_list; - c->xref_dead_list = ref; - spin_unlock(&c->erase_completion_lock); + move_xattr_ref_to_dead_list(c, ref); dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n", ref->ino, ref->xid, ref->xseqno); @@ -1090,6 +1096,40 @@ int do_jffs2_getxattr(struct inode *inode, int xprefix, const char *xname, return rc; } +static void do_jffs2_delete_xattr_ref(struct jffs2_sb_info *c, + struct jffs2_xattr_ref *ref) +{ + uint32_t request, length; + int err; + struct jffs2_xattr_datum *xd; + + request = PAD(sizeof(struct jffs2_raw_xref)); + err = jffs2_reserve_space(c, request, &length, + ALLOC_NORMAL, JFFS2_SUMMARY_XREF_SIZE); + down_write(&c->xattr_sem); + if (err) { + JFFS2_WARNING("jffs2_reserve_space()=%d, request=%u\n", + err, request); + delete_xattr_ref(c, ref); + up_write(&c->xattr_sem); + return; + } + + xd = ref->xd; + ref->ino = ref->ic->ino; + ref->xid = xd->xid; + ref->xseqno |= XREF_DELETE_MARKER; + save_xattr_ref(c, ref); + + move_xattr_ref_to_dead_list(c, ref); + dbg_xattr("xref(ino=%u, xid=%u, xseqno=%u) was removed.\n", + ref->ino, ref->xid, ref->xseqno); + unrefer_xattr_datum(c, xd); + + up_write(&c->xattr_sem); + jffs2_complete_reservation(c); +} + int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, const char *buffer, size_t size, int flags) { @@ -1097,7 +1137,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, struct jffs2_sb_info *c = JFFS2_SB_INFO(inode->i_sb); struct jffs2_inode_cache *ic = f->inocache; struct jffs2_xattr_datum *xd; - struct jffs2_xattr_ref *ref, *newref, **pref; + struct jffs2_xattr_ref *ref, *newref, *oldref, **pref; uint32_t length, request; int rc; @@ -1113,6 +1153,7 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, return rc; } + oldref = NULL; /* Find existing xattr */ down_write(&c->xattr_sem); retry: @@ -1196,11 +1237,13 @@ int do_jffs2_setxattr(struct inode *inode, int xprefix, const char *xname, rc = PTR_ERR(newref); unrefer_xattr_datum(c, xd); } else if (ref) { - delete_xattr_ref(c, ref); + oldref = ref; } out: up_write(&c->xattr_sem); jffs2_complete_reservation(c); + if (oldref) + do_jffs2_delete_xattr_ref(c, oldref); return rc; } -- 2.16.2.dirty