Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp838372ybl; Wed, 11 Dec 2019 08:15:21 -0800 (PST) X-Google-Smtp-Source: APXvYqyI9JZbCnR7rjvTdrQv77T+N7V3BbPa9wdcDSrJk/SzztVl22fg7U3GgA8k4m/N0Ow5lsgW X-Received: by 2002:a05:6830:1608:: with SMTP id g8mr2685789otr.169.1576080920825; Wed, 11 Dec 2019 08:15:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576080920; cv=none; d=google.com; s=arc-20160816; b=SRB1MdNyMI1Thvm31E7ywy2NwV7kB3m6x4o2wD7eCwU5fZSjE2b2zlrmP31XCySOA+ P1K+8CkSt6lncrXPwUTAmmT9/f/rkrnGQ/Sp3NZmiqyJCrJsupwYIMZTB7NCysb1+UGw BogZD4UT3CX69Zp8+KLZW5L4eEztlXZlfw07tk79EW2ZqndLpaRGc/rw7galWNlb9fEl mwK2wbvAFr7dR2jGRh3Nh98eHW+phnrqNH/WmvncuUTfaLItxDb18v4YbyPD0I6eHv7S +OmtswfBnDdODO2U4WHzS9tb7RA2aWBpjBVFEES07il08fEATq6gZQ0+Pcrf09lYn+WM V/OQ== 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:dkim-signature; bh=trSi+YWCgY5YlElcH70RJw4wO/n0/dYoaNFVTSH4oEk=; b=i1R5/QOkzH3Z4B/Ri995tNfBtkg/nFe4UBv4Ir2zCHex5TkKIkcEaJxVXrs8DiHFrz ZhUv7o5cPU8T9F4aY2Vc3GIysjGrbN4RJo7E+a13pq2AvC3j+gBSmJ9hySRrtfvUcTcp nnfyxroTJXaefB1790JEdBunSFfEJA3Uw6o0YDWHYy2zRa626WhSSg/Km2BO0aJqcTsF 7V0Px5wSE+hQiY6ZIqIKq3B41mM1xU7057WkYX1kWiWiLzeXMr5UHVQgfKhFIKOJ8WX7 R6CIJnv6kfhlwa+KoVJ31jyvpFEUBTwkSOfhHSk9SR8WDH0b/ceo9eLvbUMIZB31PUX3 pL0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=lq0owAKv; 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 r6si1343322otq.95.2019.12.11.08.15.07; Wed, 11 Dec 2019 08:15:20 -0800 (PST) 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=lq0owAKv; 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 S1730130AbfLKPHt (ORCPT + 99 others); Wed, 11 Dec 2019 10:07:49 -0500 Received: from mail.kernel.org ([198.145.29.99]:55012 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730076AbfLKPHs (ORCPT ); Wed, 11 Dec 2019 10:07:48 -0500 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 6560520663; Wed, 11 Dec 2019 15:07:46 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1576076866; bh=3m563FRZtB/k4I8XP+18gcNzctJF6R2qy2jQ07wZW0A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lq0owAKvDQPAE61LUoH8/lNEgrm3rAzap/gTchhpIUYp8O+Q2+sJtn9oTyugY4ey5 XSAu7+WwyxVmt8JsaBHWaX3d+O87OTxVyiaA9zV1zhlJMoOFtCS5dN18t7zRY9F+Gs pZUgCsIPF6lEdAv+QKAyGpdSyhbgctiEaYLf9HTk= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Pavel Begunkov , Jens Axboe Subject: [PATCH 5.4 20/92] io_uring: fix dead-hung for non-iter fixed rw Date: Wed, 11 Dec 2019 16:05:11 +0100 Message-Id: <20191211150227.929391888@linuxfoundation.org> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20191211150221.977775294@linuxfoundation.org> References: <20191211150221.977775294@linuxfoundation.org> User-Agent: quilt/0.66 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 From: Pavel Begunkov commit 311ae9e159d81a1ec1cf645daf40b39ae5a0bd84 upstream. Read/write requests to devices without implemented read/write_iter using fixed buffers can cause general protection fault, which totally hangs a machine. io_import_fixed() initialises iov_iter with bvec, but loop_rw_iter() accesses it as iovec, dereferencing random address. kmap() page by page in this case Cc: stable@vger.kernel.org Signed-off-by: Pavel Begunkov Signed-off-by: Jens Axboe Signed-off-by: Greg Kroah-Hartman --- fs/io_uring.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) --- a/fs/io_uring.c +++ b/fs/io_uring.c @@ -1351,9 +1351,19 @@ static ssize_t loop_rw_iter(int rw, stru return -EAGAIN; while (iov_iter_count(iter)) { - struct iovec iovec = iov_iter_iovec(iter); + struct iovec iovec; ssize_t nr; + if (!iov_iter_is_bvec(iter)) { + iovec = iov_iter_iovec(iter); + } else { + /* fixed buffers import bvec */ + iovec.iov_base = kmap(iter->bvec->bv_page) + + iter->iov_offset; + iovec.iov_len = min(iter->count, + iter->bvec->bv_len - iter->iov_offset); + } + if (rw == READ) { nr = file->f_op->read(file, iovec.iov_base, iovec.iov_len, &kiocb->ki_pos); @@ -1362,6 +1372,9 @@ static ssize_t loop_rw_iter(int rw, stru iovec.iov_len, &kiocb->ki_pos); } + if (iov_iter_is_bvec(iter)) + kunmap(iter->bvec->bv_page); + if (nr < 0) { if (!ret) ret = nr;