|
| 1 | +From 05e4ba7b0d126eea4c04387dcf40596059ee24af Mon Sep 17 00:00:00 2001 |
| 2 | +From: Hangbin Liu <liuhangbin@gmail.com> |
| 3 | +Date: Wed, 5 Jun 2024 11:57:43 +0800 |
| 4 | +Subject: [PATCH] libndp: valid route information option length |
| 5 | + |
| 6 | +RFC 4191 specifies that the Route Information Option Length should be 1, 2, |
| 7 | +or 3, depending on the Prefix Length. A malicious node could potentially |
| 8 | +trigger a buffer overflow and crash the tool by sending an IPv6 router |
| 9 | +advertisement message containing the "Route Information" option with a |
| 10 | +"Length" field larger than 3. |
| 11 | + |
| 12 | +To address this, add a check on the length field. |
| 13 | + |
| 14 | +Fixes: 8296a5bf0755 ("add support for Route Information Option (rfc4191)") |
| 15 | +Reported-by: Evgeny Vereshchagin <evverx@gmail.com> |
| 16 | +Suggested-by: Felix Maurer <fmaurer@redhat.com> |
| 17 | +Signed-off-by: Hangbin Liu <liuhangbin@gmail.com> |
| 18 | +Signed-off-by: Jiri Pirko <jiri@nvidia.com> |
| 19 | +--- |
| 20 | + libndp/libndp.c | 11 +++++++++++ |
| 21 | + 1 file changed, 11 insertions(+) |
| 22 | + |
| 23 | +diff --git a/libndp/libndp.c b/libndp/libndp.c |
| 24 | +index 6314717..72ec92e 100644 |
| 25 | +--- a/libndp/libndp.c |
| 26 | ++++ b/libndp/libndp.c |
| 27 | +@@ -1231,6 +1231,17 @@ static bool ndp_msg_opt_route_check_valid(void *opt_data) |
| 28 | + */ |
| 29 | + if (((ri->nd_opt_ri_prf_reserved >> 3) & 3) == 2) |
| 30 | + return false; |
| 31 | ++ |
| 32 | ++ /* The Length field is 1, 2, or 3 depending on the Prefix Length. |
| 33 | ++ * If Prefix Length is greater than 64, then Length must be 3. |
| 34 | ++ * If Prefix Length is greater than 0, then Length must be 2 or 3. |
| 35 | ++ * If Prefix Length is zero, then Length must be 1, 2, or 3. |
| 36 | ++ */ |
| 37 | ++ if (ri->nd_opt_ri_len > 3 || |
| 38 | ++ (ri->nd_opt_ri_prefix_len > 64 && ri->nd_opt_ri_len != 3) || |
| 39 | ++ (ri->nd_opt_ri_prefix_len > 0 && ri->nd_opt_ri_len == 1)) |
| 40 | ++ return false; |
| 41 | ++ |
| 42 | + return true; |
| 43 | + } |
| 44 | + |
0 commit comments