Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1833323imm; Mon, 3 Sep 2018 10:36:29 -0700 (PDT) X-Google-Smtp-Source: ANB0VdZHiAyCOO48gg2RcPyHAbExgkhVBVj0BzY31EFv6LEOcBnSz2rReHu3zcFS12FhAeeIuBmz X-Received: by 2002:a62:b604:: with SMTP id j4-v6mr30562788pff.199.1535996189208; Mon, 03 Sep 2018 10:36:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535996189; cv=none; d=google.com; s=arc-20160816; b=n24o3NXR8AfBNgUrBRfeGb6Rf+RaeirAz6o4veTW7RFwb7ZDEiY1YMUtoGdvJbPSjJ 5k0YmgtCQ0M7ORo4/Ri/W4CsKqijhhWcVdSURraFcddyMQQK0GP3h63XQ7XAIznxL2Yl uK/absbv4jGNeAyUcD6RetTOo16WB4D1p1nDT9SseHmBkBMC2Aijei8lDF1HJMHnkIpI xhsiYbIuFFpMconuZolENx1AZNEyFalXGR12HvO4BP9ZNlUfAm/ICGU0EFHNKXRDaF+c lD618YLsAc5gO+dspZxLHJRgkJPC8ycPH6ChqkccY2k60QmkyNyZl3vtLrhJzUdEoMcd 9ECA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from :arc-authentication-results; bh=5WYBTC/vNaFGJt16b2CUnCuVDyovv4I+TB5YomPkgRU=; b=HZGYHqZZXS8MBnW5mOQCcE77W94pIBnivaCjtzB2O1DrnsSXrRHv7rSKafHisc2SdZ L92RHHB/TsBRzgbkPDKR3vrojTrydGEd7U32eFU4NUu57Lrr8mvfjeDvXtUh5h4eK6GD qhVAjFBNjYgX/bBJYcAkZEEXanfBsA/WZTtCk+ZXXkLeyVAY8AaeZcQh1PVfhcDDrfXR bU2WBNGUH6zlC7zotnED3/Pbh3mPXkiLCuKkCNxMUwk//PKVggDAgDwOoYId3dxVPPHp QLbssS6iBxLzwfvINsa82yR5CiqRB7C7E7nQA9igZw3/6Vnw8CdX1srKIK8WRj+fOrJs fwYA== 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 bc6-v6si18357392plb.115.2018.09.03.10.36.14; Mon, 03 Sep 2018 10:36:29 -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 S1731324AbeICV4W (ORCPT + 99 others); Mon, 3 Sep 2018 17:56:22 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:47966 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727972AbeICV4V (ORCPT ); Mon, 3 Sep 2018 17:56:21 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id C8321D1B; Mon, 3 Sep 2018 17:35:11 +0000 (UTC) From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Andrey Ryabinin , Miklos Szeredi Subject: [PATCH 4.18 058/123] fuse: Dont access pipe->buffers without pipe_lock() Date: Mon, 3 Sep 2018 18:56:42 +0200 Message-Id: <20180903165721.893005227@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165719.499675257@linuxfoundation.org> References: <20180903165719.499675257@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: Andrey Ryabinin commit a2477b0e67c52f4364a47c3ad70902bc2a61bd4c upstream. fuse_dev_splice_write() reads pipe->buffers to determine the size of 'bufs' array before taking the pipe_lock(). This is not safe as another thread might change the 'pipe->buffers' between the allocation and taking the pipe_lock(). So we end up with too small 'bufs' array. Move the bufs allocations inside pipe_lock()/pipe_unlock() to fix this. Fixes: dd3bb14f44a6 ("fuse: support splice() writing to fuse device") Signed-off-by: Andrey Ryabinin Cc: # v2.6.35 Signed-off-by: Miklos Szeredi Signed-off-by: Greg Kroah-Hartman --- fs/fuse/dev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1944,12 +1944,15 @@ static ssize_t fuse_dev_splice_write(str if (!fud) return -EPERM; + pipe_lock(pipe); + bufs = kmalloc_array(pipe->buffers, sizeof(struct pipe_buffer), GFP_KERNEL); - if (!bufs) + if (!bufs) { + pipe_unlock(pipe); return -ENOMEM; + } - pipe_lock(pipe); nbuf = 0; rem = 0; for (idx = 0; idx < pipe->nrbufs && rem < len; idx++)