Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3066741imu; Sun, 9 Dec 2018 16:30:47 -0800 (PST) X-Google-Smtp-Source: AFSGD/V/61SWOZuiaMOV484OEi8PD/h18FNw1c+FDj8VnYdDkG7szf5IRLEtRNHJeq6CLX6X+Yyx X-Received: by 2002:a63:f412:: with SMTP id g18mr9198771pgi.262.1544401847191; Sun, 09 Dec 2018 16:30:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544401847; cv=none; d=google.com; s=arc-20160816; b=WH/rCS6ynJ0beMsNn/hPWSMeGRwSgJlXau0CwgjpN0+9uRzOMPCypcW/ugFzzuFEfM 6PWaXDufYcCCCtL7qh7CKrBwHxwg/bm9WkjSnwo2/wrPz0p2bKa3SMQlWPWURL7S0QVH x/oRs+mNZ90/gXeHz1q9wmsLrZUxL626le9sBnLI4TbFA9fl1Jnaz3jDbXWuH7XLkZaY WuIXObHaKKFm0K3wvzkBNGpuOJoQPHBYQ08Pr4oXQqEN2JWFI1kAEDP7aheudEsxkLO+ Wj4yv1j0aACjxGGKqMpfDnAcYh9i4+vz2cnGxjhpCxUzcEZY5Ky6TB5lrGPQSfzy/HvJ rfhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:subject:message-id:date:cc:to :from:mime-version:content-transfer-encoding:content-disposition; bh=W+hC2mqtizofBSx4OYRO2ChXLTSzWZD30xGXu1DvXSo=; b=cblk9GXzfAn/O0zNJ+ha3CcuxobvlEOjfiqB5QfRcBUwz1tMYU7WtvBNS8x1dUoJqA WHvzPypVUDEAZ85hmf5izSaIdFtcS++29HRpZVe442oopEI+GHigCxVTpotyE5lmRuyX 4ZfL3gVJ5BFeAcNpbOthn7KEnW/mFzhV4pRKa/BYM/PKVpweuDum9IatmgM0rwmOWzQo HE6x4tZkPlhMP5puIGReRXhPnGsqRLXt4oTltax9YBiQQGFlmH7fJYh/j5KCMAiw4km8 0lR6p/TQ/38FG5dvm4suWsFjoRGyNKduvjlRvdg4+nGRK0/GGtVPTzFAGaRa3pSrlH0x fYaw== 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 t4si9417184pfj.183.2018.12.09.16.30.31; Sun, 09 Dec 2018 16:30:47 -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; 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 S1727961AbeLIWLx (ORCPT + 99 others); Sun, 9 Dec 2018 17:11:53 -0500 Received: from shadbolt.e.decadent.org.uk ([88.96.1.126]:37732 "EHLO shadbolt.e.decadent.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727603AbeLIWLv (ORCPT ); Sun, 9 Dec 2018 17:11:51 -0500 Received: from pub.yeoldevic.com ([81.174.156.145] helo=deadeye) by shadbolt.decadent.org.uk with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gW73L-0002il-Gn; Sun, 09 Dec 2018 21:55:55 +0000 Received: from ben by deadeye with local (Exim 4.91) (envelope-from ) id 1gW72a-0003I4-PE; Sun, 09 Dec 2018 21:55:08 +0000 Content-Type: text/plain; charset="UTF-8" Content-Disposition: inline Content-Transfer-Encoding: 8bit MIME-Version: 1.0 From: Ben Hutchings To: linux-kernel@vger.kernel.org, stable@vger.kernel.org CC: akpm@linux-foundation.org, "Andrey Ryabinin" , "Miklos Szeredi" Date: Sun, 09 Dec 2018 21:50:33 +0000 Message-ID: X-Mailer: LinuxStableQueue (scripts by bwh) X-Patchwork-Hint: ignore Subject: [PATCH 3.16 074/328] fuse: Don't access pipe->buffers without pipe_lock() In-Reply-To: X-SA-Exim-Connect-IP: 81.174.156.145 X-SA-Exim-Mail-From: ben@decadent.org.uk X-SA-Exim-Scanned: No (on shadbolt.decadent.org.uk); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 3.16.62-rc1 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 Signed-off-by: Miklos Szeredi [bwh: Backported to 3.16: adjust context] Signed-off-by: Ben Hutchings --- fs/fuse/dev.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) --- a/fs/fuse/dev.c +++ b/fs/fuse/dev.c @@ -1913,11 +1913,14 @@ static ssize_t fuse_dev_splice_write(str if (!fc) 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++)