readelf: recognize FDO Packaging Metadata ELF note

Message ID 20211119010328.481640-1-luca.boccassi@gmail.com
State New
Headers show
Series
  • readelf: recognize FDO Packaging Metadata ELF note
Related show

Commit Message

Mike Frysinger via Binutils Nov. 19, 2021, 1:03 a.m.
From: Luca Boccassi <luca.boccassi@microsoft.com>


As defined on: https://systemd.io/COREDUMP_PACKAGE_METADATA/
this note will be used starting from Fedora 36. Allow
readelf --notes to pretty print it:

Displaying notes found in: .note.package
  Owner                Data size 	Description
  FDO                  0x00000039	FDO_PACKAGING_METADATA
    Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"}

Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>

---
 binutils/readelf.c   | 12 ++++++++++++
 include/elf/common.h |  3 +++
 2 files changed, 15 insertions(+)

-- 
2.30.2

Comments

Mike Frysinger via Binutils Nov. 25, 2021, 11:08 a.m. | #1
Hi Luca,

> As defined on: https://systemd.io/COREDUMP_PACKAGE_METADATA/

> this note will be used starting from Fedora 36. Allow

> readelf --notes to pretty print it:

> 

> Displaying notes found in: .note.package

>    Owner                Data size 	Description

>    FDO                  0x00000039	FDO_PACKAGING_METADATA

>      Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"}

> 


Approved - please apply.

Cheers
   Nick
Mike Frysinger via Binutils Dec. 1, 2021, 12:40 p.m. | #2
On Thu, 2021-11-25 at 11:08 +0000, Nick Clifton wrote:
> Hi Luca,

> 

> > As defined on: https://systemd.io/COREDUMP_PACKAGE_METADATA/

> > this note will be used starting from Fedora 36. Allow

> > readelf --notes to pretty print it:

> > 

> > Displaying notes found in: .note.package

> >    Owner                Data size 	Description

> >    FDO                  0x00000039	FDO_PACKAGING_METADATA

> >      Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"}

> > 

> 

> Approved - please apply.

> 

> Cheers

>    Nick


Thank you - any update on committing it?

-- 
Kind regards,
Luca Boccassi
Mike Frysinger via Binutils Dec. 1, 2021, 2:45 p.m. | #3
Hi Luca,

>> Approved - please apply.


(That was a hint to suggest that you could apply the patch yourself).


> Thank you - any update on committing it?


Done. :-)

Cheers
   Nick
Mike Frysinger via Binutils Dec. 1, 2021, 3:47 p.m. | #4
On Wed, 2021-12-01 at 14:45 +0000, Nick Clifton wrote:
> Hi Luca,

> 

> > > Approved - please apply.

> 

> (That was a hint to suggest that you could apply the patch yourself).


Oh sorry, didn't get that - but I'm not a maintainer so I don't think I
can do that?

> > Thank you - any update on committing it?

> 

> Done. :-)


Thank you!

But looks like there was some fuzz or something like that? One part got
applied in the wrong section - from the original email:

@@ -19197,6 +19197,8 @@ get_note_type (Filedata * filedata, unsigned e_type)
 	return _("func");
       case NT_GO_BUILDID:
 	return _("GO BUILDID");
+      case FDO_PACKAGING_METADATA:
+	return _("FDO_PACKAGING_METADATA");
       default:
 	break;
       }

Applied:

@@ -19220,6 +19220,8 @@ get_note_type (Filedata * filedata, unsigned e_type)
        return _("NT_SIGINFO (siginfo_t data)");
       case NT_FILE:
        return _("NT_FILE (mapped files)");
+      case FDO_PACKAGING_METADATA:
+       return _("FDO_PACKAGING_METADATA");
       default:
        break;
       }

But the latter doesn't work, as it's for ELF exec/libs rather than
corefiles:

    Displaying notes found in: .note.package
      Owner                Data size        Description
      FDO                  0x00000039       Unknown note type: (0xcafe1a7e)
        Packaging Metadata: {"type":"deb","name":"fsverity-utils","version":"1.3-1"}


But it's an easy fix, sent a follow-up:

https://sourceware.org/pipermail/binutils/2021-December/118746.html

-- 
Kind regards,
Luca Boccassi
Mike Frysinger via Binutils Dec. 1, 2021, 4:18 p.m. | #5
Hi Luca,

> Oh sorry, didn't get that - but I'm not a maintainer so I don't think I

> can do that?


Actually anyone with write permission can apply patches, although they
do need to be reviewed and approved first, of course.  If you do not
have write permission then an email like the one you sent will do...


> But it's an easy fix, sent a follow-up:

> 

> https://sourceware.org/pipermail/binutils/2021-December/118746.html


Doh - sorry - fixed.

Cheers
   Nick

Patch

diff --git a/binutils/readelf.c b/binutils/readelf.c
index 116f879c892..3ed45f87332 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -19197,6 +19197,8 @@  get_note_type (Filedata * filedata, unsigned e_type)
 	return _("func");
       case NT_GO_BUILDID:
 	return _("GO BUILDID");
+      case FDO_PACKAGING_METADATA:
+	return _("FDO_PACKAGING_METADATA");
       default:
 	break;
       }
@@ -20407,6 +20409,14 @@  print_stapsdt_note (Elf_Internal_Note *pnote)
   return false;
 }
 
+static bool
+print_fdo_note (Elf_Internal_Note *pnote)
+{
+  if (pnote->descsz > 0 && pnote->type == FDO_PACKAGING_METADATA)
+    printf (_("    Packaging Metadata: %.*s\n"), (int) pnote->descsz, pnote->descdata);
+  return true;
+}
+
 static const char *
 get_ia64_vms_note_type (unsigned e_type)
 {
@@ -21140,6 +21150,8 @@  process_note (Elf_Internal_Note *  pnote,
     return print_stapsdt_note (pnote);
   else if (startswith (pnote->namedata, "CORE"))
     return print_core_note (pnote);
+  else if (startswith (pnote->namedata, "FDO"))
+    return print_fdo_note (pnote);
   else if (((startswith (pnote->namedata, "GA")
 	     && strchr ("*$!+", pnote->namedata[2]) != NULL)
 	    || strchr ("*$!+", pnote->namedata[0]) != NULL)
diff --git a/include/elf/common.h b/include/elf/common.h
index 5d31e35ec89..c8331a76e3d 100644
--- a/include/elf/common.h
+++ b/include/elf/common.h
@@ -997,6 +997,9 @@ 
 
 #define NT_FREEBSD_ABI_TAG	1
 
+/* Values for FDO .note.package notes as defined on https://systemd.io/COREDUMP_PACKAGE_METADATA/  */
+#define FDO_PACKAGING_METADATA 0xcafe1a7e
+
 /* These three macros disassemble and assemble a symbol table st_info field,
    which contains the symbol binding and symbol type.  The STB_ and STT_
    defines identify the binding and type.  */