xfs: check log iovec size to make sure it's plausibly a buffer log format
authorDarrick J. Wong <darrick.wong@oracle.com>
Tue, 14 Jan 2020 00:33:46 +0000 (16:33 -0800)
committerDarrick J. Wong <darrick.wong@oracle.com>
Thu, 16 Jan 2020 16:07:24 +0000 (08:07 -0800)
When log recovery is processing buffer log items, we should check that
the incoming iovec actually describes a region of memory large enough to
contain the log format and the dirty map.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
fs/xfs/xfs_buf_item.c
fs/xfs/xfs_buf_item.h
fs/xfs/xfs_log_recover.c

index be691d1d9fad21b2d7a3ab7396501aabeb8ff19c..5be8973a452c915a0a77e4635856be468789e137 100644 (file)
@@ -27,6 +27,23 @@ static inline struct xfs_buf_log_item *BUF_ITEM(struct xfs_log_item *lip)
 
 STATIC void    xfs_buf_do_callbacks(struct xfs_buf *bp);
 
+/* Is this log iovec plausibly large enough to contain the buffer log format? */
+bool
+xfs_buf_log_check_iovec(
+       struct xfs_log_iovec            *iovec)
+{
+       struct xfs_buf_log_format       *blfp = iovec->i_addr;
+       char                            *bmp_end;
+       char                            *item_end;
+
+       if (offsetof(struct xfs_buf_log_format, blf_data_map) > iovec->i_len)
+               return false;
+
+       item_end = (char *)iovec->i_addr + iovec->i_len;
+       bmp_end = (char *)&blfp->blf_data_map[blfp->blf_map_size];
+       return bmp_end <= item_end;
+}
+
 static inline int
 xfs_buf_log_format_size(
        struct xfs_buf_log_format *blfp)
index 4a054b11011a076c81357a0281e5fa2156b2bf5c..30114b5103325bd091682d3de7daaa24bf52758e 100644 (file)
@@ -61,6 +61,7 @@ void  xfs_buf_iodone_callbacks(struct xfs_buf *);
 void   xfs_buf_iodone(struct xfs_buf *, struct xfs_log_item *);
 bool   xfs_buf_resubmit_failed_buffers(struct xfs_buf *,
                                        struct list_head *);
+bool   xfs_buf_log_check_iovec(struct xfs_log_iovec *iovec);
 
 extern kmem_zone_t     *xfs_buf_item_zone;
 
index 99ec3fba45485a1aff9c665be127d102dced6a26..0d683fb963966443a3b626be0f1617f20766dba8 100644 (file)
@@ -1934,6 +1934,12 @@ xlog_recover_buffer_pass1(
        struct list_head        *bucket;
        struct xfs_buf_cancel   *bcp;
 
+       if (!xfs_buf_log_check_iovec(&item->ri_buf[0])) {
+               xfs_err(log->l_mp, "bad buffer log item size (%d)",
+                               item->ri_buf[0].i_len);
+               return -EFSCORRUPTED;
+       }
+
        /*
         * If this isn't a cancel buffer item, then just return.
         */