]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
btf: Protect BTF_KIND_INFO against invalid kind
authorWill Hawkins <hawkinsw@obs.cr>
Mon, 29 Jul 2024 14:42:48 +0000 (10:42 -0400)
committerDavid Faust <david.faust@oracle.com>
Fri, 9 Aug 2024 15:55:23 +0000 (08:55 -0700)
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>
include/btf.h

index 3f45ffb0b6bbd2b839390edff0ae3912098190de..0c3e1a1cf51858277e464d2220e8d6b95ce6b883 100644 (file)
@@ -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.  */