Skip to contentSkip to conversation

libavb: fix avb_replace() OOM handling

PATCH In review Josh Law 6 participants 9 messages May 21 – May 26

lore
Share & tools
lore

Josh Law

author
#0 lore raw

cover libavb: fix avb_replace() OOM handling

Hi folks,

Since I am a new contributor, I would like to introduce myself first. I am 15, I am from the UK, and I write C. I am interested in lib/, ARM devices, and Android.

Enough of the introduction. Let's talk about the patch.

avb_replace() is documented to return NULL on OOM. It already did that before any output was built, but if a later allocation failed after the first replacement, it returned the partial buffer instead. The callers only treat NULL as failure, so they could keep booting with truncated AVB bootargs.

This patch frees the partial buffer and returns NULL. The existing callers can then report OOM instead of accepting a shortened result.

Josh Law (1):
libavb: fix avb_replace() OOM handling

 lib/libavb/avb_util.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
Signature · 1 line
2.47.3
author
#1 lore raw

PATCH 1/1 libavb: fix avb_replace() OOM handling

avb_replace() promises NULL on OOM. Once it had built the first replacement, a later allocation failure returned that partial buffer. Callers treat any result as success, so AVB could keep booting with truncated bootargs.

Free the partial result and return NULL. The existing callers can then take their OOM path.

---
 lib/libavb/avb_util.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
lib/libavb/avb_util.c +7 -3
index 8719ede15a7..9e2e6ea3495 100644
@@ -272,7 +272,7 @@ char* avb_replace(const char* str, const char* search, const char* replace) {
       num_new = num_before + replace_len + 1;
       ret = avb_malloc(num_new);
       if (ret == NULL) {
-        goto out;
+        goto fail;
       }
       avb_memcpy(ret, str, num_before);
       avb_memcpy(ret + num_before, replace, replace_len);
@@ -283,7 +283,7 @@ char* avb_replace(const char* str, const char* search, const char* replace) {
       num_new = ret_len + num_before + replace_len + 1;
       new_str = avb_malloc(num_new);
       if (new_str == NULL) {
-        goto out;
+        goto fail;
       }
       avb_memcpy(new_str, ret, ret_len);
       avb_memcpy(new_str + ret_len, str, num_before);
@@ -308,7 +308,7 @@ char* avb_replace(const char* str, const char* search, const char* replace) {
     size_t num_new = ret_len + num_remaining + 1;
     char* new_str = avb_malloc(num_new);
     if (new_str == NULL) {
-      goto out;
+      goto fail;
     }
     avb_memcpy(new_str, ret, ret_len);
     avb_memcpy(new_str + ret_len, str_after_last_replace, num_remaining);
@@ -320,6 +320,10 @@ char* avb_replace(const char* str, const char* search, const char* replace) {
 
 out:
   return ret;
+
+fail:
+  avb_free(ret);
+  return NULL;
 }
 
 /* We only support a limited amount of strings in avb_strdupv(). */
Signature · 1 line
2.47.3
Reviewed-by on v1 1/1
#2 lore raw
Quoted 7 lines · Josh Law

libavb: fix avb_replace() OOM handling

avb_replace() promises NULL on OOM. Once it had built the first replacement, a later allocation failure returned that partial buffer. Callers treat any result as success, so AVB could keep booting with truncated bootargs.

Quoted 7 lines

Free the partial result and return NULL. The existing callers can then take their OOM path.

lib/libavb/avb_util.c | 10 +++++++---

 1 file changed, 7 insertions(+), 3 deletions(-)
#3 lore raw
In reply to Josh Law
Quoted 4 lines · Josh Law

Hi folks,

Since I am a new contributor, I would like to introduce myself first. I am 15...

Wow, we have a "Benjamin Button" case here. I seem to remember he was 19 in the kernel mailing list ... :shrug:

--
Javier Viguera
Digi International Inc.

#4 lore raw

Hi Javier,

Quoted 7 lines · Javier Viguera
Quoted 4 lines · Josh Law

Hi folks,

Since I am a new contributor, I would like to introduce myself first. I am 15...

Wow, we have a "Benjamin Button" case here. I seem to remember he was 19 in the kernel mailing list ... :shrug:

Thank you for emailing a about this. Your message made me curious so i've found:
https://lore.kernel.org/lkml/[email protected]/

I'm no longer sure now if I should spend time reviewing this patch or not (because of bot suspicion)

Quoted 4 lines

--
Javier Viguera
Digi International Inc.

author
#5 lore raw
Quoted 13 lines · Mattijs Korpershoek

Hi Javier,

Quoted 7 lines · Javier Viguera
Quoted 4 lines · Josh Law

Hi folks,

Since I am a new contributor, I would like to introduce myself first. I am 15...

Wow, we have a "Benjamin Button" case here. I seem to remember he was 19 in the kernel mailing list ... :shrug:

Quoted 6 lines

Thank you for emailing a about this. Your message made me curious so i've found:
https://lore.kernel.org/lkml/[email protected]/

I'm no longer sure now if I should spend time reviewing this patch or not (because of bot suspicion)

Hey Mattijs,

It's entirely your choice if you would like to review this!

If you have any questions, feel free to ask! :)

Any concerns also feel free to make known.

(P.S: Simon did some of the heavy lifting with his tag :) )

If you choose not to review this that's fine!

Thanks for the polite comment, it's appreciated :)

Quoted 5 lines
Quoted 4 lines

--
Javier Viguera
Digi International Inc.

Thanks!

#6 lore raw
In reply to Mattijs Korpershoek
Quoted 12 lines · Mattijs Korpershoek

Hi Javier,

Quoted 7 lines · Javier Viguera
Quoted 4 lines · Josh Law

Hi folks,

Since I am a new contributor, I would like to introduce myself first. I am 15...

Wow, we have a "Benjamin Button" case here. I seem to remember he was 19 in the kernel mailing list ... :shrug:

Quoted 6 lines

Thank you for emailing a about this. Your message made me curious so i've found:
https://lore.kernel.org/lkml/[email protected]/

I'm no longer sure now if I should spend time reviewing this patch or not (because of bot suspicion)

Yes, I've moved to Deferred in patchwork as this is an extremely disappointing thing to have happened.

Signature · 1 line
Tom
#7 lore raw
Quoted 10 lines · Tom Rini
Quoted 9 lines · Mattijs Korpershoek

Hi Javier,

Quoted 5 lines · Javier Viguera
Quoted 4 lines · Josh Law

Hi folks,

Since I am a new contributor, I would like to introduce myself first. I am 15...

Claiming to be 15 does deepen my concern, because I clearly remember seeing Josh claim to be 19 on the lkml about two months ago [1], so this is clearly a mismatch. If even his age has different versions, it makes me doubt whether the rest of what he says can be trusted.

I previously had a private conversation with Steven Rostedt regarding Josh. At the time, Steven felt that Josh was just a young kid that didn't know any better, but in the end, Steven also gave up and decided to stop helping him [2].

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/

Regards,
Kuan-Wei

Quoted 15 lines
Quoted 9 lines
Quoted 2 lines

Wow, we have a "Benjamin Button" case here. I seem to remember he was 19 in the kernel mailing list ... :shrug:

Thank you for emailing a about this. Your message made me curious so i've found:
https://lore.kernel.org/lkml/[email protected]/

I'm no longer sure now if I should spend time reviewing this patch or not (because of bot suspicion)

Yes, I've moved to Deferred in patchwork as this is an extremely disappointing thing to have happened.

Signature · 1 line
Tom
#8 lore raw
Quoted 17 lines · Kuan-Wei Chiu
Quoted 10 lines · Tom Rini
Quoted 9 lines · Mattijs Korpershoek

Hi Javier,

Quoted 5 lines · Javier Viguera
Quoted 4 lines · Josh Law

Hi folks,

Since I am a new contributor, I would like to introduce myself first. I am 15...

Claiming to be 15 does deepen my concern, because I clearly remember seeing Josh claim to be 19 on the lkml about two months ago [1], so this is clearly a mismatch. If even his age has different versions, it makes me doubt whether the rest of what he says can be trusted.

Quoted 7 lines

I previously had a private conversation with Steven Rostedt regarding Josh. At the time, Steven felt that Josh was just a young kid that didn't know any better, but in the end, Steven also gave up and decided to stop helping him [2].

[1]: https://lore.kernel.org/lkml/[email protected]/
[2]: https://lore.kernel.org/lkml/[email protected]/

Thanks for bringing the further background to the rest of the U-Boot community's attention.

Signature · 1 line
Tom