Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3405947imu; Thu, 29 Nov 2018 22:58:54 -0800 (PST) X-Google-Smtp-Source: AFSGD/VxuC5FgQkGLChUxvzlOaItiiZwCvHl1E1sAH8H1XzNoLHPYOIPRbMJ/75bLTVTc5G+evij X-Received: by 2002:a62:d504:: with SMTP id d4mr4477446pfg.38.1543561134453; Thu, 29 Nov 2018 22:58:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543561134; cv=none; d=google.com; s=arc-20160816; b=pChxoLx89uubRFn+03ff8ywYLxm6dhQ6IjVxTNPD/qI4jg4NpY2eGB+KnwCSFnpGnD 2wfdjQjuvOfBr+H8VqBWUZBIH0up70mY4y643LLsn8Kk0Rkw1MOCS+PHhmhgr6wPZ4bh 7cCEFQtProtGdtpRsVmpfqTzEE7zPQZu9f3rf0IrZiLDdTjQZV979a6BFVTcoio2fHBe qP5xlBBbHfI8t3mz7e8osanZO5cG2wVQyIZcGszTlxYeST1Sl4UFpOcG0Ey50sc2PMeJ jNFEdtQHw27398HJgvcffA4fJLLEglwzrMQkbO5oV0jlNMjZAO6oYXgWDX+Uhw7OHKC9 oPNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=LohekHXlwOu/g69A1gl8vWxTQ4ALoF6D+ZlhPdotyuw=; b=Ags9KMfCDgL2ikS/jza1qw5kAJ4m+z9hHYk8J9MT4fvsIaQG7J58vpzWxBp+w5VULF 1DzVo/plp5tIPtOV3f8PQI7DdS06z0J4N3vPZhT8gsj/3syx7bGHAS0M/ERqo3L0qgbH ldGXwQf56kjm7EvCShFaXKMAYbbX/xX3kIlZxJF2AerHJq5CzWvoqoHm2cX8utNhHCXn /TM3buKSX8EWph5/bluUfw3gT11e0pIm6VbOCsjFmXJAOyuFXAWVOL747NWmtcbwJKEB C6JuNe/fru1bH2U3/ZpKTuL9zM/NNC355ITaEAsnugIGJ4xO5K+0LvyRTcKbpzJobcfI YOTw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id r12si4497089plo.59.2018.11.29.22.58.40; Thu, 29 Nov 2018 22:58:54 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727032AbeK3SFu (ORCPT + 99 others); Fri, 30 Nov 2018 13:05:50 -0500 Received: from mxhk.zte.com.cn ([63.217.80.70]:45350 "EHLO mxhk.zte.com.cn" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726826AbeK3SFt (ORCPT ); Fri, 30 Nov 2018 13:05:49 -0500 Received: from mse01.zte.com.cn (unknown [10.30.3.20]) by Forcepoint Email with ESMTPS id 31C33D718A6C74EAF65A; Fri, 30 Nov 2018 14:57:30 +0800 (CST) Received: from notes_smtp.zte.com.cn ([10.30.1.239]) by mse01.zte.com.cn with ESMTP id wAU6vKDZ086462; Fri, 30 Nov 2018 14:57:20 +0800 (GMT-8) (envelope-from wen.yang99@zte.com.cn) Received: from localhost.localdomain ([10.75.9.60]) by szsmtp06.zte.com.cn (Lotus Domino Release 8.5.3FP6) with ESMTP id 2018113014575815-13904801 ; Fri, 30 Nov 2018 14:57:58 +0800 From: Wen Yang To: mareklindner@neomailbox.ch, sw@simonwunderlich.de, a@unstable.cc, davem@davemloft.net Cc: netdev@vger.kernel.org, b.a.t.m.a.n@lists.open-mesh.org, linux-kernel@vger.kernel.org, zhong.weidong@zte.com.cn, wen.yang99@zte.com.cn Subject: [PATCH] batman-adv: fix null pointer dereference in batadv_gw_election Date: Fri, 30 Nov 2018 15:00:02 +0800 Message-Id: <1543561202-614-1-git-send-email-wen.yang99@zte.com.cn> X-Mailer: git-send-email 1.8.3.1 X-MIMETrack: Itemize by SMTP Server on SZSMTP06/server/zte_ltd(Release 8.5.3FP6|November 21, 2013) at 2018-11-30 14:57:58, Serialize by Router on notes_smtp/zte_ltd(Release 9.0.1FP7|August 17, 2016) at 2018-11-30 14:57:04, Serialize complete at 2018-11-30 14:57:04 X-MAIL: mse01.zte.com.cn wAU6vKDZ086462 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org This patch fixes a possible null pointer dereference in batadv_gw_election, detected by the semantic patch deref_null.cocci, with the following warning: ./net/batman-adv/gateway_client.c:289:15-24: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:290:15-29: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:291:15-29: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:292:15-27: ERROR: next_gw is NULL but dereferenced. ./net/batman-adv/gateway_client.c:293:15-27: ERROR: next_gw is NULL but dereferenced. Signed-off-by: Wen Yang Reviewed-by: Tan Hu --- net/batman-adv/gateway_client.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 140c61a..d80ef1c 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c @@ -284,14 +284,16 @@ void batadv_gw_election(struct batadv_priv *bat_priv) batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_ADD, gw_addr); } else { - batadv_dbg(BATADV_DBG_BATMAN, bat_priv, - "Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n", - next_gw->orig_node->orig, - next_gw->bandwidth_down / 10, - next_gw->bandwidth_down % 10, - next_gw->bandwidth_up / 10, - next_gw->bandwidth_up % 10, - router_ifinfo->bat_iv.tq_avg); + if (next_gw) { + batadv_dbg(BATADV_DBG_BATMAN, bat_priv, + "Changing route to gateway %pM (bandwidth: %u.%u/%u.%u MBit, tq: %i)\n", + next_gw->orig_node->orig, + next_gw->bandwidth_down / 10, + next_gw->bandwidth_down % 10, + next_gw->bandwidth_up / 10, + next_gw->bandwidth_up % 10, + router_ifinfo->bat_iv.tq_avg); + } batadv_throw_uevent(bat_priv, BATADV_UEV_GW, BATADV_UEV_CHANGE, gw_addr); } -- 2.9.5