From patchwork Fri Sep 1 21:03:32 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Dumazet X-Patchwork-Id: 808995 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="QWOuq2At"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3xkWtd5X3Qz9sNr for ; Sat, 2 Sep 2017 07:03:37 +1000 (AEST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752554AbdIAVDf (ORCPT ); Fri, 1 Sep 2017 17:03:35 -0400 Received: from mail-pg0-f67.google.com ([74.125.83.67]:37822 "EHLO mail-pg0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752436AbdIAVDe (ORCPT ); Fri, 1 Sep 2017 17:03:34 -0400 Received: by mail-pg0-f67.google.com with SMTP id t193so773159pgc.4 for ; Fri, 01 Sep 2017 14:03:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=VGDVHJy3bKb/6XEtxxvKrUI3kfWfu01yBdAupCKu7Mc=; b=QWOuq2AtpI/Eb+8sfK2+Dnl1FrTUEKwvCpPFQbnK4wGRmA9Wr124vbr8+/nIF/DmkG KnJmXsuw95P1awIx4YEhVc3Bn/ItqhKI6YA5zlKhp9Lu0yvfLH8q92UmzZE56X4taVEB faLRK4PYuAiLhbGv1f8AqVM4oeiygTcqcku06hXxfMBTWr1qGy9mhbt03/bXA220SAgb 5ic/OkKuqM5ogf0+/QxcG1uUQfgDquCMs2Au3z53GaslxPhKbcWhOrx1b2WI8xIvsH+w F7k8329Cwonf/2gsit3vcpN+70GSqoIwIq+Z7hQQ8ryzQWDCqwMMqGksxPrZ1QVIM93J 5s0A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:subject:from:to:cc:date:mime-version :content-transfer-encoding; bh=VGDVHJy3bKb/6XEtxxvKrUI3kfWfu01yBdAupCKu7Mc=; b=H1WClNEqmZsYlhPmj4PHj5CK3ppOVG0yf3fu76yRWn5/HXuKTxFW36rBnyKAUsPp6+ MFfsJmlzcSL0RMn6xl5zFEwZww+4Sr0kgQ66+/Y35mJlTrP5Q/SEYz4o7cBawO2/BTNi ND+o5hGpaWhWijAnbsNOaXSiZhXAAa5vlLlPq1FCHA9PNA0EvmtxH6gUqEmvCpPpzvRT CWA/mIo8nZCW/9D/5VCkyTfM+Gu6f0yKDB2SVhSIOEK3UDt80bC+7jfo88xbxtRTHkfV ioSMYXo3/+bWaRG6MCQkkr4o+lsCRgGBpNec4mNLhwMJ1j0Q4reVKrN5544j+lq0Ovjo jgkg== X-Gm-Message-State: AHPjjUgQ3scXLIrz+aNYIfUj9SsrWB61YdtqB7h4K7AGkeyHYO6bkP0s oJC0GFzSbzDjSB8C X-Google-Smtp-Source: ADKCNb7bUdf0miLUSi5AtQ22NJtY/S6jba4wGiKmDDozBvCTV5pgZ8fIWqYC9ZWLNBKJ1Zl4DrUA5A== X-Received: by 10.84.237.15 with SMTP id s15mr3861834plk.69.1504299813861; Fri, 01 Sep 2017 14:03:33 -0700 (PDT) Received: from [192.168.86.171] (c-67-180-167-114.hsd1.ca.comcast.net. [67.180.167.114]) by smtp.googlemail.com with ESMTPSA id d6sm1224984pfh.113.2017.09.01.14.03.33 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Sep 2017 14:03:33 -0700 (PDT) Message-ID: <1504299812.15310.26.camel@edumazet-glaptop3.roam.corp.google.com> Subject: [PATCH net-next] inetpeer: fix RCU lookup() From: Eric Dumazet To: David Miller Cc: netdev Date: Fri, 01 Sep 2017 14:03:32 -0700 X-Mailer: Evolution 3.10.4-0ubuntu2 Mime-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Eric Dumazet Excess of seafood or something happened while I cooked the commit adding RB tree to inetpeer. Of course, RCU rules need to be respected or bad things can happen. In this particular loop, we need to read *pp once per iteration, not twice. Fixes: b145425f269a ("inetpeer: remove AVL implementation in favor of RB tree") Reported-by: John Sperbeck Signed-off-by: Eric Dumazet --- net/ipv4/inetpeer.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c index 337ad41bb80a5fcd3db7ac674292c5b5d462982e..e7eb590c86ce2b33654c17c61619de74ff07bfd1 100644 --- a/net/ipv4/inetpeer.c +++ b/net/ipv4/inetpeer.c @@ -102,15 +102,18 @@ static struct inet_peer *lookup(const struct inetpeer_addr *daddr, struct rb_node **parent_p, struct rb_node ***pp_p) { - struct rb_node **pp, *parent; + struct rb_node **pp, *parent, *next; struct inet_peer *p; pp = &base->rb_root.rb_node; parent = NULL; - while (*pp) { + while (1) { int cmp; - parent = rcu_dereference_raw(*pp); + next = rcu_dereference_raw(*pp); + if (!next) + break; + parent = next; p = rb_entry(parent, struct inet_peer, rb_node); cmp = inetpeer_addr_cmp(daddr, &p->daddr); if (cmp == 0) {