From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754589AbdJINzG (ORCPT ); Mon, 9 Oct 2017 09:55:06 -0400 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:41922 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754241AbdJIMo6 (ORCPT ); Mon, 9 Oct 2017 08:44:58 -0400 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Paolo Abeni" , "David S. Miller" Date: Mon, 09 Oct 2017 13:44:25 +0100 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) Subject: [PATCH 3.16 140/192] net/route: enforce hoplimit max value In-Reply-To: X-SA-Exim-Connect-IP: 2a02:8011:400e:2:6f00:88c8:c921:d332 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.49-rc1 review patch. If anyone has any objections, please let me know. ------------------ From: Paolo Abeni [ Upstream commit 626abd59e51d4d8c6367e03aae252a8aa759ac78 ] Currently, when creating or updating a route, no check is performed in both ipv4 and ipv6 code to the hoplimit value. The caller can i.e. set hoplimit to 256, and when such route will be used, packets will be sent with hoplimit/ttl equal to 0. This commit adds checks for the RTAX_HOPLIMIT value, in both ipv4 ipv6 route code, substituting any value greater than 255 with 255. This is consistent with what is currently done for ADVMSS and MTU in the ipv4 code. Signed-off-by: Paolo Abeni Signed-off-by: David S. Miller [bwh: Backported to 3.16: for IPv6, add the check to fib6_commit_metrics()] Signed-off-by: Ben Hutchings --- --- a/net/ipv4/fib_semantics.c +++ b/net/ipv4/fib_semantics.c @@ -862,6 +862,8 @@ struct fib_info *fib_create_info(struct val = 65535 - 40; if (type == RTAX_MTU && val > 65535 - 15) val = 65535 - 15; + if (type == RTAX_HOPLIMIT && val > 255) + val = 255; fi->fib_metrics[type - 1] = val; } } --- a/net/ipv6/ip6_fib.c +++ b/net/ipv6/ip6_fib.c @@ -653,10 +653,14 @@ static int fib6_commit_metrics(struct ds int type = nla_type(nla); if (type) { + u32 val = nla_get_u32(nla); + if (type > RTAX_MAX) return -EINVAL; - mp[type - 1] = nla_get_u32(nla); + if (type == RTAX_HOPLIMIT && val > 255) + val = 255; + mp[type - 1] = val; } } return 0;