Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp1342792imm; Tue, 2 Oct 2018 06:49:57 -0700 (PDT) X-Google-Smtp-Source: ACcGV60AHDOTnSFotV0NvFtLnKd30yzB+sSbPMBJO09O7Gk2vyDYFfrgZDESe/9AefwCkVu8ojMs X-Received: by 2002:a17:902:780d:: with SMTP id p13-v6mr16549452pll.96.1538488197915; Tue, 02 Oct 2018 06:49:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538488197; cv=none; d=google.com; s=arc-20160816; b=iE07xEf3BbuQOo3ljmPxsDGApw8HftR0Afy1Tn3UFCLIJ56X3tCQ56iNuFOFnOtOIt p/ghN0uWYIvj+8GeY77UdLGRTCtI0mBeKh4JskskBJ/YApVRkCH6rA1sgsybh3uAjQWs e0HVzrq2vxsKtbgoVVNsvcDpNBVjO+5nOkYok4zbeoy7HdrD5nxhatQka7yBLkmjNRNS 1hkdtCZr0UwSmquDuMbNj1A+VRPMzjcm7dLR4v80iyO0vakL+Y8XSKjMG+twnFG+wSdR FZrEHsmmkBznH7+wxav2a8G8kEAIcqLdc+9ODMSUD/HYMgpAcy2jyjDG4Wz4cm7eW/ue aRnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from; bh=OjkSunGiakzQFNhBXbSotyqyXKapvn5rWp5y4ITs0Hc=; b=xGg7WahkOQ8YgFfy35cmh4aHr1Vy8Nxp+F+qKuSWOv4Yaz0lwfolkowfsYWCU2CEAH 4iUrRrGfLRO/V/kvlfYLpGoxrE805U1x6Vy1e3AEOxdyOGbQ2hT7L335OmuMZV4K5yCG +kHplBzabkJcpRHRpErx8u7S1SVWAfkRfjT2fmveMpBn08k3jk/06cZUm+JepGTWgOZo TBGRBnvemUyTIxqFOfwQhjDIJvboTaUxKSxfXz58KNcxJmAcCARMMmtpESH/fTLyY9x2 84n+2cVRKeIpgh0Xizb2Nb5i1QQxxmOHBPHN2s6B/hhVkDynfYlo4a1gbjI1Wsoaj7zm RT8A== 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 q16-v6si14581063pgb.18.2018.10.02.06.49.42; Tue, 02 Oct 2018 06:49:57 -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 S1732235AbeJBURm (ORCPT + 99 others); Tue, 2 Oct 2018 16:17:42 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:35252 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729661AbeJBURl (ORCPT ); Tue, 2 Oct 2018 16:17:41 -0400 Received: from localhost (24-104-73-23-ip-static.hfc.comcastbusiness.net [24.104.73.23]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 93DCF5AA; Tue, 2 Oct 2018 13:34:17 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mike Marciniszyn , Lukasz Odzioba , "Michael J. Ruhl" , Dennis Dalessandro , Jason Gunthorpe Subject: [PATCH 4.14 106/137] IB/hfi1: Invalid user input can result in crash Date: Tue, 2 Oct 2018 06:25:07 -0700 Message-Id: <20181002132505.917891806@linuxfoundation.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181002132458.446916963@linuxfoundation.org> References: <20181002132458.446916963@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Michael J. Ruhl commit 94694d18cf27a6faad91487a38ce516c2b16e7d9 upstream. If the number of packets in a user sdma request does not match the actual iovectors being sent, sdma_cleanup can be called on an uninitialized request structure, resulting in a crash similar to this: BUG: unable to handle kernel NULL pointer dereference at 0000000000000008 IP: [] __sdma_txclean+0x57/0x1e0 [hfi1] PGD 8000001044f61067 PUD 1052706067 PMD 0 Oops: 0000 [#1] SMP CPU: 30 PID: 69912 Comm: upsm Kdump: loaded Tainted: G OE ------------ 3.10.0-862.el7.x86_64 #1 Hardware name: Intel Corporation S2600KPR/S2600KPR, BIOS SE5C610.86B.01.01.0019.101220160604 10/12/2016 task: ffff8b331c890000 ti: ffff8b2ed1f98000 task.ti: ffff8b2ed1f98000 RIP: 0010:[] [] __sdma_txclean+0x57/0x1e0 [hfi1] RSP: 0018:ffff8b2ed1f9bab0 EFLAGS: 00010286 RAX: 0000000000008b2b RBX: ffff8b2adf6e0000 RCX: 0000000000000000 RDX: 00000000000000a0 RSI: ffff8b2e9eedc540 RDI: ffff8b2adf6e0000 RBP: ffff8b2ed1f9bad8 R08: 0000000000000000 R09: ffffffffc0b04a06 R10: ffff8b331c890190 R11: ffffe6ed00bf1840 R12: ffff8b3315480000 R13: ffff8b33154800f0 R14: 00000000fffffff2 R15: ffff8b2e9eedc540 FS: 00007f035ac47740(0000) GS:ffff8b331e100000(0000) knlGS:0000000000000000 CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 CR2: 0000000000000008 CR3: 0000000c03fe6000 CR4: 00000000001607e0 Call Trace: [] user_sdma_send_pkts+0xdcd/0x1990 [hfi1] [] ? gup_pud_range+0x140/0x290 [] ? hfi1_mmu_rb_insert+0x155/0x1b0 [hfi1] [] hfi1_user_sdma_process_request+0xc5b/0x11b0 [hfi1] [] hfi1_aio_write+0xba/0x110 [hfi1] [] do_sync_readv_writev+0x7b/0xd0 [] do_readv_writev+0xce/0x260 [] ? tty_ldisc_deref+0x19/0x20 [] ? n_tty_ioctl+0xe0/0xe0 [] vfs_writev+0x35/0x60 [] SyS_writev+0x7f/0x110 [] system_call_fastpath+0x1c/0x21 Code: 06 49 c7 47 18 00 00 00 00 0f 87 89 01 00 00 5b 41 5c 41 5d 41 5e 41 5f 5d c3 66 2e 0f 1f 84 00 00 00 00 00 48 8b 4e 10 48 89 fb <48> 8b 51 08 49 89 d4 83 e2 0c 41 81 e4 00 e0 00 00 48 c1 ea 02 RIP [] __sdma_txclean+0x57/0x1e0 [hfi1] RSP CR2: 0000000000000008 There are two exit points from user_sdma_send_pkts(). One (free_tx) merely frees the slab entry and one (free_txreq) cleans the sdma_txreq prior to freeing the slab entry. The free_txreq variation can only be called after one of the sdma_init*() variations has been called. In the panic case, the slab entry had been allocated but not inited. Fix the issue by exiting through free_tx thus avoiding sdma_clean(). Cc: # 4.9.x+ Fixes: 7724105686e7 ("IB/hfi1: add driver files") Reviewed-by: Mike Marciniszyn Reviewed-by: Lukasz Odzioba Signed-off-by: Michael J. Ruhl Signed-off-by: Dennis Dalessandro Signed-off-by: Greg Kroah-Hartman Signed-off-by: Jason Gunthorpe --- drivers/infiniband/hw/hfi1/user_sdma.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) --- a/drivers/infiniband/hw/hfi1/user_sdma.c +++ b/drivers/infiniband/hw/hfi1/user_sdma.c @@ -828,7 +828,7 @@ static int user_sdma_send_pkts(struct us if (ACCESS_ONCE(iovec->offset) == iovec->iov.iov_len) { if (++req->iov_idx == req->data_iovs) { ret = -EFAULT; - goto free_txreq; + goto free_tx; } iovec = &req->iovs[req->iov_idx]; WARN_ON(iovec->offset);