nalika / rpms / grub2

Forked from rpms/grub2 2 years ago
Clone

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

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