From patchwork Mon Nov 9 12:52:15 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Colin King X-Patchwork-Id: 322056 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-12.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DFF3AC56201 for ; Mon, 9 Nov 2020 12:52:28 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9968A20684 for ; Mon, 9 Nov 2020 12:52:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729854AbgKIMw2 (ORCPT ); Mon, 9 Nov 2020 07:52:28 -0500 Received: from youngberry.canonical.com ([91.189.89.112]:51404 "EHLO youngberry.canonical.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729836AbgKIMw0 (ORCPT ); Mon, 9 Nov 2020 07:52:26 -0500 Received: from 1.general.cking.uk.vpn ([10.172.193.212] helo=localhost) by youngberry.canonical.com with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.86_2) (envelope-from ) id 1kc6ee-00069P-2a; Mon, 09 Nov 2020 12:52:16 +0000 From: Colin King To: Mat Martineau , Matthieu Baerts , "David S . Miller" , Jakub Kicinski , Geliang Tang , Paolo Abeni , netdev@vger.kernel.org, mptcp@lists.01.org Cc: kernel-janitors@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH][next] mptcp: fix a dereference of pointer before msk is null checked. Date: Mon, 9 Nov 2020 12:52:15 +0000 Message-Id: <20201109125215.2080172-1-colin.king@canonical.com> X-Mailer: git-send-email 2.28.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Colin Ian King Currently the assignment of pointer net from the sock_net(sk) call is potentially dereferencing a null pointer sk. sk points to the same location as pointer msk and msk is being null checked after the sock_net call. Fix this by calling sock_net after the null check on pointer msk. Addresses-Coverity: ("Dereference before null check") Fixes: 00cfd77b9063 ("mptcp: retransmit ADD_ADDR when timeout") Signed-off-by: Colin Ian King --- net/mptcp/pm_netlink.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index ed60538df7b2..e76879ea5a30 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -206,13 +206,15 @@ static void mptcp_pm_add_timer(struct timer_list *timer) struct mptcp_pm_add_entry *entry = from_timer(entry, timer, add_timer); struct mptcp_sock *msk = entry->sock; struct sock *sk = (struct sock *)msk; - struct net *net = sock_net(sk); + struct net *net; pr_debug("msk=%p", msk); if (!msk) return; + net = sock_net(sk); + if (inet_sk_state_load(sk) == TCP_CLOSE) return;