f0ad2aa
From 0000000000000000000000000000000000000000 Mon Sep 17 00:00:00 2001
f0ad2aa
From: Daniel Axtens <dja@axtens.net>
f0ad2aa
Date: Tue, 18 Jan 2022 14:29:20 +1100
f0ad2aa
Subject: [PATCH] net/tftp: Avoid a trivial UAF
f0ad2aa
f0ad2aa
Under tftp errors, we print a tftp error message from the tftp header.
f0ad2aa
However, the tftph pointer is a pointer inside nb, the netbuff. Previously,
f0ad2aa
we were freeing the nb and then dereferencing it. Don't do that, use it
f0ad2aa
and then free it later.
f0ad2aa
f0ad2aa
This isn't really _bad_ per se, especially as we're single-threaded, but
f0ad2aa
it trips up fuzzers.
f0ad2aa
f0ad2aa
Signed-off-by: Daniel Axtens <dja@axtens.net>
f0ad2aa
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
f0ad2aa
(cherry picked from commit 956f4329cec23e4375182030ca9b2be631a61ba5)
f0ad2aa
---
f0ad2aa
 grub-core/net/tftp.c | 2 +-
f0ad2aa
 1 file changed, 1 insertion(+), 1 deletion(-)
f0ad2aa
f0ad2aa
diff --git a/grub-core/net/tftp.c b/grub-core/net/tftp.c
f0ad2aa
index 788ad1dc44..a95766dcbd 100644
f0ad2aa
--- a/grub-core/net/tftp.c
f0ad2aa
+++ b/grub-core/net/tftp.c
f0ad2aa
@@ -251,9 +251,9 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
f0ad2aa
       return GRUB_ERR_NONE;
f0ad2aa
     case TFTP_ERROR:
f0ad2aa
       data->have_oack = 1;
f0ad2aa
-      grub_netbuff_free (nb);
f0ad2aa
       grub_error (GRUB_ERR_IO, "%s", tftph->u.err.errmsg);
f0ad2aa
       grub_error_save (&data->save_err);
f0ad2aa
+      grub_netbuff_free (nb);
f0ad2aa
       return GRUB_ERR_NONE;
f0ad2aa
     default:
f0ad2aa
       grub_netbuff_free (nb);