|
| 1 | +From 8ab67bb3b37cec634490294560d082bafda7cc66 Mon Sep 17 00:00:00 2001 |
| 2 | +From: jykanase < [email protected]> |
| 3 | +Date: Mon, 2 Jun 2025 07:47:48 +0000 |
| 4 | +Subject: [PATCH] CVE-2025-0624 |
| 5 | +Upstream Reference Patch: https://lists.gnu.org/archive/html/grub-devel/2025-02/msg00052.html |
| 6 | +https://lists.gnu.org/archive/html/grub-devel/2025-02/msg00027.html |
| 7 | +--- |
| 8 | + grub-core/net/net.c | 7 ++++--- |
| 9 | + grub-core/normal/main.c | 2 +- |
| 10 | + include/grub/misc.h | 39 +++++++++++++++++++++++++++++++++++++++ |
| 11 | + include/grub/net.h | 2 +- |
| 12 | + 4 files changed, 45 insertions(+), 5 deletions(-) |
| 13 | + |
| 14 | +diff --git a/grub-core/net/net.c b/grub-core/net/net.c |
| 15 | +index 4d3eb5c..ec7f01c 100644 |
| 16 | +--- a/grub-core/net/net.c |
| 17 | ++++ b/grub-core/net/net.c |
| 18 | +@@ -1773,14 +1773,15 @@ grub_config_search_through (char *config, char *suffix, |
| 19 | + } |
| 20 | + |
| 21 | + grub_err_t |
| 22 | +-grub_net_search_config_file (char *config) |
| 23 | ++grub_net_search_config_file (char *config, grub_size_t config_buf_len) |
| 24 | + { |
| 25 | +- grub_size_t config_len; |
| 26 | ++ grub_size_t config_len, suffix_len; |
| 27 | + char *suffix; |
| 28 | + |
| 29 | + config_len = grub_strlen (config); |
| 30 | + config[config_len] = '-'; |
| 31 | + suffix = config + config_len + 1; |
| 32 | ++ suffix_len = config_buf_len - (config_len + 1); |
| 33 | + |
| 34 | + struct grub_net_network_level_interface *inf; |
| 35 | + FOR_NET_NETWORK_LEVEL_INTERFACES (inf) |
| 36 | +@@ -1806,7 +1807,7 @@ grub_net_search_config_file (char *config) |
| 37 | + |
| 38 | + if (client_uuid) |
| 39 | + { |
| 40 | +- grub_strcpy (suffix, client_uuid); |
| 41 | ++ grub_strlcpy (suffix, client_uuid, suffix_len); |
| 42 | + if (grub_config_search_through (config, suffix, 1, 0) == 0) |
| 43 | + return GRUB_ERR_NONE; |
| 44 | + } |
| 45 | +diff --git a/grub-core/normal/main.c b/grub-core/normal/main.c |
| 46 | +index c4ebe9e..68ef09c 100644 |
| 47 | +--- a/grub-core/normal/main.c |
| 48 | ++++ b/grub-core/normal/main.c |
| 49 | +@@ -344,7 +344,7 @@ grub_cmd_normal (struct grub_command *cmd __attribute__ ((unused)), |
| 50 | + |
| 51 | + if (grub_strncmp (prefix + 1, "tftp", sizeof ("tftp") - 1) == 0 && |
| 52 | + !disable_net_search) |
| 53 | +- grub_net_search_config_file (config); |
| 54 | ++ grub_net_search_config_file (config, config_len); |
| 55 | + |
| 56 | + grub_enter_normal_mode (config); |
| 57 | + grub_free (config); |
| 58 | +diff --git a/include/grub/misc.h b/include/grub/misc.h |
| 59 | +index 7d2b551..0507567 100644 |
| 60 | +--- a/include/grub/misc.h |
| 61 | ++++ b/include/grub/misc.h |
| 62 | +@@ -64,6 +64,45 @@ grub_stpcpy (char *dest, const char *src) |
| 63 | + return d - 1; |
| 64 | + } |
| 65 | + |
| 66 | ++static inline grub_size_t |
| 67 | ++grub_strlcpy (char *dest, const char *src, grub_size_t size) |
| 68 | ++{ |
| 69 | ++ char *d = dest; |
| 70 | ++ grub_size_t res = 0; |
| 71 | ++ /* |
| 72 | ++ * We do not subtract one from size here to avoid dealing with underflowing |
| 73 | ++ * the value, which is why to_copy is always checked to be greater than one |
| 74 | ++ * throughout this function. |
| 75 | ++ */ |
| 76 | ++ grub_size_t to_copy = size; |
| 77 | ++ |
| 78 | ++ /* Copy size - 1 bytes to dest. */ |
| 79 | ++ if (to_copy > 1) |
| 80 | ++ while ((*d++ = *src++) != '\0' && ++res && --to_copy > 1) |
| 81 | ++ ; |
| 82 | ++ |
| 83 | ++ /* |
| 84 | ++ * NUL terminate if size != 0. The previous step may have copied a NUL byte |
| 85 | ++ * if it reached the end of the string, but we know dest[size - 1] must always |
| 86 | ++ * be a NUL byte. |
| 87 | ++ */ |
| 88 | ++ if (size != 0) |
| 89 | ++ dest[size - 1] = '\0'; |
| 90 | ++ |
| 91 | ++ /* If there is still space in dest, but are here, we reached the end of src. */ |
| 92 | ++ if (to_copy > 1) |
| 93 | ++ return res; |
| 94 | ++ |
| 95 | ++ /* |
| 96 | ++ * If we haven't reached the end of the string, iterate through to determine |
| 97 | ++ * the strings total length. |
| 98 | ++ */ |
| 99 | ++ while (*src++ != '\0' && ++res) |
| 100 | ++ ; |
| 101 | ++ |
| 102 | ++ return res; |
| 103 | ++} |
| 104 | ++ |
| 105 | + /* XXX: If grub_memmove is too slow, we must implement grub_memcpy. */ |
| 106 | + static inline void * |
| 107 | + grub_memcpy (void *dest, const void *src, grub_size_t n) |
| 108 | +diff --git a/include/grub/net.h b/include/grub/net.h |
| 109 | +index 7ae4b6b..d6ba8b1 100644 |
| 110 | +--- a/include/grub/net.h |
| 111 | ++++ b/include/grub/net.h |
| 112 | +@@ -570,7 +570,7 @@ void |
| 113 | + grub_net_remove_dns_server (const struct grub_net_network_level_address *s); |
| 114 | + |
| 115 | + grub_err_t |
| 116 | +-grub_net_search_config_file (char *config); |
| 117 | ++grub_net_search_config_file (char *config, grub_size_t config_buf_len); |
| 118 | + |
| 119 | + extern char *grub_net_default_server; |
| 120 | + |
| 121 | +-- |
| 122 | +2.45.2 |
| 123 | + |
0 commit comments