Skip to content

Commit b8862a0

Browse files
Christoph Hellwigcmaiolino
authored andcommitted
xfs: don't validate error tags in the I/O path
We can trust XFS developers enough to not pass random stuff to XFS_ERROR_TEST/DELAY. Open code the validity check in xfs_errortag_add, which is the only place that receives unvalidated error tag values from user space, and drop the now pointless xfs_errortag_enabled helper. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Hans Holmberg <hans.holmberg@wdc.com> Reviewed-by: Carlos Maiolino <cmaiolino@redhat.com> Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Carlos Maiolino <cem@kernel.org>
1 parent 394969e commit b8862a0

3 files changed

Lines changed: 12 additions & 30 deletions

File tree

fs/xfs/libxfs/xfs_errortag.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* Drop-writes support removed because write error handling cannot trash
5454
* pre-existing delalloc extents in any useful way anymore. We retain the
5555
* definition so that we can reject it as an invalid value in
56-
* xfs_errortag_valid().
56+
* xfs_errortag_add().
5757
*/
5858
#define XFS_ERRTAG_DROP_WRITES 28
5959
#define XFS_ERRTAG_LOG_BAD_CRC 29

fs/xfs/xfs_error.c

Lines changed: 10 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -125,30 +125,6 @@ xfs_errortag_del(
125125
xfs_sysfs_del(&mp->m_errortag_kobj);
126126
}
127127

128-
static bool
129-
xfs_errortag_valid(
130-
unsigned int error_tag)
131-
{
132-
if (error_tag >= XFS_ERRTAG_MAX)
133-
return false;
134-
135-
/* Error out removed injection types */
136-
if (error_tag == XFS_ERRTAG_DROP_WRITES)
137-
return false;
138-
return true;
139-
}
140-
141-
bool
142-
xfs_errortag_enabled(
143-
struct xfs_mount *mp,
144-
unsigned int tag)
145-
{
146-
if (!xfs_errortag_valid(tag))
147-
return false;
148-
149-
return mp->m_errortag[tag] != 0;
150-
}
151-
152128
bool
153129
xfs_errortag_test(
154130
struct xfs_mount *mp,
@@ -158,9 +134,6 @@ xfs_errortag_test(
158134
{
159135
unsigned int randfactor;
160136

161-
if (!xfs_errortag_valid(error_tag))
162-
return false;
163-
164137
randfactor = mp->m_errortag[error_tag];
165138
if (!randfactor || get_random_u32_below(randfactor))
166139
return false;
@@ -178,8 +151,17 @@ xfs_errortag_add(
178151
{
179152
BUILD_BUG_ON(ARRAY_SIZE(xfs_errortag_random_default) != XFS_ERRTAG_MAX);
180153

181-
if (!xfs_errortag_valid(error_tag))
154+
if (error_tag >= XFS_ERRTAG_MAX)
155+
return -EINVAL;
156+
157+
/* Error out removed injection types */
158+
switch (error_tag) {
159+
case XFS_ERRTAG_DROP_WRITES:
182160
return -EINVAL;
161+
default:
162+
break;
163+
}
164+
183165
mp->m_errortag[error_tag] = xfs_errortag_random_default[error_tag];
184166
return 0;
185167
}

fs/xfs/xfs_error.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ bool xfs_errortag_enabled(struct xfs_mount *mp, unsigned int tag);
4444
#define XFS_ERRORTAG_DELAY(mp, tag) \
4545
do { \
4646
might_sleep(); \
47-
if (!xfs_errortag_enabled((mp), (tag))) \
47+
if (!mp->m_errortag[tag]) \
4848
break; \
4949
xfs_warn_ratelimited((mp), \
5050
"Injecting %ums delay at file %s, line %d, on filesystem \"%s\"", \

0 commit comments

Comments
 (0)