2018-06-06 02:42:14 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
2005-11-02 03:58:39 +00:00
|
|
|
* Copyright (c) 2000-2005 Silicon Graphics, Inc.
|
|
|
|
* All Rights Reserved.
|
2005-04-16 22:20:36 +00:00
|
|
|
*/
|
|
|
|
#ifndef __XFS_TYPES_H__
|
|
|
|
#define __XFS_TYPES_H__
|
|
|
|
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef uint32_t prid_t; /* project ID */
|
2013-08-12 10:49:31 +00:00
|
|
|
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef uint32_t xfs_agblock_t; /* blockno in alloc. group */
|
|
|
|
typedef uint32_t xfs_agino_t; /* inode # within allocation grp */
|
|
|
|
typedef uint32_t xfs_extlen_t; /* extent length in blocks */
|
|
|
|
typedef uint32_t xfs_agnumber_t; /* allocation group number */
|
2021-11-16 07:28:40 +00:00
|
|
|
typedef uint64_t xfs_extnum_t; /* # of extents in a file */
|
|
|
|
typedef uint32_t xfs_aextnum_t; /* # extents in an attribute fork */
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef int64_t xfs_fsize_t; /* bytes in a file */
|
|
|
|
typedef uint64_t xfs_ufsize_t; /* unsigned bytes in a file */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef int32_t xfs_suminfo_t; /* type of bitmap summary info */
|
2018-05-31 16:07:20 +00:00
|
|
|
typedef uint32_t xfs_rtword_t; /* word type for bitmap manipulations */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef int64_t xfs_lsn_t; /* log sequence number */
|
2021-06-18 15:21:52 +00:00
|
|
|
typedef int64_t xfs_csn_t; /* CIL sequence number */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef uint32_t xfs_dablk_t; /* dir/attr block number (in file) */
|
|
|
|
typedef uint32_t xfs_dahash_t; /* dir/attr hash value */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef uint64_t xfs_fsblock_t; /* blockno in filesystem (agno|agbno) */
|
|
|
|
typedef uint64_t xfs_rfsblock_t; /* blockno in filesystem (raw) */
|
|
|
|
typedef uint64_t xfs_rtblock_t; /* extent (block) in realtime area */
|
|
|
|
typedef uint64_t xfs_fileoff_t; /* block number in a file */
|
|
|
|
typedef uint64_t xfs_filblks_t; /* number of blocks in a file */
|
2005-04-16 22:20:36 +00:00
|
|
|
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef int64_t xfs_srtblock_t; /* signed version of xfs_rtblock_t */
|
2012-04-23 05:58:58 +00:00
|
|
|
|
2017-10-18 04:37:33 +00:00
|
|
|
/*
|
|
|
|
* New verifiers will return the instruction address of the failing check.
|
|
|
|
* NULL means everything is ok.
|
|
|
|
*/
|
|
|
|
typedef void * xfs_failaddr_t;
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* Null values for the types.
|
|
|
|
*/
|
|
|
|
#define NULLFSBLOCK ((xfs_fsblock_t)-1)
|
|
|
|
#define NULLRFSBLOCK ((xfs_rfsblock_t)-1)
|
|
|
|
#define NULLRTBLOCK ((xfs_rtblock_t)-1)
|
|
|
|
#define NULLFILEOFF ((xfs_fileoff_t)-1)
|
|
|
|
|
|
|
|
#define NULLAGBLOCK ((xfs_agblock_t)-1)
|
|
|
|
#define NULLAGNUMBER ((xfs_agnumber_t)-1)
|
|
|
|
|
|
|
|
#define NULLCOMMITLSN ((xfs_lsn_t)-1)
|
|
|
|
|
2012-04-23 05:58:58 +00:00
|
|
|
#define NULLFSINO ((xfs_ino_t)-1)
|
|
|
|
#define NULLAGINO ((xfs_agino_t)-1)
|
|
|
|
|
2012-06-22 08:50:07 +00:00
|
|
|
/*
|
|
|
|
* Minimum and maximum blocksize and sectorsize.
|
|
|
|
* The blocksize upper limit is pretty much arbitrary.
|
|
|
|
* The sectorsize upper limit is due to sizeof(sb_sectsize).
|
2016-11-09 01:11:12 +00:00
|
|
|
* CRC enable filesystems use 512 byte inodes, meaning 512 byte block sizes
|
|
|
|
* cannot be used.
|
2012-06-22 08:50:07 +00:00
|
|
|
*/
|
|
|
|
#define XFS_MIN_BLOCKSIZE_LOG 9 /* i.e. 512 bytes */
|
|
|
|
#define XFS_MAX_BLOCKSIZE_LOG 16 /* i.e. 65536 bytes */
|
|
|
|
#define XFS_MIN_BLOCKSIZE (1 << XFS_MIN_BLOCKSIZE_LOG)
|
|
|
|
#define XFS_MAX_BLOCKSIZE (1 << XFS_MAX_BLOCKSIZE_LOG)
|
2016-11-09 01:11:12 +00:00
|
|
|
#define XFS_MIN_CRC_BLOCKSIZE (1 << (XFS_MIN_BLOCKSIZE_LOG + 1))
|
2012-06-22 08:50:07 +00:00
|
|
|
#define XFS_MIN_SECTORSIZE_LOG 9 /* i.e. 512 bytes */
|
|
|
|
#define XFS_MAX_SECTORSIZE_LOG 15 /* i.e. 32768 bytes */
|
|
|
|
#define XFS_MIN_SECTORSIZE (1 << XFS_MIN_SECTORSIZE_LOG)
|
|
|
|
#define XFS_MAX_SECTORSIZE (1 << XFS_MAX_SECTORSIZE_LOG)
|
|
|
|
|
2013-08-12 10:49:23 +00:00
|
|
|
/*
|
|
|
|
* Inode fork identifiers.
|
|
|
|
*/
|
|
|
|
#define XFS_DATA_FORK 0
|
|
|
|
#define XFS_ATTR_FORK 1
|
2016-10-03 16:11:32 +00:00
|
|
|
#define XFS_COW_FORK 2
|
2013-08-12 10:49:23 +00:00
|
|
|
|
2021-08-17 20:09:26 +00:00
|
|
|
#define XFS_WHICHFORK_STRINGS \
|
|
|
|
{ XFS_DATA_FORK, "data" }, \
|
|
|
|
{ XFS_ATTR_FORK, "attr" }, \
|
|
|
|
{ XFS_COW_FORK, "cow" }
|
|
|
|
|
2005-11-01 23:34:53 +00:00
|
|
|
/*
|
|
|
|
* Min numbers of data/attr fork btree root pointers.
|
|
|
|
*/
|
|
|
|
#define MINDBTPTRS 3
|
|
|
|
#define MINABTPTRS 2
|
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
/*
|
|
|
|
* MAXNAMELEN is the length (including the terminating null) of
|
|
|
|
* the longest permissible file (component) name.
|
|
|
|
*/
|
|
|
|
#define MAXNAMELEN 256
|
|
|
|
|
2018-12-18 22:32:29 +00:00
|
|
|
/*
|
|
|
|
* This enum is used in string mapping in xfs_trace.h; please keep the
|
|
|
|
* TRACE_DEFINE_ENUMs for it up to date.
|
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
typedef enum {
|
|
|
|
XFS_LOOKUP_EQi, XFS_LOOKUP_LEi, XFS_LOOKUP_GEi
|
|
|
|
} xfs_lookup_t;
|
|
|
|
|
2018-12-18 22:32:30 +00:00
|
|
|
#define XFS_AG_BTREE_CMP_FORMAT_STR \
|
|
|
|
{ XFS_LOOKUP_EQi, "eq" }, \
|
|
|
|
{ XFS_LOOKUP_LEi, "le" }, \
|
|
|
|
{ XFS_LOOKUP_GEi, "ge" }
|
|
|
|
|
2018-12-18 22:32:31 +00:00
|
|
|
/*
|
2018-12-18 22:32:31 +00:00
|
|
|
* This enum is used in string mapping in xfs_trace.h and scrub/trace.h;
|
|
|
|
* please keep the TRACE_DEFINE_ENUMs for it up to date.
|
2018-12-18 22:32:31 +00:00
|
|
|
*/
|
2005-04-16 22:20:36 +00:00
|
|
|
typedef enum {
|
2016-08-03 01:30:32 +00:00
|
|
|
XFS_BTNUM_BNOi, XFS_BTNUM_CNTi, XFS_BTNUM_RMAPi, XFS_BTNUM_BMAPi,
|
2016-10-03 16:11:16 +00:00
|
|
|
XFS_BTNUM_INOi, XFS_BTNUM_FINOi, XFS_BTNUM_REFCi, XFS_BTNUM_MAX
|
2005-04-16 22:20:36 +00:00
|
|
|
} xfs_btnum_t;
|
|
|
|
|
2018-12-18 22:32:31 +00:00
|
|
|
#define XFS_BTNUM_STRINGS \
|
|
|
|
{ XFS_BTNUM_BNOi, "bnobt" }, \
|
|
|
|
{ XFS_BTNUM_CNTi, "cntbt" }, \
|
|
|
|
{ XFS_BTNUM_RMAPi, "rmapbt" }, \
|
|
|
|
{ XFS_BTNUM_BMAPi, "bmbt" }, \
|
|
|
|
{ XFS_BTNUM_INOi, "inobt" }, \
|
|
|
|
{ XFS_BTNUM_FINOi, "finobt" }, \
|
|
|
|
{ XFS_BTNUM_REFCi, "refcbt" }
|
|
|
|
|
2008-04-10 02:22:07 +00:00
|
|
|
struct xfs_name {
|
2010-01-19 23:44:58 +00:00
|
|
|
const unsigned char *name;
|
|
|
|
int len;
|
2013-08-12 10:50:09 +00:00
|
|
|
int type;
|
2008-04-10 02:22:07 +00:00
|
|
|
};
|
|
|
|
|
2013-08-12 10:49:26 +00:00
|
|
|
/*
|
|
|
|
* uid_t and gid_t are hard-coded to 32 bits in the inode.
|
|
|
|
* Hence, an 'id' in a dquot is 32 bits..
|
|
|
|
*/
|
2017-06-16 18:00:05 +00:00
|
|
|
typedef uint32_t xfs_dqid_t;
|
2013-08-12 10:49:26 +00:00
|
|
|
|
2013-08-12 10:49:29 +00:00
|
|
|
/*
|
|
|
|
* Constants for bit manipulations.
|
|
|
|
*/
|
|
|
|
#define XFS_NBBYLOG 3 /* log2(NBBY) */
|
|
|
|
#define XFS_WORDLOG 2 /* log2(sizeof(xfs_rtword_t)) */
|
|
|
|
#define XFS_NBWORDLOG (XFS_NBBYLOG + XFS_WORDLOG)
|
|
|
|
#define XFS_NBWORD (1 << XFS_NBWORDLOG)
|
|
|
|
#define XFS_WORDMASK ((1 << XFS_WORDLOG) - 1)
|
|
|
|
|
2017-11-03 17:34:43 +00:00
|
|
|
struct xfs_iext_cursor {
|
2017-11-03 17:34:46 +00:00
|
|
|
struct xfs_iext_leaf *leaf;
|
|
|
|
int pos;
|
2017-11-03 17:34:43 +00:00
|
|
|
};
|
2013-08-12 10:49:29 +00:00
|
|
|
|
2017-11-03 17:34:47 +00:00
|
|
|
typedef enum {
|
|
|
|
XFS_EXT_NORM, XFS_EXT_UNWRITTEN,
|
|
|
|
} xfs_exntst_t;
|
|
|
|
|
|
|
|
typedef struct xfs_bmbt_irec
|
|
|
|
{
|
|
|
|
xfs_fileoff_t br_startoff; /* starting file offset */
|
|
|
|
xfs_fsblock_t br_startblock; /* starting block number */
|
|
|
|
xfs_filblks_t br_blockcount; /* number of blocks */
|
|
|
|
xfs_exntst_t br_state; /* extent state */
|
|
|
|
} xfs_bmbt_irec_t;
|
|
|
|
|
xfs: track cow/shared record domains explicitly in xfs_refcount_irec
Just prior to committing the reflink code into upstream, the xfs
maintainer at the time requested that I find a way to shard the refcount
records into two domains -- one for records tracking shared extents, and
a second for tracking CoW staging extents. The idea here was to
minimize mount time CoW reclamation by pushing all the CoW records to
the right edge of the keyspace, and it was accomplished by setting the
upper bit in rc_startblock. We don't allow AGs to have more than 2^31
blocks, so the bit was free.
Unfortunately, this was a very late addition to the codebase, so most of
the refcount record processing code still treats rc_startblock as a u32
and pays no attention to whether or not the upper bit (the cow flag) is
set. This is a weakness is theoretically exploitable, since we're not
fully validating the incoming metadata records.
Fuzzing demonstrates practical exploits of this weakness. If the cow
flag of a node block key record is corrupted, a lookup operation can go
to the wrong record block and start returning records from the wrong
cow/shared domain. This causes the math to go all wrong (since cow
domain is still implicit in the upper bit of rc_startblock) and we can
crash the kernel by tricking xfs into jumping into a nonexistent AG and
tripping over xfs_perag_get(mp, <nonexistent AG>) returning NULL.
To fix this, start tracking the domain as an explicit part of struct
xfs_refcount_irec, adjust all refcount functions to check the domain
of a returned record, and alter the function definitions to accept them
where necessary.
Found by fuzzing keys[2].cowflag = add in xfs/464.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-10-10 16:06:24 +00:00
|
|
|
enum xfs_refc_domain {
|
|
|
|
XFS_REFC_DOMAIN_SHARED = 0,
|
|
|
|
XFS_REFC_DOMAIN_COW,
|
|
|
|
};
|
|
|
|
|
2022-10-26 21:23:58 +00:00
|
|
|
#define XFS_REFC_DOMAIN_STRINGS \
|
|
|
|
{ XFS_REFC_DOMAIN_SHARED, "shared" }, \
|
|
|
|
{ XFS_REFC_DOMAIN_COW, "cow" }
|
|
|
|
|
2022-10-10 15:47:59 +00:00
|
|
|
struct xfs_refcount_irec {
|
|
|
|
xfs_agblock_t rc_startblock; /* starting block number */
|
|
|
|
xfs_extlen_t rc_blockcount; /* count of free blocks */
|
|
|
|
xfs_nlink_t rc_refcount; /* number of inodes linked here */
|
xfs: track cow/shared record domains explicitly in xfs_refcount_irec
Just prior to committing the reflink code into upstream, the xfs
maintainer at the time requested that I find a way to shard the refcount
records into two domains -- one for records tracking shared extents, and
a second for tracking CoW staging extents. The idea here was to
minimize mount time CoW reclamation by pushing all the CoW records to
the right edge of the keyspace, and it was accomplished by setting the
upper bit in rc_startblock. We don't allow AGs to have more than 2^31
blocks, so the bit was free.
Unfortunately, this was a very late addition to the codebase, so most of
the refcount record processing code still treats rc_startblock as a u32
and pays no attention to whether or not the upper bit (the cow flag) is
set. This is a weakness is theoretically exploitable, since we're not
fully validating the incoming metadata records.
Fuzzing demonstrates practical exploits of this weakness. If the cow
flag of a node block key record is corrupted, a lookup operation can go
to the wrong record block and start returning records from the wrong
cow/shared domain. This causes the math to go all wrong (since cow
domain is still implicit in the upper bit of rc_startblock) and we can
crash the kernel by tricking xfs into jumping into a nonexistent AG and
tripping over xfs_perag_get(mp, <nonexistent AG>) returning NULL.
To fix this, start tracking the domain as an explicit part of struct
xfs_refcount_irec, adjust all refcount functions to check the domain
of a returned record, and alter the function definitions to accept them
where necessary.
Found by fuzzing keys[2].cowflag = add in xfs/464.
Signed-off-by: Darrick J. Wong <djwong@kernel.org>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
2022-10-10 16:06:24 +00:00
|
|
|
enum xfs_refc_domain rc_domain; /* shared or cow staging extent? */
|
2022-10-10 15:47:59 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#define XFS_RMAP_ATTR_FORK (1 << 0)
|
|
|
|
#define XFS_RMAP_BMBT_BLOCK (1 << 1)
|
|
|
|
#define XFS_RMAP_UNWRITTEN (1 << 2)
|
|
|
|
#define XFS_RMAP_KEY_FLAGS (XFS_RMAP_ATTR_FORK | \
|
|
|
|
XFS_RMAP_BMBT_BLOCK)
|
|
|
|
#define XFS_RMAP_REC_FLAGS (XFS_RMAP_UNWRITTEN)
|
|
|
|
struct xfs_rmap_irec {
|
|
|
|
xfs_agblock_t rm_startblock; /* extent start block */
|
|
|
|
xfs_extlen_t rm_blockcount; /* extent length */
|
|
|
|
uint64_t rm_owner; /* extent owner */
|
|
|
|
uint64_t rm_offset; /* offset within the owner */
|
|
|
|
unsigned int rm_flags; /* state flags */
|
|
|
|
};
|
|
|
|
|
2019-08-26 19:08:10 +00:00
|
|
|
/* per-AG block reservation types */
|
|
|
|
enum xfs_ag_resv_type {
|
|
|
|
XFS_AG_RESV_NONE = 0,
|
|
|
|
XFS_AG_RESV_AGFL,
|
|
|
|
XFS_AG_RESV_METADATA,
|
|
|
|
XFS_AG_RESV_RMAPBT,
|
|
|
|
};
|
|
|
|
|
2023-04-12 02:00:10 +00:00
|
|
|
/* Results of scanning a btree keyspace to check occupancy. */
|
|
|
|
enum xbtree_recpacking {
|
|
|
|
/* None of the keyspace maps to records. */
|
|
|
|
XBTREE_RECPACKING_EMPTY = 0,
|
|
|
|
|
|
|
|
/* Some, but not all, of the keyspace maps to records. */
|
|
|
|
XBTREE_RECPACKING_SPARSE,
|
|
|
|
|
|
|
|
/* The entire keyspace maps to records. */
|
|
|
|
XBTREE_RECPACKING_FULL,
|
|
|
|
};
|
|
|
|
|
2018-06-07 14:53:33 +00:00
|
|
|
/*
|
|
|
|
* Type verifier functions
|
|
|
|
*/
|
|
|
|
struct xfs_mount;
|
|
|
|
|
|
|
|
bool xfs_verify_fsbno(struct xfs_mount *mp, xfs_fsblock_t fsbno);
|
2020-12-04 21:20:00 +00:00
|
|
|
bool xfs_verify_fsbext(struct xfs_mount *mp, xfs_fsblock_t fsbno,
|
|
|
|
xfs_fsblock_t len);
|
2018-06-07 14:53:33 +00:00
|
|
|
|
|
|
|
bool xfs_verify_ino(struct xfs_mount *mp, xfs_ino_t ino);
|
|
|
|
bool xfs_internal_inum(struct xfs_mount *mp, xfs_ino_t ino);
|
|
|
|
bool xfs_verify_dir_ino(struct xfs_mount *mp, xfs_ino_t ino);
|
|
|
|
bool xfs_verify_rtbno(struct xfs_mount *mp, xfs_rtblock_t rtbno);
|
2020-12-04 21:24:22 +00:00
|
|
|
bool xfs_verify_rtext(struct xfs_mount *mp, xfs_rtblock_t rtbno,
|
|
|
|
xfs_rtblock_t len);
|
2018-07-26 17:10:42 +00:00
|
|
|
bool xfs_verify_icount(struct xfs_mount *mp, unsigned long long icount);
|
2019-02-01 17:08:53 +00:00
|
|
|
bool xfs_verify_dablk(struct xfs_mount *mp, xfs_fileoff_t off);
|
2019-04-26 01:26:24 +00:00
|
|
|
void xfs_icount_range(struct xfs_mount *mp, unsigned long long *min,
|
|
|
|
unsigned long long *max);
|
2020-12-04 21:28:35 +00:00
|
|
|
bool xfs_verify_fileoff(struct xfs_mount *mp, xfs_fileoff_t off);
|
|
|
|
bool xfs_verify_fileext(struct xfs_mount *mp, xfs_fileoff_t off,
|
|
|
|
xfs_fileoff_t len);
|
2018-06-07 14:53:33 +00:00
|
|
|
|
2005-04-16 22:20:36 +00:00
|
|
|
#endif /* __XFS_TYPES_H__ */
|