From nobody Fri Feb 13 14:11:33 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 70408CE7A88 for ; Sat, 23 Sep 2023 03:37:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230027AbjIWDfJ (ORCPT ); Fri, 22 Sep 2023 23:35:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44046 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229592AbjIWDfH (ORCPT ); Fri, 22 Sep 2023 23:35:07 -0400 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1A42A9 for ; Fri, 22 Sep 2023 20:34:59 -0700 (PDT) Received: from kwepemm000013.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4RsvmH6jzlztSZt; Sat, 23 Sep 2023 11:30:39 +0800 (CST) Received: from huawei.com (10.175.104.67) by kwepemm000013.china.huawei.com (7.193.23.81) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.31; Sat, 23 Sep 2023 11:34:56 +0800 From: Zhihao Cheng To: , , CC: , , Subject: [PATCH] ubifs: ubifs_link: Fix wrong name len calculating when UBIFS is encrypted Date: Sat, 23 Sep 2023 11:28:59 +0800 Message-ID: <20230923032859.3857274-1-chengzhihao1@huawei.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Originating-IP: [10.175.104.67] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To kwepemm000013.china.huawei.com (7.193.23.81) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The length of dentry name is calculated after the raw name is encrypted, except for ubifs_link(), which could make the size of dir underflow. Here is a reproducer: touch $TMP/file mkdir $TMP/dir stat $TMP/dir for i in $(seq 1 8) do ln $TMP/file $TMP/dir/$i unlink $TMP/dir/$i done stat $TMP/dir The size of dir will be underflow(-96). Fix it by calculating dentry name's length after the name is encrypted. Fixes: f4f61d2cc6d8 ("ubifs: Implement encrypted filenames") Reported-by: Roland Ruckerbauer Link: https://lore.kernel.org/linux-mtd/1638777819.2925845.1695222544742.Ja= vaMail.zimbra@robart.cc/T/#u Signed-off-by: Zhihao Cheng --- fs/ubifs/dir.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fs/ubifs/dir.c b/fs/ubifs/dir.c index 2f48c58d47cd..5dc1ac4d826d 100644 --- a/fs/ubifs/dir.c +++ b/fs/ubifs/dir.c @@ -724,7 +724,7 @@ static int ubifs_link(struct dentry *old_dentry, struct= inode *dir, struct inode *inode =3D d_inode(old_dentry); struct ubifs_inode *ui =3D ubifs_inode(inode); struct ubifs_inode *dir_ui =3D ubifs_inode(dir); - int err, sz_change =3D CALC_DENT_SIZE(dentry->d_name.len); + int err, sz_change; struct ubifs_budget_req req =3D { .new_dent =3D 1, .dirtied_ino =3D 2, .dirtied_ino_d =3D ALIGN(ui->data_len, 8) }; struct fscrypt_name nm; @@ -748,6 +748,8 @@ static int ubifs_link(struct dentry *old_dentry, struct= inode *dir, if (err) return err; =20 + sz_change =3D CALC_DENT_SIZE(fname_len(&nm)); + err =3D dbg_check_synced_i_size(c, inode); if (err) goto out_fname; --=20 2.39.2