From patchwork Sat Jun 17 17:42:44 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Wei Wang X-Patchwork-Id: 777356 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 3wql3n6CsPz9s76 for ; Sun, 18 Jun 2017 03:44:21 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VP14qEtb"; dkim-atps=neutral Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752902AbdFQRoP (ORCPT ); Sat, 17 Jun 2017 13:44:15 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:35021 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752792AbdFQRnv (ORCPT ); Sat, 17 Jun 2017 13:43:51 -0400 Received: by mail-pf0-f193.google.com with SMTP id s66so11093738pfs.2 for ; Sat, 17 Jun 2017 10:43:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=FEgcO4bbkhe9Wtcs2ehKoH2s+Udej5g83Pnlf/r6yXU=; b=VP14qEtbZJiLB1hDedInGzUI5Go5+Kbo4r2bu2s+s8FP/TccbrTY9lSR5OFyAsPc6P d+7SBjrzUuWN+qCVDs6UoUaDC96oKkMr+W2zTzCn/kx9T3M5nvWR515hH/WS5sYYzFLl 5AmQDi9XZLoreRJp1bkwTJ03l6YhIT67sX0jReKKcJ7PjuJLB6+55bG2dd+vlK1XjTL2 PIt4AYqTSPHPjQ3jVlVYQhepGIZSbbW0JcWcdGatX9vWWrdEFhcgj4uCJ+zDsTYaX7sD lb6GHHpRftVKF2+GddpqzMp3s5c+9OxJ0sehgkcMsvVZOWgp78ufh3HFgvFS+KTF21yw nW7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=FEgcO4bbkhe9Wtcs2ehKoH2s+Udej5g83Pnlf/r6yXU=; b=OzHGCPRAkBUMbRCgqzv7g8qqYrZNHpKdc8Sux7M++NzM0GGzWrKlmPWEyargUuiSAe EmXQ/c4OuVAa1yJPiM9GPUPXK4YO6iWvYg8uMNwbi9JIERmUMVeAwwiUB8QyiWIkZUCK YhkaZhIiDlMxeuGa+so7zPIizvwZxy9hXNyNqKWigMb0CLrdrqud5Gj/MP80yEbHg0Xf SdFMOHcyMei+BUH7Znd7jBaGxwbAOhMhY9K1YZgEXgt3ud3vxUo5rHqO/E7KZ4Gu2z0V sjKPa2TYgeeWhfiORG4LgSb/GMmGk2CzlTcjVqpIVCYkJ9qSu7+mF7gBWBp63FSXWCP2 6Onw== X-Gm-Message-State: AKS2vOz6f3SM5JkiuPL0+wLW/+4L2U9T1w0rIG3/Hpx7t61hNJmh9yvV wnBwd4V9lQ8sJQCzPtk= X-Received: by 10.98.62.193 with SMTP id y62mr16813089pfj.49.1497721431090; Sat, 17 Jun 2017 10:43:51 -0700 (PDT) Received: from weiwan0.mtv.corp.google.com ([100.123.230.66]) by smtp.gmail.com with ESMTPSA id h7sm11352777pfc.97.2017.06.17.10.43.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 17 Jun 2017 10:43:50 -0700 (PDT) From: Wei Wang To: David Miller , netdev@vger.kernel.org Cc: Eric Dumazet , Martin KaFai Lau , Wei Wang Subject: [PATCH v2 net-next 21/21] net: add debug atomic_inc_not_zero() in dst_hold() Date: Sat, 17 Jun 2017 10:42:44 -0700 Message-Id: <20170617174244.132862-22-tracywwnj@gmail.com> X-Mailer: git-send-email 2.13.1.518.g3df882009-goog In-Reply-To: <20170617174244.132862-1-tracywwnj@gmail.com> References: <20170617174244.132862-1-tracywwnj@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Wei Wang This patch is meant to add a debug warning on the situation where dst is being held during its destroy phase. This could potentially cause double free issue on the dst. Signed-off-by: Wei Wang Acked-by: Martin KaFai Lau --- include/net/dst.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/net/dst.h b/include/net/dst.h index d912b44d2dcb..f73611ec4017 100644 --- a/include/net/dst.h +++ b/include/net/dst.h @@ -251,7 +251,7 @@ static inline void dst_hold(struct dst_entry *dst) * __pad_to_align_refcnt declaration in struct dst_entry */ BUILD_BUG_ON(offsetof(struct dst_entry, __refcnt) & 63); - atomic_inc(&dst->__refcnt); + WARN_ON(atomic_inc_not_zero(&dst->__refcnt) == 0); } static inline void dst_use(struct dst_entry *dst, unsigned long time)