🇰🇷 한글 설명
TensorFlow의 tf.io.decode_raw 함수에서 fixed_length와 넓은 데이터 타입을 함께 사용할 때 포인터 연산 오류가 발생합니다. 이로 인해 잘못된 결과가 생성되거나 Python 인터프리터가 충돌하며, 메모리 경계를 벗어난 쓰기(OOB Write)가 발생할 수 있습니다.
💡 쉬운 설명
데이터를 읽어오는 과정에서 계산 실수로 인해 정해진 메모리 범위를 넘어서 데이터를 쓰게 되는 버그입니다. 이로 인해 프로그램이 갑자기 꺼지거나 해커가 시스템을 공격할 위험이 있습니다.
🇺🇸 원문 (English)
TensorFlow is an end-to-end open source platform for machine learning. The implementation of `tf.io.decode_raw` produces incorrect results and crashes the Python interpreter when combining `fixed_length` and wider datatypes. The implementation of the padded version(https://github.com/tensorflow/tensorflow/blob/1d8903e5b167ed0432077a3db6e462daf781d1fe/tensorflow/core/kernels/decode_padded_raw_op.cc) is buggy due to a confusion about pointer arithmetic rules. First, the code computes(https://github.com/tensorflow/tensorflow/blob/1d8903e5b167ed0432077a3db6e462daf781d1fe/tensorflow/core/kernels/decode_padded_raw_op.cc#L61) the width of each output element by dividing the `fixed_length` value to the size of the type argument. The `fixed_length` argument is also used to determine the size needed for the output tensor(https://github.com/tensorflow/tensorflow/blob/1d8903e5b167ed0432077a3db6e462daf781d1fe/tensorflow/core/kernels/decode_padded_raw_op.cc#L63-L79). This is followed by reencoding code(https://github.com/tensorflow/tensorflow/blob/1d8903e5b167ed0432077a3db6e462daf781d1fe/tensorflow/core/kernels/decode_padded_raw_op.cc#L85-L94). The erroneous code is the last line above: it is moving the `out_data` pointer by `fixed_length * sizeof(T)` bytes whereas it only copied at most `fixed_length` bytes from the input. This results in parts of the input not being decoded into the output. Furthermore, because the pointer advance is far wider than desired, this quickly leads to writing to outside the bounds of the backing data. This OOB write leads to interpreter crash in the reproducer mentioned here, but more severe attacks can be mounted too, given that this gadget allows writing to periodically placed locations in memory. The fix will be included in TensorFlow 2.5.0. We will also cherrypick this commit on TensorFlow 2.4.2, TensorFlow 2.3.3, TensorFlow 2.2.3 and TensorFlow 2.1.4, as these are also affected and still in supported range.
📍 영향받는 시스템
TensorFlow 2.5.0 미만 버전 (2.4.2, 2.3.3, 2.2.3, 2.1.4 포함)
⚔️ 공격 벡터
조작된 데이터를 포함한 TensorFlow 모델 또는 입력값을 처리하도록 유도하여 메모리 오염 유발
🛡️ 대응 방법
TensorFlow를 2.5.0 이상 버전으로 업데이트하거나, 해당 버전의 보안 패치가 적용된 2.4.2, 2.3.3, 2.2.3, 2.1.4 버전으로 업데이트
🔧 검증 코드
출력된 버전 번호가 2.5.0 미만인지 확인하여 취약 여부를 판단합니다.
python3 -c 'import tensorflow as tf; print(tf.__version__)'