Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp1811123imm; Mon, 3 Sep 2018 10:03:00 -0700 (PDT) X-Google-Smtp-Source: ANB0VdaoYhpf64YbnLohmDy+4Vi/pB6XBclLe9wimiSkT63QcXA8+UQbP0T34cgvtugqunhTmTDi X-Received: by 2002:a62:9042:: with SMTP id a63-v6mr30351986pfe.52.1535994180725; Mon, 03 Sep 2018 10:03:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1535994180; cv=none; d=google.com; s=arc-20160816; b=ymA+aVj6Be7/PXlg1DCF7FeCSuPG42S2uTPFICDCZt7Jo2mQTt47nQRAOcL8gQGMtN fx9ukMGUN9Cm00vIEG2ew0t22RegdKJIMm9lSUxJgQDTVjNytAcoUK8YQvIfoN5uM12b HqwbmCoXaxFZSwDVJRVAXy8QrzpPcq2k8VxmAEBH/bcKmo/xANFXD3dbym3M9YlacWNa BI0RDNXc9xgTq8L9H1BH5+NG1Z+t6IwetJh8JRktoDw3WyFQ5siGU2CIJ9Qkd9a0j4Sm 0TzKQOSRuLV32UY9e8plgnBTevvG+/va0Yk1jZs2cH9l0mRtrXEhNuTLzmj9qKI/1it5 Lqsg== 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=vf9uCa16exjWG5TeaCQk6Tnj61ipzpT+cekLSi+7A9o=; b=u5weIzkinPLnjre94olIq6tnxAKHSNGiEW3lrrcxaZoMCFsxV6JabYGWyqZHp3EXso 090exk+ZixVAeTwzp3KtloyS+2rG5ujTXjPBExnVTrvGPoiOsn4t8QSl3CbW2qk3NKZW X5EOl2nCBtErixryayOQEBckiPHid4etzg6qBb1eXbzTKDaIjGxj4vdcp69m6MQINJAI /n51MP3R6wTWg3qemhRMADQMX2l3t0eipSZOB/ABNdZtxFnuExyotFGu7yMql3zl60sE kFLGERbwQHDWk1DJdgJ8H++uWlGGImyx8bJscUeickDtuX1HWcRn+9IVMiYQXR9WIyn0 LDFw== 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 g69-v6si18886181plb.297.2018.09.03.10.02.45; Mon, 03 Sep 2018 10:03:00 -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 S1728663AbeICVWR (ORCPT + 99 others); Mon, 3 Sep 2018 17:22:17 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:38678 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728169AbeICVWR (ORCPT ); Mon, 3 Sep 2018 17:22:17 -0400 Received: from localhost (ip-213-127-74-90.ip.prioritytelecom.net [213.127.74.90]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id 2A4B4CFE; Mon, 3 Sep 2018 17:01:16 +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.4 57/80] fuse: Dont access pipe->buffers without pipe_lock() Date: Mon, 3 Sep 2018 18:49:35 +0200 Message-Id: <20180903164936.429793723@linuxfoundation.org> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20180903164934.171677301@linuxfoundation.org> References: <20180903164934.171677301@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.4-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 @@ -1991,11 +1991,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++)