From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 23B613858000; Mon, 1 Nov 2021 17:48:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 23B613858000 From: "npv1310 at gmail dot com" To: glibc-bugs@sourceware.org Subject: [Bug libc/28524] New: Conversion from ISO-2022-JP-3 with iconv may emit spurious NUL character on state reset Date: Mon, 01 Nov 2021 17:48:27 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: libc X-Bugzilla-Version: unspecified X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: npv1310 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter cc target_milestone attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: glibc-bugs@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Glibc-bugs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 01 Nov 2021 17:48:28 -0000 https://sourceware.org/bugzilla/show_bug.cgi?id=3D28524 Bug ID: 28524 Summary: Conversion from ISO-2022-JP-3 with iconv may emit spurious NUL character on state reset Product: glibc Version: unspecified Status: UNCONFIRMED Severity: normal Priority: P2 Component: libc Assignee: unassigned at sourceware dot org Reporter: npv1310 at gmail dot com CC: drepper.fsp at gmail dot com Target Milestone: --- Created attachment 13751 --> https://sourceware.org/bugzilla/attachment.cgi?id=3D13751&action=3Ded= it Proof of concept Hello, while investigating CVE-2021-3326 patch [here: https://sourceware.org/git/?p=3Dglibc.git;a=3Dcommit;h=3D7d88c6142c6efc160c= 0ee5e4f85cde382c072888] I've found that it is possible to force iconv() to emit spurious NUL charac= ter by converting from ISO-2022-JP-3 encoding and resetting internal state (inb= uf =3D NULL). This is possible because code sequence in iconvdata/iso-2022-jp-3.c which is responsible for resetting internal state doesn't ensure that any character has actually been saved. The main condition [data->__statep->__co= unt !=3D ASCII_set] also picks a cases where current set is different from ASCI= I_set. I've written small proof-of-concept which is attached. In a research environment, proof-of-concept program was compiled with follo= wing command sequence: $ gcc iconv-issue.c -c -Wall -o /tmp/iconv-issue.o $ gcc -o /tmp/iconv-issue -nostdlib -nostartfiles /root/glibc-build/csu/Scr= t1.o /root/glibc-build/csu/crti.o `gcc --print-file-name=3DcrtbeginS.o` /tmp/iconv-issue.o -Wl,-rpath-link=3D/root/glibc-build:/root/glibc-build/math:/root/glibc-buil= d/elf:/root/glibc-build/dlfcn:/root/glibc-build/nss:/root/glibc-build/nis:/= root/glibc-build/rt:/root/glibc-build/resolv:/root/glibc-build/mathvec:/roo= t/glibc-build/support:/root/glibc-build/crypt:/root/glibc-build/nptl /root/glibc-build/libc.so.6 `gcc --print-file-name=3DcrtendS.o` /root/glibc-build/csu/crtn.o $ env GCONV_PATH=3D/root/glibc-build/iconvdata LOCPATH=3D/root/glibc-build/localedata LC_ALL=3DC /root/glibc-build/elf/ld-linux-x86-64.so.2 --library-path /root/glibc-build:/root/glibc-build/math:/root/glibc-build/elf:/root/glibc-= build/dlfcn:/root/glibc-build/nss:/root/glibc-build/nis:/root/glibc-build/r= t:/root/glibc-build/resolv:/root/glibc-build/mathvec:/root/glibc-build/supp= ort:/root/glibc-build/crypt:/root/glibc-build/nptl /tmp/iconv-issue Here /root/glibc-build is a build root for up-to-date version of glibc. The last command results in a following output: Step#1 Input characters consumed =3D 3 Output characters produced =3D 0 Step#2 Output characters produced =3D 1 With glibc lacking CVE-2021-3326 fix output is normal: Step#1 Input characters consumed =3D 3 Output characters produced =3D 0 Step#2 Output characters produced =3D 0 I assess that this behavior may affect data integrity in certain use patter= ns of iconv where extra data ('\0') is added. Such NUL character may confuse programs expecting NUL as the data terminato= r. --=20 You are receiving this mail because: You are on the CC list for the bug.=