Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jLhYL-0006q1-Hn for mharc-grub-devel@gnu.org; Tue, 07 Apr 2020 02:17:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:34090) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jLhYI-0006my-FD for grub-devel@gnu.org; Tue, 07 Apr 2020 02:17:39 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1jLhYH-0005XS-7F for grub-devel@gnu.org; Tue, 07 Apr 2020 02:17:38 -0400 Received: from mail-pj1-x1042.google.com ([2607:f8b0:4864:20::1042]:38231) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1jLhYH-0005Wi-0i for grub-devel@gnu.org; Tue, 07 Apr 2020 02:17:37 -0400 Received: by mail-pj1-x1042.google.com with SMTP id m15so308156pje.3 for ; Mon, 06 Apr 2020 23:17:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=axtens.net; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kpWa0ZhDOXHsDn53rO8HBEqYVjyN+9sV/jTeoTbMUIQ=; b=qCp1ZWcdinl+us21UpPuwZtC6/WEm4JOg/Fpa0ZKrPs4UowxkVDHJT6aC6oyWIQ2pC FtiofuPvJDFSXNKUe7x9xohuMdsWthFh0IyKrw8zBu0OhD6kfujIwApkEsLaTmy3Bv2S /fkyuclhLHio94Nt/GMhJHu9BAE2SGPcPd5S8= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=kpWa0ZhDOXHsDn53rO8HBEqYVjyN+9sV/jTeoTbMUIQ=; b=KpAYTxqg1qMDdQSm8saXC1s3xbMoMph4IrVG+7NiO16qHAFzTWWn5TAZdmsvQxovOa p6kst1uTy48Yz69mCyWy5aYRNWUJC4SyiGbMvzBLrbr71F6w1OxEAWBhPHDZ3PI3E823 VSXCcN3JJydOCDHuacFVw7TuY+/aSbxeeguaAsxa4mTFVthw9NvUK5Eew66ZI56s7VZt S9S8QvMIz1CE77gOGocHengAf4m0hIAbFmOVJhgVHZdFVBYiityhZ1EPXgRcfBIm7gmG OtjY7dT0lj3tKwiSpXfHvn04rV/NpLmuQ9oM/bgAPqYgWBQqpjuMnbBVWS9A90FhtRjV wFIA== X-Gm-Message-State: AGi0PubvoMoSeFz7+6VUOVMAhSy+8hohCuB13d6LsMVtkJX1WlgS4UCc bKg4g0ZGUMKuCcI8u+qMsgirD6OvJWc= X-Google-Smtp-Source: APiQypL8c/7143HXiEQNxMBzSDU4KKMBnpbMCdSN4AjaajEoYsY2EmlQeJeVBuFykTEdJXC4xJ7nHQ== X-Received: by 2002:a17:90a:aa96:: with SMTP id l22mr398292pjq.1.1586240254916; Mon, 06 Apr 2020 23:17:34 -0700 (PDT) Received: from localhost (2001-44b8-111e-5c00-ed8d-5978-7d9f-d028.static.ipv6.internode.on.net. [2001:44b8:111e:5c00:ed8d:5978:7d9f:d028]) by smtp.gmail.com with ESMTPSA id my15sm665898pjb.28.2020.04.06.23.17.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Apr 2020 23:17:34 -0700 (PDT) From: Daniel Axtens To: grub-devel@gnu.org Cc: Daniel Axtens Subject: [PATCH] mkimage: powerpc: fix CHRP note descsz Date: Tue, 7 Apr 2020 16:17:26 +1000 Message-Id: <20200407061726.18460-1-dja@axtens.net> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::1042 X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 07 Apr 2020 06:17:39 -0000 Currently, an image generated with 'grub-mkimage -n' causes an error when read with 'readelf -a': Displaying notes found at file offset 0x000106f0 with length 0x0000002c: Owner Data size Description readelf: Warning: note with invalid namesz and/or descsz found at offset 0x0 readelf: Warning: type: 0x1275, namesize: 0x00000008, descsize: 0x0000002c, alignment: 4 This is because the descsz of the CHRP note is set to sizeof (struct grub_ieee1275_note) which is the size of the entire note, including name and elf header. The desczs should contain only the contents, not the name and header sizes. Set the descsz instead to 'sizeof (struct grub_ieee1275_note_desc)' Resultant readelf output: Displaying notes found at file offset 0x00010710 with length 0x0000002c: Owner Data size Description PowerPC 0x00000018 Unknown note type: (0x00001275) description data: ff ff ff ff 00 c0 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 00 00 40 00 So far as I can tell this issue has existed for as long as the note generation code has existed, but I guess nothing really checks descsz. Signed-off-by: Daniel Axtens --- These days you can't (AFAICT) add a note section with grub-install, you have to use grub-mkimage and install the binary manually, so the change is unlikely to cause a regression. I also can't find any code in SLOF that would read this note, so I guess it's only the proprietary IBM hypervisor that looks for it. Nonetheless, it would be nice to have the fix: I ended up duplicating the bug into some new code I'm writing to add a different note section at the end of the binary and it cost me a fair bit of time. --- util/grub-mkimagexx.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/util/grub-mkimagexx.c b/util/grub-mkimagexx.c index d16ec63a16ff..ab6dfab79242 100644 --- a/util/grub-mkimagexx.c +++ b/util/grub-mkimagexx.c @@ -463,7 +463,7 @@ SUFFIX (grub_mkimage_generate_elf) (const struct grub_install_image_target_desc grub_util_info ("adding CHRP NOTE segment"); note_ptr->header.n_namesz = grub_host_to_target32 (sizeof (GRUB_IEEE1275_NOTE_NAME)); - note_ptr->header.n_descsz = grub_host_to_target32 (note_size); + note_ptr->header.n_descsz = grub_host_to_target32 (sizeof (struct grub_ieee1275_note_desc)); note_ptr->header.n_type = grub_host_to_target32 (GRUB_IEEE1275_NOTE_TYPE); strcpy (note_ptr->name, GRUB_IEEE1275_NOTE_NAME); note_ptr->descriptor.real_mode = grub_host_to_target32 (0xffffffff); -- 2.20.1