From patchwork Mon Nov 9 13:59:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 11891575 X-Patchwork-Delegate: kuba@kernel.org 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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,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 9EB86C2D0A3 for ; Mon, 9 Nov 2020 13:59:38 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4769B2076E for ; Mon, 9 Nov 2020 13:59:38 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CNrSrMzh" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731158AbgKIN7h (ORCPT ); Mon, 9 Nov 2020 08:59:37 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58414 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730991AbgKIN7f (ORCPT ); Mon, 9 Nov 2020 08:59:35 -0500 Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5D8CEC0613CF; Mon, 9 Nov 2020 05:59:34 -0800 (PST) Received: by mail-pf1-x442.google.com with SMTP id q5so5268384pfk.6; Mon, 09 Nov 2020 05:59:34 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=ZQzJKKt4uzjrRFSl3mDjwbikP5PjZvNDeMBTReKioBA=; b=CNrSrMzhRAe8BycT/VihxX80QHsZ4eBZO6O5ghk9vJGd/crz9MNtICGaJTJlBCg5eB Pp0vvKcGbpZJ4aOnvy3nnVgTivcS1LaNl5PX4iZwMY2eTBWXk7DF0feqiNakmsT3+awl sa5hZqiovdiOUtpHghtbW3fIk7fvVgJKvewBxrAMkwhEMHUIotkLPc2U2C1KAeMzf4MK 2U3kIilP9bUch+cZQn3nBR0SpD+1kNeue8jIn79cQZ1Ij1hw5mlp4JffskDt++x+ksvZ qGkEoaVDsbLXG/WtWuq97JKKIrhjnthaA8HGZwam/+2Huxn9oiLWa2kwQNG9wNiyVQnG yllg== 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=ZQzJKKt4uzjrRFSl3mDjwbikP5PjZvNDeMBTReKioBA=; b=rymq3o6DmW5SgcfwO4eK4n4bLrD1mosZcDWYm2zsZx7BJgBGEaXEBsBbkLNWAxEaeL HjTjY5nA7KRgALzpIvPwvguJSICeAUiu8vrt3ZmVl+2JMz+7/SgeHvZ1GTcQYUso2kbh xG7hRYRuiIE+SDL7ZWhvMnBg/WpZbu81sBSSlISRHEIuZZ3RxoMAWK2EOvl7DBG+KwMC MQ/F7JTe6GrO+ZlT85Zw5QXO7cj0sUTVHF/LKDR7P752//kcuuzWekHU7V70xNAiUyBC IzJUL2Tha1KtJhTWgXWr7NzMMRWwDMdpTgTQ226jMyOx1DN2RCyvNf7KBS8iD42nAzOL MSwQ== X-Gm-Message-State: AOAM533hRJ9kU7usUTV32+N85sjJzJBjlZ9Ps20iokumfcVp/86b0wlV IDmWL7STBFvzYd620XxOht0= X-Google-Smtp-Source: ABdhPJylyjr2UPg4t6JoPmDdRHSuS8ldb+M9pROgcq0fb84tA3vx1LoXJFP5TYx73cDshNyuibHiLw== X-Received: by 2002:a62:d114:0:b029:18a:e114:1eb4 with SMTP id z20-20020a62d1140000b029018ae1141eb4mr14387707pfg.41.1604930373913; Mon, 09 Nov 2020 05:59:33 -0800 (PST) Received: from localhost ([209.9.72.213]) by smtp.gmail.com with ESMTPSA id f4sm5800397pjp.3.2020.11.09.05.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 05:59:32 -0800 (PST) From: Geliang Tang To: Mat Martineau , Matthieu Baerts , "David S. Miller" , Jakub Kicinski , Paolo Abeni Cc: Geliang Tang , netdev@vger.kernel.org, mptcp@lists.01.org, linux-kernel@vger.kernel.org, Dan Carpenter Subject: [MPTCP][PATCH net 1/2] mptcp: fix static checker warnings in mptcp_pm_add_timer Date: Mon, 9 Nov 2020 21:59:21 +0800 Message-Id: X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org Fix the following Smatch complaint: net/mptcp/pm_netlink.c:213 mptcp_pm_add_timer() warn: variable dereferenced before check 'msk' (see line 208) net/mptcp/pm_netlink.c 207 struct mptcp_sock *msk = entry->sock; 208 struct sock *sk = (struct sock *)msk; 209 struct net *net = sock_net(sk); ^^ "msk" dereferenced here. 210 211 pr_debug("msk=%p", msk); 212 213 if (!msk) ^^^^ Too late. 214 return; 215 Fixes: 93f323b9cccc ("mptcp: add a new sysctl add_addr_timeout") Reported-by: Dan Carpenter Signed-off-by: Geliang Tang Reviewed-by: Dan Carpenter Reviewed-by: Matthieu Baerts --- net/mptcp/pm_netlink.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 6180a8b39a3f..03f2c28f11f5 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -206,7 +206,6 @@ 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); pr_debug("msk=%p", msk); @@ -235,7 +234,7 @@ static void mptcp_pm_add_timer(struct timer_list *timer) if (entry->retrans_times < ADD_ADDR_RETRANS_MAX) sk_reset_timer(sk, timer, - jiffies + mptcp_get_add_addr_timeout(net)); + jiffies + mptcp_get_add_addr_timeout(sock_net(sk))); spin_unlock_bh(&msk->pm.lock); From patchwork Mon Nov 9 13:59:22 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Geliang Tang X-Patchwork-Id: 11891579 X-Patchwork-Delegate: kuba@kernel.org 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.6 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 6B92DC4741F for ; Mon, 9 Nov 2020 13:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0A6B92076E for ; Mon, 9 Nov 2020 13:59:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="uheTqZt3" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731296AbgKIN7l (ORCPT ); Mon, 9 Nov 2020 08:59:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58426 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729854AbgKIN7k (ORCPT ); Mon, 9 Nov 2020 08:59:40 -0500 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 797FEC0613CF; Mon, 9 Nov 2020 05:59:38 -0800 (PST) Received: by mail-pf1-x443.google.com with SMTP id e7so8228542pfn.12; Mon, 09 Nov 2020 05:59:38 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=gSYjZ1cUgOekEM7SwW9yeu6llfvLPIn9JJb6KN19b+0=; b=uheTqZt3G2+6GJj/cnThwf9U010w83aj61EMBOva7nathZ8x/txGFq9RJd7zy5O7q7 Z+qZveWsaJMx7KsOK8BCgsRr9Myqdh+/u3J9225VqAXndLlOSf3W0jhO3XBASTAN7gdW RyRm6KF5rY6emONkNlZRtKwm5EWhnhpLPg3NBtFbJ09MQusOUAd3uPRgMDrF4fGiVqIV Em0N3pqiUpDkxQgKxMqrH9W4PezYE3c5d5LixTPQh4NGjXRyKXPEJXyCuusXMbO4YZAw mmTQoO4ihtK6Ysm8eStgwwssoRRNxXaopu3jCWJpvhyzV1vXCFNvPEwj6qfM0XXHQePs ucKw== 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=gSYjZ1cUgOekEM7SwW9yeu6llfvLPIn9JJb6KN19b+0=; b=bCsQuA2DYlYSj7Sc5SZD2eDZfFHnyCFnLY+IqKun9DF8DXC+Y7O4jEQNBKQObsvLh5 NVX2moim0TTguzUec7wAmmy/IFmZqPYkbKkLPCv4qTIK/kMFFZs4QypUkAFE11jKpyJD ST50t9xx6Gzf9yJSkdb1GmLAs2sjahc1ko+p1W836gq2mzQ8pxPa4eYJWbIk40hNN/WN er7kVX8Z7wrAsLPmwZOOYSzSCFlU5pYOrpqql2r1m15Uz0ciZ6ldlVmtjLXCN1k0yJP4 hp75oyneEVhsWDDnDzfnsynuOLMEKs4b0EWbYUaxc6iQSASuMNl73pN3mH4xw/Xw5wUC kseg== X-Gm-Message-State: AOAM531Tl5HVFOsD5ydaMXSCNI5JjScvT3OvJ44QrDWCJoY3BdvZDaD9 fryguhVl/qACkUpjVKwLtZy65i7SKCvn8Q== X-Google-Smtp-Source: ABdhPJyfg6WaH76st17Ot4HhGAxk1PA0a1hNeb+g2YZFvH9jjh5LnZNprzZ3mGoKYIKRbp8mH0SqoQ== X-Received: by 2002:a17:90b:1642:: with SMTP id il2mr12300961pjb.81.1604930378160; Mon, 09 Nov 2020 05:59:38 -0800 (PST) Received: from localhost ([209.9.72.213]) by smtp.gmail.com with ESMTPSA id j12sm10422175pga.78.2020.11.09.05.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 09 Nov 2020 05:59:37 -0800 (PST) From: Geliang Tang To: Mat Martineau , Matthieu Baerts , "David S. Miller" , Jakub Kicinski , Paolo Abeni Cc: Geliang Tang , netdev@vger.kernel.org, mptcp@lists.01.org, linux-kernel@vger.kernel.org, Dan Carpenter Subject: [MPTCP][PATCH net 2/2] mptcp: cleanup for mptcp_pm_alloc_anno_list Date: Mon, 9 Nov 2020 21:59:22 +0800 Message-Id: <0f17d2f60c188554d093e820c45caf20fe53aab0.1604930005.git.geliangtang@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org This patch added NULL pointer check for mptcp_pm_alloc_anno_list, and avoided similar static checker warnings in mptcp_pm_add_timer. Signed-off-by: Geliang Tang Reviewed-by: Dan Carpenter --- net/mptcp/pm_netlink.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/net/mptcp/pm_netlink.c b/net/mptcp/pm_netlink.c index 03f2c28f11f5..dfc1bed4a55f 100644 --- a/net/mptcp/pm_netlink.c +++ b/net/mptcp/pm_netlink.c @@ -266,7 +266,9 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, { struct mptcp_pm_add_entry *add_entry = NULL; struct sock *sk = (struct sock *)msk; - struct net *net = sock_net(sk); + + if (!msk) + return false; if (lookup_anno_list_by_saddr(msk, &entry->addr)) return false; @@ -283,7 +285,7 @@ static bool mptcp_pm_alloc_anno_list(struct mptcp_sock *msk, timer_setup(&add_entry->add_timer, mptcp_pm_add_timer, 0); sk_reset_timer(sk, &add_entry->add_timer, - jiffies + mptcp_get_add_addr_timeout(net)); + jiffies + mptcp_get_add_addr_timeout(sock_net(sk))); return true; }