]> xenbits.xensource.com Git - xen.git/commitdiff
libfsimage/xfs: Add compile-time check to libfsimage
authorAlejandro Vallejo <alejandro.vallejo@cloud.com>
Thu, 14 Sep 2023 12:22:53 +0000 (13:22 +0100)
committerAndrew Cooper <andrew.cooper3@citrix.com>
Wed, 11 Oct 2023 05:36:50 +0000 (06:36 +0100)
Adds the common tools include folder to the -I compile flags
of libfsimage. This allows us to use:
  xen-tools/common-macros.h:BUILD_BUG_ON()

With it, statically assert a sanitized "blocklog - SECTOR_BITS" cannot
underflow.

This is part of XSA-443 / CVE-2023-34325

Signed-off-by: Alejandro Vallejo <alejandro.vallejo@cloud.com>
Reviewed-by: Jan Beulich <jbeulich@suse.com>
tools/libfsimage/common.mk
tools/libfsimage/xfs/fsys_xfs.c

index 4fc8c66795994876e9ff77876fdf98142c5a0fa0..e4336837d045a7fc7b1f63665cbb173a48dc7389 100644 (file)
@@ -1,7 +1,7 @@
 include $(XEN_ROOT)/tools/Rules.mk
 
 FSDIR := $(libdir)/xenfsimage
-CFLAGS += -Wno-unknown-pragmas -I$(XEN_ROOT)/tools/libfsimage/common/ -DFSIMAGE_FSDIR=\"$(FSDIR)\"
+CFLAGS += -Wno-unknown-pragmas -I$(XEN_ROOT)/tools/libfsimage/common/ $(CFLAGS_xeninclude) -DFSIMAGE_FSDIR=\"$(FSDIR)\"
 CFLAGS += -D_GNU_SOURCE
 LDFLAGS += -L../common/
 
index b5c53d3d222b4577a3905b366b3658a989f2a551..e98b367901a8ab80d9a2d33f34ab966d25feaa6f 100644 (file)
@@ -20,6 +20,7 @@
 #include <stddef.h>
 #include <stdbool.h>
 #include <xenfsimage_grub.h>
+#include <xen-tools/common-macros.h>
 #include "xfs.h"
 
 #define MAX_LINK_COUNT 8
@@ -475,9 +476,10 @@ xfs_mount (fsi_file_t *ffi, const char *options)
        xfs.agblklog = super.sb_agblklog;
 
        /* Derived from sanitized parameters */
+       BUILD_BUG_ON(XFS_SB_BLOCKLOG_MIN < SECTOR_BITS);
+       xfs.bdlog = super.sb_blocklog - SECTOR_BITS;
        xfs.bsize = 1 << super.sb_blocklog;
        xfs.blklog = super.sb_blocklog;
-       xfs.bdlog = super.sb_blocklog - SECTOR_BITS;
        xfs.isize = 1 << super.sb_inodelog;
        xfs.dirbsize = 1 << (super.sb_blocklog + super.sb_dirblklog);
        xfs.inopblog = super.sb_blocklog - super.sb_inodelog;