xfs: xfs_trans->t_flags overflow
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
@@ -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
@@ -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)
fs/xfs/xfs_log_priv.h typedef struct xlog_ticket {
Quoted 31 lines · Wengang Wang
Current
xfs_trans->t_flagsis of typeuint8_t(8 bits long). We are storingXFS_TRANS_LOWMODE, which is0x100, tot_flags. The highest set bit ofXFS_TRANS_LOWMODEoverflows.Fix:
Change the type fromuint8_ttouint16_t.Signed-off-by Wengang Wang <[email protected]>--- 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@@ -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@@ -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
-1int 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)
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_flagsis of typeuint8_t(8 bits long). We are storingXFS_TRANS_LOWMODE, which is0x100, tot_flags. The highest set bit ofXFS_TRANS_LOWMODEoverflows.Fix:
Change the type fromuint8_ttouint16_t.Signed-off-by Wengang Wang <[email protected]>---
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@@ -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@@ -151,7 +151,7 @@ typedef struct xlog_ticket {Huh?
xlog_ticket!=xfs_trans.typedef struct
xfs_trans{
unsigned intt_magic; /* magic number */
...
unsigned intt_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 */
chart_ocnt; /* original unit count */
chart_cnt; /* current unit count */
-uint8_tt_flags; /* properties of reservation */
+uint16_tt_flags; /* properties of reservation */ intt_iclog_hdrs; /* iclog hdrs int_curr_res*/ }xlog_ticket_t;Signature · 1 line
2.21.0 (Apple Git-122.2)