* Re: [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 [not found] <00000000000049964e06041f2cbf@google.com> @ 2023-10-07 21:05 ` Eric Biggers 2023-10-09 17:29 ` Kees Cook 0 siblings, 1 reply; 5+ messages in thread From: Eric Biggers @ 2023-10-07 21:05 UTC (permalink / raw) To: Nick Terrell Cc: syzbot, clm, dsterba, josef, linux-btrfs, linux-fsdevel, linux-kernel, syzkaller-bugs, terrelln, linux-hardening Hi Nick, On Wed, Aug 30, 2023 at 12:49:53AM -0700, syzbot wrote: > UBSAN: array-index-out-of-bounds in lib/zstd/common/fse_decompress.c:345:30 > index 33 is out of range for type 'FSE_DTable[1]' (aka 'unsigned int[1]') Zstandard needs to be converted to use C99 flex-arrays instead of length-1 arrays. https://github.com/facebook/zstd/pull/3785 would fix this in upstream Zstandard, though it doesn't work well with the fact that upstream Zstandard supports C90. Not sure how you want to handle this. - Eric ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 2023-10-07 21:05 ` [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 Eric Biggers @ 2023-10-09 17:29 ` Kees Cook 2023-10-12 19:55 ` Nick Terrell 0 siblings, 1 reply; 5+ messages in thread From: Kees Cook @ 2023-10-09 17:29 UTC (permalink / raw) To: Eric Biggers Cc: Nick Terrell, syzbot, clm, dsterba, josef, linux-btrfs, linux-fsdevel, linux-kernel, syzkaller-bugs, linux-hardening On Sat, Oct 07, 2023 at 02:05:56PM -0700, Eric Biggers wrote: > Hi Nick, > > On Wed, Aug 30, 2023 at 12:49:53AM -0700, syzbot wrote: > > UBSAN: array-index-out-of-bounds in lib/zstd/common/fse_decompress.c:345:30 > > index 33 is out of range for type 'FSE_DTable[1]' (aka 'unsigned int[1]') > > Zstandard needs to be converted to use C99 flex-arrays instead of length-1 > arrays. https://github.com/facebook/zstd/pull/3785 would fix this in upstream > Zstandard, though it doesn't work well with the fact that upstream Zstandard > supports C90. Not sure how you want to handle this. For the kernel, we just need: diff --git a/lib/zstd/common/fse_decompress.c b/lib/zstd/common/fse_decompress.c index a0d06095be83..b11e87fff261 100644 --- a/lib/zstd/common/fse_decompress.c +++ b/lib/zstd/common/fse_decompress.c @@ -312,7 +312,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size typedef struct { short ncount[FSE_MAX_SYMBOL_VALUE + 1]; - FSE_DTable dtable[1]; /* Dynamically sized */ + FSE_DTable dtable[]; /* Dynamically sized */ } FSE_DecompressWksp; And if upstream wants to stay C89 compat, perhaps: #if __STDC_VERSION__ >= 199901L # define __FLEX_ARRAY_DIM /*C99*/ #else # define __FLEX_ARRAY_DIM 0 #endif and then use __FLEX_ARRAY_DIM as needed (and keep the other "-1" changes in the github commit): typedef struct { short ncount[FSE_MAX_SYMBOL_VALUE + 1]; - FSE_DTable dtable[1]; /* Dynamically sized */ + FSE_DTable dtable[__FLEX_ARRAY_DIM]; /* Dynamically sized */ } FSE_DecompressWksp; -- Kees Cook ^ permalink raw reply related [flat|nested] 5+ messages in thread
* Re: [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 2023-10-09 17:29 ` Kees Cook @ 2023-10-12 19:55 ` Nick Terrell 2023-10-12 20:13 ` Kees Cook 0 siblings, 1 reply; 5+ messages in thread From: Nick Terrell @ 2023-10-12 19:55 UTC (permalink / raw) To: Kees Cook Cc: Nick Terrell, Eric Biggers, Nick Terrell, syzbot, Chris Mason, dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-hardening@vger.kernel.org > On Oct 9, 2023, at 1:29 PM, Kees Cook <keescook@chromium.org> wrote: > > !-------------------------------------------------------------------| > This Message Is From an External Sender > > |-------------------------------------------------------------------! > > On Sat, Oct 07, 2023 at 02:05:56PM -0700, Eric Biggers wrote: >> Hi Nick, >> >> On Wed, Aug 30, 2023 at 12:49:53AM -0700, syzbot wrote: >>> UBSAN: array-index-out-of-bounds in lib/zstd/common/fse_decompress.c:345:30 >>> index 33 is out of range for type 'FSE_DTable[1]' (aka 'unsigned int[1]') >> >> Zstandard needs to be converted to use C99 flex-arrays instead of length-1 >> arrays. https://github.com/facebook/zstd/pull/3785 would fix this in upstream >> Zstandard, though it doesn't work well with the fact that upstream Zstandard >> supports C90. Not sure how you want to handle this. > > For the kernel, we just need: > > diff --git a/lib/zstd/common/fse_decompress.c b/lib/zstd/common/fse_decompress.c > index a0d06095be83..b11e87fff261 100644 > --- a/lib/zstd/common/fse_decompress.c > +++ b/lib/zstd/common/fse_decompress.c > @@ -312,7 +312,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size > > typedef struct { > short ncount[FSE_MAX_SYMBOL_VALUE + 1]; > - FSE_DTable dtable[1]; /* Dynamically sized */ > + FSE_DTable dtable[]; /* Dynamically sized */ > } FSE_DecompressWksp; Thanks Eric and Kees for the report and the fix! I am working on putting this patch up now, just need to test the fix myself to ensure I can reproduce the issue and the fix. In your opinion does this worth trying to get this patch into v6.6, or should it wait for v6.7? Best, Nick Terrell > And if upstream wants to stay C89 compat, perhaps: > > #if __STDC_VERSION__ >= 199901L > # define __FLEX_ARRAY_DIM /*C99*/ > #else > # define __FLEX_ARRAY_DIM 0 > #endif > > and then use __FLEX_ARRAY_DIM as needed (and keep the other "-1" changes > in the github commit): > > typedef struct { > short ncount[FSE_MAX_SYMBOL_VALUE + 1]; > - FSE_DTable dtable[1]; /* Dynamically sized */ > + FSE_DTable dtable[__FLEX_ARRAY_DIM]; /* Dynamically sized */ > } FSE_DecompressWksp; > > > -- > Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 2023-10-12 19:55 ` Nick Terrell @ 2023-10-12 20:13 ` Kees Cook 2023-10-12 20:23 ` Nick Terrell 0 siblings, 1 reply; 5+ messages in thread From: Kees Cook @ 2023-10-12 20:13 UTC (permalink / raw) To: Nick Terrell Cc: Eric Biggers, syzbot, Chris Mason, dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-hardening@vger.kernel.org On Thu, Oct 12, 2023 at 07:55:55PM +0000, Nick Terrell wrote: > > > On Oct 9, 2023, at 1:29 PM, Kees Cook <keescook@chromium.org> wrote: > > > > !-------------------------------------------------------------------| > > This Message Is From an External Sender > > > > |-------------------------------------------------------------------! > > > > On Sat, Oct 07, 2023 at 02:05:56PM -0700, Eric Biggers wrote: > >> Hi Nick, > >> > >> On Wed, Aug 30, 2023 at 12:49:53AM -0700, syzbot wrote: > >>> UBSAN: array-index-out-of-bounds in lib/zstd/common/fse_decompress.c:345:30 > >>> index 33 is out of range for type 'FSE_DTable[1]' (aka 'unsigned int[1]') > >> > >> Zstandard needs to be converted to use C99 flex-arrays instead of length-1 > >> arrays. https://github.com/facebook/zstd/pull/3785 would fix this in upstream > >> Zstandard, though it doesn't work well with the fact that upstream Zstandard > >> supports C90. Not sure how you want to handle this. > > > > For the kernel, we just need: > > > > diff --git a/lib/zstd/common/fse_decompress.c b/lib/zstd/common/fse_decompress.c > > index a0d06095be83..b11e87fff261 100644 > > --- a/lib/zstd/common/fse_decompress.c > > +++ b/lib/zstd/common/fse_decompress.c > > @@ -312,7 +312,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size > > > > typedef struct { > > short ncount[FSE_MAX_SYMBOL_VALUE + 1]; > > - FSE_DTable dtable[1]; /* Dynamically sized */ > > + FSE_DTable dtable[]; /* Dynamically sized */ > > } FSE_DecompressWksp; > > Thanks Eric and Kees for the report and the fix! I am working on putting this > patch up now, just need to test the fix myself to ensure I can reproduce the > issue and the fix. > > In your opinion does this worth trying to get this patch into v6.6, or should it > wait for v6.7? For all these flex array conversions we're mostly on a "slow and steady" route, so there's no rush really. I think waiting for v6.7 is fine. If anyone ends up wanting to backport it, it should be pretty clean I imagine. Thanks for getting it all landed! :) -Kees -- Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 2023-10-12 20:13 ` Kees Cook @ 2023-10-12 20:23 ` Nick Terrell 0 siblings, 0 replies; 5+ messages in thread From: Nick Terrell @ 2023-10-12 20:23 UTC (permalink / raw) To: Kees Cook Cc: Nick Terrell, Eric Biggers, syzbot, Chris Mason, dsterba@suse.com, josef@toxicpanda.com, linux-btrfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com, linux-hardening@vger.kernel.org > On Oct 12, 2023, at 4:13 PM, Kees Cook <keescook@chromium.org> wrote: > > !-------------------------------------------------------------------| > This Message Is From an External Sender > > |-------------------------------------------------------------------! > > On Thu, Oct 12, 2023 at 07:55:55PM +0000, Nick Terrell wrote: >> >>> On Oct 9, 2023, at 1:29 PM, Kees Cook <keescook@chromium.org> wrote: >>> >>> !-------------------------------------------------------------------| >>> This Message Is From an External Sender >>> >>> |-------------------------------------------------------------------! >>> >>> On Sat, Oct 07, 2023 at 02:05:56PM -0700, Eric Biggers wrote: >>>> Hi Nick, >>>> >>>> On Wed, Aug 30, 2023 at 12:49:53AM -0700, syzbot wrote: >>>>> UBSAN: array-index-out-of-bounds in lib/zstd/common/fse_decompress.c:345:30 >>>>> index 33 is out of range for type 'FSE_DTable[1]' (aka 'unsigned int[1]') >>>> >>>> Zstandard needs to be converted to use C99 flex-arrays instead of length-1 >>>> arrays. https://github.com/facebook/zstd/pull/3785 would fix this in upstream >>>> Zstandard, though it doesn't work well with the fact that upstream Zstandard >>>> supports C90. Not sure how you want to handle this. >>> >>> For the kernel, we just need: >>> >>> diff --git a/lib/zstd/common/fse_decompress.c b/lib/zstd/common/fse_decompress.c >>> index a0d06095be83..b11e87fff261 100644 >>> --- a/lib/zstd/common/fse_decompress.c >>> +++ b/lib/zstd/common/fse_decompress.c >>> @@ -312,7 +312,7 @@ size_t FSE_decompress_wksp(void* dst, size_t dstCapacity, const void* cSrc, size >>> >>> typedef struct { >>> short ncount[FSE_MAX_SYMBOL_VALUE + 1]; >>> - FSE_DTable dtable[1]; /* Dynamically sized */ >>> + FSE_DTable dtable[]; /* Dynamically sized */ >>> } FSE_DecompressWksp; >> >> Thanks Eric and Kees for the report and the fix! I am working on putting this >> patch up now, just need to test the fix myself to ensure I can reproduce the >> issue and the fix. >> >> In your opinion does this worth trying to get this patch into v6.6, or should it >> wait for v6.7? > > For all these flex array conversions we're mostly on a "slow and steady" > route, so there's no rush really. I think waiting for v6.7 is fine. If > anyone ends up wanting to backport it, it should be pretty clean > I imagine. Sounds good, thanks for the context! I’ll make sure the fix gets backported. Eric Biggers already has a PR up! [0] [0] https://github.com/facebook/zstd/pull/3785 > Thanks for getting it all landed! :) > > -Kees > > -- > Kees Cook ^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2023-10-12 20:23 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <00000000000049964e06041f2cbf@google.com>
2023-10-07 21:05 ` [syzbot] [zstd] UBSAN: array-index-out-of-bounds in FSE_decompress_wksp_body_bmi2 Eric Biggers
2023-10-09 17:29 ` Kees Cook
2023-10-12 19:55 ` Nick Terrell
2023-10-12 20:13 ` Kees Cook
2023-10-12 20:23 ` Nick Terrell
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox