Received: by 2002:a25:824b:0:0:0:0:0 with SMTP id d11csp8571053ybn; Tue, 1 Oct 2019 09:59:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqz188XIRzMnrJkMvKII0Am6gEmXz1C7VlhMtU3ImdDBs6CBtcTNh9r2+34/H2LTNmz55bMt X-Received: by 2002:a50:9734:: with SMTP id c49mr26883111edb.93.1569949160198; Tue, 01 Oct 2019 09:59:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1569949160; cv=none; d=google.com; s=arc-20160816; b=ZQOK5MMb92G317vtd+a1wE5A+DkbFpQWAwoShdMOE9b+glWGngmVwKCJ5Gd1h+Pxq7 x5v7vwqk+5D688vzead4+doLZQG//y+yBUXdvaVIqYgr0FtCrqJCM/v8oMtO1lDmTeUW 0aLoZnO02g0aUjzhVybzMLin0vCv7F/k+OCAvyNsPA3o0XLAq2zkwjExSobXpNVPVnqH 0a2fCo26nl7bfGbrY9sf7n4EDZI9O2+sWiYmd2NeC6YVzsmoq+wsD0gVr9kx48ElME5m RrqP6/bgmMm0YDDPHlfjMBi7WyhyW2lSnXLL90f723kYJs0j8xWbSellg5fVUNdtqqKO 0WDQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=XiXmJc/dy6EE0JuS0FjWMIgUQ2PHF0EO8lSw4Cd4SPU=; b=S+j9oyomiFfdPkOvRREfX0uSRZY6Nf/Fx5Jso603IzMP4M8f9CmL8wL3S0/v8H2I8g SbyXyWeJ2GgH3C5RxqP48Z2mTnD4MhvZqD6ISYSqL1y6/PkToAo7JZQk5C9+WmUtxiie CWaEJwbRa2QjWGkfVz5eiJZWFeJnMRUuXyl/f6bYosCtiEnd4FmhsWRp11rYhjihUEsh Th3czrNfV8I5oKyX9eARMvJXoD9VBUKcTjlZW6FYPfoUAXqCZxuwWnxQ2RdBgKXBPsYK p1Is8kn79suVs7iAe4SN7j34hDjsd3omJKGsw0e/Y7XuCbYOzNHXoO5n/kndIrfQA++Y HwzA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0tOVHOQw; 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 b9si9678364edj.0.2019.10.01.09.58.54; Tue, 01 Oct 2019 09:59:20 -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=@kernel.org header.s=default header.b=0tOVHOQw; 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 S1732181AbfJAQ4T (ORCPT + 99 others); Tue, 1 Oct 2019 12:56:19 -0400 Received: from mail.kernel.org ([198.145.29.99]:39260 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731801AbfJAQ4O (ORCPT ); Tue, 1 Oct 2019 12:56:14 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0A147206BB; Tue, 1 Oct 2019 16:56:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1569948973; bh=5rOmi/hQpmZC8qAgYpId4kUI81s/ozuuSGWHgczZ5BM=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=0tOVHOQwoEb0OxWlsUfzG6QSwR/67paORUCTvwb3UaFOhbnfzkMSlLGkYTRiIJQQ1 Xim6ULBJisHYLja++NzlTwlRQQ4o5CY4EdqD91HQhPrWDknDarp5s2rM63i9F87/eE 93URjYeeEg6jxTWkYLTulKf2l+yql5WIBEXxaAj0= Date: Tue, 1 Oct 2019 18:56:11 +0200 From: Greg KH To: Potnuri Bharat Teja , Doug Ledford , Jason Gunthorpe Cc: linux-rdma@vger.kernel.org, linux-kernel@vger.kernel.org, Nicolas Waisman Subject: [PATCH v2] cxgb4: do not dma memory off of the stack Message-ID: <20191001165611.GA3542072@kroah.com> References: <20191001153917.GA3498459@kroah.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191001153917.GA3498459@kroah.com> User-Agent: Mutt/1.12.2 (2019-09-21) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Nicolas pointed out that the cxgb4 driver is doing dma off of the stack, which is generally considered a very bad thing. On some architectures it could be a security problem, but odds are none of them actually run this driver, so it's just a "normal" bug. Resolve this by allocating the memory for a message off of the heap instead of the stack. kmalloc() always will give us a proper memory location that DMA will work correctly from. Reported-by: Nicolas Waisman Signed-off-by: Greg Kroah-Hartman --- v2: clean up memory on error case, pointed out by Nicolas v1: https://lore.kernel.org/r/20191001153917.GA3498459@kroah.com Test-built only, I don't have this hardware to actually run this code at all. diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c index aa772ee0706f..35c284af574d 100644 --- a/drivers/infiniband/hw/cxgb4/mem.c +++ b/drivers/infiniband/hw/cxgb4/mem.c @@ -275,13 +275,17 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, struct sk_buff *skb, struct c4iw_wr_wait *wr_waitp) { int err; - struct fw_ri_tpte tpt; + struct fw_ri_tpte *tpt; u32 stag_idx; static atomic_t key; if (c4iw_fatal_error(rdev)) return -EIO; + tpt = kmalloc(sizeof(*tpt), GFP_KERNEL); + if (!tpt) + return -ENOMEM; + stag_state = stag_state > 0; stag_idx = (*stag) >> 8; @@ -291,6 +295,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, mutex_lock(&rdev->stats.lock); rdev->stats.stag.fail++; mutex_unlock(&rdev->stats.lock); + kfree(tpt); return -ENOMEM; } mutex_lock(&rdev->stats.lock); @@ -305,28 +310,28 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, /* write TPT entry */ if (reset_tpt_entry) - memset(&tpt, 0, sizeof(tpt)); + memset(tpt, 0, sizeof(*tpt)); else { - tpt.valid_to_pdid = cpu_to_be32(FW_RI_TPTE_VALID_F | + tpt->valid_to_pdid = cpu_to_be32(FW_RI_TPTE_VALID_F | FW_RI_TPTE_STAGKEY_V((*stag & FW_RI_TPTE_STAGKEY_M)) | FW_RI_TPTE_STAGSTATE_V(stag_state) | FW_RI_TPTE_STAGTYPE_V(type) | FW_RI_TPTE_PDID_V(pdid)); - tpt.locread_to_qpid = cpu_to_be32(FW_RI_TPTE_PERM_V(perm) | + tpt->locread_to_qpid = cpu_to_be32(FW_RI_TPTE_PERM_V(perm) | (bind_enabled ? FW_RI_TPTE_MWBINDEN_F : 0) | FW_RI_TPTE_ADDRTYPE_V((zbva ? FW_RI_ZERO_BASED_TO : FW_RI_VA_BASED_TO))| FW_RI_TPTE_PS_V(page_size)); - tpt.nosnoop_pbladdr = !pbl_size ? 0 : cpu_to_be32( + tpt->nosnoop_pbladdr = !pbl_size ? 0 : cpu_to_be32( FW_RI_TPTE_PBLADDR_V(PBL_OFF(rdev, pbl_addr)>>3)); - tpt.len_lo = cpu_to_be32((u32)(len & 0xffffffffUL)); - tpt.va_hi = cpu_to_be32((u32)(to >> 32)); - tpt.va_lo_fbo = cpu_to_be32((u32)(to & 0xffffffffUL)); - tpt.dca_mwbcnt_pstag = cpu_to_be32(0); - tpt.len_hi = cpu_to_be32((u32)(len >> 32)); + tpt->len_lo = cpu_to_be32((u32)(len & 0xffffffffUL)); + tpt->va_hi = cpu_to_be32((u32)(to >> 32)); + tpt->va_lo_fbo = cpu_to_be32((u32)(to & 0xffffffffUL)); + tpt->dca_mwbcnt_pstag = cpu_to_be32(0); + tpt->len_hi = cpu_to_be32((u32)(len >> 32)); } err = write_adapter_mem(rdev, stag_idx + (rdev->lldi.vr->stag.start >> 5), - sizeof(tpt), &tpt, skb, wr_waitp); + sizeof(*tpt), tpt, skb, wr_waitp); if (reset_tpt_entry) { c4iw_put_resource(&rdev->resource.tpt_table, stag_idx); @@ -334,6 +339,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry, rdev->stats.stag.cur -= 32; mutex_unlock(&rdev->stats.lock); } + kfree(tpt); return err; }