Uh oh!
There was an error while loading. Please reload this page.
fix(hpux): net_io_counters()가 미초기화 힙을 NIC 이름으로 반환하던 문제 (SERVER-1987) - #3
Open
Y-JaeHyun wants to merge 1 commit into
Open
fix(hpux): net_io_counters()가 미초기화 힙을 NIC 이름으로 반환하던 문제 (SERVER-1987)#3Y-JaeHyun wants to merge 1 commit into
Y-JaeHyun wants to merge 1 commit into
Conversation
psutil_net_io_counters()는 ID_ifNumber(논리 인터페이스 수)만큼 루프를 돌지만, get_physical_stat()이 실제로 채우는 항목 수는 그보다 적을 수 있다. whaHP_IA(HP-UX 11.23 IA) 실측: ifNumber=4 인데 채워지는 것은 lan0/lan1/lo0 3개. 버퍼를 malloc으로 잡아 초기화하지 않았기 때문에 4번째 항목은 이전 힙 내용이 그대로 남아 있었고, nm_device[0]=='\0' 가드도 통과해 미초기화 메모리가 인터페이스 이름으로 반환됐다. 실측 40회 호출 40회 모두 재현: 'lo0', 'lan1', 'lan0', '~\xe6\xbb\x80~\xe6\xbb\xa0~\xe6\xbb\xc0~\xe6\xbb\xe0~\xe6\xbc' 바이트를 뜯어보면 32바이트 간격의 빅엔디안 32비트 힙 포인터 배열이다. 이 이름은 python-infra 에이전트에서 'ifconfig ' + name 형태로 셸에 전달되어, '>' 가 섞이면 작업 디렉토리에 파일을 만들고 다른 메타문자면 root 권한 명령 실행으로 이어질 수 있었다(SERVER-1987 B안에서 별도 차단). - malloc -> calloc: 채워지지 않은 항목이 0으로 남아 기존 nm_device 가드가 의도대로 동작한다. get_physical_stat 의 정확한 계약과 무관하게 안전하다. - get_physical_stat 반환값이 항목 수로 보이면(0 <= ret < count) 그 값으로 루프를 제한한다. 아니면 no-op 이므로 손해가 없다. - count <= 0 이면 빈 dict 반환. 기존에는 count 초기값 -1 로 malloc(음수*size) 경로가 있었다. - 이름이 필드를 가득 채운 경우를 대비해 사용 직전 널 종료를 보장한다. 검증: 대상 장비(whaHP_IA)에서 실제 헤더로 컴파일 확인 cc -c +z -DPSUTIL_VERSION=596 -I<python2.7 include> _psutil_hpux.c -> 에러 0 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
배경/목적
HP-UX(IA) 장비에서 에이전트 작업 디렉토리에 이름이 깨진 0바이트 파일이 계속 쌓였습니다(whaHP_IA 실측:
/1140개,/test1327개). 추적 결과 원인은 이 확장의psutil_net_io_counters()가 미초기화 힙 메모리를 인터페이스 이름으로 반환하는 것이었습니다.ID_ifNumber(논리 인터페이스 수)만큼 루프를 도는데,get_physical_stat()이 실제로 채우는 항목 수는 그보다 적을 수 있습니다.ifNumber = 4, 실제로 채워지는 것은lan0/lan1/lo03개malloc으로 잡아 초기화하지 않아 4번째 항목은 이전 힙 내용이 남아 있고,nm_device[0]=='\0'가드도 통과40회 호출 40회 모두 재현됩니다:
바이트를 뜯어보면 무작위가 아니라 32바이트 간격의 빅엔디안 32비트 힙 포인터 배열입니다.
이 이름은 python-infra 에이전트에서
'ifconfig ' + name형태로 셸에 전달되어,>가 섞이면 파일이 생기고 다른 메타문자면 root 권한 명령 실행으로 이어질 수 있었습니다. 에이전트 쪽 차단은 별도 PR(B안)로 진행합니다.변경 내용
malloc→calloc: 채워지지 않은 항목이 0으로 남아 기존nm_device가드가 의도대로 동작합니다.get_physical_stat의 정확한 계약과 무관하게 안전한 수정입니다.get_physical_stat반환값이 항목 수로 보이면(0 <= ret < count) 그 값으로 루프를 제한합니다. 아니면 no-op이라 손해가 없습니다.count <= 0이면 빈 dict 반환 — 기존에는count초기값-1로malloc(음수*size)경로가 있었습니다.테스트
대상 장비(whaHP_IA, HP-UX B.11.23 IA)에서 실제 헤더로 컴파일 검증:
cc로 임시 링크한.so는 Python 심볼 해석 문제로 로드에 실패해, 정식 빌드(setup.py) 산출물로 확인이 필요합니다. 리뷰어께서 정식 빌드로net_io_counters()키에 쓰레기가 사라지는지 확인해 주시면 좋겠습니다.파리티 영향
없음 (HP-UX 전용 경로).
문서
없음.
관련
fix/SERVER-1987-hpux-nic-shell-injection🤖 Generated with Claude Code