Skip to contentSkip to conversation

test for EA validity checking

DISCUSSION Andreas Dilger 1 participant 2 messages Nov 10, 2007 – Nov 15, 2007

lore
Share & tools
lore
#0 lore raw

Attached is a test image for extended attribute block checking. This small image contains a number of different kinds of corruptions (bad magic, bad checksum, empty block, bad EA block number), as well as an old-format (v1) EA, and a valid v2 EA.

Cheers, Andreas
--
Andreas Dilger
Sr. Software Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

#1 lore raw
Quoted 4 lines · Andreas Dilger

Attached is a test image for extended attribute block checking. This small image contains a number of different kinds of corruptions (bad magic, bad checksum, empty block, bad EA block number), as well as an old-format (v1) EA, and a valid v2 EA.

Attached is an updated patch with a new test image, that includes a corrupt EA set on a block device. That had been causing us some e2fsck heartburn because of random inode table corruption.

This goes along with an updated "expand-extra-isize" patch. The root of the problem was that I had added an extra check to verify the EA magic in ext2fs_read_ext_attr(), but the return value of this function was used in check_blocks() to set pctx->errcode, and later in check_ext_attr() the non-zero value of pctx->errcode caused an abort when ext2fs_inode_has_valid_blocks() was false and it caused PR_1_BLOCK_ITERATE to be hit (a fatal error).

I ended up checking the magic in all of the ext2fs_read_ext_attr() callsites, but IMHO the library should at least be doing basic validity checking like this.

One question that remains unclear is whether pctx->errcode being set from the early call of check_ext_attr() should cause check_blocks() to abort? In the common regular-file/directory/slow-symlink case pctx->errcode is reset by the call to ext2fs_block_iterate2(), so it would seem reasonable to go back to checking EA magic in ext2fs_read_ext_attr(), and then clearing pctx->errcode in check_ext_attr() if the problem is fixed.

Cheers, Andreas
--
Andreas Dilger
Sr. Software Engineer, Lustre Group
Sun Microsystems of Canada, Inc.

tests/f_ea_checks/expect.1 new file +57 -0
Index: e2fsprogs-cfs/tests/f_ea_checks/expect.1
===================================================================
@@ -0,0 +1,57 @@
+Pass 1: Checking inodes, blocks, and sizes
+Inode 13 has a bad extended attribute block 26.  Clear? yes
+
+Inode 13, i_blocks is 4, should be 2.  Fix? yes
+
+Extended attribute in inode 14 has a hash (1649340189) which is invalid
+Clear? yes
+
+Inode 14, i_blocks is 2, should be 0.  Fix? yes
+
+Inode 17 has a bad extended attribute block 28.  Clear? yes
+
+Inode 17, i_blocks is 4, should be 2.  Fix? yes
+
+Inode 16 has a bad extended attribute block 29.  Clear? yes
+
+Inode 16, i_blocks is 2, should be 0.  Fix? yes
+
+Inode 19 has a bad extended attribute block 33.  Clear? yes
+
+Inode 19, i_blocks is 2, should be 0.  Fix? yes
+
+Inode 12 has a bad extended attribute block 55.  Clear? yes
+
+Inode 12, i_blocks is 2, should be 0.  Fix? yes
+
+Inode 15, i_blocks is 2, should be 0.  Fix? yes
+
+Pass 2: Checking directory structure
+Extended attribute block for inode 15 (/far) is invalid (999).
+Clear? yes
+
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+Block bitmap differences:  -(26--29) -33 -55
+Fix? yes
+
+Free blocks count wrong for group #0 (481, counted=484).
+Fix? yes
+
+Free blocks count wrong (481, counted=484).
+Fix? yes
+
+Inode bitmap differences:  -18
+Fix? yes
+
+Free inodes count wrong for group #0 (47, counted=46).
+Fix? yes
+
+Free inodes count wrong (47, counted=46).
+Fix? yes
+
+
+test_filesys: ***** FILE SYSTEM WAS MODIFIED *****
+test_filesys: 18/64 files (0.0% non-contiguous), 28/512 blocks
+Exit status is 1
tests/f_ea_checks/expect.2 new file +7 -0
Index: e2fsprogs-cfs/tests/f_ea_checks/expect.2
===================================================================
@@ -0,0 +1,7 @@
+Pass 1: Checking inodes, blocks, and sizes
+Pass 2: Checking directory structure
+Pass 3: Checking directory connectivity
+Pass 4: Checking reference counts
+Pass 5: Checking group summary information
+test_filesys: 18/64 files (0.0% non-contiguous), 28/512 blocks
+Exit status is 0
tests/f_ea_checks/image.gz new file +4 -0
Index: e2fsprogs-cfs/tests/f_ea_checks/image.gz
===================================================================
@@ -0,0 +1,4 @@
+��,;Gimage.new��	tT��dDA
�V����M$�ybADA[-HKX���U+����UcQ����(Z&3I8�(R�� h-��A�RA�$Z����}��y�̻/����r���pվ�K���JjJJ��2��'TDY�+gu^5$�szJ���o���K��9��[�]lW5�q��o]�zчg�֏��T|J���[λ����g[4<�?n����>7�jS7tк�q|
R}��KKFz2*�����]��}���K�8�_��|�U>0�����7y��V����:���L�9Ʃp��(�Z��J��A��MFF2�%�d���ɨ���ɨ����(ۦΗ�?���e�d�ɨ�I��Cv/�G��eA����;}&�A�~�{���u���w����!���ȿ����P�4kx��i_�����ށ8���.M����F�g+;������̯���d����	���E��9���������DS-ߠ�{�G���Z~��Z����)UB��G������C���+��ԁ�������y}G�?�h�)FV�'�z�O�cʟ���In[��ljZz��a�y��S�3��^ZE���t��?����@��P����?�����m���#
����ߦ�����������e����}�P�
+}������������}���;�L�j���7��]�)��gO(�8;��9مC�f�����{b���󳖷>&v��i�>}WĎh�>6j��ئY�5�#��R.XZk�mY�ߕ>.4.|\�[�n�������N�➬��_~�g��Ksқ�V����t\,c��؜f�c�Z\ԿQ���^��Մ�w_�7kj��������^���������7_��Y.�iDx��Y���i��-X:qA��ď:��,�[9��X��&Ͼ.w��r�,�>��1�r�]ta��-r_���[����e���犟�s�҅K�/�2�c�5K��^��J^|2���7���qD�ҹ���tk�|qa��A�[Ң;��+:jr��[37�Xճd�ÓK�̝\R�scIʐ[Kz��*���Β��&��kY�ک��{Ly4����чv�r���8��#�s��#��=�sv�k�3~sJNV���m՗+vI\xZ��u+>e���*k������,Ll�:����{���6������h�J������sy����%���&����x��#�Ƕ	6=5)�[�i�,ؔ�2�gcp�Q��OM�������x�8on0qɄ`���5=]��o{]|��"��g�K�n8.��Ķ�u�C��ۜly��`꠬�����Xg�%��W.������k��D/�"�����u�=���h��gG'^U3�\�`���9{�Edn�_�N����^���}Rb��U�W��IP��#�÷�k�4�3?8������ő�Ffܾ*r��n���G�B���5V7���(#�s�������
�?���l죉-V&>Xv{�͙���7��{r����A��
+Z������P�ڻ�M;?�~i0l���9�n�ȸ`Fb��ى��]����xo|p�/w�7��XtR4{CF���u�?��l�蝢�7�I�i}_b�x���i��$^�R��:)8��� ��֠o�g��ߝ<|�9�3i�"���/z�������&��Q�/���{�۫%�9*3ѫu�Ĭ_l�_ۥJ�{�K#��9:�� ;�ᦓ������3�.�,���V5���P�����EC�
+��:=rl�#��ZY���"G�P�}���:�lP4iڜ�ճ�-2|9�8y�
\ No newline at end of file
tests/f_ea_checks/name new file +1 -0
Index: e2fsprogs-cfs/tests/f_ea_checks/name
===================================================================
@@ -0,0 +1 @@
+extended attribute block checks
lib/ext2fs/ext_attr.c +913 -3

947 lines not on this page · raw message

e2fsck/unix.c +51 -0

63 lines not on this page · raw message

lib/ext2fs/ext2_ext_attr.h +29 -0
Index: e2fsprogs-1.40.1/lib/ext2fs/ext2_ext_attr.h
===================================================================
@@ -15,6 +15,9 @@
 /* Maximum number of references to one attribute block */
 #define EXT2_EXT_ATTR_REFCOUNT_MAX	1024
 
+#define XATTR_CREATE    0x1     /* set value, fail if attr already exists */
+#define XATTR_REPLACE   0x2     /* set value, fail if attr does not exist */
+
 struct ext2_ext_attr_header {
 	__u32	h_magic;	/* magic number for identification */
 	__u32	h_refcount;	/* reference count */
@@ -35,6 +38,32 @@ struct ext2_ext_attr_entry {
 #endif
 };
 
+#define BHDR(block) ((struct ext2_ext_attr_header *) block)
+#define IHDR(inode)			   	\
+	((__u32 *) ((char *)inode +	     	\
+		    EXT2_GOOD_OLD_INODE_SIZE +  \
+		    (inode)->i_extra_isize))
+#define ENTRY(ptr) ((struct ext2_ext_attr_entry *)(ptr))
+
+/* Name indexes */
+#define EXT2_ATTR_INDEX_USER		    	1
+#define EXT2_ATTR_INDEX_POSIX_ACL_ACCESS	2
+#define EXT2_ATTR_INDEX_POSIX_ACL_DEFAULT	3
+#define EXT2_ATTR_INDEX_TRUSTED			4
+#define EXT2_ATTR_INDEX_LUSTRE			5
+#define EXT2_ATTR_INDEX_SECURITY		6
+#define EXT2_ATTR_INDEX_MAX			7
+
+#define EXT2_ATTR_INDEX_USER_PREFIX		 "user."
+#define EXT2_ATTR_INDEX_POSIX_ACL_ACCESS_PREFIX	 "system.posix_acl_access"
+#define EXT2_ATTR_INDEX_POSIX_ACL_DEFAULT_PREFIX "system.posix_acl_default"
+#define EXT2_ATTR_INDEX_TRUSTED_PREFIX		 "trusted."
+#define EXT2_ATTR_INDEX_LUSTRE_PREFIX		 "lustre."
+#define EXT2_ATTR_INDEX_SECURITY_PREFIX		 "security."
+
+#define EXT2_ATTR_PREFIX(index) (index ## _PREFIX)
+#define EXT2_ATTR_PREFIX_LEN(index) (index ## _PRE_LEN)
+
 #define EXT2_EXT_ATTR_PAD_BITS		2
 #define EXT2_EXT_ATTR_PAD		((unsigned) 1<<EXT2_EXT_ATTR_PAD_BITS)
 #define EXT2_EXT_ATTR_ROUND		(EXT2_EXT_ATTR_PAD-1)
e2fsck/e2fsck.h +10 -0
Index: e2fsprogs-1.40.1/e2fsck/e2fsck.h
===================================================================
@@ -172,6 +172,7 @@ struct resource_track {
 #define E2F_FLAG_RESTARTED	0x0200 /* E2fsck has been restarted */
 #define E2F_FLAG_RESIZE_INODE	0x0400 /* Request to recreate resize inode */
 #define E2F_FLAG_GOT_DEVSIZE	0x0800 /* Device size has been fetched */
+#define E2F_FLAG_EXPAND_EISIZE	0x2000 /* Expand the inodes (i_extra_isize) */
 
 /*
  * Defines for indicating the e2fsck pass number
@@ -348,6 +349,15 @@ struct e2fsck_struct {
 
 	profile_t	profile;
 
+	/* Expand large inodes to atleast these many bytes */
+	int want_extra_isize;
+	/* minimum i_extra_isize found in used inodes. Should not be lesser
+	 * than s_min_extra_isize.
+	 */
+	__u32 min_extra_isize;
+	int fs_unexpanded_inodes;
+	ext2fs_inode_bitmap expand_eisize_map;
+
 	/*
 	 * For the use of callers of the e2fsck functions; not used by
 	 * e2fsck functions themselves.
lib/ext2fs/ext2_fs.h +8 -0
Index: e2fsprogs-1.40.1/lib/ext2fs/ext2_fs.h
===================================================================
@@ -411,10 +411,17 @@ struct ext2_inode_large {
 	__u32	i_atime_extra;	/* extra Access time (nsec << 2 | epoch) */
 	__u32	i_crtime;	/* File creation time */
 	__u32	i_crtime_extra;	/* extra File creation time (nsec << 2 | epoch)*/
+	__u32   i_version_hi;   /* high 32 bits for 64-bit version */
 };
 
 #define i_size_high	i_dir_acl
 
+#define EXT2_FITS_IN_INODE(inode, field)		\
+	((offsetof(struct ext2_inode_large, field) +	\
+	 sizeof((inode)->field)) <=			\
+	 		 (EXT2_GOOD_OLD_INODE_SIZE +	\
+	     		  (inode)->i_extra_isize))	\
+
 #if defined(__KERNEL__) || defined(__linux__)
 #define i_reserved1	osd1.linux1.l_i_reserved1
 #define i_frag		osd2.linux2.l_i_frag
@@ -648,6 +655,7 @@ struct ext2_super_block {
 #define EXT2_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER| \
 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE| \
 					 EXT4_FEATURE_RO_COMPAT_DIR_NLINK| \
+					 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE| \
 					 EXT2_FEATURE_RO_COMPAT_BTREE_DIR)
 
 /*
e2fsck/pass1.c +192 -7

250 lines not on this page · raw message

lib/ext2fs/ext2fs.h +17 -0
Index: e2fsprogs-1.40.1/lib/ext2fs/ext2fs.h
===================================================================
@@ -425,6 +425,12 @@ typedef struct ext2_icount *ext2_icount_
 #define EXT2_CHECK_MAGIC(struct, code) \
 	  if ((struct)->magic != (code)) return (code)
 
+/*
+ * Flags for returning status of ext2fs_expand_extra_isize()
+ */
+#define EXT2_EXPAND_EISIZE_UNSAFE	0x0001
+#define EXT2_EXPAND_EISIZE_NEW_BLOCK 	0x0002
+#define EXT2_EXPAND_EISIZE_NOSPC	0x0004
 
 /*
  * For ext2 compression support
@@ -467,6 +473,7 @@ typedef struct ext2_icount *ext2_icount_
 #define EXT2_LIB_FEATURE_RO_COMPAT_SUPP	(EXT2_FEATURE_RO_COMPAT_SPARSE_SUPER|\
 					 EXT2_FEATURE_RO_COMPAT_LARGE_FILE|\
 					 EXT4_FEATURE_RO_COMPAT_DIR_NLINK|\
+					 EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE| \
 					 EXT4_FEATURE_RO_COMPAT_GDT_CSUM)
 
 /*
@@ -728,6 +735,16 @@ extern errcode_t ext2fs_expand_dir(ext2_
 /* ext_attr.c */
 extern __u32 ext2fs_ext_attr_hash_entry(struct ext2_ext_attr_entry *entry,
 					void *data);
+int ext2fs_attr_get_next_attr(struct ext2_ext_attr_entry *entry, int name_index,
+			      char *buffer, int buffer_size, int start);
+errcode_t ext2fs_attr_set(ext2_filsys fs, ext2_ino_t ino,
+			  struct ext2_inode *inode,
+			  int name_index, const char *name, const char *value,
+			  int value_len, int flags);
+extern errcode_t ext2fs_expand_extra_isize(ext2_filsys fs, ext2_ino_t ino,
+					   struct ext2_inode_large *inode,
+					   int new_extra_isize, int *ret,
+					   int *needed_size);
 extern errcode_t ext2fs_read_ext_attr(ext2_filsys fs, blk_t block, void *buf);
 extern errcode_t ext2fs_write_ext_attr(ext2_filsys fs, blk_t block,
 				       void *buf);
e2fsck/problem.h +32 -0
Index: e2fsprogs-1.40.1/e2fsck/problem.h
===================================================================
@@ -212,6 +212,16 @@ struct problem_context {
 /* Last group block bitmap is uninitialized. */
 #define PR_0_BB_UNINIT_LAST			0x000039
 
+/* Invalid s_min_extra_isize */
+#define PR_0_MIN_EXTRA_ISIZE_INVALID		0x00003A
+
+/* Invalid s_want_extra_isize */
+#define PR_0_WANT_EXTRA_ISIZE_INVALID		0x00003B
+
+/* Clear EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE flag */
+#define PR_0_CLEAR_EXTRA_ISIZE			0x00003C
+
+
 /*
  * Pass 1 errors
  */
@@ -498,6 +508,25 @@ struct problem_context {
 /* extent/index was modified & repaired - not really a problem */
 #define PR_1_EXTENT_CHANGED		0x010067
 
+/* Warning for user that all inodes need to be expanded atleast by
+ * s_min_extra_isize
+ */
+#define PR_1_EXPAND_EISIZE_WARNING	0x010068
+
+/* Expand the inode */
+#define PR_1_EXPAND_EISIZE		0x010069
+
+/* Delete an EA so that EXTRA_ISIZE may be enabled */
+#define PR_1_EISIZE_DELETE_EA		0x01006A
+
+/* An EA needs to be deleted by e2fsck is being run with -p or -y */
+#define PR_1_EA_BLK_NOSPC		0x01006B
+
+/* Disable EXTRA_ISIZE feature as inode cannot be expanded
+ * without deletion of an EA
+ */
+#define PR_1_CLEAR_EXTRA_ISIZE		0x01006C
+
 /*
  * Pass 1b errors
  */
@@ -961,6 +990,9 @@ struct problem_context {
 /* Inode in use but group is marked INODE_UNINIT */
 #define PR_5_INODE_UNINIT		0x050019
 
+/* Expand the inodes which need a new EA block */
+#define PR_5_EXPAND_EISIZE		0x05001a
+
 /*
  * Post-Pass 5 errors
  */
e2fsck/problem.c +50 -0

68 lines not on this page · raw message

e2fsck/e2fsck.c +1 -0
Index: e2fsprogs-1.40.1/e2fsck/e2fsck.c
===================================================================
@@ -150,6 +150,7 @@ errcode_t e2fsck_reset_context(e2fsck_t 
 	ctx->fs_tind_count = 0;
 	ctx->fs_fragmented = 0;
 	ctx->large_files = 0;
+	ctx->fs_unexpanded_inodes = 0;
 
 	/* Reset the superblock to the user's requested value */
 	ctx->superblock = ctx->use_superblock;
e2fsck/pass5.c +36 -0
Index: e2fsprogs-1.40.1/e2fsck/pass5.c
===================================================================
@@ -64,6 +64,42 @@ void e2fsck_pass5(e2fsck_t ctx)
 	ext2fs_free_block_bitmap(ctx->block_found_map);
 	ctx->block_found_map = 0;
 
+	if (ctx->flags & E2F_FLAG_EXPAND_EISIZE) {
+		int min_extra_isize;
+
+		if (!ctx->expand_eisize_map)
+			goto set_min_extra_isize;
+
+		for (pctx.ino = 1; pctx.ino < ctx->fs->super->s_inodes_count;
+		     pctx.ino++) {
+			if (ext2fs_test_inode_bitmap(ctx->expand_eisize_map,
+			    pctx.ino)) {
+				fix_problem(ctx, PR_5_EXPAND_EISIZE, &pctx);
+				ext2fs_expand_extra_isize(ctx->fs, pctx.ino, 0,
+							  ctx->want_extra_isize,
+							  NULL, NULL);
+			}
+		}
+		ext2fs_free_inode_bitmap(ctx->expand_eisize_map);
+
+set_min_extra_isize:
+		if (ctx->fs->super->s_min_extra_isize)
+			min_extra_isize = ctx->fs->super->s_min_extra_isize;
+		else
+			min_extra_isize = ctx->want_extra_isize;
+		if (ctx->min_extra_isize >= min_extra_isize &&
+		    !ctx->fs_unexpanded_inodes) {
+			ctx->fs->super->s_min_extra_isize =ctx->min_extra_isize;
+			ctx->fs->super->s_feature_ro_compat |=
+					EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE;
+		} else {
+			ctx->fs->super->s_min_extra_isize = 0;
+			ctx->fs->super->s_feature_ro_compat &=
+					~EXT4_FEATURE_RO_COMPAT_EXTRA_ISIZE;
+		}
+		ext2fs_mark_super_dirty(ctx->fs);
+	}
+
 #ifdef RESOURCE_TRACK
 	if (ctx->options & E2F_OPT_TIME2) {
 		e2fsck_clear_progbar(ctx);
lib/ext2fs/ext2_err.et.in +24 -0
Index: e2fsprogs-1.40.1/lib/ext2fs/ext2_err.et.in
===================================================================
@@ -338,5 +338,29 @@ ec	EXT2_ET_EXTENT_LEAF_BAD,
 ec	EXT2_ET_EXTENT_NO_SPACE,
 	"No free space in extent map"
 
+ec	EXT2_ET_EA_BAD_MAGIC,
+	"Extended attribute block has bad magic value"
+
+ec	EXT2_ET_EA_BAD_ENTRIES,
+	"Extended attribute block has bad entries"
+
+ec	EXT2_ET_EA_NO_SPACE,
+	"No free space for extended attribute"
+
+ec	EXT2_ET_EA_TOO_BIG,
+	"Extended attribute too big for buffer"
+
+ec	EXT2_ET_EA_NAME_TOO_BIG,
+	"Extended attribute name too big for header"
+
+ec	EXT2_ET_EA_BAD_NAME,
+	"Extended attribute name is bad"
+
+ec	EXT2_ET_EA_NAME_NOT_FOUND,
+	"Extended attribute name not found"
+
+ec	EXT2_ET_EA_NAME_EXISTS,
+	"Extended attribute name already exists"
+
 	end