Skip to contentSkip to conversation

xfs: xfs_trans->t_flags overflow

PATCH In review Wengang Wang 2 participants 3 messages Jul 13, 2023 XFS filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfs: xfs_trans->t_flags overflow

Current xfs_trans->t_flags is of type uint8_t (8 bits long). We are storing XFS_TRANS_LOWMODE, which is 0x100, to t_flags. The highest set bit of XFS_TRANS_LOWMODE overflows.

Fix:
Change the type from uint8_t to uint16_t.

---
 fs/xfs/libxfs/xfs_shared.h | 2 +-
 fs/xfs/xfs_log_priv.h      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_shared.h +1 -1
index c4381388c0c1..5532d6480d53 100644
@@ -82,7 +82,7 @@ void	xfs_log_get_max_trans_res(struct xfs_mount *mp,
  * for free space from AG 0. If the correct transaction reservations have been
  * made then this algorithm will eventually find all the space it needs.
  */
-#define XFS_TRANS_LOWMODE	0x100	/* allocate in low space mode */
+#define XFS_TRANS_LOWMODE	(1u << 8)	/* allocate in low space mode */
 
 /*
  * Field values for xfs_trans_mod_sb.
fs/xfs/xfs_log_priv.h +1 -1
index 1bd2963e8fbd..e4b03edbc87b 100644
@@ -151,7 +151,7 @@ typedef struct xlog_ticket {
 	int			t_unit_res;	/* unit reservation */
 	char			t_ocnt;		/* original unit count */
 	char			t_cnt;		/* current unit count */
-	uint8_t			t_flags;	/* properties of reservation */
+	uint16_t		t_flags;	/* properties of reservation */
 	int			t_iclog_hdrs;	/* iclog hdrs in t_curr_res */
 } xlog_ticket_t;
 
Signature · 1 line
2.21.0 (Apple Git-122.2)
#1 lore raw

fs/xfs/xfs_log_priv.h typedef struct xlog_ticket {

Quoted 31 lines · Wengang Wang

Current xfs_trans->t_flags is of type uint8_t (8 bits long). We are storing XFS_TRANS_LOWMODE, which is 0x100, to t_flags. The highest set bit of XFS_TRANS_LOWMODE overflows.

Fix:
Change the type from uint8_t to uint16_t.

---
 fs/xfs/libxfs/xfs_shared.h | 2 +-
 fs/xfs/xfs_log_priv.h      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_shared.h +1 -1
index c4381388c0c1..5532d6480d53 100644
@@ -82,7 +82,7 @@ void	xfs_log_get_max_trans_res(struct xfs_mount *mp,
  * for free space from AG 0. If the correct transaction reservations have been
  * made then this algorithm will eventually find all the space it needs.
  */
-#define XFS_TRANS_LOWMODE	0x100	/* allocate in low space mode */
+#define XFS_TRANS_LOWMODE	(1u << 8)	/* allocate in low space mode */
 
 /*
  * Field values for xfs_trans_mod_sb.
fs/xfs/xfs_log_priv.h +0 -0
index 1bd2963e8fbd..e4b03edbc87b 100644
@@ -151,7 +151,7 @@ typedef struct xlog_ticket {

Huh? xlog_ticket != xfs_trans.

typedef struct xfs_trans {
	unsigned int		t_magic;	/* magic number */
	...
	unsigned int		t_flags;	/* misc flags */
	...
};

This declaration looks wide enough to me. The only place I see xlog_ticket.t_flags used is to set, clear, and test XLOG_TIC_PERM_RESERV.

--D

Quoted 11 lines
fs/xfs/xfs_log_priv.h +1 -1
 	int			t_unit_res;	/* unit reservation */
 	char			t_ocnt;		/* original unit count */
 	char			t_cnt;		/* current unit count */
-	uint8_t			t_flags;	/* properties of reservation */
+	uint16_t		t_flags;	/* properties of reservation */
 	int			t_iclog_hdrs;	/* iclog hdrs in t_curr_res */
 } xlog_ticket_t;
 
Signature · 1 line
2.21.0 (Apple Git-122.2)
#2 lore raw
Quoted 46 lines · Darrick J. Wong

fs/xfs/xfs_log_priv.h typedef struct xlog_ticket {

Quoted 31 lines · Wengang Wang

Current xfs_trans->t_flags is of type uint8_t (8 bits long). We are storing XFS_TRANS_LOWMODE, which is 0x100, to t_flags. The highest set bit of XFS_TRANS_LOWMODE overflows.

Fix:
Change the type from uint8_t to uint16_t.

---
fs/xfs/libxfs/xfs_shared.h | 2 +-
fs/xfs/xfs_log_priv.h | 2 +-

2 files changed, 2 insertions(+), 2 deletions(-)
fs/xfs/libxfs/xfs_shared.h +1 -1
index c4381388c0c1..5532d6480d53 100644
@@ -82,7 +82,7 @@ void xfs_log_get_max_trans_res(struct xfs_mount *mp,
 * for free space from AG 0. If the correct transaction reservations have been
 * made then this algorithm will eventually find all the space it needs.
 */
-#define XFS_TRANS_LOWMODE 0x100 /* allocate in low space mode */
+#define XFS_TRANS_LOWMODE (1u << 8) /* allocate in low space mode */
 
 /*
 * Field values for xfs_trans_mod_sb.
fs/xfs/xfs_log_priv.h +0 -0
index 1bd2963e8fbd..e4b03edbc87b 100644
@@ -151,7 +151,7 @@ typedef struct xlog_ticket {

Huh? xlog_ticket != xfs_trans.

typedef struct xfs_trans {
unsigned int t_magic; /* magic number */
...
unsigned int t_flags; /* misc flags */
...
};

Quoted 3 lines

This declaration looks wide enough to me. The only place I see xlog_ticket.t_flags used is to set, clear, and test XLOG_TIC_PERM_RESERV.

Oh, yes, I misread it. Sorry, pls ignore.

thanks,
wengang

Quoted 13 lines

--D

Quoted 11 lines

int t_unit_res; /* unit reservation */
char t_ocnt; /* original unit count */
char t_cnt; /* current unit count */
- uint8_t t_flags; /* properties of reservation */
+ uint16_t t_flags; /* properties of reservation */ int t_iclog_hdrs; /* iclog hdrs in t_curr_res */ } xlog_ticket_t;

Signature · 1 line
2.21.0 (Apple Git-122.2)