diff mbox series

LTO: buffer overflow in lto_output_init_mode_table

Message ID CAHso6sMRM9YmzmpuHTeMNAd1e2PKXkCkkkdnM1-M34YqGZ8b2w@mail.gmail.com
State New
Headers show
Series LTO: buffer overflow in lto_output_init_mode_table | expand

Commit Message

Jivan Hakobyan June 22, 2023, 11:36 a.m. UTC
In the case when enabled -flto=N GCC aborted compilation.
The reason is the overflowing streamer_mode_table buffer.
It has 1 << 8 bytes but lto_output_init_mode_table() tries to fill
with MAX_MACHINE_MODE bytes.

gcc/ChangeLog:
       * tree-streamer.h (streamer_mode_table): Changed buffer size
       * tree-streamer.cc (streamer_mode_table): Likewise.

Comments

Robin Dapp June 22, 2023, 11:42 a.m. UTC | #1
Hi Jivan,

I think Pan is already on this problem.  Please see this thread:
https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622129.html

Regards
 Robin
Jivan Hakobyan June 22, 2023, 12:36 p.m. UTC | #2
Hi Robbin.

Thank you for responding.
I will defer my thread.


On Thu, Jun 22, 2023 at 3:42 PM Robin Dapp <rdapp.gcc@gmail.com> wrote:

> Hi Jivan,
>
> I think Pan is already on this problem.  Please see this thread:
> https://gcc.gnu.org/pipermail/gcc-patches/2023-June/622129.html
>
> Regards
>  Robin
>
diff mbox series

Patch

diff --git a/gcc/tree-streamer.cc b/gcc/tree-streamer.cc
index ed65a7692e3..a28ef9c7920 100644
--- a/gcc/tree-streamer.cc
+++ b/gcc/tree-streamer.cc
@@ -35,7 +35,7 @@  along with GCC; see the file COPYING3.  If not see
    During streaming in, we translate the on the disk mode using this
    table.  For normal LTO it is set to identity, for ACCEL_COMPILER
    depending on the mode_table content.  */
-unsigned char streamer_mode_table[1 << 8];
+unsigned char streamer_mode_table[MAX_MACHINE_MODE];
 
 /* Check that all the TS_* structures handled by the streamer_write_* and
    streamer_read_* routines are exactly ALL the structures defined in
diff --git a/gcc/tree-streamer.h b/gcc/tree-streamer.h
index 170d61cf20b..51a292c8d80 100644
--- a/gcc/tree-streamer.h
+++ b/gcc/tree-streamer.h
@@ -75,7 +75,7 @@  void streamer_write_tree_body (struct output_block *, tree);
 void streamer_write_integer_cst (struct output_block *, tree);
 
 /* In tree-streamer.cc.  */
-extern unsigned char streamer_mode_table[1 << 8];
+extern unsigned char streamer_mode_table[MAX_MACHINE_MODE];
 void streamer_check_handled_ts_structures (void);
 bool streamer_tree_cache_insert (struct streamer_tree_cache_d *, tree,
 				 hashval_t, unsigned *);