Message ID | 20240729144248.911058-1-hawkinsw@obs.cr |
---|---|
State | New |
Headers | show |
Series | btf: Protect BTF_KIND_INFO against invalid kind | expand |
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. */
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. */
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 --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. */
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(-)