From patchwork Mon Feb 25 21:27:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Safonov X-Patchwork-Id: 1047991 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@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; dmarc=pass (p=quarantine dis=none) header.from=arista.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=arista.com header.i=@arista.com header.b="eE5nVzwv"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 447bCW6Y59z9s71 for ; Tue, 26 Feb 2019 08:47:51 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731726AbfBYV10 (ORCPT ); Mon, 25 Feb 2019 16:27:26 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:40859 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731385AbfBYV1Y (ORCPT ); Mon, 25 Feb 2019 16:27:24 -0500 Received: by mail-ed1-f68.google.com with SMTP id 10so8870359eds.7 for ; Mon, 25 Feb 2019 13:27:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=arista.com; s=googlenew; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=FulHKGK+C01DQCuWzsfZQemo7UUyLjvaf8+wgmRlrVI=; b=eE5nVzwvRFfHE+FpwEOPUNNj3tHEQPCyB9FjJEUkRs+Ai8N7I/Qp7ryWCMww/f2B33 DvlPtkNQac/rY1o9f0V6ruJsGFAJzx/i0lliCZC8achnkb4jRGQ7qWHOwuvO/eLIazJo Tx0rYZKJ5jBmzD3iguIQ6yHHW4mcgIAsqevL8NIsT51Png2sOl0GEw9D+xt0ZKUdCR5d g8zIXw6GFy3lAzSjgZuTk+xLx8i6iRU83w0wrWPix75RFu4aZzwu9VMz4/YolttItsix /CaxvVWBBciCzSa+zxncM6yDbSzY1NHx8c43+H3aTdzlbueLTgxRzZJyO7eDNS846ZI+ h1QA== 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:mime-version :content-transfer-encoding; bh=FulHKGK+C01DQCuWzsfZQemo7UUyLjvaf8+wgmRlrVI=; b=kL/EuFJTTHR7O+sGNVsmgwqckH2mUuhK5xVh2IzTaeWV2KgkyXEi+gpubL8ZdGbw+d 7bPZxCYOInPs6JhmOp4iO3FKfIECIvqLdd6vpHDb8Sz3Afz4/3bQR81pRbQhxF2cSY09 YCUwMjIDoJ4kfDBBWejrLuINA/VQqQWGyYSXeVXEX9xmlqjUzubWEzVFsKbWQ8YW1+Og aB4st4SiVT3qfBwIFrvRKl8J0dlECXqQdCGcscJPro+fLzuc43f7K8j4B3aMk+Ujd9JE wulfC467zBMIflRPblX+PUMf+FdsPsJ8jk6mHm2aymGnKQ1cc4d9mRwAzjxY+NOeT2No VEkA== X-Gm-Message-State: AHQUAuYxEPL2FOTEapRd6gE/Bh1AVhnW7IJpIn0LF64uz8KvMgr9+BbA 8NqGJYK3eEpnLHiqnXvetpmMuw== X-Google-Smtp-Source: AHgI3Ibrcu1SNtXFKMANSiqMQgey+yhnCEpHmeaaOSlQ5T9csfiJUyDfZmmrNUMuNLVrVvuuFXUBiQ== X-Received: by 2002:a50:aa2e:: with SMTP id o43mr3445491edc.67.1551130042613; Mon, 25 Feb 2019 13:27:22 -0800 (PST) Received: from Mindolluin.ire.aristanetworks.com ([217.173.96.166]) by smtp.gmail.com with ESMTPSA id d12sm2969908edb.3.2019.02.25.13.27.21 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Feb 2019 13:27:21 -0800 (PST) From: Dmitry Safonov To: linux-kernel@vger.kernel.org Cc: 0x7f454c46@gmail.com, Dmitry Safonov , "David S. Miller" , Florian Westphal , "Hannes Frederic Sowa" , netdev@vger.kernel.org Subject: [PATCH] rtnetlink: Synchronze net in rtnl_unregister() Date: Mon, 25 Feb 2019 21:27:21 +0000 Message-Id: <20190225212721.2908-1-dima@arista.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org rtnl_unregister() unsets handler from table, which is protected by rtnl_lock or RCU. At this moment only dump handlers access the table with rcu_lock(). Every other user accesses under rtnl. Callers may expect that rtnl_unregister() prevents any further handlers calls, alike rtnl_unregister_all(). And they do expect it. I've looked on in-tree caller uses: br_mdb: safe, but in err-path br_netlink_init() fib_rules: safe - err-path is very early in __init ip6mr: safe - following unregister_pernet_subsys() calls internally rcu_barrier() qrtr: safe - following sock_unregister() calls internally synchronize_rcu() While it's possible to document that rtnl_unregister() requires synchronize_net() afterwards - unlike rtnl_unregister_all(), I believe the module exit is very much slow-path. Issue seems to be very theoretical and unlikely, so I'm not Cc'ing stable tree. Fixes: 6853dd488119 ("rtnetlink: protect handler table with rcu") Cc: "David S. Miller" Cc: Florian Westphal Cc: "Hannes Frederic Sowa" Cc: netdev@vger.kernel.org Signed-off-by: Dmitry Safonov --- net/core/rtnetlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 5ea1bed08ede..3db70da4f951 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -308,7 +308,9 @@ int rtnl_unregister(int protocol, int msgtype) rcu_assign_pointer(tab[msgindex], NULL); rtnl_unlock(); - kfree_rcu(link, rcu); + synchronize_net(); + + kfree(link); return 0; }