From patchwork Sat Feb 23 06:34:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joel Fernandes X-Patchwork-Id: 10827423 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1048B17E9 for ; Sat, 23 Feb 2019 10:40:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB96F2F33D for ; Sat, 23 Feb 2019 10:40:08 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DDD8D2F365; Sat, 23 Feb 2019 10:40:08 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.3 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from mother.openwall.net (mother.openwall.net [195.42.179.200]) by mail.wl.linuxfoundation.org (Postfix) with SMTP id 18A382F33D for ; Sat, 23 Feb 2019 10:40:07 +0000 (UTC) Received: (qmail 5812 invoked by uid 550); 23 Feb 2019 10:40:03 -0000 Mailing-List: contact kernel-hardening-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Delivered-To: mailing list kernel-hardening@lists.openwall.com Delivered-To: moderator for kernel-hardening@lists.openwall.com Received: (qmail 15543 invoked from network); 23 Feb 2019 06:35:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=joelfernandes.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zc6wY8rNCewGZVDgSPtq8BlfOuPURI6nN/IPxD75L4o=; b=eDCPmLQERqkYYc/bGxU7OS66Icgp+XunDLdFECdIPqDGXVeyhvqvuBAhTiXdAR99Dq s+GbkyxtCPFUulsLNPUdRTKGM0yr1m9jKQr9M2WpCmNb5xL1jyylsgvJeD71CIg0p0eu pfWs7ErgnCkoanOoY6gZQxnaRcq5DSWNmDVWg= 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:mime-version:content-transfer-encoding; bh=Zc6wY8rNCewGZVDgSPtq8BlfOuPURI6nN/IPxD75L4o=; b=eOfXFaJ1z469vbJEuYz6BlhT5+TS6OG9UiIZZi0dbksYM2cCmJNL9bO1rHZ8z44F8c YSUH8Lb0rV9YjIeANq24oDHfyJ0m7eAX1yLxqpTtsme7ws6s355z3PQYsdPROiaWx46M F4yc2O/ebBR+V+S9OIko441KmHuce+zzVeeTq81JOo12Y9C6Wh5x840dGPX+VpeSupcl e5jHOySBbZ+PZigNphM2TBnZe6d1AMt3KRT36tChWtELM8i37mqTA7Xvq+D8zvCwnq1/ KPbqbULDTuji70wm/QKZeyaX2mTmCRC03pp6nUo9VuG6EplaMkgHhgSY3vomdWNrIzB1 lc0A== X-Gm-Message-State: AHQUAuYAmZEcsM4M5E71mMCpgbxnwpGJ2yfIaOwEGOVIC1/poXumQxx6 FtAztzBOYWh69t27d4qMPRBqJg== X-Google-Smtp-Source: AHgI3IYdAZ9LpDlYKNIOJJbI2dWRj2jR/BzqrefjE6BsZ3jOMxDi9AMbLP8ORBFoMg4jKW+d9sv/aQ== X-Received: by 2002:a0c:9802:: with SMTP id c2mr6078462qvd.13.1550903691926; Fri, 22 Feb 2019 22:34:51 -0800 (PST) From: "Joel Fernandes (Google)" To: linux-kernel@vger.kernel.org Cc: "Joel Fernandes (Google)" , Alexei Starovoitov , Christian Brauner , Daniel Borkmann , David Ahern , "David S. Miller" , Ingo Molnar , Jakub Kicinski , Jeff Kirsher , Jesper Dangaard Brouer , John Fastabend , Josh Triplett , keescook@chromium.org, kernel-hardening@lists.openwall.com, kernel-team@android.com, Kirill Tkhai , Lai Jiangshan , Martin KaFai Lau , Mathieu Desnoyers , netdev@vger.kernel.org, "Paul E. McKenney" , Peter Zijlstra , Quentin Perret , rcu@vger.kernel.org, Song Liu , Steven Rostedt , Vincent Guittot , xdp-newbies@vger.kernel.org, Yonghong Song Subject: [PATCH v2 1/6] net: rtnetlink: Fix incorrect RCU API usage Date: Sat, 23 Feb 2019 01:34:29 -0500 Message-Id: <20190223063434.6793-2-joel@joelfernandes.org> X-Mailer: git-send-email 2.21.0.rc0.258.g878e2cd30e-goog In-Reply-To: <20190223063434.6793-1-joel@joelfernandes.org> References: <20190223063434.6793-1-joel@joelfernandes.org> MIME-Version: 1.0 X-Virus-Scanned: ClamAV using ClamSMTP rtnl_register_internal() and rtnl_unregister_all tries to directly dereference an RCU protected pointed outside RCU read side section. While this is Ok to do since a lock is held, let us use the correct API to avoid programmer bugs in the future. This also fixes sparse warnings arising from not using RCU API. net/core/rtnetlink.c:332:13: warning: incorrect type in assignment (different address spaces) net/core/rtnetlink.c:332:13: expected struct rtnl_link **tab net/core/rtnetlink.c:332:13: got struct rtnl_link *[noderef] * Signed-off-by: Joel Fernandes (Google) Reviewed-by: Paul E. McKenney --- net/core/rtnetlink.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c index 5ea1bed08ede..98be4b4818a9 100644 --- a/net/core/rtnetlink.c +++ b/net/core/rtnetlink.c @@ -188,7 +188,7 @@ static int rtnl_register_internal(struct module *owner, msgindex = rtm_msgindex(msgtype); rtnl_lock(); - tab = rtnl_msg_handlers[protocol]; + tab = rtnl_dereference(rtnl_msg_handlers[protocol]); if (tab == NULL) { tab = kcalloc(RTM_NR_MSGTYPES, sizeof(void *), GFP_KERNEL); if (!tab) @@ -329,7 +329,7 @@ void rtnl_unregister_all(int protocol) BUG_ON(protocol < 0 || protocol > RTNL_FAMILY_MAX); rtnl_lock(); - tab = rtnl_msg_handlers[protocol]; + tab = rtnl_dereference(rtnl_msg_handlers[protocol]); if (!tab) { rtnl_unlock(); return;