From patchwork Fri Jan 22 21:22:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Weinberger X-Patchwork-Id: 1430569 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.infradead.org; envelope-from=linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=OigI/w7D; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4DMsgq2h8pz9sCD for ; Sat, 23 Jan 2021 08:23:35 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To:Message-Id:Date: Subject:To:From:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=YSXvrWWD8/efNrDpVF07oyhMYM+8WS/AGWmia+1P+U4=; b=OigI/w7D/Ac+J/XsYNiLFmnb6 FsI0rcAVeddPvNIlUHtbYP/yOneJG52FjXG4b6sBiMhgqo1rnX/+pgowXUu8SMw/7Il4mCXx1gcHa m8xPpoQl6qAyQJkWGVSuvkA+kPXhQPvF8hnCECMGu6dQO72KDae/gOwPk3c1vFKekRkX+aps3QOsk xzyLugN4t3Cc6v7CX9RukLppri7kxYK38LIWLzbcVLEJwSRJUgjyJVLzdqCxvDyvpQgBHxJozP7Ey DZNr4NXO6SLEzkH2Ti4U+b0nG4fXksKnAcM9SWnc5moGyq4YeRHJ/bjoT1B0Ge1WJCKHy0MZRJglS pQ+NdRrZw==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1l33tL-0002ET-BS; Fri, 22 Jan 2021 21:22:51 +0000 Received: from lilium.sigma-star.at ([109.75.188.150]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1l33t9-0002Bw-Jv for linux-mtd@lists.infradead.org; Fri, 22 Jan 2021 21:22:42 +0000 Received: from localhost (localhost [127.0.0.1]) by lilium.sigma-star.at (Postfix) with ESMTP id 2197D181CBE08; Fri, 22 Jan 2021 22:22:36 +0100 (CET) Received: from lilium.sigma-star.at ([127.0.0.1]) by localhost (lilium.sigma-star.at [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id 8QZnjaY9GVmZ; Fri, 22 Jan 2021 22:22:35 +0100 (CET) Received: from lilium.sigma-star.at ([127.0.0.1]) by localhost (lilium.sigma-star.at [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id 5sE-lpCPrN4m; Fri, 22 Jan 2021 22:22:35 +0100 (CET) From: Richard Weinberger To: linux-mtd@lists.infradead.org Subject: [PATCH 4/4] ubifs: Harden ubifs_jnl_write_inode() Date: Fri, 22 Jan 2021 22:22:29 +0100 Message-Id: <20210122212229.17072-5-richard@nod.at> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20210122212229.17072-1-richard@nod.at> References: <20210122212229.17072-1-richard@nod.at> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210122_162240_104725_DE499C2E X-CRM114-Status: UNSURE ( 9.23 ) X-CRM114-Notice: Please train this message. X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 T_SPF_PERMERROR SPF: test of record failed (permerror) X-BeenThere: linux-mtd@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux MTD discussion mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: richard@nod.at, david@sigma-star.at, linux-kernel@vger.kernel.org Sender: "linux-mtd" Errors-To: linux-mtd-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Make sure that ubifs_jnl_write_inode() cannot be abused and will not write less data then expected. Signed-off-by: Richard Weinberger --- fs/ubifs/journal.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fs/ubifs/journal.c b/fs/ubifs/journal.c index 03410ae0813a..1b28fcc5b9fe 100644 --- a/fs/ubifs/journal.c +++ b/fs/ubifs/journal.c @@ -844,10 +844,12 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode) struct ubifs_ino_node *ino, *ino_start; struct ubifs_inode *ui = ubifs_inode(inode); int sync = 0, write_len = 0, ilen = UBIFS_INO_NODE_SZ; - int last_reference = !inode->i_nlink; + int last_reference = !inode->i_nlink, xattr_inos_written = 0; int kill_xattrs = ui->xattr_cnt && last_reference; u8 hash[UBIFS_HASH_ARR_SZ]; + ubifs_assert(c, !ui->xattr); + dbg_jnl("ino %lu, nlink %u", inode->i_ino, inode->i_nlink); /* @@ -917,12 +919,14 @@ int ubifs_jnl_write_inode(struct ubifs_info *c, const struct inode *inode) pack_inode(c, ino, xino, 0); ino = (void *)ino + UBIFS_INO_NODE_SZ; iput(xino); + xattr_inos_written++; kfree(pxent); pxent = xent; key_read(c, &xent->key, &key); } kfree(pxent); + ubifs_assert(c, xattr_inos_written == ui->xattr_cnt); } pack_inode(c, ino, inode, 1);