From nobody Sun Mar 10 19:12:34 2024 X-Original-To: bugs@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4Tt8g71hsQz5DR85 for ; Sun, 10 Mar 2024 19:12:35 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Tt8g671Gtz4KdS for ; Sun, 10 Mar 2024 19:12:34 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1710097955; a=rsa-sha256; cv=none; b=TjpAGDbiGVaxJ3qpgDJi3OmmffpKCfFyf9G0KoQVRbliqJteTz+PZ7kAbfthbKs2ARV1zw SmqktKU3np3LNAj0wvIznFL283zv1CWOZUGUM2xQSu7WPlSslImzZeM/cu6KKzKkPzOMcy IN6hCm0U6uGFwVFPiD46IGXAcV7cAtPQ8a9eYk+sG188tYhh7DDbDgFxy3m2ExSkxrB25k wBa4AcBWQ8T52wOyxqf6QR8bnGlpsE50A8cNyFrAV+t+auOYqdOAW3JSz+qGb8Ha+g3u8I /JTV2JHe6VjGAJy1DFgPugG/ZW2KT4hOkeaNHcHj2aSIv4U2HDLq78Zcsejd6A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1710097955; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=iktcwSfGPJbIJdiqRkLcmTF3z94tyWp0jdZSF2oc//E=; b=MoUisKKeBiyrd9IeH8K39uDbnNOkQH6tFjhIkdzzQ+W+Kh3HWSwJBbLlRFqKYkSTZXcgQY 4mYfT315TSc2BQ+b5s4T6bUJQXWcvUVi253pVpLCMj7VFe1cenmd5irUdH2Z3X9n6CALEs EWIj0YY8hRYEo07jdlmu72m41gUNxtjh0tJzCF3CQ0OHar+x+7Kl1akkeYV+XILomptDg7 WszQVABVSlbRFkbLFdrrgb6fio0Q2OFw8PejFa/uSpNct03hCFMHCN0VQ+F4VqtSk4tw/4 3B890o5IXxw6cLBBZpOD57jGqKRedP6/wKd/ldE01my0yyb2IusVgln3BH4njw== Received: from kenobi.freebsd.org (kenobi.freebsd.org [IPv6:2610:1c1:1:606c::50:1d]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4Tt8g66bfSzxjR for ; Sun, 10 Mar 2024 19:12:34 +0000 (UTC) (envelope-from bugzilla-noreply@freebsd.org) Received: from kenobi.freebsd.org ([127.0.1.5]) by kenobi.freebsd.org (8.15.2/8.15.2) with ESMTP id 42AJCYB2058051 for ; Sun, 10 Mar 2024 19:12:34 GMT (envelope-from bugzilla-noreply@freebsd.org) Received: (from www@localhost) by kenobi.freebsd.org (8.15.2/8.15.2/Submit) id 42AJCYUH058050 for bugs@FreeBSD.org; Sun, 10 Mar 2024 19:12:34 GMT (envelope-from bugzilla-noreply@freebsd.org) X-Authentication-Warning: kenobi.freebsd.org: www set sender to bugzilla-noreply@freebsd.org using -f From: bugzilla-noreply@freebsd.org To: bugs@FreeBSD.org Subject: [Bug 277616] ldd uses elf phdr.p_offset without checking Date: Sun, 10 Mar 2024 19:12:34 +0000 X-Bugzilla-Reason: AssignedTo X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: Base System X-Bugzilla-Component: bin X-Bugzilla-Version: CURRENT X-Bugzilla-Keywords: X-Bugzilla-Severity: Affects Some People X-Bugzilla-Who: rtm@lcs.mit.edu X-Bugzilla-Status: New X-Bugzilla-Resolution: X-Bugzilla-Priority: --- X-Bugzilla-Assigned-To: bugs@FreeBSD.org X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version rep_platform op_sys bug_status bug_severity priority component assigned_to reporter attachments.created Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: https://bugs.freebsd.org/bugzilla/ Auto-Submitted: auto-generated List-Id: Bug reports List-Archive: https://lists.freebsd.org/archives/freebsd-bugs List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-freebsd-bugs@freebsd.org MIME-Version: 1.0 https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D277616 Bug ID: 277616 Summary: ldd uses elf phdr.p_offset without checking Product: Base System Version: CURRENT Hardware: Any OS: Any Status: New Severity: Affects Some People Priority: --- Component: bin Assignee: bugs@FreeBSD.org Reporter: rtm@lcs.mit.edu Created attachment 249076 --> https://bugs.freebsd.org/bugzilla/attachment.cgi?id=3D249076&action= =3Dedit an elf file with a huge phdr.p_offset The attached corrupt elf file contains a program header with a huge offset, which causes ldd to dereference a bad pointer. ldd's is_executable() says: case PT_DYNAMIC: dynamic =3D true; if (ehdr.e_type =3D=3D ET_DYN) pie =3D is_pie(fname, elf, &ehdr, phdr.p_of= fset, phdr.p_filesz); and is_pie() says: src.d_buf =3D buf + offset; and calls gelf_xlatetom() with src. There's a similar problem in has_freebsd_abi_tag(), and both functions use len (phdr.p_filesz) without a check. # uname -a FreeBSD stock14 15.0-CURRENT FreeBSD 15.0-CURRENT #19 main-n268743-a58813fd701e: Sat Mar 9 07:18:21 AST 2024=20=20=20=20 root@stock14:/usr/obj/usr/src/amd64.amd64/sys/GENERIC amd64 # ldd ldd1b.exe=20 Bus error (core dumped) Program received signal SIGBUS, Bus error. Object-specific hardware error. _libelf_cvt_DYN64_tom (dst=3D, dsz=3D,=20 src=3D, count=3D, byteswap=3D0) at libelf_convert.c:529 529 READ_SXWORD(s,t.d_tag); (gdb) where #0 _libelf_cvt_DYN64_tom (dst=3D, dsz=3D,=20 src=3D, count=3D, byteswap=3D0) at libelf_convert.c:529 #1 0x00000008010782ac in _libelf_xlate (dst=3D0x7fffffffe8a0,=20 src=3D0x7fffffffe870, encoding=3D, elfclass=3D2, elfmach= ine=3D243,=20 direction=3Ddirection@entry=3D1) at /usr/src/contrib/elftoolchain/libelf/libelf_xlate.c:143 #2 0x00000008010757a2 in gelf_xlatetom (e=3De@entry=3D0x801809000,=20 dst=3D0x80106bef0, dst@entry=3D0x7fffffffe8a0, src=3D0x2,=20 src@entry=3D0x7fffffffe870, encoding=3D384) at /usr/src/contrib/elftoolchain/libelf/gelf_xlate.c:68 #3 0x0000000001023a7c in is_pie (fname=3D0x7fffffffed4a "ldd1b.exe",=20 elf=3D0x801809000, ehdr=3D0x7fffffffe8d0, offset=3D, len= =3D400) at /usr/src/usr.bin/ldd/ldd.c:369 #4 is_executable (fname=3D0x7fffffffed4a "ldd1b.exe", fd=3D3,=20 is_shlib=3D, type=3D) at /usr/src/usr.bin/ldd/ldd.c:447 #5 main (argc=3D1, argv=3D0x7fffffffe9d8) at /usr/src/usr.bin/ldd/ldd.c:174 (gdb) print/x phdr $1 =3D {p_type =3D 0x2, p_flags =3D 0x6, p_offset =3D 0x7fffffffbfa9ae7f,=20 p_vaddr =3D 0x28e0, p_paddr =3D 0x28e0, p_filesz =3D 0x190, p_memsz =3D 0= x190,=20 p_align =3D 0x8} --=20 You are receiving this mail because: You are the assignee for the bug.=