Skip to contentSkip to conversation

Delete Net Routes for Deleted Interfaces

PATCH In review Andrew Hamilton 1 participant 4 messages Sep 1, 2024 – Oct 3, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

v2 cover Delete Net Routes for Deleted Interfaces

Correct incorrect handling of routes being maintained when an associated interface is deleted. Previously the route(s) for an interface being removed were not deleted. This resulted in displaying corrupted output to the console in the following sequence:
net_add_addr
if0 emu0 192.168.100.2
net_ls_routes if0:local 192.168.100.0/24 if0
net_del_addr if0
net_ls_routes if0:local 192.168.100.0/24 ???
...
net_ls_routes
if0:local 192.168.100.0/24 ?7?
The fields including the question marks above will contain pseudo-random data from the heap which may change over time. In some cases this may have resulted in crashes as well after a route was deleted and attempted to be used in actual network routing operations.
With this update, routes mapped to a deleted interface will be deleted.

In addition, a test was added for testing the network commands. This test will still run without the net.c change but it will fail. With the net.c change, this test will pass on grub-emu and be skipped for other platforms.

Changes since v1:
(Ref:
https://lists.gnu.org/archive/html/grub-devel/2024-08/msg00138.html)
- Add net_test
- Resubmit net.c change due to incorrect patch submission before.

Andrew Hamilton (2):
Add a test for the grub-emu environment to test various network
commands such as adding addresses, updating routes, etc.
Correct incorrect handling of routes being maintained when an
associated interface is deleted. Previously the route(s) for an interface being removed were not deleted. This resulted in displaying corrupted output to the console in the following
sequence: net_add_addr if0 emu0 192.168.100.2 net_ls_routes if0:local 192.168.100.0/24 if0 net_del_addr if0 net_ls_routes if0:local 192.168.100.0/24 ??? ... net_ls_routes if0:local 192.168.100.0/24 ?7? The fields including the question marks above will contain pseudo-random data from the heap which may change over time. In some cases this may have resulted in crashes as well after a route was deleted and attempted to be used in actual network routing operations. With this update, routes mapped to a deleted interface will be deleted.

 Makefile.util.def   |   6 ++
 grub-core/net/net.c |  17 ++++
 tests/net_test.in   | 187 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 210 insertions(+)
 create mode 100644 tests/net_test.in
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#1 lore raw

PATCH v2 1/2 tests: Add net_test for network commands

Makefile.util.def +6 -0
index 0f74a1680..9ed211bc5 100644
@@ -1131,6 +1131,12 @@ script = {
   common = tests/cdboot_test.in;
 };
 
+script = {
+  testcase = nonnative;
+  name = net_test;
+  common = tests/net_test.in;
+};
+
 script = {
   testcase = nonnative;
   name = netboot_test;
tests/net_test.in new file +187 -0

187 lines not on this page · raw message

Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#2 lore raw

PATCH v2 2/2 net/net: Delete Routes for Deleted Interfaces

In reply to Andrew Hamilton
---
 grub-core/net/net.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
grub-core/net/net.c +17 -0
index 8cad4fb6d..51e0dd312 100644
@@ -718,6 +718,23 @@ grub_cmd_deladdr (struct grub_command *cmd __attribute__ ((unused)),
     return grub_error (GRUB_ERR_IO,
 		       N_("you can't delete this address"));
 
+  struct grub_net_route *route;
+  struct grub_net_route **prev;
+
+  /* Remove any existing routes using this interface. */
+  for (prev = &grub_net_routes, route = *prev; route;
+       prev = &((*prev)->next), route = *prev)
+    {
+      if (grub_strcmp (route->interface->name, inter->name) == 0)
+        {
+          *prev = route->next;
+          grub_free (route->name);
+          grub_free (route);
+          if (*prev == NULL)
+            break;
+        }
+    }
+
   grub_net_network_level_interface_unregister (inter);
   grub_free (inter->name);
   grub_free (inter);
Signature · 7 lines
2.39.2


_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel
#3 lore raw
In reply to Andrew Hamilton

Any feedback on this? I can regenerate and resend the patch if there are any conflicts with other updates.

Thanks,
Andrew

Quoted 46 lines · Andrew Hamilton

Correct incorrect handling of routes being maintained when an associated interface is deleted. Previously the route(s) for an interface being removed were not deleted. This resulted in displaying corrupted output to the console in the following sequence:
net_add_addr
if0 emu0 192.168.100.2
net_ls_routes if0:local 192.168.100.0/24 if0
net_del_addr if0
net_ls_routes if0:local 192.168.100.0/24 ???
...
net_ls_routes
if0:local 192.168.100.0/24 ?7?
The fields including the question marks above will contain pseudo-random data from the heap which may change over time. In some cases this may have resulted in crashes as well after a route was deleted and attempted to be used in actual network routing operations.
With this update, routes mapped to a deleted interface will be deleted.

In addition, a test was added for testing the network commands. This test will still run without the net.c change but it will fail. With the net.c change, this test will pass on grub-emu and be skipped for other platforms.

Changes since v1:
(Ref:
https://lists.gnu.org/archive/html/grub-devel/2024-08/msg00138.html)
- Add net_test
- Resubmit net.c change due to incorrect patch submission before.

Andrew Hamilton (2):
Add a test for the grub-emu environment to test various network
commands such as adding addresses, updating routes, etc.
Correct incorrect handling of routes being maintained when an
associated interface is deleted. Previously the route(s) for an interface being removed were not deleted. This resulted in displaying corrupted output to the console in the following
sequence: net_add_addr if0 emu0 192.168.100.2 net_ls_routes if0:local 192.168.100.0/24 if0 net_del_addr if0 net_ls_routes if0:local 192.168.100.0/24 ??? ... net_ls_routes if0:local 192.168.100.0/24 ?7? The fields including the question marks above will contain pseudo-random data from the heap which may change over time. In some cases this may have resulted in crashes as well after a route was deleted and attempted to be used in actual network routing operations. With this update, routes mapped to a deleted interface will be deleted.

Quoted 10 lines
 Makefile.util.def   |   6 ++
 grub-core/net/net.c |  17 ++++
 tests/net_test.in   | 187 ++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 210 insertions(+)
 create mode 100644 tests/net_test.in

--
2.39.2

_______________________________________________
Grub-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel