Received: by 10.223.164.221 with SMTP id h29csp3687500wrb; Tue, 31 Oct 2017 03:19:21 -0700 (PDT) X-Google-Smtp-Source: ABhQp+Qt8PrJWTrbmiqESlWeUyaXWxapbwxE+fOGE/wONWxVgVVIT7mVcfkmwoCulshGvWfRcJF+ X-Received: by 10.98.62.17 with SMTP id l17mr1566032pfa.210.1509445161659; Tue, 31 Oct 2017 03:19:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1509445161; cv=none; d=google.com; s=arc-20160816; b=s1gZUEu44gY6R2JHxAbnoD+wktmglsxlHiDZfm2FekaOa7fTfAuVa8PCzzYxu4pHvC X/NReQCKTHHlLOHiAYAphxOnqV5a3942HRk8hTrl5LOWg33Dk4vgkoCqOdxzqL+rZaBU kmnG4uvpRoye+O+fUm1+QDRV7tNVWBOJDkvh8eGqf6zjdfnpdhOtpmJ8eqQswChNON1l g4en3fXMib7aKrNXIg9vZhJjTog9wP7vVAAxrWVNrLhYx8VZvJ1+0WX+TUQhzn98LGsC kYXhauN4IFyZRkBI9dvzIgCvBeSnAjGXVsAI9AWS3Vgwk3jLsTYyIjJz05oA5WNPbj9Y rG1A== 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:to:from :arc-authentication-results; bh=aOF5n2eT+Q71L/6twx2ZLVs7JVmndMekNudbIjMJaF0=; b=AWJqmx/wnYHnuUJEje98IY5W0cFGYNQIDk7ZXW1DCFSNEYMQFF5u7tx5UmUjuhlHQu tM33Vh3hYKxONFjhGCU/Cl5nibj+1epW0jDsGLD7SRO1uHFkpImHkzxixZANN+vqDaF9 BYIP8LPs/VAwd6oArhVP9PZrPA/uRIll37m6l1eJq3w0v2wFe901ESl0azrpXShm45gj 6UNJCjQOtsatnJbK1vk/bG3FUi8kRMAA1bySm/BVLDG1Whxk5lffXEIo/LONg7nKlfzc JWJKlJlfWnfdiCuckt8OUB2UNHXGtXj4M1JF78rMnmz0JrWuEBMOZF3Kvl0ldB5W1yXs 7DdQ== 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 7si1296737ple.549.2017.10.31.03.19.08; Tue, 31 Oct 2017 03:19:21 -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; 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 S1753828AbdJaKSd (ORCPT + 99 others); Tue, 31 Oct 2017 06:18:33 -0400 Received: from mx2.suse.de ([195.135.220.15]:42324 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753608AbdJaKSa (ORCPT ); Tue, 31 Oct 2017 06:18:30 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (charybdis-ext.suse.de [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 67F02ABED; Tue, 31 Oct 2017 10:18:29 +0000 (UTC) From: Thomas Bogendoerfer To: Moni Shoua , Doug Ledford , linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2] IB/rxe: don't crash, if allocation of crc algorithm failed Date: Tue, 31 Oct 2017 11:16:46 +0100 Message-Id: <20171031101647.45111-1-tbogendoerfer@suse.de> X-Mailer: git-send-email 2.12.3 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Following crash happens, if crc algorithm couldn't be allocated: [ 1087.989072] rdma_rxe: loaded [ 1097.855397] PCLMULQDQ-NI instructions are not detected. [ 1097.901220] rdma_rxe: failed to allocate crc algorithmi err:-2 [ 1097.901248] BUG: unable to handle kernel [ 1097.901249] NULL pointer dereference [ 1097.901250] at 0000000000000046 [...] Reason is that rxe->tfm is assigned the error return, which will then be used for crypto_free_shash() in rxe_cleanup. Fix by using a temporary variable and assigning it rxe->tfm after allocation succeeded. Fixes: cee2688e3cd6 ("IB/rxe: Offload CRC calculation when possible") Signed-off-by: Thomas Bogendoerfer --- drivers/infiniband/sw/rxe/rxe_verbs.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/infiniband/sw/rxe/rxe_verbs.c b/drivers/infiniband/sw/rxe/rxe_verbs.c index ff77f4f66970..d03002b9d84d 100644 --- a/drivers/infiniband/sw/rxe/rxe_verbs.c +++ b/drivers/infiniband/sw/rxe/rxe_verbs.c @@ -1192,6 +1192,7 @@ int rxe_register_device(struct rxe_dev *rxe) int err; int i; struct ib_device *dev = &rxe->ib_dev; + struct crypto_shash *tfm; strlcpy(dev->name, "rxe%d", IB_DEVICE_NAME_MAX); strlcpy(dev->node_desc, "rxe", sizeof(dev->node_desc)); @@ -1289,12 +1290,13 @@ int rxe_register_device(struct rxe_dev *rxe) dev->get_hw_stats = rxe_ib_get_hw_stats; dev->alloc_hw_stats = rxe_ib_alloc_hw_stats; - rxe->tfm = crypto_alloc_shash("crc32", 0, 0); - if (IS_ERR(rxe->tfm)) { + tfm = crypto_alloc_shash("crc32", 0, 0); + if (IS_ERR(tfm)) { pr_err("failed to allocate crc algorithm err:%ld\n", - PTR_ERR(rxe->tfm)); - return PTR_ERR(rxe->tfm); + PTR_ERR(tfm)); + return PTR_ERR(tfm); } + rxe->tfm = tfm; err = ib_register_device(dev, NULL); if (err) { -- 2.12.3 From 1583741173380519567@xxx Sat Nov 11 04:08:00 +0000 2017 X-GM-THRID: 1583741173380519567 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread