nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

Blame SOURCES/0530-net-tftp-Avoid-a-trivial-UAF.patch

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