aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Biggers <ebiggers@google.com>2023-10-26 20:07:24 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-10-26 20:07:24 +0000
commitea48e068e7b02320187ff65c516c15ede376a7a6 (patch)
tree211911b40f11a7e070e60d26679c3e092115c465
parent42cd5495f949192933669c4ca9fca50750591ceb (diff)
parent51a297aadc2f5ade585fc0d022e14188f98521e0 (diff)
downloadf2fs-tools-ea48e068e7b02320187ff65c516c15ede376a7a6.tar.gz
DO NOT MERGE - f2fs-tools: ensure that unused xattr space is zeroized am: f7c0ca9f8b am: 51a297aadc
Original change: https://googleplex-android-review.googlesource.com/c/platform/external/f2fs-tools/+/25177146 Change-Id: I8f08d331c7cf55a33de192fb2a429c7da552a45c Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--fsck/fsck.c36
1 files changed, 27 insertions, 9 deletions
diff --git a/fsck/fsck.c b/fsck/fsck.c
index 4a18ecb..d38ad1e 100644
--- a/fsck/fsck.c
+++ b/fsck/fsck.c
@@ -685,6 +685,17 @@ void fsck_reada_all_direct_node_blocks(struct f2fs_sb_info *sbi,
}
}
+static bool is_zeroed(const u8 *p, size_t size)
+{
+ size_t i;
+
+ for (i = 0; i < size; i++) {
+ if (p[i])
+ return false;
+ }
+ return true;
+}
+
int chk_extended_attributes(struct f2fs_sb_info *sbi, u32 nid,
struct f2fs_node *inode)
{
@@ -692,6 +703,7 @@ int chk_extended_attributes(struct f2fs_sb_info *sbi, u32 nid,
void *last_base_addr;
struct f2fs_xattr_entry *ent;
__u32 xattr_size = XATTR_SIZE(&inode->i);
+ bool need_fix = false;
if (xattr_size == 0)
return 0;
@@ -707,18 +719,24 @@ int chk_extended_attributes(struct f2fs_sb_info *sbi, u32 nid,
ASSERT_MSG("[0x%x] last xattr entry (offset: %lx) "
"crosses the boundary",
nid, (long int)((void *)ent - xattr));
- if (c.fix_on) {
- memset(ent, 0,
- (char *)last_base_addr - (char *)ent);
- write_all_xattrs(sbi, inode, xattr_size, xattr);
- FIX_MSG("[0x%x] nullify wrong xattr entries",
- nid);
- return 1;
- }
+ need_fix = true;
break;
}
}
-
+ if (!need_fix &&
+ !is_zeroed((u8 *)ent, (u8 *)last_base_addr - (u8 *)ent)) {
+ ASSERT_MSG("[0x%x] nonzero bytes in xattr space after "
+ "end of list", nid);
+ need_fix = true;
+ }
+ if (need_fix && c.fix_on) {
+ memset(ent, 0, (u8 *)last_base_addr - (u8 *)ent);
+ write_all_xattrs(sbi, inode, xattr_size, xattr);
+ FIX_MSG("[0x%x] nullify wrong xattr entries", nid);
+ free(xattr);
+ return 1;
+ }
+ free(xattr);
return 0;
}