aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWill Hawkins <hawkinsw@obs.cr>2024-07-29 10:42:48 -0400
committerDavid Faust <david.faust@oracle.com>2024-08-09 08:55:23 -0700
commitd0bc1cbf6a8938220f42d8102031fd6f6644e171 (patch)
treed410fde5c6894a13c09dd609d39562bb98533948
parent786ebbd6058540b2110da16a693f0c582c11413c (diff)
downloadgcc-d0bc1cbf6a8938220f42d8102031fd6f6644e171.zip
gcc-d0bc1cbf6a8938220f42d8102031fd6f6644e171.tar.gz
gcc-d0bc1cbf6a8938220f42d8102031fd6f6644e171.tar.bz2
btf: Protect BTF_KIND_INFO against invalid kind
If the user provides a kind value that is more than 5 bits, the BTF_KIND_INFO macro would emit incorrect values for info (by clobbering values of the kind flag). Tested on x86_64-redhat-linux. include/ChangeLog: * btf.h (BTF_TYPE_INFO): Protect against user providing invalid kind. Signed-off-by: Will Hawkins <hawkinsw@obs.cr>
-rw-r--r--include/btf.h4
1 files changed, 2 insertions, 2 deletions
diff --git a/include/btf.h b/include/btf.h
index 3f45ffb..0c3e1a1 100644
--- a/include/btf.h
+++ b/include/btf.h
@@ -82,7 +82,7 @@ struct btf_type
};
};
-/* The folloing macros access the information encoded in btf_type.info. */
+/* The following macros access the information encoded in btf_type.info. */
/* Type kind. See below. */
#define BTF_INFO_KIND(info) (((info) >> 24) & 0x1f)
/* Number of entries of variable length data following certain type kinds.
@@ -95,7 +95,7 @@ struct btf_type
/* Encoding for struct btf_type.info. */
#define BTF_TYPE_INFO(kind, kflag, vlen) \
- ((((kflag) ? 1 : 0 ) << 31) | ((kind) << 24) | ((vlen) & 0xffff))
+ ((((kflag) ? 1 : 0 ) << 31) | ((kind & 0x1f) << 24) | ((vlen) & 0xffff))
#define BTF_KIND_UNKN 0 /* Unknown or invalid. */
#define BTF_KIND_INT 1 /* Integer. */