All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC PATCH] xfs: don't run off the end of the buffer reading inline dirents
@ 2017-03-08 21:01 Darrick J. Wong
  2017-03-13 12:39 ` Brian Foster
  0 siblings, 1 reply; 7+ messages in thread
From: Darrick J. Wong @ 2017-03-08 21:01 UTC (permalink / raw)
  To: Darrick J. Wong; +Cc: xfs

Check that we don't run off the end of the inline data buffer when we're
trying to read directory entries.  xfs/348 triggered kernel memory being
exposed to userspace and a related complaint from the usercopy code.

Evidently once we call dir_emit, the VFS ignores error return values
since it's already begun copying data back to userspace.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
 fs/xfs/xfs_dir2_readdir.c |    8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
index 003a99b..70bdd21 100644
--- a/fs/xfs/xfs_dir2_readdir.c
+++ b/fs/xfs/xfs_dir2_readdir.c
@@ -69,6 +69,7 @@ xfs_dir2_sf_getdents(
 	xfs_dir2_dataptr_t	dotdot_offset;
 	xfs_ino_t		ino;
 	struct xfs_da_geometry	*geo = args->geo;
+	char *endp;
 
 	ASSERT(dp->i_df.if_flags & XFS_IFINLINE);
 	/*
@@ -83,6 +84,7 @@ xfs_dir2_sf_getdents(
 	ASSERT(dp->i_df.if_u1.if_data != NULL);
 
 	sfp = (xfs_dir2_sf_hdr_t *)dp->i_df.if_u1.if_data;
+	endp = dp->i_df.if_u1.if_data + dp->i_df.if_bytes;
 
 	if (dp->i_d.di_size < xfs_dir2_sf_hdr_size(sfp->i8count))
 		return -EFSCORRUPTED;
@@ -130,6 +132,12 @@ xfs_dir2_sf_getdents(
 	for (i = 0; i < sfp->count; i++) {
 		__uint8_t filetype;
 
+		/* If we pass the end of the buffer, we're done. */
+		if (((char *)sfep + sizeof(*sfep)) >= endp ||
+		    (char *)dp->d_ops->sf_nextentry(sfp, sfep) > endp) {
+			break;
+		}
+
 		off = xfs_dir2_db_off_to_dataptr(geo, geo->datablk,
 				xfs_dir2_sf_get_offset(sfep));
 

^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-03-14 23:55 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-03-08 21:01 [RFC PATCH] xfs: don't run off the end of the buffer reading inline dirents Darrick J. Wong
2017-03-13 12:39 ` Brian Foster
2017-03-13 20:55   ` Darrick J. Wong
2017-03-14 11:33     ` Brian Foster
2017-03-14 18:37       ` Darrick J. Wong
2017-03-14 20:24         ` Brian Foster
2017-03-14 23:55           ` Darrick J. Wong

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.