From patchwork Wed Sep 21 21:57:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pascal Eberhard X-Patchwork-Id: 673061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2001:1868:205::9]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sfYWv0kCBz9sCp for ; Thu, 22 Sep 2016 08:02:35 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b=tsGSot5N; dkim-atps=neutral Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bmpZF-0000tY-Fg; Wed, 21 Sep 2016 22:00:37 +0000 Received: from mail-wm0-x241.google.com ([2a00:1450:400c:c09::241]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bmpZC-0008Rt-31 for linux-mtd@lists.infradead.org; Wed, 21 Sep 2016 22:00:35 +0000 Received: by mail-wm0-x241.google.com with SMTP id w84so10893122wmg.0 for ; Wed, 21 Sep 2016 15:00:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=E3Gau849uqpp99NOn4oMKxBeVyA887I6l2A9Hbt/UGU=; b=tsGSot5NOhviCHynJ76AaupPV95gMcUtN9T0yZB/nmb00eYIi1V/y1jwka7PH+bIwX h1/Er50WQNXSWrtT2gWFJpgqDHjrzfhshLTTguTgYWeoUC+kxpUqoDt0bwxtWLKGLwTB n53/wh2PO9c8Mr/zc9eG5maEgVy+0Ij8WEJOhR4c2UqOFvp9OC5W89NpDvmsXDKYXQ/k XPXqC2CJO9ep/HKVp31tAsvVkMhCu2B35cm36D01BfX9lTQhdZFEsrht20UlVd4hB45r SRK5g3i2I+cBWsTVqqX+ZyuXTTjQHFTWPW/XgHsbMQ+InrlnUwwMawhirmmE8MznPP2b tdcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=E3Gau849uqpp99NOn4oMKxBeVyA887I6l2A9Hbt/UGU=; b=BWfK03/Af2R5beAbWbUg+NyhIlTN5ZQdZt/sYFx5PD8XqNOeJRejCOLLrtsUuhrwWf 9xtaA08PdjTVnAud3LlH3Yf4adMKhZzRZ4dzOKGu+JBTyP5y+AMnHN72swFVRTUgPvd9 p1Gks2F+2wWQgJXfP/rNR31V0UlwpMNv3vDx7btnhR5rmCabtM/HGgw81sq+R9mnlQw1 5riRL/rgnAqLR85NyLgPOuM3Gi1W5iJHkH+u1DSCeotalP2RDONI1w0KL/ZwJ8Mn8ufT Hm3qnlgnFmS4VFL0jcVECAkOhkhVmYaHFqZKveS0q7a7v6qHH03jTTcZWIfKZF+Xb7UP RS0w== X-Gm-Message-State: AE9vXwPt7Z2nBMxSVUUtmD1O9XYMpDfVDqRGFCFss3rNbHsbpgIApgUq60L5F/V9fnRvGA== X-Received: by 10.28.2.85 with SMTP id 82mr4859142wmc.23.1474495211883; Wed, 21 Sep 2016 15:00:11 -0700 (PDT) Received: from localhost.localdomain (85-171-152-29.rev.numericable.fr. [85.171.152.29]) by smtp.gmail.com with ESMTPSA id 193sm34503804wmo.14.2016.09.21.15.00.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 21 Sep 2016 15:00:09 -0700 (PDT) From: Pascal Eberhard To: richard@nod.at Subject: [PATCH] ubifs: fix host xattr_len when changing xattr Date: Wed, 21 Sep 2016 23:57:30 +0200 Message-Id: <1474495050-13529-1-git-send-email-pascal.eberhard@gmail.com> X-Mailer: git-send-email 2.7.4 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160921_150034_371699_B8FBFAAC X-CRM114-Status: GOOD ( 12.14 ) X-Spam-Score: -2.7 (--) X-Spam-Report: SpamAssassin version 3.4.0 on bombadil.infradead.org summary: Content analysis details: (-2.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.7 RCVD_IN_DNSWL_LOW RBL: Sender listed at http://www.dnswl.org/, low trust [2a00:1450:400c:c09:0:0:0:241 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (pascal.eberhard[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Pascal Eberhard , linux-mtd@lists.infradead.org MIME-Version: 1.0 Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org When an extended attribute is changed, xattr_len of host inode is recalculated. ui->data_len is updated before computation and result is wrong. This patch adds a temporary variable to fix computation. To reproduce the issue: ~# > a.txt ~# attr -s an-attr -V a-value a.txt ~# attr -s an-attr -V a-bit-bigger-value a.txt Now host inode xattr_len is wrong. Forcing dbg_check_filesystem() generates the following error: [ 130.620140] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" started, PID 565 [ 131.470790] UBIFS error (ubi0:2 pid 564): check_inodes: inode 646 has xattr size 240, but calculated size is 256 [ 131.481697] UBIFS (ubi0:2): dump of the inode 646 sitting in LEB 29:114688 [ 131.488953] magic 0x6101831 [ 131.492876] crc 0x9fce9091 [ 131.496836] node_type 0 (inode node) [ 131.501193] group_type 1 (in node group) [ 131.505788] sqnum 9278 [ 131.509191] len 160 [ 131.512549] key (646, inode) [ 131.516688] creat_sqnum 9270 [ 131.520133] size 0 [ 131.523264] nlink 1 [ 131.526398] atime 1053025857.0 [ 131.530574] mtime 1053025857.0 [ 131.534714] ctime 1053025906.0 [ 131.538849] uid 0 [ 131.542009] gid 0 [ 131.545140] mode 33188 [ 131.548636] flags 0x1 [ 131.551977] xattr_cnt 1 [ 131.555108] xattr_size 240 [ 131.558420] xattr_names 12 [ 131.561670] compr_type 0x1 [ 131.564983] data len 0 [ 131.568125] UBIFS error (ubi0:2 pid 564): dbg_check_filesystem: file-system check failed with error -22 [ 131.578074] CPU: 0 PID: 564 Comm: mount Not tainted 4.4.12-g3639bea54a #24 [ 131.585352] Hardware name: Generic AM33XX (Flattened Device Tree) [ 131.591918] [] (unwind_backtrace) from [] (show_stack+0x10/0x14) [ 131.600177] [] (show_stack) from [] (dbg_check_filesystem+0x464/0x4d0) [ 131.608934] [] (dbg_check_filesystem) from [] (ubifs_mount+0x14f8/0x2130) [ 131.617991] [] (ubifs_mount) from [] (mount_fs+0x14/0x98) [ 131.625572] [] (mount_fs) from [] (vfs_kern_mount+0x4c/0xd4) [ 131.633435] [] (vfs_kern_mount) from [] (do_mount+0x988/0xb50) [ 131.641471] [] (do_mount) from [] (SyS_mount+0x74/0xa0) [ 131.648837] [] (SyS_mount) from [] (ret_fast_syscall+0x0/0x3c) [ 131.665315] UBIFS (ubi0:2): background thread "ubifs_bgt0_2" stops Signed-off-by: Pascal Eberhard --- fs/ubifs/xattr.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fs/ubifs/xattr.c b/fs/ubifs/xattr.c index 11a0041..6c2f4d4 100644 --- a/fs/ubifs/xattr.c +++ b/fs/ubifs/xattr.c @@ -200,6 +200,7 @@ static int change_xattr(struct ubifs_info *c, struct inode *host, struct ubifs_inode *host_ui = ubifs_inode(host); struct ubifs_inode *ui = ubifs_inode(inode); void *buf = NULL; + int old_size; struct ubifs_budget_req req = { .dirtied_ino = 2, .dirtied_ino_d = ALIGN(size, 8) + ALIGN(host_ui->data_len, 8) }; @@ -217,12 +218,13 @@ static int change_xattr(struct ubifs_info *c, struct inode *host, kfree(ui->data); ui->data = buf; inode->i_size = ui->ui_size = size; + old_size = ui->data_len; ui->data_len = size; mutex_unlock(&ui->ui_mutex); mutex_lock(&host_ui->ui_mutex); host->i_ctime = ubifs_current_time(host); - host_ui->xattr_size -= CALC_XATTR_BYTES(ui->data_len); + host_ui->xattr_size -= CALC_XATTR_BYTES(old_size); host_ui->xattr_size += CALC_XATTR_BYTES(size); /* @@ -241,7 +243,7 @@ static int change_xattr(struct ubifs_info *c, struct inode *host, out_cancel: host_ui->xattr_size -= CALC_XATTR_BYTES(size); - host_ui->xattr_size += CALC_XATTR_BYTES(ui->data_len); + host_ui->xattr_size += CALC_XATTR_BYTES(old_size); mutex_unlock(&host_ui->ui_mutex); make_bad_inode(inode); out_free: