From patchwork Mon Dec 19 11:13:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nick Clifton X-Patchwork-Id: 34476 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e747:0:0:0:0:0 with SMTP id c7csp2339874wrn; Mon, 19 Dec 2022 03:53:18 -0800 (PST) X-Google-Smtp-Source: AA0mqf5HM1Bq8TupVM52GGEx5ukmOCi+xR3n2Hst7TPfghDEbFS04Ypx2mNdeXrsW/WoyCHCUHAQ X-Received: by 2002:a17:906:2898:b0:7ad:a350:7fd9 with SMTP id o24-20020a170906289800b007ada3507fd9mr34489363ejd.52.1671450798377; Mon, 19 Dec 2022 03:53:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671450798; cv=none; d=google.com; s=arc-20160816; b=wBngIrqf2VwzdPbbUt0sBDwDd8nuWrnRi8ERtUpYQPur+l6x4s3WM8heRicqgF3xbw 7o2uemD5qwMhIdHGArbFVi3hKtYYuYRTDv1r8rRE3qj+/ho3d4bjKnR4+FIZkkJzBEvX OHEBCo5QybvACpvm6xiwL1eNKxHTglLzz3otesrR+bmNMNyrzta6rCte1WQb8VViLrsW KTwtSznONS+bfbL8da6JzsY7r5WJc1Dlqh5ZCYXEwtbcwaV1gREgsmeqHYg8pzJDQ7Z2 BD7PTVJmHi804fgH2TeVn4DdL8I3Z/y449r2ssLYudLu4e32VBk7JvIOUy19DGgNp4nn /sfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence:mime-version :message-id:date:subject:to:dmarc-filter:delivered-to:dkim-signature :dkim-filter; bh=ld4DVRt1JN2SltqKTwBmpAQ8RCTqLeCocgcIq+9gkdY=; b=spVbjSjCbYrvPcbCvljR7njZBDQu1zxLC4iprYkUt53mSQ/VdKTshS69opwjTOtTkM fKuHpLMN/V7m00X/22BpSKh9h/8Dha10tg8nYNY2OdzV22lRzpWSoq/dCRD3eCZlWTfv 9TBN5MPsziYYLTUzFSLX10OxplyFRSIIm2ckwI+bh6tePcx79QjGGtzAYBJgWNvBmVeN ucwmm3wLBWbIx5wyv/cGLA4CZAg5jJXjaw/QGTD1xVkJL+dxwxZ8fwCO4SB8Pn5tf9Hb JnDOOPI144t0E0CeKbB5qIs+jDS0HngYM+Xk5El/c8ajZttTDdMrYLUcDRZZ4FVgX01N mVXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=BqLPoWc8; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id e17-20020a056402089100b0046b807c1a06si8173046edy.350.2022.12.19.03.53.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 03:53:18 -0800 (PST) Received-SPF: pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@sourceware.org header.s=default header.b=BqLPoWc8; spf=pass (google.com: domain of binutils-bounces+ouuuleilei=gmail.com@sourceware.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="binutils-bounces+ouuuleilei=gmail.com@sourceware.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A889C389B9F7 for ; Mon, 19 Dec 2022 11:14:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A889C389B9F7 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1671448451; bh=ld4DVRt1JN2SltqKTwBmpAQ8RCTqLeCocgcIq+9gkdY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=BqLPoWc8ZiFb2jNTUP8Y4+HO64nlvloExlv+WjEdXy96qrDBquz8UWK9qd4Hn2DEn T1xAWPou8c7eI6BG7KIf99ZBL4ObEPxrAShJw2MWalaUjFmshTfyedNpj+pcimhiNQ fKNlIcUA5VLwfgN8A11Rn3DcEgDj4nk7QMn56Chs= X-Original-To: binutils@sourceware.org Delivered-To: binutils@sourceware.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 16C3038C2658 for ; Mon, 19 Dec 2022 11:13:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 16C3038C2658 Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-311-PGpcj-vVO1OxwmU-AfpZmw-1; Mon, 19 Dec 2022 06:13:19 -0500 X-MC-Unique: PGpcj-vVO1OxwmU-AfpZmw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 1CDD0811E6E for ; Mon, 19 Dec 2022 11:13:19 +0000 (UTC) Received: from prancer.redhat.com (unknown [10.33.36.23]) by smtp.corp.redhat.com (Postfix) with ESMTPS id C49EA1121314 for ; Mon, 19 Dec 2022 11:13:18 +0000 (UTC) To: binutils@sourceware.org Subject: Commit: Add more tests for corrupt DWARF data Date: Mon, 19 Dec 2022 11:13:17 +0000 Message-ID: <87r0wvsl2q.fsf@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.3 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-9.7 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: binutils@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Binutils mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Nick Clifton via Binutils From: Nick Clifton Reply-To: Nick Clifton Errors-To: binutils-bounces+ouuuleilei=gmail.com@sourceware.org Sender: "Binutils" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752643192076588728?= X-GMAIL-MSGID: =?utf-8?q?1752643192076588728?= Hi Guys, I am applying the patch below to add a couple more tests to binutils/dwarf.c to catch cases of corrupt DWARF information. Cheers Nick binutils/ChangeLog 2022-12-19 Nick Clifton PR 29914 * dwarf.c (fetch_indexed_value): Fail if the section is not big enough to contain a header size field. (display_debug_addr): Fail if the computed address size is too big or too small. diff --git a/binutils/dwarf.c b/binutils/dwarf.c index 03b36afcec0..b792902c496 100644 --- a/binutils/dwarf.c +++ b/binutils/dwarf.c @@ -739,6 +739,13 @@ fetch_indexed_value (uint64_t idx, return -1; } + if (section->size < 4) + { + warn (_("Section %s is too small to contain an value indexed from another section!\n"), + section->name); + return -1; + } + uint32_t pointer_size, bias; if (byte_get (section->start, 4) == 0xffffffff) @@ -7770,6 +7777,13 @@ display_debug_addr (struct dwarf_section *section, header = end; idx = 0; + if (address_size < 1 || address_size > sizeof (uint64_t)) + { + warn (_("Corrupt %s section: address size (%x) is wrong"), + section->name, address_size); + return 0; + } + while ((size_t) (end - entry) >= address_size) { uint64_t base = byte_get (entry, address_size);