Possible SIGSEGV durning aset memory tracking
Maintainer thường phản hồi trong vòng 3 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
The crash path runs through src/backend/utils/mmgr/aset.c: AllocSetContextCreateInternal, AllocSetDelete and AllocSetTransferAccounting all cast the parent context to AllocSet without checking its type. Reproduce with the test extension linked in the issue, starting from the backtrace through MemoryContextSetParent in mcxt.c. Done means the reproduction no longer crashes and the parent-type checks are in place, though the issue leaves open whether to add validation or move accounting into mcxt.c, which is a design decision for maintainers.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Memory context allocation mostly tracked at aset.c and the code relied on the assumption that context tree is an AllocSet context tree, previously that was correct, but now the next query:
-- table test contains only i int column
select * from test order by i;
may allocate a Generation context (from tuplesort_begin_batch) in the context tree and this commit adds additional context validation.
But seems it's not enough:
AllocSetContextCreateInternaldoesn't validate parent context for it's type: here, and here, so after invalid cast there would be invalid pointersAllocSetDeletedoesn't validate parent context type, it's only perform unconditional cast - after invalid cast there may be memory corruptionAllocSetTransferAccountingafter finding parent it's type isn't checked
Suppose that at some point there would be Generation context under the AccountingRoot (aset) context and over leaf Aset context - there would be performed an invalid type cast with further invalid writes which leads to SIGSEGV. Such cases may seems insubstantial, but postgres code base may mix context in further releases.
Here is a test extension which leads to SIGSEGV:
#include "postgres.h"
#include "access/htup_details.h"
#include "commands/async.h"
#include "commands/trigger.h"
#include "executor/spi.h"
#include "lib/stringinfo.h"
#include "utils/rel.h"
#include "utils/memutils.h"
#include "utils/syscache.h"
PG_MODULE_MAGIC;
PG_FUNCTION_INFO_V1(test_ctx);
Datum
test_ctx(PG_FUNCTION_ARGS)
{
MemoryContext newAset = AllocSetContextCreate(CurrentMemoryContext,
"test preparent aset",
ALLOCSET_DEFAULT_SIZES);
// create and remove context, so further context would be created
// from freelist
MemoryContext deleteAse = AllocSetContextCreate(CurrentMemoryContext,
"to drop aset",
ALLOCSET_DEFAULT_SIZES);
MemoryContextDelete(deleteAse);
MemoryContext newGen = GenerationContextCreate(newAset, "test mid",
SLAB_DEFAULT_BLOCK_SIZE,
SLAB_DEFAULT_BLOCK_SIZE,
SLAB_DEFAULT_BLOCK_SIZE
);
MemoryContext asetLast = AllocSetContextCreate(newGen,
"last aset",
ALLOCSET_DEFAULT_SIZES);
MemoryContextDelete(newGen);
elog(INFO, "last ctx addr %p", (void*)asetLast);
PG_RETURN_VOID();
}
And here is a link to full test extension
The backtrace
#0 __pthread_kill_implementation (threadid=<optimized out>, signo=11, no_tid=0) at ./nptl/pthread_kill.c:44
#1 __pthread_kill_internal (threadid=<optimized out>, signo=11) at ./nptl/pthread_kill.c:89
#2 __GI___pthread_kill (threadid=<optimized out>, signo=signo@entry=11) at ./nptl/pthread_kill.c:100
#3 0x00007e41fb245b7e in __GI_raise (sig=11) at ../sysdeps/posix/raise.c:26
#4 0x00005865986bae91 in StandardHandlerForSigillSigsegvSigbus_OnMainThread (processName=0x586598e5dabb "Master process", postgres_signal_arg=11) at elog.c:5547
#5 0x0000586598487a83 in CdbProgramErrorHandler (postgres_signal_arg=11) at postgres.c:3990
#6 0x0000586598c8e953 in wrapper_handler (postgres_signal_arg=11) at pqsignal.c:90
#7 <signal handler called>
#8 AllocSetTransferAccounting (context=0x5865b8655080, new_parent=0x0) at aset.c:1874
#9 0x000058659870899e in MemoryContextSetParent (context=0x5865b8655080, new_parent=0x0) at mcxt.c:596
#10 0x00005865987086f5 in MemoryContextDeleteImpl (context=0x5865b8655080, sfile=0x586598ec3e7f "mcxt.c", func=0x0, sline=497) at mcxt.c:468
#11 0x000058659870879d in MemoryContextDeleteChildren (context=0x5865b864f040) at mcxt.c:497
#12 0x00005865987086c8 in MemoryContextDeleteImpl (context=0x5865b864f040, sfile=0x7e41fbdcf021 "ctx.c", func=0x0, sline=40)
The problem occurs on the debug build with --enable-cassert
For now I suppose the problem should be closed by additional validation, but seems more correct way is to move the logic of memory tracking from aset to mctx and also extend Generation context methods to support tracking.
- Ngôn ngữ chính
- C
- Star
- 1.4k
- Fork
- 260
- Merge trung bình
- 4 ngày 19 giờ
- Pull request đã merge (30 ngày)
- 54
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của apache/cloudberry
-
[Bug] Expand fails to recognize user-defined tablespacesCó thể đã có người làm @nix-oss đã nhận 58 ngày trước. Đang mởtype: Bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
apache/cloudberry#1885 · 2 reaction ·
Maintainer thường phản hồi trong vòng 3 ngày
-
gpexpand first stage fails: 'SyncPackages' object has no attribute 'ret' (extension sync never runs; regression)Có thể đã có người làm @talmacschen-arch đã nhận 119 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 86/100
apache/cloudberry#1825 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
type: Bug
Độ khó 3/5 Nửa ngày Mức phù hợp với người mới 58/100
apache/cloudberry#2137 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
type: Proposal
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 22/100
apache/cloudberry#2136 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 3 ngày
-
type: Bug
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 30/100
apache/cloudberry#2135 ·
Maintainer thường phản hồi trong vòng 3 ngày
Tất cả issue của apache/cloudberry
Issue tương tự
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
ChrisTitusTech/dwm-titus#397 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Translate gcc cheat sheet to frĐang mởgood first issue help wanted language:fr translation
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 85/100
mrvi0/cli-cheatsheet#160 ·
-
Test modules use volatile int for cross-thread flags instead of atomicsCó thể đã có người làm @rahimuddin140 đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
valkey-io/valkey#4899 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
Profiler (Remotery) leaks a socket for every connection that fails the WebSocket handshakeCó thể đã có người làm @rthery đã nhận hôm nay. Đang mởtriage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Symlink in release archive attempts traversalCó thể đã có người làm @Tiancheng-Xu đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
redis/hiredis#1388 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày