Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1826800imm; Mon, 3 Sep 2018 10:26:44 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYP5hw8I6UfSEBJiBJdTEbu8dbr1bRo1DZ1ZSLiw54WMahcb7FG5Y/R7ej9R1zsr6mxNSf+ X-Received: by 2002:a63:cd4c:: with SMTP id a12-v6mr27567166pgj.15.1535995604634; Mon, 03 Sep 2018 10:26:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535995604; cv=none; d=google.com; s=arc-20160816; b=Dhuk3ov5q5vmDBFJc1qeeN6UbbWS6VQ3Of0wfcdm1zm66H9cubqkfsYFee/couNCKz ag2zCWUT28LDm0bWAswchkM47PAlOD5GjjV6PqvH/L6TmcWCD3OC2kVRRx9VdmKdXiJs OT5KEVYVXJCekm6EhkBnTnvf76KGVIWgAmzIfthj3KXzMDeG0NFKtSTcYucxEBEF3xOM U1ndTAxB7sxSvNZXDeebsI/ovYs61F0Mzczm7f8GcNbjwkOxFepSmL7fIEAbOou35hSN kCcNr/1zorRhOyZGS8X3UIW3L9+SDNELDXn9/wD5QCuIyPI06b/VnsGE/1WKrCo2qgt5 pLGQ== 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=bMhdxjMgR2Kp2U1DZ/a2quQFwYMGJ/FFdXePM0NK8q8=; b=eXbHY/rZKJr3pdxufMxg0sBLGTXVHVUhEZOuMry2iMMO8QdOxVBTnj30Zsfx+yxn4Q F5AcxHjcDRWq4ngiSvfqU2IZ4qZyjYz3e1dQpBq/w5S2enmYVr2x9zwLR34cH+g40YMl IPaYBoGcI3dbv3yeumsz/wWnzHBx/0JbVLpJqvywqVCe54dzHhlYuKY3JgSvkrFVA3IR qPL3JVHg4XvF5y8E2XOnjIJy1+e87AO666UTr051iZ0zfTMVFP5nbvtHLc7CURz+ePdA gNUlIHsyzlN5eUQt8vIHcuShTrV8KclgFbYZroZRuY/lrUnMs0eJLNxZYny4oEfQZcuX sJ6g== 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 r7-v6si19446100pli.248.2018.09.03.10.26.29; Mon, 03 Sep 2018 10:26:44 -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 S1730639AbeICVqc (ORCPT + 99 others); Mon, 3 Sep 2018 17:46:32 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:45738 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728380AbeICVqb (ORCPT ); Mon, 3 Sep 2018 17:46:31 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 7BB2AD36; Mon, 3 Sep 2018 17:25:24 +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.14 118/165] fuse: Dont access pipe->buffers without pipe_lock() Date: Mon, 3 Sep 2018 18:56:44 +0200 Message-Id: <20180903165701.452352986@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903165655.003605184@linuxfoundation.org> References: <20180903165655.003605184@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.14-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 @@ -1941,11 +1941,14 @@ static ssize_t fuse_dev_splice_write(str if (!fud) return -EPERM; + pipe_lock(pipe); + bufs = kmalloc(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++)