Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp358123ybi; Fri, 26 Jul 2019 10:56:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqwzT6dKVqb9lk4PEaMEpVyWeb33OH/5derVX2YTB6k+uHBhHPn0HlU3511apcdM3l1m8ayd X-Received: by 2002:a17:902:1a6:: with SMTP id b35mr1363682plb.190.1564163789523; Fri, 26 Jul 2019 10:56:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1564163789; cv=none; d=google.com; s=arc-20160816; b=kJbpw6T5j8BtPDv2GywGAYQnjChka8PE/bTT84F/RAEQqtr4rdKXnD4yw0UIVGgq9w NlJb+hvKNKe+BpvPkUSIoOYTQ7TUiJFAGGrCcFQLkDLpZb3bsuaK78CEWRo+nXbf3ZWa GxvGYKwqLErlRjskpwFJSthT3l/EySmJvFFiFEbofUFcQwHrnEMzC67TrvED6JQ0Ek3R tk2lSg5FZ9tnvX4tcvQ4da9rin9sPSGJ7eMvWzrzI4BSSqgRG+CTimINg+FsMIv/N84d GM2gquRZ46SSP84B/ijCeXHMJVqbE/VH5A+rPvidPT/ssZBqBFFMcOqWg0vsyhFs6vmM 1Glg== 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=dNnqQwHX3ETnAbhTD2AqV3KPRBqgqiL6QbUT7t0Db40=; b=XKAULX/ZdObnJsmboXF67lOlzHFvU3JXa05Czk4lzgCjubNrFczSfGXAwME7KKtRyI 5EvwjBQoVHObmQVy/jRZ8T5lTprNV7vZZW02D5i8OyfYT0dz9TXMxfp7a8iJ9sKmsDyh vIBi1hLjsSLEryqqAhzAXLCirg1/VcoM/OsmMCzJJbzjkRCol7svoeCRRjtMG8hEcp14 DaeYOQqCv5LtiXsTgi9M00CnYYVCEaLNbKUg6VaAa22adAssbHXJT2d2z/4LcR0ZRhiv UDr/9wajE2J43OySvJHSLL9EJotqbdDrbGZeb2SDTKMz63CWFH2VPtD6oN9/qMhXJIRx ZRyQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=aCuPaDhX; 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 i198si19805484pfe.228.2019.07.26.10.56.14; Fri, 26 Jul 2019 10:56:29 -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=aCuPaDhX; 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 S1728088AbfGZORN (ORCPT + 99 others); Fri, 26 Jul 2019 10:17:13 -0400 Received: from mail-pf1-f195.google.com ([209.85.210.195]:42698 "EHLO mail-pf1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727358AbfGZORN (ORCPT ); Fri, 26 Jul 2019 10:17:13 -0400 Received: by mail-pf1-f195.google.com with SMTP id q10so24586986pff.9; Fri, 26 Jul 2019 07:17:12 -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=dNnqQwHX3ETnAbhTD2AqV3KPRBqgqiL6QbUT7t0Db40=; b=aCuPaDhXVM0L+4hA6IRjIBoywOkmHWDMoGVV8FRhqt4MYj3M7Fhzi+b6Lb1sfpBDTn Us31F+UYEGzp/6hNLWyB3wTdQYnV603w845xUBGcOc41Dv5/Qz49XnOqGJDdRkTBTp7M arVmCDNZ0tz54v6N4mLpaTsibLt/xDg93Z5ZNLCM3LbXnHMOoCJkwpfflvm2bA2xeBEG x/GVx1DJejxlYLJanhWmcGZkTU1HVOaznc0cvMIURwMquqM4VqME9UUgzC6YdwzV0yAc NX5hUNourXGvVqvaUPTO7Y5uLX0K1MnPMq5B9epbstfcWpknZOVl2APDjPfqPNGbxgK3 UT1A== 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=dNnqQwHX3ETnAbhTD2AqV3KPRBqgqiL6QbUT7t0Db40=; b=mliyaJ6yDNbGjQvrcD1cXQUw0xNdyhar29DWAmzymj2RpjmROL1FNCkjlCtXQ+kz9e duLDbzcmDqiuS0QiV5o1SlIhjrloqtMN8BsBJ6GW12upUtbbSaBXDR6irKHUOG75zM/t i3OrazZOur2nl31ba/+dU10bC6m4zQzO/urOhltCsJ5xioD5yhrI4UzJrDi1o4N2/M7n GhcuhY0gUlMHPTV1zxuhpofpTqnGL8tFBUBahlfNWrCHbCpJ7kwCuvhAAcr2eFIRDbYI YpEkj2vBW1qCCefTPSvBkYixLTp2m5Xd1jJjb0IMi99lvAOlrnf08BXEbZ2wR7W4HB1u psGQ== X-Gm-Message-State: APjAAAVZqty9QronGIidQxj7hV3+D4hs0zE1xvgTUsE76zk5RUV0uKSF zUXe/m+z9VJWy66pVtHEtn0= X-Received: by 2002:aa7:9afc:: with SMTP id y28mr22080870pfp.252.1564150632442; Fri, 26 Jul 2019 07:17:12 -0700 (PDT) Received: from oslab.tsinghua.edu.cn ([2402:f000:4:72:808::3ca]) by smtp.gmail.com with ESMTPSA id j6sm70251565pjd.19.2019.07.26.07.17.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jul 2019 07:17:11 -0700 (PDT) From: Jia-Ju Bai To: santosh.shilimkar@oracle.com, davem@davemloft.net Cc: netdev@vger.kernel.org, linux-rdma@vger.kernel.org, rds-devel@oss.oracle.com, linux-kernel@vger.kernel.org, Jia-Ju Bai Subject: [PATCH] net: rds: Fix possible null-pointer dereferences in rds_rdma_cm_event_handler_cmn() Date: Fri, 26 Jul 2019 22:17:05 +0800 Message-Id: <20190726141705.9585-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 rds_rdma_cm_event_handler_cmn(), there are some if statements to check whether conn is NULL, such as on lines 65, 96 and 112. But conn is not checked before being used on line 108: trans->cm_connect_complete(conn, event); and on lines 140-143: rdsdebug("DISCONNECT event - dropping connection " "%pI6c->%pI6c\n", &conn->c_laddr, &conn->c_faddr); rds_conn_drop(conn); Thus, possible null-pointer dereferences may occur. To fix these bugs, conn 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/rds/rdma_transport.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/net/rds/rdma_transport.c b/net/rds/rdma_transport.c index ff74c4bbb9fc..9986d6065c4d 100644 --- a/net/rds/rdma_transport.c +++ b/net/rds/rdma_transport.c @@ -105,7 +105,8 @@ static int rds_rdma_cm_event_handler_cmn(struct rdma_cm_id *cm_id, break; case RDMA_CM_EVENT_ESTABLISHED: - trans->cm_connect_complete(conn, event); + if (conn) + trans->cm_connect_complete(conn, event); break; case RDMA_CM_EVENT_REJECTED: @@ -137,6 +138,8 @@ static int rds_rdma_cm_event_handler_cmn(struct rdma_cm_id *cm_id, break; case RDMA_CM_EVENT_DISCONNECTED: + if (!conn) + break; rdsdebug("DISCONNECT event - dropping connection " "%pI6c->%pI6c\n", &conn->c_laddr, &conn->c_faddr); -- 2.17.0