]> git.ipfire.org Git - thirdparty/grub.git/commitdiff
net/tftp: Avoid a trivial UAF
authorDaniel Axtens <dja@axtens.net>
Tue, 18 Jan 2022 03:29:20 +0000 (14:29 +1100)
committerDaniel Kiper <daniel.kiper@oracle.com>
Tue, 7 Jun 2022 14:39:33 +0000 (16:39 +0200)
Under tftp errors, we print a tftp error message from the tftp header.
However, the tftph pointer is a pointer inside nb, the netbuff. Previously,
we were freeing the nb and then dereferencing it. Don't do that, use it
and then free it later.

This isn't really _bad_ per se, especially as we're single-threaded, but
it trips up fuzzers.

Signed-off-by: Daniel Axtens <dja@axtens.net>
Reviewed-by: Daniel Kiper <daniel.kiper@oracle.com>
grub-core/net/tftp.c

index ee305e18a2a48485ca84848153f65492b29e30dd..7dbd3056d6639737feabdef18f59f1bc17af0442 100644 (file)
@@ -251,9 +251,9 @@ tftp_receive (grub_net_udp_socket_t sock __attribute__ ((unused)),
       return GRUB_ERR_NONE;
     case TFTP_ERROR:
       data->have_oack = 1;
-      grub_netbuff_free (nb);
       grub_error (GRUB_ERR_IO, "%s", tftph->u.err.errmsg);
       grub_error_save (&data->save_err);
+      grub_netbuff_free (nb);
       return GRUB_ERR_NONE;
     default:
       grub_netbuff_free (nb);