Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp9514623ybi; Wed, 24 Jul 2019 05:30:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2jWlqTX1VIopLScDSUbRTw21YhYNGBgegryzz2APq5lfMae+OOxM6+nZZv3Vyfx4TdQKD X-Received: by 2002:a17:902:2a29:: with SMTP id i38mr86238462plb.46.1563971424146; Wed, 24 Jul 2019 05:30:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1563971424; cv=none; d=google.com; s=arc-20160816; b=GpBQAAh2EperTQGjttjvPVkSxrSl0ldBZg2UDxYpnwNSCjWWRLFpeuEIkwF3qgTiAp TXh3TV0IeiAg6Q6WciaoG0GJ5AU9o4I9lfm1ODNyjo74XMvBtX3dOmkKdfqsqOqlTaA0 TACTjDfslFAauS5lZg8/oDRpO5DU6vAshvohOs1Biyf3LxXfNBdqOIPXtad3sCZt54yb ImXZd41jZ6DZUJ0QNz6Oaf2kOTnzSU1JVv4GDH4ZzUJpABYWLeqS1tbubSwlfp4Lq/5I 88JqwgYuufQ/dmEasq3q1ZgqvfkSt11f4HbDeKvPtacZsbNeuSujrUO4n9m3f4uF1x/q 113w== 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 :dkim-signature; bh=wO4O/Gvif+MADZGPdW4dqB529LtcQYyXiVt50YTB8sQ=; b=C9Jc92ut+UHq4NH00xU5DafwhtDsAQTzs4hPx0SpWeW6g6kBEJJpysf9bHsDEF46f/ 5uwWlW7C6G7YWjuIb39G6TJ5WTMQl/2mm/z1TZcDxMZkaHlZvX9RUBKGCGhtlbBc7QvX CVGAuVZoSJbnQOq751/BcLulV7jYQrpldAb342gV67/fpxjEsVnmnS8FvVBkwcmlj3o/ M8tnaNfG1sbSw9jCzBfN5eYisSbALn5MTPi1+fXeKmB7J00PPZzLiDYhUvTrQuHd2KyL qt3EGxmhf63OiG03NAHxXG7PCzqbpO3b+ruq3vY6AvR+b2tkREbl8IS0Ux1KB/g8oIj5 c9cg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="L4Cn/0ZM"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id j4si1720778pfa.141.2019.07.24.05.30.09; Wed, 24 Jul 2019 05:30:24 -0700 (PDT) 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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="L4Cn/0ZM"; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727239AbfGXKj4 (ORCPT + 99 others); Wed, 24 Jul 2019 06:39:56 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:41142 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726300AbfGXKj4 (ORCPT ); Wed, 24 Jul 2019 06:39:56 -0400 Received: by mail-pf1-f193.google.com with SMTP id m30so20754890pff.8; Wed, 24 Jul 2019 03:39:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=wO4O/Gvif+MADZGPdW4dqB529LtcQYyXiVt50YTB8sQ=; b=L4Cn/0ZMJQOyjLGxVaYXm152UsTOpbzYiYWqFq9i917amlQjuDqAGIDml7mnGbbS18 hr2goSQqpjPH+wib0GQ1sPE4/MmxAPeSOzHpdZYyxwWeORTnnZtFuHpqArXYlnhHuB0/ AU3Nr3KjBpWkKtCMlJBtl6PXylB84eX4sKomMC0Q9hXUa2/UWO3gGU5WPtpwKvnC2V5t pVXYu7f3G3tabd0agHqv02mcBr2ywbWKxqDIlnQQDricK/1cnQIMKCRjmpxJHxkmrDtV m3/5YUtHLMA8fuCdjIphE7TmX/xOXeZMiE/ukZmvmKj6fmdN3Byo7VO/vWb+k2JHHmgw gEBQ== 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; bh=wO4O/Gvif+MADZGPdW4dqB529LtcQYyXiVt50YTB8sQ=; b=SX3KLZ46c8nU9x49ebt3HiSclf584+41RXH47ewLzhefhK5yrJh1tVmb6PvoBQPV5l WlYj7ll5F8sgR4u837uyw+gs+QLRisH1Qqz6Qwc/Aa6eOJNatPZzKQFfXNmCqeQBBBVm WJgowtvtaLwQcP8rQKMSegBVYUivRVfDQCj5QeyFVs8G1UoE9wWu+6A4WaCQd6/IX3Pt YAw/6FU2u2N4wv+0k1BG3iT/KHiDmz+1wrGrGBQtucbUIeBM2SsrKO/ofw4jqFPh7V5y pzfzLReR1ahGHGXwt4+plpqmsnRzbEsp85yboxSJ9du7rrFOHgCq6AZDFsw8I6f1bDz7 ZPGg== X-Gm-Message-State: APjAAAVj0i+VdsviT++HgBJZAKbewrv1S6JXiSuj+StELYe4vfeTifzy jJ7DPMivAH6vJJKs4/R6Zr3TqYxdqcA= X-Received: by 2002:a62:1515:: with SMTP id 21mr10953193pfv.100.1563964795549; Wed, 24 Jul 2019 03:39:55 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id i7sm36393739pjk.24.2019.07.24.03.39.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 24 Jul 2019 03:39:55 -0700 (PDT) From: Jia-Ju Bai To: ericvh@gmail.com, lucho@ionkov.net, asmadeus@codewreck.org, davem@davemloft.net Cc: v9fs-developer@lists.sourceforge.net, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] net: 9p: Fix possible null-pointer dereferences in p9_cm_event_handler() Date: Wed, 24 Jul 2019 18:39:48 +0800 Message-Id: <20190724103948.5834-1-baijiaju1990@gmail.com> X-Mailer: git-send-email 2.17.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org In p9_cm_event_handler(), there is an if statement on 260 to check whether rdma is NULL, which indicates that rdma can be NULL. If so, using rdma->xxx may cause a possible null-pointer dereference. To fix these bugs, rdma is checked before being used. These bugs are found by a static analysis tool STCheck written by us. Signed-off-by: Jia-Ju Bai --- net/9p/trans_rdma.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/net/9p/trans_rdma.c b/net/9p/trans_rdma.c index bac8dad5dd69..eba3c5fc2731 100644 --- a/net/9p/trans_rdma.c +++ b/net/9p/trans_rdma.c @@ -242,18 +242,24 @@ p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) struct p9_trans_rdma *rdma = c->trans; switch (event->event) { case RDMA_CM_EVENT_ADDR_RESOLVED: - BUG_ON(rdma->state != P9_RDMA_INIT); - rdma->state = P9_RDMA_ADDR_RESOLVED; + if (rdma) { + BUG_ON(rdma->state != P9_RDMA_INIT); + rdma->state = P9_RDMA_ADDR_RESOLVED; + } break; case RDMA_CM_EVENT_ROUTE_RESOLVED: - BUG_ON(rdma->state != P9_RDMA_ADDR_RESOLVED); - rdma->state = P9_RDMA_ROUTE_RESOLVED; + if (rdma) { + BUG_ON(rdma->state != P9_RDMA_ADDR_RESOLVED); + rdma->state = P9_RDMA_ROUTE_RESOLVED; + } break; case RDMA_CM_EVENT_ESTABLISHED: - BUG_ON(rdma->state != P9_RDMA_ROUTE_RESOLVED); - rdma->state = P9_RDMA_CONNECTED; + if (rdma) { + BUG_ON(rdma->state != P9_RDMA_ROUTE_RESOLVED); + rdma->state = P9_RDMA_CONNECTED; + } break; case RDMA_CM_EVENT_DISCONNECTED: @@ -277,12 +283,14 @@ p9_cm_event_handler(struct rdma_cm_id *id, struct rdma_cm_event *event) case RDMA_CM_EVENT_ADDR_ERROR: case RDMA_CM_EVENT_UNREACHABLE: c->status = Disconnected; - rdma_disconnect(rdma->cm_id); + if (rdma) + rdma_disconnect(rdma->cm_id); break; default: BUG(); } - complete(&rdma->cm_done); + if (rdma) + complete(&rdma->cm_done); return 0; } -- 2.17.0