From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by sourceware.org (Postfix) with ESMTPS id EAB153858D1E for ; Wed, 14 Sep 2022 00:45:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org EAB153858D1E Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102e.google.com with SMTP id q3so12934141pjg.3 for ; Tue, 13 Sep 2022 17:45:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :from:to:cc:subject:date; bh=0ahQuJ0r8yC9iVOxFFNnsG6uZrmv3CUVl2eUI3j/mhk=; b=mCb+xAdttd6lhGLW8Pog/GZBpZkPmyBTND7K9yUa2B/dwmiM6+hBK3PyyWGnTSxmWy 5Ub/BN6aWlq9RNZSq6CPXbl6PXi16GUC5U1Zd3KhDfE5+KvbOOX/OlC+1YbomzsIOkSF /mhSzQB3PKlIfPV0PVV8etUA2q1r5rc4R+H944oCTYSaoF5fdPZv9N0K4qtv4+oZB+Pm JbyRuo5pRya5jqIR1Qf+MnPtD6kMthkujTNJRix2UC+UULXvhMuPn17ba4qZWb1CLD4m XBFPiEZBzttPAJDz2VLyNQrU5ZPH4iYKEw0qsq/TlQKIvF4wX+Ro7kNa5GBtL+m27ZQq F6Ew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-disposition:mime-version:message-id:subject:to:from:date :x-gm-message-state:from:to:cc:subject:date; bh=0ahQuJ0r8yC9iVOxFFNnsG6uZrmv3CUVl2eUI3j/mhk=; b=vy/c1U+ws+lOISk3HyuWP2+B2RYBIz8yBuhnnjmCvAkU6x+FDE3+46lEDMuTAMwblz yBZA7ZPa1lpdBQNkzrNImBZI+YDPgVplBr21z4lpDFHKvWamjW6PIa5zJH2lrYJhJB4l y7R7Vl48j+aZYy0wUCJhsrlG1QEBHr/j0KsXuM0zTreECaCJc22tjyPDkpdS+W85OH32 pASnyz24vFgFshQ4AwWXWaM1eSPCVX1qvJ9pDohyOM3ezdMq12TubQhY27wz9q0CqQyB E0JctvZHir6YeiEYX3GZYdfUypv5m9Nqx4TSl0fI10mZGL1+qhS8kzJEci146KKFl0WX cN1g== X-Gm-Message-State: ACrzQf2fQ7eIu3a8RScAfzk9oVu6wGAoNCQE+j8tcU4xcPO4W0eUlO0u 7pC+fH6ie/OH+QTVRBMcNAspprKoF+c= X-Google-Smtp-Source: AMsMyM656j84i5/ML3Q3xi04rQc1eRlw29RTZzw3zwW7v5MhhhgBqkMKQss5a+9HI3VybBsqlREcpQ== X-Received: by 2002:a17:90a:64c8:b0:202:6d4a:90f8 with SMTP id i8-20020a17090a64c800b002026d4a90f8mr1982480pjm.11.1663116323893; Tue, 13 Sep 2022 17:45:23 -0700 (PDT) Received: from squeak.grove.modra.org ([2406:3400:51d:8cc0:e54b:c5e7:d44e:f16]) by smtp.gmail.com with ESMTPSA id a9-20020a170902ecc900b0017839e5abfasm4841583plh.263.2022.09.13.17.45.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Sep 2022 17:45:23 -0700 (PDT) Received: by squeak.grove.modra.org (Postfix, from userid 1000) id D65F01140ABA; Wed, 14 Sep 2022 10:15:20 +0930 (ACST) Date: Wed, 14 Sep 2022 10:15:20 +0930 From: Alan Modra To: binutils@sourceware.org Subject: asan: som_set_reloc_info heap buffer overflow Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3035.8 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,GIT_PATCH_0,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: Also a bugfix. The first time the section was read, the contents didn't supply an addend. * som.c (som_set_reloc_info): Sanity check offset. Do process contents after reading. Tidy section->contents after freeing. diff --git a/bfd/som.c b/bfd/som.c index 38c574a97c8..9b0a5513209 100644 --- a/bfd/som.c +++ b/bfd/som.c @@ -5251,7 +5251,9 @@ som_set_reloc_info (unsigned char *fixup, section->contents = contents; deallocate_contents = 1; } - else if (rptr->addend == 0) + if (rptr->addend == 0 + && offset - var ('L') <= section->size + && section->size - (offset - var ('L')) >= 4) rptr->addend = bfd_get_32 (section->owner, (section->contents + offset - var ('L'))); @@ -5269,7 +5271,10 @@ som_set_reloc_info (unsigned char *fixup, } } if (deallocate_contents) - free (section->contents); + { + free (section->contents); + section->contents = NULL; + } return count; -- Alan Modra Australia Development Lab, IBM