public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] btf: Protect BTF_KIND_INFO against invalid kind
@ 2024-07-29 14:42 Will Hawkins
  2024-07-29 18:14 ` David Faust
  0 siblings, 1 reply; 4+ messages in thread
From: Will Hawkins @ 2024-07-29 14:42 UTC (permalink / raw)
  To: gcc-patches; +Cc: Will Hawkins

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>
---

Notes:
     I have a small out-of-tree test but was not sure whether a) it should
		 be included and/or b) where it should be included. If you would
		 like me to include it, please just let me know where it should go!

 include/btf.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/btf.h b/include/btf.h
index 3f45ffb0b6b..0c3e1a1cf51 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.  */
-- 
2.45.2


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2024-08-09 15:58 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-29 14:42 [PATCH] btf: Protect BTF_KIND_INFO against invalid kind Will Hawkins
2024-07-29 18:14 ` David Faust
2024-08-07 17:19   ` Will Hawkins
2024-08-09 15:58     ` David Faust

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).