diff options
author | Darrick J. Wong <darrick.wong@oracle.com> | 2018-06-04 13:23:54 -0400 |
---|---|---|
committer | Darrick J. Wong <darrick.wong@oracle.com> | 2018-06-04 21:25:05 -0400 |
commit | 2551a53053de52993be8752731f084fad3cfc4d8 (patch) | |
tree | 1956959bc2647d950a2ba4325ead3baa3271f7b8 | |
parent | 85ae01098c1a6a8e3ce908f8808f2d8f8effdbe3 (diff) |
xfs: explicitly pass buffer size to xfs_corruption_error
Explicitly pass the buffer length to xfs_corruption_error() instead of
assuming XFS_CORRUPTION_DUMP_LEN so that we avoid dumping off the end
of the buffer.
Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
-rw-r--r-- | fs/xfs/libxfs/xfs_btree.c | 3 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_da_btree.c | 2 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_dir2_data.c | 5 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_dir2_leaf.c | 3 | ||||
-rw-r--r-- | fs/xfs/libxfs/xfs_dir2_node.c | 3 | ||||
-rw-r--r-- | fs/xfs/xfs_attr_list.c | 5 | ||||
-rw-r--r-- | fs/xfs/xfs_error.c | 5 | ||||
-rw-r--r-- | fs/xfs/xfs_error.h | 9 | ||||
-rw-r--r-- | fs/xfs/xfs_log_recover.c | 15 |
9 files changed, 31 insertions, 19 deletions
diff --git a/fs/xfs/libxfs/xfs_btree.c b/fs/xfs/libxfs/xfs_btree.c index 4f83d7949a21..6b589e4f703e 100644 --- a/fs/xfs/libxfs/xfs_btree.c +++ b/fs/xfs/libxfs/xfs_btree.c | |||
@@ -1932,7 +1932,8 @@ xfs_btree_lookup( | |||
1932 | if (level != 0 || cur->bc_nlevels != 1) { | 1932 | if (level != 0 || cur->bc_nlevels != 1) { |
1933 | XFS_CORRUPTION_ERROR(__func__, | 1933 | XFS_CORRUPTION_ERROR(__func__, |
1934 | XFS_ERRLEVEL_LOW, | 1934 | XFS_ERRLEVEL_LOW, |
1935 | cur->bc_mp, block); | 1935 | cur->bc_mp, block, |
1936 | sizeof(*block)); | ||
1936 | return -EFSCORRUPTED; | 1937 | return -EFSCORRUPTED; |
1937 | } | 1938 | } |
1938 | 1939 | ||
diff --git a/fs/xfs/libxfs/xfs_da_btree.c b/fs/xfs/libxfs/xfs_da_btree.c index 39c1013358ed..1427887a1974 100644 --- a/fs/xfs/libxfs/xfs_da_btree.c +++ b/fs/xfs/libxfs/xfs_da_btree.c | |||
@@ -306,7 +306,7 @@ xfs_da3_node_read( | |||
306 | break; | 306 | break; |
307 | default: | 307 | default: |
308 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, | 308 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, |
309 | tp->t_mountp, info); | 309 | tp->t_mountp, info, sizeof(*info)); |
310 | xfs_trans_brelse(tp, *bpp); | 310 | xfs_trans_brelse(tp, *bpp); |
311 | *bpp = NULL; | 311 | *bpp = NULL; |
312 | return -EFSCORRUPTED; | 312 | return -EFSCORRUPTED; |
diff --git a/fs/xfs/libxfs/xfs_dir2_data.c b/fs/xfs/libxfs/xfs_dir2_data.c index 2c16bb4f2155..c672846a0303 100644 --- a/fs/xfs/libxfs/xfs_dir2_data.c +++ b/fs/xfs/libxfs/xfs_dir2_data.c | |||
@@ -251,7 +251,8 @@ xfs_dir3_data_check( | |||
251 | if (!fa) | 251 | if (!fa) |
252 | return; | 252 | return; |
253 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, dp->i_mount, | 253 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, dp->i_mount, |
254 | bp->b_addr, __FILE__, __LINE__, fa); | 254 | bp->b_addr, BBTOB(bp->b_length), __FILE__, __LINE__, |
255 | fa); | ||
255 | ASSERT(0); | 256 | ASSERT(0); |
256 | } | 257 | } |
257 | #endif | 258 | #endif |
@@ -1157,7 +1158,7 @@ xfs_dir2_data_use_free( | |||
1157 | return 0; | 1158 | return 0; |
1158 | corrupt: | 1159 | corrupt: |
1159 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, args->dp->i_mount, | 1160 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, args->dp->i_mount, |
1160 | hdr, __FILE__, __LINE__, fa); | 1161 | hdr, sizeof(*hdr), __FILE__, __LINE__, fa); |
1161 | return -EFSCORRUPTED; | 1162 | return -EFSCORRUPTED; |
1162 | } | 1163 | } |
1163 | 1164 | ||
diff --git a/fs/xfs/libxfs/xfs_dir2_leaf.c b/fs/xfs/libxfs/xfs_dir2_leaf.c index 9367f2a41b35..77240f4de0e0 100644 --- a/fs/xfs/libxfs/xfs_dir2_leaf.c +++ b/fs/xfs/libxfs/xfs_dir2_leaf.c | |||
@@ -81,7 +81,8 @@ xfs_dir3_leaf_check( | |||
81 | if (!fa) | 81 | if (!fa) |
82 | return; | 82 | return; |
83 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, dp->i_mount, | 83 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, dp->i_mount, |
84 | bp->b_addr, __FILE__, __LINE__, fa); | 84 | bp->b_addr, BBTOB(bp->b_length), __FILE__, __LINE__, |
85 | fa); | ||
85 | ASSERT(0); | 86 | ASSERT(0); |
86 | } | 87 | } |
87 | #else | 88 | #else |
diff --git a/fs/xfs/libxfs/xfs_dir2_node.c b/fs/xfs/libxfs/xfs_dir2_node.c index 9df096cc3c37..a5e7d9bd7552 100644 --- a/fs/xfs/libxfs/xfs_dir2_node.c +++ b/fs/xfs/libxfs/xfs_dir2_node.c | |||
@@ -84,7 +84,8 @@ xfs_dir3_leaf_check( | |||
84 | if (!fa) | 84 | if (!fa) |
85 | return; | 85 | return; |
86 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, dp->i_mount, | 86 | xfs_corruption_error(__func__, XFS_ERRLEVEL_LOW, dp->i_mount, |
87 | bp->b_addr, __FILE__, __LINE__, fa); | 87 | bp->b_addr, BBTOB(bp->b_length), __FILE__, __LINE__, |
88 | fa); | ||
88 | ASSERT(0); | 89 | ASSERT(0); |
89 | } | 90 | } |
90 | #else | 91 | #else |
diff --git a/fs/xfs/xfs_attr_list.c b/fs/xfs/xfs_attr_list.c index 3e59a348ea71..276465ed276e 100644 --- a/fs/xfs/xfs_attr_list.c +++ b/fs/xfs/xfs_attr_list.c | |||
@@ -139,7 +139,8 @@ xfs_attr_shortform_list(xfs_attr_list_context_t *context) | |||
139 | ((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) { | 139 | ((char *)sfe >= ((char *)sf + dp->i_afp->if_bytes)))) { |
140 | XFS_CORRUPTION_ERROR("xfs_attr_shortform_list", | 140 | XFS_CORRUPTION_ERROR("xfs_attr_shortform_list", |
141 | XFS_ERRLEVEL_LOW, | 141 | XFS_ERRLEVEL_LOW, |
142 | context->dp->i_mount, sfe); | 142 | context->dp->i_mount, sfe, |
143 | sizeof(*sfe)); | ||
143 | kmem_free(sbuf); | 144 | kmem_free(sbuf); |
144 | return -EFSCORRUPTED; | 145 | return -EFSCORRUPTED; |
145 | } | 146 | } |
@@ -241,7 +242,7 @@ xfs_attr_node_list_lookup( | |||
241 | if (magic != XFS_DA_NODE_MAGIC && | 242 | if (magic != XFS_DA_NODE_MAGIC && |
242 | magic != XFS_DA3_NODE_MAGIC) { | 243 | magic != XFS_DA3_NODE_MAGIC) { |
243 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, | 244 | XFS_CORRUPTION_ERROR(__func__, XFS_ERRLEVEL_LOW, mp, |
244 | node); | 245 | node, sizeof(*node)); |
245 | goto out_corruptbuf; | 246 | goto out_corruptbuf; |
246 | } | 247 | } |
247 | 248 | ||
diff --git a/fs/xfs/xfs_error.c b/fs/xfs/xfs_error.c index 7975634cb8fe..fedb2730ea9b 100644 --- a/fs/xfs/xfs_error.c +++ b/fs/xfs/xfs_error.c | |||
@@ -334,13 +334,14 @@ xfs_corruption_error( | |||
334 | const char *tag, | 334 | const char *tag, |
335 | int level, | 335 | int level, |
336 | struct xfs_mount *mp, | 336 | struct xfs_mount *mp, |
337 | void *p, | 337 | void *buf, |
338 | size_t bufsize, | ||
338 | const char *filename, | 339 | const char *filename, |
339 | int linenum, | 340 | int linenum, |
340 | xfs_failaddr_t failaddr) | 341 | xfs_failaddr_t failaddr) |
341 | { | 342 | { |
342 | if (level <= xfs_error_level) | 343 | if (level <= xfs_error_level) |
343 | xfs_hex_dump(p, XFS_CORRUPTION_DUMP_LEN); | 344 | xfs_hex_dump(buf, bufsize); |
344 | xfs_error_report(tag, level, mp, filename, linenum, failaddr); | 345 | xfs_error_report(tag, level, mp, filename, linenum, failaddr); |
345 | xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair"); | 346 | xfs_alert(mp, "Corruption detected. Unmount and run xfs_repair"); |
346 | } | 347 | } |
diff --git a/fs/xfs/xfs_error.h b/fs/xfs/xfs_error.h index ce391349e78b..f8c3667790de 100644 --- a/fs/xfs/xfs_error.h +++ b/fs/xfs/xfs_error.h | |||
@@ -24,8 +24,9 @@ extern void xfs_error_report(const char *tag, int level, struct xfs_mount *mp, | |||
24 | const char *filename, int linenum, | 24 | const char *filename, int linenum, |
25 | xfs_failaddr_t failaddr); | 25 | xfs_failaddr_t failaddr); |
26 | extern void xfs_corruption_error(const char *tag, int level, | 26 | extern void xfs_corruption_error(const char *tag, int level, |
27 | struct xfs_mount *mp, void *p, const char *filename, | 27 | struct xfs_mount *mp, void *buf, size_t bufsize, |
28 | int linenum, xfs_failaddr_t failaddr); | 28 | const char *filename, int linenum, |
29 | xfs_failaddr_t failaddr); | ||
29 | extern void xfs_buf_verifier_error(struct xfs_buf *bp, int error, | 30 | extern void xfs_buf_verifier_error(struct xfs_buf *bp, int error, |
30 | const char *name, void *buf, size_t bufsz, | 31 | const char *name, void *buf, size_t bufsz, |
31 | xfs_failaddr_t failaddr); | 32 | xfs_failaddr_t failaddr); |
@@ -37,8 +38,8 @@ extern void xfs_inode_verifier_error(struct xfs_inode *ip, int error, | |||
37 | 38 | ||
38 | #define XFS_ERROR_REPORT(e, lvl, mp) \ | 39 | #define XFS_ERROR_REPORT(e, lvl, mp) \ |
39 | xfs_error_report(e, lvl, mp, __FILE__, __LINE__, __return_address) | 40 | xfs_error_report(e, lvl, mp, __FILE__, __LINE__, __return_address) |
40 | #define XFS_CORRUPTION_ERROR(e, lvl, mp, mem) \ | 41 | #define XFS_CORRUPTION_ERROR(e, lvl, mp, buf, bufsize) \ |
41 | xfs_corruption_error(e, lvl, mp, mem, \ | 42 | xfs_corruption_error(e, lvl, mp, buf, bufsize, \ |
42 | __FILE__, __LINE__, __return_address) | 43 | __FILE__, __LINE__, __return_address) |
43 | 44 | ||
44 | #define XFS_ERRLEVEL_OFF 0 | 45 | #define XFS_ERRLEVEL_OFF 0 |
diff --git a/fs/xfs/xfs_log_recover.c b/fs/xfs/xfs_log_recover.c index 06a09cb948b5..750124b170e5 100644 --- a/fs/xfs/xfs_log_recover.c +++ b/fs/xfs/xfs_log_recover.c | |||
@@ -3115,7 +3115,8 @@ xlog_recover_inode_pass2( | |||
3115 | if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) && | 3115 | if ((ldip->di_format != XFS_DINODE_FMT_EXTENTS) && |
3116 | (ldip->di_format != XFS_DINODE_FMT_BTREE)) { | 3116 | (ldip->di_format != XFS_DINODE_FMT_BTREE)) { |
3117 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(3)", | 3117 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(3)", |
3118 | XFS_ERRLEVEL_LOW, mp, ldip); | 3118 | XFS_ERRLEVEL_LOW, mp, ldip, |
3119 | sizeof(*ldip)); | ||
3119 | xfs_alert(mp, | 3120 | xfs_alert(mp, |
3120 | "%s: Bad regular inode log record, rec ptr "PTR_FMT", " | 3121 | "%s: Bad regular inode log record, rec ptr "PTR_FMT", " |
3121 | "ino ptr = "PTR_FMT", ino bp = "PTR_FMT", ino %Ld", | 3122 | "ino ptr = "PTR_FMT", ino bp = "PTR_FMT", ino %Ld", |
@@ -3128,7 +3129,8 @@ xlog_recover_inode_pass2( | |||
3128 | (ldip->di_format != XFS_DINODE_FMT_BTREE) && | 3129 | (ldip->di_format != XFS_DINODE_FMT_BTREE) && |
3129 | (ldip->di_format != XFS_DINODE_FMT_LOCAL)) { | 3130 | (ldip->di_format != XFS_DINODE_FMT_LOCAL)) { |
3130 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(4)", | 3131 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(4)", |
3131 | XFS_ERRLEVEL_LOW, mp, ldip); | 3132 | XFS_ERRLEVEL_LOW, mp, ldip, |
3133 | sizeof(*ldip)); | ||
3132 | xfs_alert(mp, | 3134 | xfs_alert(mp, |
3133 | "%s: Bad dir inode log record, rec ptr "PTR_FMT", " | 3135 | "%s: Bad dir inode log record, rec ptr "PTR_FMT", " |
3134 | "ino ptr = "PTR_FMT", ino bp = "PTR_FMT", ino %Ld", | 3136 | "ino ptr = "PTR_FMT", ino bp = "PTR_FMT", ino %Ld", |
@@ -3139,7 +3141,8 @@ xlog_recover_inode_pass2( | |||
3139 | } | 3141 | } |
3140 | if (unlikely(ldip->di_nextents + ldip->di_anextents > ldip->di_nblocks)){ | 3142 | if (unlikely(ldip->di_nextents + ldip->di_anextents > ldip->di_nblocks)){ |
3141 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(5)", | 3143 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(5)", |
3142 | XFS_ERRLEVEL_LOW, mp, ldip); | 3144 | XFS_ERRLEVEL_LOW, mp, ldip, |
3145 | sizeof(*ldip)); | ||
3143 | xfs_alert(mp, | 3146 | xfs_alert(mp, |
3144 | "%s: Bad inode log record, rec ptr "PTR_FMT", dino ptr "PTR_FMT", " | 3147 | "%s: Bad inode log record, rec ptr "PTR_FMT", dino ptr "PTR_FMT", " |
3145 | "dino bp "PTR_FMT", ino %Ld, total extents = %d, nblocks = %Ld", | 3148 | "dino bp "PTR_FMT", ino %Ld, total extents = %d, nblocks = %Ld", |
@@ -3151,7 +3154,8 @@ xlog_recover_inode_pass2( | |||
3151 | } | 3154 | } |
3152 | if (unlikely(ldip->di_forkoff > mp->m_sb.sb_inodesize)) { | 3155 | if (unlikely(ldip->di_forkoff > mp->m_sb.sb_inodesize)) { |
3153 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(6)", | 3156 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(6)", |
3154 | XFS_ERRLEVEL_LOW, mp, ldip); | 3157 | XFS_ERRLEVEL_LOW, mp, ldip, |
3158 | sizeof(*ldip)); | ||
3155 | xfs_alert(mp, | 3159 | xfs_alert(mp, |
3156 | "%s: Bad inode log record, rec ptr "PTR_FMT", dino ptr "PTR_FMT", " | 3160 | "%s: Bad inode log record, rec ptr "PTR_FMT", dino ptr "PTR_FMT", " |
3157 | "dino bp "PTR_FMT", ino %Ld, forkoff 0x%x", __func__, | 3161 | "dino bp "PTR_FMT", ino %Ld, forkoff 0x%x", __func__, |
@@ -3162,7 +3166,8 @@ xlog_recover_inode_pass2( | |||
3162 | isize = xfs_log_dinode_size(ldip->di_version); | 3166 | isize = xfs_log_dinode_size(ldip->di_version); |
3163 | if (unlikely(item->ri_buf[1].i_len > isize)) { | 3167 | if (unlikely(item->ri_buf[1].i_len > isize)) { |
3164 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(7)", | 3168 | XFS_CORRUPTION_ERROR("xlog_recover_inode_pass2(7)", |
3165 | XFS_ERRLEVEL_LOW, mp, ldip); | 3169 | XFS_ERRLEVEL_LOW, mp, ldip, |
3170 | sizeof(*ldip)); | ||
3166 | xfs_alert(mp, | 3171 | xfs_alert(mp, |
3167 | "%s: Bad inode log record length %d, rec ptr "PTR_FMT, | 3172 | "%s: Bad inode log record length %d, rec ptr "PTR_FMT, |
3168 | __func__, item->ri_buf[1].i_len, item); | 3173 | __func__, item->ri_buf[1].i_len, item); |