From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by sourceware.org (Postfix) with ESMTPS id 60D84384AB79 for ; Fri, 19 Apr 2024 09:27:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 60D84384AB79 Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=suse.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 60D84384AB79 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2a00:1450:4864:20::32c ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713518837; cv=none; b=VEa7FubiN8S/9NFbHYZhpjHF6y3hD6OBohlkaYkMSlz49nKW2HikU2v7KjwXEOESrdiPyplbUq/4rQDv4hbZbG1G+CkJEQszkcJCcwc0c41UlgFPp2myyLiXU3cgEdw/SKm2oHsnw3CAAO6eOwP7OhodSp+5yXFPZKz+o6vF8y0= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1713518837; c=relaxed/simple; bh=V/xfdXbeu251hXcBHePvdRL71OAHKsXQ7HT4yyPa6kk=; h=DKIM-Signature:Message-ID:Date:MIME-Version:To:From:Subject; b=vQsh+Vov398fsLPkzWDdpdXHArLnZOfcBtWuLK2nL1pKbmSa8ucD3iD68G0IIT6F7GhZyu9HAIK/UPMsSwgzbAlheja5vRXXQkNMB24/b5n5bRax0f0tP5r2rIkJ1j4A+jXwP6gNmCjj57LlKEhau8eOokIuvJog7TNi07Af8js= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-wm1-x32c.google.com with SMTP id 5b1f17b1804b1-41882c16824so14592725e9.3 for ; Fri, 19 Apr 2024 02:27:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1713518834; x=1714123634; darn=sourceware.org; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id:from:to:cc :subject:date:message-id:reply-to; bh=VEOircw0jfByTbN8pxNbn68FybSc3JIs4qT6NCZuVUg=; b=GKk5VyYBnMzXQDtxNX59pSH4l0ITUnH5QkQh3HQUFI4b6tdP3/mIF4JSNx5+huypSj WY2S/kCPxtH26crbJb2L4Ow32epNgIa/l21P6e53XUj1kkt97IKfIAhn/B26TOnODvJx ImGMoz4aDw5jkWAux41FbZuQu3r9D+PV2r6077PKQ31C4Uonw5zrJUl4JAERgR1ChM/R I4a2qcUInyEWuPcGjT87L3GzGjL2qdQZc7XmjlqxrpHGJWEFsRv90KNVLpOdTr+VBdbU 2gonsqw4jsL2qfwzZJt/0S9hBQk1Dc9XL78lmuouk7GHU4HzSaWvvJGGqjxHncsWbcVZ Dd+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713518834; x=1714123634; h=content-transfer-encoding:autocrypt:subject:from:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=VEOircw0jfByTbN8pxNbn68FybSc3JIs4qT6NCZuVUg=; b=T+DUvhxtHUb+IlYIpGWvrovBWsgCQiy4OT8vVC2iiYR0ey8ZRmOLBlmiGhBBplcFF1 z85Tfh3fx5no03cH70munUyhjGHClMpuXhw4wnA5lcy4AeYfwNBJGPqRiG8C6fXLyuX5 GXFDWhAYZ1Ev10JLHn1Pcn5QMttXSdXmzJlLVmtvI+HrdwTotQCrxosIJfhI1kSzNVGl gLNzUOkjbAGMzMkyM+OyTJRVwzJRh4P2d8ghpDd8yqo1sU7d8E+VGP7E35DgYka57jkd PYdqmoVtgp7If41GzH+w2STBf5Ay6ZKmeEtXxYu33UTBBqcqoiUu59s470s7skNLJwob qROg== X-Gm-Message-State: AOJu0YyNMjERjE/nsd32mTinNzi9MDKmQq+PvM3I/ljbu42SY+21H5Qe 5KqmDztI9n3H56U/Z0l1lW01WZQTdbcnR+gANdor50qh/0a3F+YqIg9UPeSI+v/KVqohQzOH/bo = X-Google-Smtp-Source: AGHT+IEKmIrgDvN/yXVlP8mIvHxqH7oZAnvEH+D1rWjow6xlcKpdUEISQeyAMVTr6+2raG0dgIVztA== X-Received: by 2002:a05:600c:314e:b0:418:312b:2681 with SMTP id h14-20020a05600c314e00b00418312b2681mr1015275wmo.7.1713518834105; Fri, 19 Apr 2024 02:27:14 -0700 (PDT) Received: from [10.156.60.236] (ip-037-024-206-209.um08.pools.vodafone-ip.de. [37.24.206.209]) by smtp.gmail.com with ESMTPSA id u18-20020a05600c19d200b0041896d2a05fsm5716638wmq.5.2024.04.19.02.27.13 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 19 Apr 2024 02:27:13 -0700 (PDT) Message-ID: Date: Fri, 19 Apr 2024 11:27:13 +0200 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Content-Language: en-US To: Binutils Cc: Nick Clifton From: Jan Beulich Subject: [PATCH] objcopy: check input flavor before setting PE/COFF section alignment Autocrypt: addr=jbeulich@suse.com; keydata= xsDiBFk3nEQRBADAEaSw6zC/EJkiwGPXbWtPxl2xCdSoeepS07jW8UgcHNurfHvUzogEq5xk hu507c3BarVjyWCJOylMNR98Yd8VqD9UfmX0Hb8/BrA+Hl6/DB/eqGptrf4BSRwcZQM32aZK 7Pj2XbGWIUrZrd70x1eAP9QE3P79Y2oLrsCgbZJfEwCgvz9JjGmQqQkRiTVzlZVCJYcyGGsD /0tbFCzD2h20ahe8rC1gbb3K3qk+LpBtvjBu1RY9drYk0NymiGbJWZgab6t1jM7sk2vuf0Py O9Hf9XBmK0uE9IgMaiCpc32XV9oASz6UJebwkX+zF2jG5I1BfnO9g7KlotcA/v5ClMjgo6Gl MDY4HxoSRu3i1cqqSDtVlt+AOVBJBACrZcnHAUSuCXBPy0jOlBhxPqRWv6ND4c9PH1xjQ3NP nxJu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0A nAuWpQkjM1ASeQwSHEeAWPgskBQL Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-3025.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,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 List-Id: coff_section_data() and elf_section_data() use the same underlying field. The pointer being non-NULL therefore isn't sufficient to know that pei_section_data() can validly be used on the incoming object. Apparently in 64-bit-host builds the resulting memory corruption is benign, whereas in 32-bit-host builds a segmentation fault occurs upon de-referencing pei_section_data()'s return value. --- Of course the value (first) being set on the input bfd is suspicious in the first place: When copying e.g. ELF to PE/COFF, the option ought to be similarly respected, yet clearly it can't be set like this then on the incoming object. The change here is merely to address the testsuite failures observed for Arm64 and RISC-V ("Check if efi app format is recognized") as well as the (latent) memory corruption. --- a/binutils/objcopy.c +++ b/binutils/objcopy.c @@ -4310,6 +4310,7 @@ setup_section (bfd *ibfd, sec_ptr isecti if (p != NULL) alignment = p->alignment; else if (pe_section_alignment != (bfd_vma) -1 + && bfd_get_flavour (ibfd) == bfd_target_coff_flavour && bfd_get_flavour (obfd) == bfd_target_coff_flavour) { alignment = power_of_two (pe_section_alignment);