diff mbox series

btf: Protect BTF_KIND_INFO against invalid kind

Message ID 20240729144248.911058-1-hawkinsw@obs.cr
State New
Headers show
Series btf: Protect BTF_KIND_INFO against invalid kind | expand

Commit Message

Will Hawkins July 29, 2024, 2:42 p.m. UTC
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(-)

Comments

David Faust July 29, 2024, 6:14 p.m. UTC | #1
On 7/29/24 07:42, Will Hawkins wrote:
> 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.

OK, thanks.

> 
> 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.  */
Will Hawkins Aug. 7, 2024, 5:19 p.m. UTC | #2
On Mon, Jul 29, 2024 at 2:14 PM David Faust <david.faust@oracle.com> wrote:
>
>
> On 7/29/24 07:42, Will Hawkins wrote:
> > 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.
>
> OK, thanks.

Just let me know if there is anything else that you need from me!
Will

>
> >
> > 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.  */
David Faust Aug. 9, 2024, 3:58 p.m. UTC | #3
On 8/7/24 10:19, Will Hawkins wrote:
> On Mon, Jul 29, 2024 at 2:14 PM David Faust <david.faust@oracle.com> wrote:
>>
>>
>> On 7/29/24 07:42, Will Hawkins wrote:
>>> 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.
>>
>> OK, thanks.
> 
> Just let me know if there is anything else that you need from me!
> Will

I just checked this in on your behalf.  Apologies for the delay.
Thanks!

> 
>>
>>>
>>> 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.  */
diff mbox series

Patch

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.  */