From nobody Tue Apr 7 05:10:21 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6F93AC433FE for ; Tue, 11 Oct 2022 03:26:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229953AbiJKD0N (ORCPT ); Mon, 10 Oct 2022 23:26:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52788 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229896AbiJKDZx (ORCPT ); Mon, 10 Oct 2022 23:25:53 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1B1FC7F0A9 for ; Mon, 10 Oct 2022 20:25:49 -0700 (PDT) Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Mmgyz445TzHtw7; Tue, 11 Oct 2022 11:20:43 +0800 (CST) Received: from kwepemm600013.china.huawei.com (7.193.23.68) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 11 Oct 2022 11:25:26 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600013.china.huawei.com (7.193.23.68) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Tue, 11 Oct 2022 11:25:25 +0800 From: Zhihao Cheng To: , , CC: , , , Subject: [PATCH 5/6] ubifs: do_rename: Fix wrong space budget when target inode's nlink > 1 Date: Tue, 11 Oct 2022 11:47:31 +0800 Message-ID: <20221011034732.45605-6-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20221011034732.45605-1-chengzhihao1@huawei.com> References: <20221011034732.45605-1-chengzhihao1@huawei.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To kwepemm600013.china.huawei.com (7.193.23.68) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" If target inode is a special file (eg. block/char device) with nlink count greater than 1, the inode with ui->data will be re-written on disk. However, UBIFS losts target inode's data_len while doing space budget. Bad space budget may let make_reservation() return with -ENOSPC, which could turn ubifs to read-only mode in do_writepage() process. Fetch a reproducer in [Link]. Link: https://bugzilla.kernel.org/show_bug.cgi?id=3D216494 Fixes: 1e51764a3c2ac0 ("UBIFS: add new flash file system") Signed-off-by: Zhihao Cheng --- fs/ubifs/dir.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 53c5442f48b7..a77e859246c3 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -1323,6 +1323,8 @@ static int do_rename(struct inode *old_dir, struct de= ntry *old_dentry, if (unlink) { ubifs_assert(c, inode_is_locked(new_inode)); =20 + /* Budget for old inode's data when its nlink > 1. */ + req.dirtied_ino_d =3D ALIGN(ubifs_inode(new_inode)->data_len, 8); err =3D ubifs_purge_xattrs(new_inode); if (err) return err; --=20 2.31.1