Skip to contentSkip to conversation

Avoid segfault on x86-64 with invalid EFI boot entries

PATCH In review Rhidian De Wit 2 participants 4 messages Aug 25 – Aug 26

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Avoid segfault on x86-64 with invalid EFI boot entries

Upstream: https://github.com/rauc/rauc/pull/2029

---
 ...bootcurrent-is-valid-before-using-it.patch | 43 +++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +43 -0
new file mode 100644
index 0000000000..38fc02c5bf
@@ -0,0 +1,43 @@
+From 931d0af0f66b9afd2a7c9d9532abef1ec67b1f69 Mon Sep 17 00:00:00 2001
+From: Rhidian De Wit <[email protected]>
+Date: Mon, 24 Aug 2026 10:04:24 +0200
+Subject: [PATCH] Check if bootcurrent is valid before using it
+
+Signed-off-by: Rhidian De Wit <[email protected]>
+---
+ src/bootloaders/efi.c | 19 +++++++++++--------
+ 1 file changed, 11 insertions(+), 8 deletions(-)
+
+diff --git a/src/bootloaders/efi.c b/src/bootloaders/efi.c
+index 19224118..6de5f73d 100644
+--- a/src/bootloaders/efi.c
++++ b/src/bootloaders/efi.c
+@@ -625,14 +625,17 @@ gchar *r_efi_get_current_bootname(RaucConfig *config, GError **error)
+ 		return NULL;
+ 	}
+ 
+-	GHashTableIter iter;
+-	g_hash_table_iter_init(&iter, config->slots);
+-	RaucSlot *slot = NULL;
+-	while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
+-		if (g_strcmp0(slot->bootname, bootcurrent->name) == 0) {
+-			return slot->bootname;
+-		}
+-	}
++  if (bootcurrent != NULL)
++  {
++    GHashTableIter iter;
++    g_hash_table_iter_init(&iter, config->slots);
++    RaucSlot *slot = NULL;
++    while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
++      if (g_strcmp0(slot->bootname, bootcurrent->name) == 0) {
++        return slot->bootname;
++      }
++    }
++  }
+ 
+ 	g_set_error(error,
+ 			R_BOOTCHOOSER_ERROR,
+-- 
+2.51.0
+
Signature · 6 lines
2.51.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#1 lore raw

PATCH 1/1 Avoid double-free on x86-64 systems with no cmdline set

Upstream: https://github.com/rauc/rauc/pull/2028

---
 ...i-slot-bootname-to-avoid-double-free.patch | 39 +++++++++++++++++++
 1 file changed, 39 insertions(+)
 create mode 100644 package/rauc/0002-Duplicate-efi-slot-bootname-to-avoid-double-free.patch
package/rauc/0002-Duplicate-efi-slot-bootname-to-avoid-double-free.patch new file +39 -0
new file mode 100644
index 0000000000..a062844659
@@ -0,0 +1,39 @@
+From 1b17578e90b2929e1a7ed1f3eec8d3b5f663b673 Mon Sep 17 00:00:00 2001
+From: Rhidian De Wit <[email protected]>
+Date: Fri, 21 Aug 2026 16:37:45 +0200
+Subject: [PATCH] Duplicate efi slot bootname to avoid double free
+
+Signed-off-by: Rhidian De Wit <[email protected]>
+---
+ src/bootloaders/efi.c | 2 +-
+ test/bootchooser.c    | 1 +
+ 2 files changed, 2 insertions(+), 1 deletion(-)
+
+diff --git a/src/bootloaders/efi.c b/src/bootloaders/efi.c
+index 19224118..8b0cf820 100644
+--- a/src/bootloaders/efi.c
++++ b/src/bootloaders/efi.c
+@@ -630,7 +630,7 @@ gchar *r_efi_get_current_bootname(RaucConfig *config, GError **error)
+ 	RaucSlot *slot = NULL;
+ 	while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
+ 		if (g_strcmp0(slot->bootname, bootcurrent->name) == 0) {
+-			return slot->bootname;
++			return g_strdup(slot->bootname);
+ 		}
+ 	}
+ 
+diff --git a/test/bootchooser.c b/test/bootchooser.c
+index 43c45397..c35a78f1 100644
+--- a/test/bootchooser.c
++++ b/test/bootchooser.c
+@@ -970,6 +970,7 @@ bootname=system1\n";
+ 
+ 	bootname = r_boot_get_current_bootname(r_context()->config, "", &error);
+ 	g_assert_nonnull(bootname);
++	g_clear_pointer(&bootname, g_free);
+ }
+ 
+ /* If the underlying 'efibootmgr --bootorder ...' call fails (e.g. the
+-- 
+2.51.0
+
Signature · 6 lines
2.51.0

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot
#2 lore raw
In reply to Rhidian De Wit

Hi Rhidian!

Am 25.08.26 um 16:30 schrieb Rhidian De Wit:

Quoted 1 line

Upstream: https://github.com/rauc/rauc/pull/2029

The "Upstream" trailer needs to be in the patch file (see below, or [1] for an example).

Quoted 12 lines
---
  ...bootcurrent-is-valid-before-using-it.patch | 43 +++++++++++++++++++
  1 file changed, 43 insertions(+)

create mode 100644 package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +0 -0
new file mode 100644
index 0000000000..38fc02c5bf

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch line 5

Quoted 5 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +5 -0
@@ -0,0 +1,43 @@
+From 931d0af0f66b9afd2a7c9d9532abef1ec67b1f69 Mon Sep 17 00:00:00 2001
+From: Rhidian De Wit <[email protected]>
+Date: Mon, 24 Aug 2026 10:04:24 +0200
+Subject: [PATCH] Check if bootcurrent is valid before using it
+

This is were the "Upstream:" should be.

Quoted 22 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +22 -0
+Signed-off-by: Rhidian De Wit <[email protected]>
+---
+ src/bootloaders/efi.c | 19 +++++++++++--------
+ 1 file changed, 11 insertions(+), 8 deletions(-)
+
+diff --git a/src/bootloaders/efi.c b/src/bootloaders/efi.c
+index 19224118..6de5f73d 100644
+--- a/src/bootloaders/efi.c
++++ b/src/bootloaders/efi.c
+@@ -625,14 +625,17 @@ gchar *r_efi_get_current_bootname(RaucConfig *config, GError **error)
+ 		return NULL;
+ 	}
+
+-	GHashTableIter iter;
+-	g_hash_table_iter_init(&iter, config->slots);
+-	RaucSlot *slot = NULL;
+-	while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
+-		if (g_strcmp0(slot->bootname, bootcurrent->name) == 0) {
+-			return slot->bootname;
+-		}
+-	}
++  if (bootcurrent != NULL)

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch line 37

Quoted 10 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +10 -0
++  {
++    GHashTableIter iter;
++    g_hash_table_iter_init(&iter, config->slots);
++    RaucSlot *slot = NULL;
++    while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
++      if (g_strcmp0(slot->bootname, bootcurrent->name) == 0) {
++        return slot->bootname;
++      }
++    }
++  }

Indentation is very different from the surrounding code (tab vs. 2 spaces per level), I assume upstream will want that fixed, too.

Best regards,
Fiona

[1] https://gitlab.com/buildroot.org/buildroot/-/blob/9dc567aa78e6381ff7100b696535f1ffdd8447f7/package/musl/0003-fix-pathological-slowness-incorrect-mappings-in-icon.patch#L44

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch line 43

Quoted 6 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +6 -0
+
+ 	g_set_error(error,
+ 			R_BOOTCHOOSER_ERROR,
+--
+2.51.0
+

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot

#3 lore raw

Thanks for the pointers! Will fix them!

Op di 25 aug 2026 om 20:11 schreef Fiona Klute <[email protected]>:

Quoted 72 lines

Hi Rhidian!

Am 25.08.26 um 16:30 schrieb Rhidian De Wit:

Quoted 1 line

Upstream: https://github.com/rauc/rauc/pull/2029

The "Upstream" trailer needs to be in the patch file (see below, or [1] for an example).

Quoted 12 lines
---
  ...bootcurrent-is-valid-before-using-it.patch | 43 +++++++++++++++++++
  1 file changed, 43 insertions(+)

create mode 100644 package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +0 -0
new file mode 100644
index 0000000000..38fc02c5bf

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch line 5

Quoted 5 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +5 -0
@@ -0,0 +1,43 @@
+From 931d0af0f66b9afd2a7c9d9532abef1ec67b1f69 Mon Sep 17 00:00:00 2001
+From: Rhidian De Wit <[email protected]>
+Date: Mon, 24 Aug 2026 10:04:24 +0200
+Subject: [PATCH] Check if bootcurrent is valid before using it
+

This is were the "Upstream:" should be.

Quoted 22 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +22 -0
+Signed-off-by: Rhidian De Wit <[email protected]>
+---
+ src/bootloaders/efi.c | 19 +++++++++++--------
+ 1 file changed, 11 insertions(+), 8 deletions(-)
+
+diff --git a/src/bootloaders/efi.c b/src/bootloaders/efi.c
+index 19224118..6de5f73d 100644
+--- a/src/bootloaders/efi.c
++++ b/src/bootloaders/efi.c
+@@ -625,14 +625,17 @@ gchar *r_efi_get_current_bootname(RaucConfig *config, GError **error)
+             return NULL;
+     }
+
+-    GHashTableIter iter;
+-    g_hash_table_iter_init(&iter, config->slots);
+-    RaucSlot *slot = NULL;
+-    while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
+-            if (g_strcmp0(slot->bootname, bootcurrent->name) == 0) {
+-                    return slot->bootname;
+-            }
+-    }
++  if (bootcurrent != NULL)

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch line 37

Quoted 10 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +10 -0
++  {
++    GHashTableIter iter;
++    g_hash_table_iter_init(&iter, config->slots);
++    RaucSlot *slot = NULL;
++    while (g_hash_table_iter_next(&iter, NULL, (gpointer*) &slot)) {
++      if (g_strcmp0(slot->bootname, bootcurrent->name) == 0) {
++        return slot->bootname;
++      }
++    }
++  }

Indentation is very different from the surrounding code (tab vs. 2 spaces per level), I assume upstream will want that fixed, too.

Best regards,
Fiona

[1]
https://gitlab.com/buildroot.org/buildroot/-/blob/9dc567aa78e6381ff7100b696535f1ffdd8447f7/package/musl/0003-fix-pathological-slowness-incorrect-mappings-in-icon.patch#L44

Quoted 7 lines

package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch line 43

Quoted 6 lines
package/rauc/0001-Check-if-bootcurrent-is-valid-before-using-it.patch new file +6 -0
+
+     g_set_error(error,
+                     R_BOOTCHOOSER_ERROR,
+--
+2.51.0
+

_______________________________________________
buildroot mailing list
[email protected]
https://lists.buildroot.org/mailman/listinfo/buildroot