micropython/py
Angus Gratton 4bed614e70 py/objarray: Fix use-after-free if extending a bytearray from itself.
Two cases, one assigning to a slice.
Closes https://github.com/micropython/micropython/issues/13283

Second is extending a slice from itself, similar logic.

In both cases the problem occurs when m_renew causes realloc to move the
buffer, leaving a dangling pointer behind.

There are more complex and hard to fix cases when either argument is a
memoryview into the buffer, currently resizing to a new address breaks
memoryviews into that object.

Reproducing this bug and confirming the fix was done by running the unix
port under valgrind with GC-aware extensions.

Note in default configurations with GIL this bug exists but has no impact
(the free buffer won't be reused while the function is still executing, and
is no longer referenced after it returns).

Signed-off-by: Angus Gratton <angus@redyak.com.au>
2024-04-22 11:50:52 +10:00
..
argcheck.c py: Remove the word "yet" from exception messages. 2022-12-06 13:34:52 +11:00
asmarm.c py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. 2024-03-19 10:31:36 +11:00
asmarm.h py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. 2024-03-19 10:31:36 +11:00
asmbase.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
asmbase.h py/emit: Suppress unreachable bytecode/native code that follows jump. 2022-06-20 22:28:18 +10:00
asmthumb.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
asmthumb.h py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. 2024-03-19 10:31:36 +11:00
asmx64.c py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. 2024-03-19 10:31:36 +11:00
asmx64.h py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. 2024-03-19 10:31:36 +11:00
asmx86.c py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. 2024-03-19 10:31:36 +11:00
asmx86.h py/asm: Add ASM_NOT_REG and ASM_NEG_REG macros for unary ops. 2024-03-19 10:31:36 +11:00
asmxtensa.c py/asmxtensa: Optimise asm_xtensa_mov_reg_i32_optimised() for tiny ints. 2024-03-19 10:31:36 +11:00
asmxtensa.h py/asmxtensa: Optimise asm_xtensa_mov_reg_i32_optimised() for tiny ints. 2024-03-19 10:31:36 +11:00
bc.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
bc.h py/emitglue: Include fun_data_len in mp_raw_code_t only when saving. 2024-02-16 14:17:01 +11:00
bc0.h py: Change jump-if-x-or-pop opcodes to have unsigned offset argument. 2022-03-28 15:43:09 +11:00
binary.c py/binary: Support half-float 'e' format in struct pack/unpack. 2024-03-20 14:13:49 +11:00
binary.h py/binary: Change mp_uint_t to size_t for index, size, align args. 2019-09-02 13:14:27 +10:00
builtin.h py/makemoduledefs.py: Automatically declare delegation attr functions. 2023-06-14 19:03:46 +10:00
builtinevex.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
builtinhelp.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
builtinimport.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
compile.c py/compile: Add option to allow compiling top-level await. 2024-03-22 13:05:25 +11:00
compile.h py/compile: Add option to allow compiling top-level await. 2024-03-22 13:05:25 +11:00
dynruntime.h py/dynruntime: Add mp_binary_get_size/get_val_array/set_val_array. 2024-03-28 16:18:09 +11:00
dynruntime.mk py/dynruntime.mk: Allow building assembly source in natmods. 2022-08-11 14:00:13 +10:00
emit.h py/compile: Fix scope of assignment expression target in comprehensions. 2023-03-09 12:13:12 +11:00
emitbc.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
emitcommon.c py/compile: Fix scope of assignment expression target in comprehensions. 2023-03-09 12:13:12 +11:00
emitglue.c py/emitglue: Make mp_emit_glue_assign_native's fun_data arg a const ptr. 2024-02-22 11:27:33 +11:00
emitglue.h py/emitglue: Add explicit cast of proto_fun to uint8_t pointer. 2024-03-04 10:27:07 +11:00
emitinlinethumb.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
emitinlinextensa.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
emitnarm.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnative.c py/emitnative: Implement viper unary ops positive, negative and invert. 2024-03-19 10:31:36 +11:00
emitnthumb.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnx64.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnx86.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
emitnxtensa.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
emitnxtensawin.c py/emitnative: Access qstr values using indirection table qstr_table. 2022-05-23 15:43:06 +10:00
formatfloat.c all: Fix various spelling mistakes found by codespell 2.2.6. 2023-10-03 11:24:50 +11:00
formatfloat.h
frozenmod.c py: Rework bytecode and .mpy file format to be mostly static data. 2022-02-24 18:08:43 +11:00
frozenmod.h py/builtin: Clean up and simplify import_stat and builtin_open config. 2022-05-25 13:04:45 +10:00
gc.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
gc.h py/gc: Add "max new split" value in result of gc.mem_free(). 2023-09-15 12:19:13 +10:00
grammar.h py/compile: Implement PEP 526, syntax for variable annotations. 2020-06-16 23:18:01 +10:00
lexer.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
lexer.h py/builtinevex: Handle invalid filenames for execfile. 2023-10-12 15:17:59 +11:00
make_root_pointers.py py/make_root_pointers: Add MP_REGISTER_ROOT_POINTER parser/generator. 2022-07-18 13:48:23 +10:00
makecompresseddata.py all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
makemoduledefs.py py/makemoduledefs.py: Automatically declare delegation attr functions. 2023-06-14 19:03:46 +10:00
makeqstrdata.py py/makeqstrdata.py: Ensure that scope names get low qstr values. 2024-03-26 22:52:25 +11:00
makeqstrdefs.py py/makeqstrdefs.py: Stop generating temporary intermediate file. 2023-12-14 22:55:08 -08:00
makeversionhdr.py py/makeversionhdr.py: Reinstate MICROPY_GIT_HASH in mpversion.h. 2024-02-19 23:36:25 +11:00
malloc.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
map.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
misc.h py/misc: Remove m_new_obj[_var]_with_finaliser macros. 2024-02-20 10:33:09 +11:00
mkenv.mk windows: Use the MicroPython logo as application icon. 2023-11-07 17:22:52 +11:00
mkrules.cmake py/mkrules.mk: List hash files as byproducts. 2023-12-15 15:48:07 +11:00
mkrules.mk ports: Fix handling of paths containing spaces in Makefiles. 2024-01-24 10:43:18 +11:00
modarray.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modbuiltins.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modcmath.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modcollections.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
moderrno.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modgc.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modio.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modmath.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modmicropython.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modstruct.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modsys.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
modthread.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
mpconfig.h py/compile: Add option to allow compiling top-level await. 2024-03-22 13:05:25 +11:00
mperrno.h all: Rename UMODULE to MODULE in preprocessor/Makefile vars. 2023-06-08 17:54:11 +10:00
mphal.h ports: Fix sys.stdout.buffer.write() return value. 2023-12-22 10:32:46 +11:00
mpprint.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
mpprint.h py/mpprint: Fix formatting typo with mp_print_ext_t struct name. 2022-08-10 14:30:47 +10:00
mpstate.c
mpstate.h py/mpstate: Don't declare mp_thread_get_state(). 2024-02-29 13:33:51 +11:00
mpthread.h py/modthread: Return thread id from start_new_thread(). 2023-09-03 18:49:18 +10:00
mpz.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
mpz.h py/mpz: Fix bugs with bitwise of -0 by ensuring all 0's are positive. 2021-12-21 18:00:05 +11:00
nativeglue.c py/dynruntime: Add mp_binary_get_size/get_val_array/set_val_array. 2024-03-28 16:18:09 +11:00
nativeglue.h py/dynruntime: Add mp_binary_get_size/get_val_array/set_val_array. 2024-03-28 16:18:09 +11:00
nlr.c py/nlr: Implement jump callbacks. 2023-06-02 21:50:57 +10:00
nlr.h py/nlr: Implement jump callbacks. 2023-06-02 21:50:57 +10:00
nlraarch64.c py/nlr: Add "memory" to asm clobbers list in nlr_jump. 2024-03-25 11:52:26 +11:00
nlrmips.c py/nlr: Add "memory" to asm clobbers list in nlr_jump. 2024-03-25 11:52:26 +11:00
nlrpowerpc.c py/nlr: Add "memory" to asm clobbers list in nlr_jump. 2024-03-25 11:52:26 +11:00
nlrsetjmp.c py/nlrsetjmp: Use MP_NLR_JUMP_HEAD macro to simplify code. 2023-06-02 21:47:34 +10:00
nlrthumb.c py/nlr: Add "memory" to asm clobbers list in nlr_jump. 2024-03-25 11:52:26 +11:00
nlrx64.c py/nlr: Add "memory" to asm clobbers list in nlr_jump. 2024-03-25 11:52:26 +11:00
nlrx86.c py/nlr: Add "memory" to asm clobbers list in nlr_jump. 2024-03-25 11:52:26 +11:00
nlrxtensa.c py/nlr: Add "memory" to asm clobbers list in nlr_jump. 2024-03-25 11:52:26 +11:00
obj.c py/obj: Introduce mp_obj_malloc_with_finaliser to allocate and set type. 2024-02-20 10:32:51 +11:00
obj.h py/obj: Fix initialiser order in MP_DEFINE_CONST_OBJ_TYPE_NARGS_ macros. 2024-04-22 11:10:23 +10:00
objarray.c py/objarray: Fix use-after-free if extending a bytearray from itself. 2024-04-22 11:50:52 +10:00
objarray.h py/objarray: Raise error on out-of-bound memoryview slice start. 2023-01-20 16:31:37 +11:00
objattrtuple.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objbool.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objboundmeth.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objcell.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objclosure.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objcomplex.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objdeque.c py/objdeque: Expand implementation to be doubly-ended and support iter. 2024-03-18 14:10:14 +11:00
objdict.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objenumerate.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objexcept.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objexcept.h py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objfilter.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objfloat.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objfun.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objfun.h py/objfun: Fix C++ compatibility with casting in inline functions. 2024-04-22 10:34:01 +10:00
objgenerator.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objgenerator.h
objgetitemiter.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objint.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objint.h py/modsys: Use consistent naming pattern for module-level const objects. 2020-05-28 10:02:14 +10:00
objint_longlong.c py: Change MP_UNARY_OP_INT to MP_UNARY_OP_INT_MAYBE. 2023-06-01 13:01:07 +10:00
objint_mpz.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objlist.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objlist.h py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objmap.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objmodule.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objmodule.h py/makemoduledefs.py: Automatically declare delegation attr functions. 2023-06-14 19:03:46 +10:00
objnamedtuple.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objnamedtuple.h py/obj: Convert make_new into a mp_obj_type_t slot. 2022-09-19 19:06:15 +10:00
objnone.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objobject.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objpolyiter.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objproperty.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objrange.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objreversed.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objset.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objsingleton.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objslice.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objstr.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objstr.h py/objstr: Add a macro to define a bytes object at compile time. 2024-03-15 13:37:31 +11:00
objstringio.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objstringio.h
objstrunicode.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objtuple.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
objtuple.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
objtype.c py/makeqstrdata.py: Ensure that scope names get low qstr values. 2024-03-26 22:52:25 +11:00
objtype.h py/obj: Optimise code size and performance for make_new as a slot. 2022-09-19 19:06:16 +10:00
objzip.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
opmethods.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
pairheap.c py/pairheap: Properly unlink node on pop and delete. 2020-03-26 01:21:04 +11:00
pairheap.h py/pairheap: Add helper function to initialise a new node. 2020-03-26 01:21:04 +11:00
parse.c py/parse: Zero out dangling parse tree pointer to fix potential GC leak. 2024-03-22 10:49:20 +11:00
parse.h py/parse: Factor obj extract code to mp_parse_node_extract_const_object. 2022-04-14 22:44:56 +10:00
parsenum.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
parsenum.h py/parsenum: Optimise when building with complex disabled. 2022-06-23 11:46:47 +10:00
parsenumbase.c all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
parsenumbase.h
persistentcode.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
persistentcode.h py/persistentcode: Bump .mpy sub-version to 6.3. 2024-03-28 16:18:26 +11:00
profile.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
profile.h py: Rework bytecode and .mpy file format to be mostly static data. 2022-02-24 18:08:43 +11:00
py.cmake all: Rename *umodule*.c to remove the "u" prefix. 2023-06-08 17:54:17 +10:00
py.mk py/py.mk: Remove extra build dir created for frozen_content. 2024-01-17 08:14:15 +11:00
pystack.c py: Introduce and use mp_raise_type_arg helper. 2021-07-15 00:12:41 +10:00
pystack.h all: Reformat C and Python source code with tools/codeformat.py. 2020-02-28 10:33:03 +11:00
qstr.c py/makeqstrdata.py: Ensure that scope names get low qstr values. 2024-03-26 22:52:25 +11:00
qstr.h py/qstr: Add support for MICROPY_QSTR_BYTES_IN_HASH=0. 2024-01-25 16:38:17 +11:00
qstrdefs.h py/modsys: Add optional mutable attributes sys.ps1/ps2 and use them. 2022-03-10 10:58:33 +11:00
reader.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
reader.h py/builtinevex: Handle invalid filenames for execfile. 2023-10-12 15:17:59 +11:00
repl.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
repl.h py/modsys: Add optional mutable attributes sys.ps1/ps2 and use them. 2022-03-10 10:58:33 +11:00
ringbuf.c py/ringbuf: Implement put_bytes/get_bytes functions. 2023-05-01 16:47:03 +10:00
ringbuf.h py/ringbuf: Implement put_bytes/get_bytes functions. 2023-05-01 16:47:03 +10:00
runtime.c extmod/machine_usb_device: Add support for Python USB devices. 2024-03-15 14:22:11 +11:00
runtime.h py/modthread: Move thread state initialisation to shared function. 2024-02-29 14:28:58 +01:00
runtime0.h py/emitglue: Simplify mp_raw_code_t's kind and scope_flags members. 2024-02-16 12:48:02 +11:00
runtime_utils.c
scheduler.c py: Add port-agnostic inline functions for event handling. 2023-12-08 12:47:00 +11:00
scope.c py/makeqstrdata.py: Ensure that scope names get low qstr values. 2024-03-26 22:52:25 +11:00
scope.h py/emitglue: Include fun_data_len in mp_raw_code_t only when saving. 2024-02-16 14:17:01 +11:00
sequence.c all: Fix spelling mistakes based on codespell check. 2023-04-27 18:03:06 +10:00
showbc.c py/emitglue: Include fun_data_len in mp_raw_code_t only when saving. 2024-02-16 14:17:01 +11:00
smallint.c
smallint.h py/smallint: Introduce MP_SMALL_INT_BITS macro. 2022-03-25 12:23:43 +11:00
stackctrl.c py/stackctrl: Add gcc pragmas to ignore dangling-pointer warning. 2023-05-04 10:08:12 +10:00
stackctrl.h py/stackctrl: Prevent unused-var warning when stack checking disabled. 2021-06-05 11:03:09 +10:00
stream.c py/stream: Factor stream implementations. 2024-03-15 18:11:28 +11:00
stream.h py/stream: Factor stream implementations. 2024-03-15 18:11:28 +11:00
unicode.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
unicode.h
usermod.cmake rp2: Add support for USER_C_MODULES to CMake build system. 2021-03-31 00:26:01 +11:00
vm.c py/emitglue: Introduce mp_proto_fun_t as a more general mp_raw_code_t. 2024-02-16 14:17:01 +11:00
vmentrytable.h py/vmentrytable: Ignore GCC -Woverride-init. 2020-10-22 11:47:36 +02:00
vstr.c all: Remove the "STATIC" macro and just use "static" instead. 2024-03-07 14:20:42 +11:00
warning.c py: Update my copyright info on some files. 2019-02-06 00:19:00 +11:00