From nobody Sat Jul 25 20:08:04 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE2B143FD0C; Tue, 14 Jul 2026 09:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784021291; cv=none; b=YTsSBgM1Jq8E7hzhH0wReKd2MbZ+YxeyJ5ZpaGGglwwGG2lJFm66BpzjI5AhoOK1k6WJDDbOtjjHQzyYo7yLnkcFmrZmgdXkt+YWKOy424e8JvP8anRhxhCe95b/WV8u+uxeI4UTBQN411+O9lEihsKEa4wwbTvFlKXVzAsclLk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784021291; c=relaxed/simple; bh=NSokBI3S+ONfPvAoH6wiWvPTcZiyO9AHpZZUkQgRD1U=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=l3Eyd7ffsyNcjW6nQfcFM988nsY84ymSuDhQRXgd//eI3QU+w/KnGIV4CUdXTCGEy9vhIhUZ2RZ893lbxYrQ75HEHaob9qHhn3rcbFsUenfhMTaNdgiwb/ojRX+eICSB/kkVh6JRYnVUnmYF6f3sdS35u9Y9tSD2rNQrKrd0jHM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 4c5575f67f6611f1aa26b74ffac11d73-20260714 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:c1501126-c86e-46ce-a2ec-9dc0cb9c2e51,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:e7bac3a,CLOUDID:e10fd2eda2430bbde43c6af0185876e8,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|136|865|898,TC:nil,Content:0|1 5|50,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI :0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 4c5575f67f6611f1aa26b74ffac11d73-20260714 X-User: liuxixin@kylinos.cn Received: from [127.0.1.1] [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 999012092; Tue, 14 Jul 2026 17:27:56 +0800 From: Xixin Liu To: linux-fsdevel@vger.kernel.org Cc: dsterba@suse.com, brauner@kernel.org, jack@suse.cz, jlayton@kernel.org, chentaotao@didiglobal.com, chuck.lever@oracle.com, dlemoal@kernel.org, liuxixin@kylinos.cn, linux-kernel@vger.kernel.org Subject: [PATCH v1 1/3] affs: fix i_size on failed OFS hole extension Date: Tue, 14 Jul 2026 17:05:29 +0800 Message-ID: <220864429a522fceb39827cddd019f15aca40227.1784019929.git.kylinos.cn> In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: affs/send-local.py Content-Type: text/plain; charset="utf-8" affs_extent_file_ofs() grows OFS mmu_private during write_begin. On allocation failure the error path still set i_size and mmu_private to newsize, so a partially extended hole left a too-large i_size. Set both to the bytes actually extended, and release the previous data block held across the failed getzeroblk_ino(). Signed-off-by: Xixin Liu --- fs/affs/file.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fs/affs/file.c b/fs/affs/file.c index 144b17482d12..3265b6b6bf9f 100644 --- a/fs/affs/file.c +++ b/fs/affs/file.c @@ -569,6 +569,7 @@ affs_extent_file_ofs(struct inode *inode, u32 newsize) pr_debug("%s(%llu, %d)\n", __func__, inode->i_ino, newsize); bsize =3D AFFS_SB(sb)->s_data_blksize; bh =3D NULL; + prev_bh =3D NULL; size =3D AFFS_I(inode)->mmu_private; bidx =3D size / bsize; boff =3D size % bsize; @@ -625,7 +626,9 @@ affs_extent_file_ofs(struct inode *inode, u32 newsize) return 0; =20 out: - inode->i_size =3D AFFS_I(inode)->mmu_private =3D newsize; + affs_brelse(prev_bh); + /* Keep i_size/mmu_private at how far we actually extended. */ + inode->i_size =3D AFFS_I(inode)->mmu_private =3D size; return PTR_ERR(bh); } =20 @@ -662,9 +665,6 @@ static int affs_write_begin_ofs(const struct kiocb *ioc= b, pr_debug("%s(%llu, %llu, %llu)\n", __func__, inode->i_ino, pos, pos + len); if (pos > AFFS_I(inode)->mmu_private) { - /* XXX: this probably leaves a too-big i_size in case of - * failure. Should really be updating i_size at write_end time - */ err =3D affs_extent_file_ofs(inode, pos); if (err) return err; --=20 2.43.0 From nobody Sat Jul 25 20:08:04 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7D04643F8C0; Tue, 14 Jul 2026 09:28:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784021291; cv=none; b=CFl3NQcczCky6xpCCGNu489Au4KCjhaNAMVv5ZVfFu/ax9CiQs/izcVCVQYERt5k6EvvHGmqu9reVDx/LVKSeKa5jkdDQfxX5wLZLE7rjFMLFb9cWeIt96pNLnGQd4JFE0YFgskiMUjAgyVKBQHUuyiyYtbwJYAIvGnQON/a8+4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784021291; c=relaxed/simple; bh=NcalsM7VD/MSv6RK/0TuYEx3ifwFDTiAiM56DT//1zg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=iSOzO46fLMlNDrqJ6Wxgj+NuOJsTk0go5Of6CJXuz4tZyvEeS9k7rLurn1MhTmqr4Q7c1b0oWzlAnnMLyBTtI06ZPS2GvleX0eUdI4DGBi2cjr/UdfdBVelv4C9zFH0EyW9HDmDp/IXO3nHGlPAxeNPyx89SdgnWid8xon8HxzY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 4dabde7c7f6611f1aa26b74ffac11d73-20260714 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:a572ca22-b5e4-4d27-8195-7502f03a9446,IP:0,U RL:0,TC:0,Content:-5,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-5 X-CID-META: VersionHash:e7bac3a,CLOUDID:0aa5a7be02f0d9d6864f90a9eeb2d35c,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|136|865|898,TC:nil,Content:0|1 5|50,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI :0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 4dabde7c7f6611f1aa26b74ffac11d73-20260714 X-User: liuxixin@kylinos.cn Received: from [127.0.1.1] [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1375123903; Tue, 14 Jul 2026 17:27:59 +0800 From: Xixin Liu To: linux-fsdevel@vger.kernel.org Cc: dsterba@suse.com, brauner@kernel.org, jack@suse.cz, jlayton@kernel.org, chentaotao@didiglobal.com, chuck.lever@oracle.com, dlemoal@kernel.org, liuxixin@kylinos.cn, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/3] affs: check sb_getblk failure in getzeroblk/getemptyblk Date: Tue, 14 Jul 2026 17:05:29 +0800 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: affs/send-local.py Content-Type: text/plain; charset="utf-8" affs_getzeroblk() and affs_getemptyblk() pass sb_getblk() to lock_buffer()/wait_on_buffer() without a NULL check, so allocation failure crashes in the helpers before callers can handle it. Return NULL when sb_getblk() fails. Signed-off-by: Xixin Liu --- fs/affs/affs.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/fs/affs/affs.h b/fs/affs/affs.h index 44a3f69d275f..651d61b3213a 100644 --- a/fs/affs/affs.h +++ b/fs/affs/affs.h @@ -250,6 +250,8 @@ affs_getzeroblk(struct super_block *sb, int block) pr_debug("%s: %d\n", __func__, block); if (affs_validblock(sb, block)) { bh =3D sb_getblk(sb, block); + if (!bh) + return NULL; lock_buffer(bh); memset(bh->b_data, 0 , sb->s_blocksize); set_buffer_uptodate(bh); @@ -265,6 +267,8 @@ affs_getemptyblk(struct super_block *sb, int block) pr_debug("%s: %d\n", __func__, block); if (affs_validblock(sb, block)) { bh =3D sb_getblk(sb, block); + if (!bh) + return NULL; wait_on_buffer(bh); set_buffer_uptodate(bh); return bh; --=20 2.43.0 From nobody Sat Jul 25 20:08:04 2026 Received: from mailgw.kylinos.cn (mailgw.kylinos.cn [124.126.103.232]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id BB33E3EB0ED; Tue, 14 Jul 2026 09:28:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=124.126.103.232 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784021300; cv=none; b=p+FX3IOlBf1lmMeCI+hLzsnrR5XlaBfqsAzduUx52SHv37EXsFAWD5NGvufrXaBsUn13O04NUS6trs7YwA6AGC3EEGLUrw1Y+JoPcJ6oupRw9DY2HuiVOc05Fgj/A3EycKki1uVyqzJSAT16TUtBUok2zOsPGqyF2TERF0OUuDE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784021300; c=relaxed/simple; bh=U07ydkqMcRM6PYx/K+gMTO0DQy3bVKsl6MnHGw+TjAk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=YWTkMM4X0E4243g76q6DDPkcA8zfsKuOelPtdYWKLOoHKdJnq+9nLRELq4I8EDSmRYi09brDC2KL60ZxSv/5XPTURcDesaM+g+UnWPTfyHbHhpeVwfMzCRexkwBdnoVsiHVK7urHjufGflsWpwNy1H8hKudzw9MdwWwH9shy9yo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn; spf=pass smtp.mailfrom=kylinos.cn; arc=none smtp.client-ip=124.126.103.232 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=kylinos.cn Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=kylinos.cn X-UUID: 4f045fba7f6611f1aa26b74ffac11d73-20260714 X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.3.12,REQID:8736ac21-773c-49f6-9a8a-c1cd333a92d5,IP:0,U RL:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION: release,TS:0 X-CID-META: VersionHash:e7bac3a,CLOUDID:0da4ae78c7b721b123bd192d7981210a,BulkI D:nil,BulkQuantity:0,Recheck:0,SF:81|82|102|136|865|898,TC:nil,Content:0|1 5|50,EDM:-3,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI :0,OSA:0,AV:0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 2,SSN|SDN X-CID-BAS: 2,SSN|SDN,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-CID-RHF: D41D8CD98F00B204E9800998ECF8427E X-UUID: 4f045fba7f6611f1aa26b74ffac11d73-20260714 X-User: liuxixin@kylinos.cn Received: from [127.0.1.1] [(10.44.16.150)] by mailgw.kylinos.cn (envelope-from ) (Generic MTA with TLSv1.3 TLS_AES_256_GCM_SHA384 256/256) with ESMTP id 1263517067; Tue, 14 Jul 2026 17:28:01 +0800 From: Xixin Liu To: linux-fsdevel@vger.kernel.org Cc: dsterba@suse.com, brauner@kernel.org, jack@suse.cz, jlayton@kernel.org, chentaotao@didiglobal.com, chuck.lever@oracle.com, dlemoal@kernel.org, liuxixin@kylinos.cn, linux-kernel@vger.kernel.org Subject: [PATCH v1 3/3] affs: restore directory entry after failed rename insert Date: Tue, 14 Jul 2026 17:05:29 +0800 Message-ID: In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Mailer: affs/send-local.py Content-Type: text/plain; charset="utf-8" affs_rename() removes the object from the old directory hash before inserting it under the new name. If insert_hash() fails, the object keeps the new name but is linked in neither directory. On failure, restore the original name from old_dentry and re-insert into the old directory. Still return the insert error; warn if rollback fails. Apply the same best-effort rollback to affs_xrename(). Signed-off-by: Xixin Liu --- fs/affs/namei.c | 93 +++++++++++++++++++++++++++++++++++++------------ 1 file changed, 71 insertions(+), 22 deletions(-) diff --git a/fs/affs/namei.c b/fs/affs/namei.c index c3c6532da4b0..08edfdaeefc3 100644 --- a/fs/affs/namei.c +++ b/fs/affs/namei.c @@ -401,6 +401,38 @@ affs_link(struct dentry *old_dentry, struct inode *dir= , struct dentry *dentry) return affs_add_entry(dir, inode, dentry, ST_LINKFILE); } =20 +/* Write dentry name into header and insert into dir (success or rollback)= . */ +static int affs_reinsert_with_name(struct inode *dir, struct buffer_head *= bh, + struct dentry *dentry) +{ + struct super_block *sb =3D dir->i_sb; + int err; + + affs_copy_name(AFFS_TAIL(sb, bh)->name, dentry); + affs_fix_checksum(sb, bh); + affs_lock_dir(dir); + err =3D affs_insert_hash(dir, bh); + affs_unlock_dir(dir); + return err; +} + +/* Put both exchange objects back under their original names/dirs. */ +static void affs_xrename_restore(struct inode *old_dir, struct inode *new_= dir, + struct buffer_head *bh_old, + struct buffer_head *bh_new, + struct dentry *old_dentry, + struct dentry *new_dentry) +{ + if (affs_reinsert_with_name(old_dir, bh_old, old_dentry)) + affs_warning(old_dir->i_sb, "xrename", + "failed to restore inode %lu", + (unsigned long)bh_old->b_blocknr); + if (affs_reinsert_with_name(new_dir, bh_new, new_dentry)) + affs_warning(new_dir->i_sb, "xrename", + "failed to restore inode %lu", + (unsigned long)bh_new->b_blocknr); +} + static int affs_rename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) @@ -434,13 +466,15 @@ affs_rename(struct inode *old_dir, struct dentry *old= _dentry, if (retval) goto done; =20 - /* And insert it into the new directory with the new name. */ - affs_copy_name(AFFS_TAIL(sb, bh)->name, new_dentry); - affs_fix_checksum(sb, bh); - affs_lock_dir(new_dir); - retval =3D affs_insert_hash(new_dir, bh); - affs_unlock_dir(new_dir); - /* TODO: move it back to old_dir, if error? */ + /* Insert into the new directory with the new name. */ + retval =3D affs_reinsert_with_name(new_dir, bh, new_dentry); + if (retval) { + /* old_dentry still has the original name; put the object back. */ + if (affs_reinsert_with_name(old_dir, bh, old_dentry)) + affs_warning(sb, "rename", + "failed to restore inode %lu", + (unsigned long)bh->b_blocknr); + } =20 done: mmb_mark_buffer_dirty(bh, @@ -453,11 +487,10 @@ static int affs_xrename(struct inode *old_dir, struct dentry *old_dentry, struct inode *new_dir, struct dentry *new_dentry) { - struct super_block *sb =3D old_dir->i_sb; struct buffer_head *bh_old =3D NULL; struct buffer_head *bh_new =3D NULL; - int retval; + int retval, retval2; =20 bh_old =3D affs_bread(sb, d_inode(old_dentry)->i_ino); if (!bh_old) @@ -480,25 +513,41 @@ affs_xrename(struct inode *old_dir, struct dentry *ol= d_dentry, affs_lock_dir(new_dir); retval =3D affs_remove_hash(new_dir, bh_new); affs_unlock_dir(new_dir); - if (retval) + if (retval) { + /* Names unchanged; only put old back into old_dir. */ + if (affs_reinsert_with_name(old_dir, bh_old, old_dentry)) + affs_warning(sb, "xrename", + "failed to restore inode %lu", + (unsigned long)bh_old->b_blocknr); goto done; + } =20 /* Insert old into the new directory with the new name. */ - affs_copy_name(AFFS_TAIL(sb, bh_old)->name, new_dentry); - affs_fix_checksum(sb, bh_old); - affs_lock_dir(new_dir); - retval =3D affs_insert_hash(new_dir, bh_old); - affs_unlock_dir(new_dir); + retval =3D affs_reinsert_with_name(new_dir, bh_old, new_dentry); + if (retval) { + affs_xrename_restore(old_dir, new_dir, bh_old, bh_new, + old_dentry, new_dentry); + goto done; + } =20 /* Insert new into the old directory with the old name. */ - affs_copy_name(AFFS_TAIL(sb, bh_new)->name, old_dentry); - affs_fix_checksum(sb, bh_new); - affs_lock_dir(old_dir); - retval =3D affs_insert_hash(old_dir, bh_new); - affs_unlock_dir(old_dir); + retval =3D affs_reinsert_with_name(old_dir, bh_new, old_dentry); + if (retval) { + /* Undo the first insert, then restore both originals. */ + affs_lock_dir(new_dir); + retval2 =3D affs_remove_hash(new_dir, bh_old); + affs_unlock_dir(new_dir); + if (retval2) + affs_warning(sb, "xrename", + "undo insert of inode %lu failed (%d)", + (unsigned long)bh_old->b_blocknr, retval2); + affs_xrename_restore(old_dir, new_dir, bh_old, bh_new, + old_dentry, new_dentry); + } + done: - mmb_mark_buffer_dirty(bh_old, &AFFS_I(new_dir)->i_metadata_bhs); - mmb_mark_buffer_dirty(bh_new, &AFFS_I(old_dir)->i_metadata_bhs); + mmb_mark_buffer_dirty(bh_old, &AFFS_I(retval ? old_dir : new_dir)->i_meta= data_bhs); + mmb_mark_buffer_dirty(bh_new, &AFFS_I(retval ? new_dir : old_dir)->i_meta= data_bhs); affs_brelse(bh_old); affs_brelse(bh_new); return retval; --=20 2.43.0