From patchwork Thu Aug 13 19:49:01 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Whitcroft X-Patchwork-Id: 507167 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 842D01401AF for ; Fri, 14 Aug 2015 05:49:26 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753881AbbHMTtG (ORCPT ); Thu, 13 Aug 2015 15:49:06 -0400 Received: from mail-wi0-f174.google.com ([209.85.212.174]:37326 "EHLO mail-wi0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752615AbbHMTtE (ORCPT ); Thu, 13 Aug 2015 15:49:04 -0400 Received: by wibhh20 with SMTP id hh20so87699954wib.0 for ; Thu, 13 Aug 2015 12:49:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=RmgOxzBo/OiiVYgDxQgFFvC3CDCOh2jcGGdlbmpCww4=; b=W7JclvQQIu8Qn/MAZK+29cx6vxdvuuCrPpFLSAEFe+4ebM0bFIwkA8BhN+sA8coIRY zeuSOeAktUH1xlsr+jLJ3GvtxpTBEodh0EC9ew49vBh2EFOMhmGDhTPxTVG7mvfCKiRa LeXpuWEf9phI0tzrzV44Mnud7MWs2mw5Q0DfI8m8G2YCPk8o5JRxw4hT3InIJd162Bz5 kBcltft4Qwi9mXZZJNyhIziBPCYSstu4uqHGm4oUWZpzRTLpesiSDa0XtGMGspNtEghf T+qK2zR77z7NAOKwZV8DvQUuutEeGAoUFF4rAeLYtHnTZDqR9eMef4P5Fj1kKFdhk+Yj 8yaw== X-Gm-Message-State: ALoCoQmzWiu7AJgIUo+xLKEsWFKoC/d9qMj6tKDs10q9FWGNC4wDurngsYP5/ESPg6QjUgLl4J6v X-Received: by 10.180.104.68 with SMTP id gc4mr9838952wib.78.1439495343001; Thu, 13 Aug 2015 12:49:03 -0700 (PDT) Received: from localhost ([149.18.33.207]) by smtp.gmail.com with ESMTPSA id eu2sm4835237wic.8.2015.08.13.12.49.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Aug 2015 12:49:02 -0700 (PDT) From: Andy Whitcroft To: "David S. Miller" , Alexey Kuznetsov , James Morris , Hideaki YOSHIFUJI , Patrick McHardy Cc: netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Andy Whitcroft , Eric Dumazet , Alexander Duyck Subject: [PATCH 1/1 V2] ipv4: off-by-one in continuation handling in /proc/net/route Date: Thu, 13 Aug 2015 20:49:01 +0100 Message-Id: <1439495341-12095-1-git-send-email-apw@canonical.com> X-Mailer: git-send-email 2.5.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org When generating /proc/net/route we emit a header followed by a line for each route. When a short read is performed we will restart this process based on the open file descriptor. When calculating the start point we fail to take into account that the 0th entry is the header. This leads us to skip the first entry when doing a continuation read. This can be easily seen with the comparison below: while read l; do echo "$l"; done A cat /proc/net/route >B diff -bu A B | grep '^[+-]' On my example machine I have approximatly 10KB of route output. There we see the very first non-title element is lost in the while read case, and an entry around the 8K mark in the cat case: +wlan0 00000000 02021EAC 0003 0 0 400 00000000 0 0 0 -tun1 00C0AC0A 00000000 0001 0 0 950 00C0FFFF 0 0 0 Fix up the off-by-one when reaquiring position on continuation. Fixes: 8be33e955cb9 ("fib_trie: Fib walk rcu should take a tnode and key instead of a trie and a leaf") BugLink: http://bugs.launchpad.net/bugs/1483440 Acked-by: Alexander Duyck Signed-off-by: Andy Whitcroft --- net/ipv4/fib_trie.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) V2 incorporates the updated Fixes: line as suggested by Eric, and incorporates Alexander's Ack. This is for applicable to net and to suitable for stable trees v4.1 and up. diff --git a/net/ipv4/fib_trie.c b/net/ipv4/fib_trie.c index 37c4bb8..b0c6258 100644 --- a/net/ipv4/fib_trie.c +++ b/net/ipv4/fib_trie.c @@ -2465,7 +2465,7 @@ static struct key_vector *fib_route_get_idx(struct fib_route_iter *iter, key = l->key + 1; iter->pos++; - if (pos-- <= 0) + if (--pos <= 0) break; l = NULL;