From patchwork Sun Jun 5 20:13:55 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sudip Mukherjee X-Patchwork-Id: 9156313 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 40EDF60759 for ; Sun, 5 Jun 2016 20:14:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 24A3E2656B for ; Sun, 5 Jun 2016 20:14:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 07E2D2824A; Sun, 5 Jun 2016 20:14:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 139482656B for ; Sun, 5 Jun 2016 20:14:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751764AbcFEUOG (ORCPT ); Sun, 5 Jun 2016 16:14:06 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:34933 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751211AbcFEUOE (ORCPT ); Sun, 5 Jun 2016 16:14:04 -0400 Received: by mail-wm0-f66.google.com with SMTP id k184so5424251wme.2; Sun, 05 Jun 2016 13:14:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:to:cc:subject:date:message-id; bh=i8O4kD0luRkWODSCNo4h3BijYimzaIEWAMLNyyVl/4k=; b=LFRxjNJt2ucGm3M3d4QNZppt2G9EpeGbl0Mhor+cVUcGa79oiRvCMr/JfGCUD62qCz 2nfiJQjURrfZZgz3Ohb6mPfIGq1h/NQ8CFxQwe7sXt0ESEj21JtWju4n5H3Vm9SA2W7x R1VpOMQg3DQqEa5f532MrD/BLE97BpTGDmfxRvMTejybg1iygJMN5fXqv2AypEfDjdus /u65vjr6gSjNqGA2clpT6dcw4xMJkPS+v7gqW3x41ad63YQmFCJTY3Dck7TaiXnMbaG0 OYVYcrPS1fYWaQBuXlhe6kKFGbOKQo+39YR3QznLins4dkHDNhUNtOb81zx1yeYWoshE OlNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=i8O4kD0luRkWODSCNo4h3BijYimzaIEWAMLNyyVl/4k=; b=KtA/9M/hYjl7woDKUi5d7NXMJwD3zTpG5Wu0wOg6XWSpG08qQoQWEMf5TDLiuHDV3S 9f2SPgeBgrsmXcBptDa4LQVjNvWToVuYLsdVG2/TA+n+9D352SXBrGNKYz2i00fdBuBN 5f+WKLRU97PZfI2UFlvqa38pkeTwusl9rEg8RqZMAU8at+FTacR8AtZcGfzJg1n43hA8 aHcbTuBEf60xR4DlerUuY4ao9FzloF0K3asTL+MNvUu3hcMkDDXwBd5b/R8gaSxvhc0f Drmp5S0+MO0Fsw3mVh1s5uaIZiPZzuugPqckDQ0CU4VCtecCk63J52+wq41U1Ek4J1wE cM+Q== X-Gm-Message-State: ALyK8tK5KnKZWx4KcV49wfnteupZjXyGz+c6UxkY1Owy39ae+k7J7KGVHrRDXeZAvTp6og== X-Received: by 10.194.186.200 with SMTP id fm8mr12211552wjc.174.1465157643044; Sun, 05 Jun 2016 13:14:03 -0700 (PDT) Received: from sudip-laptop.lan (234.98.208.46.dyn.plus.net. [46.208.98.234]) by smtp.gmail.com with ESMTPSA id dd7sm16727587wjb.22.2016.06.05.13.14.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sun, 05 Jun 2016 13:14:01 -0700 (PDT) From: Sudip Mukherjee To: Doug Ledford , Sean Hefty , Hal Rosenstock Cc: linux-kernel@vger.kernel.org, linux-rdma@vger.kernel.org, Sudip Mukherjee Subject: [PATCH 1/2] IB/sysfs: fix NULL dereference Date: Sun, 5 Jun 2016 21:13:55 +0100 Message-Id: <1465157636-10120-1-git-send-email-sudipm.mukherjee@gmail.com> X-Mailer: git-send-email 1.9.1 Sender: linux-rdma-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-rdma@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If stats->names is NULL or stats->num_counters <= 0 we are jumping to the error path where the for loop is freeing hsag->attrs[i]. But as i is initialized to 0 so i >= 0 will be true and the loop will execute once trying to free hsag->attrs[0]. But hsag is NULL still now leading to a NULL pointer dereference. Signed-off-by: Sudip Mukherjee Reviewed-by: Leon Romanovsky --- drivers/infiniband/core/sysfs.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/infiniband/core/sysfs.c b/drivers/infiniband/core/sysfs.c index 5e573bb..fcf6f9c 100644 --- a/drivers/infiniband/core/sysfs.c +++ b/drivers/infiniband/core/sysfs.c @@ -891,7 +891,7 @@ static void setup_hw_stats(struct ib_device *device, struct ib_port *port, { struct attribute_group *hsag = NULL; struct rdma_hw_stats *stats; - int i = 0, ret; + int i = -1, ret; stats = device->alloc_hw_stats(device, port_num);