Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5430757ybi; Wed, 12 Jun 2019 02:20:33 -0700 (PDT) X-Google-Smtp-Source: APXvYqx2H5AUdt2bka3cfjT9ioIjG7Kl795/6Qgdfq6rbUwsiC2pIxN1ssZ3VdLUMWyX97o9g7AX X-Received: by 2002:a62:6844:: with SMTP id d65mr85926909pfc.175.1560331232872; Wed, 12 Jun 2019 02:20:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560331232; cv=none; d=google.com; s=arc-20160816; b=fdznV1Gs3QV08Tod0PK1Q1Ojrih3lsb7jJcIKN4CNHMxV/kWUNHY0B0dHUK6y5FS9g /TtkZCC1lC+OsT+ZTUsNRude1PHxLBQs/MOGl7VkSEJykw3kS1sDSGK20IwbhIRRiS+y uld7QtK+VwnPmdzg4UgqrzCTACAOyH1MJjkBckQTvNahQpxl9s9c2VpwANls6E4HQnCU H9MhlhAngsSEGGnbxGS4gB3LHKiQN7vNP5bIpNSuyKO5qTQnoOxBXlWjpcXvEXd7ey3Y +Z68kaGCnABWn8J4OJ3x/cdkOziYSEXxBSCAq+pVPCNBKnqDTI1kfvq/kV3zF7x9nq7k iJcg== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=zS6D9CQ6lhFjerE3i6F9F6wS5Mu2B/udYpyzI1m2DKk=; b=wMuqPk8XOesdqsnYoyhsh/xuDPJeT0GimjaBZtAomDTS1LPDAzQQkhQeMWi9XqOAPV NSV4QKwdZYgnKSu8NPGzrhsl4sp0mhcWDtszJdXuYryXRfj8/mAy3j87gr5TXmFZf++S xF6whG+0wNbkHFPy+KiKEtwFbPGF9u+slpLXuSxTg4yyjV5wkor8j2UkZYR0w18FwJj7 hKLtbZikp+rV2+g0Lbf5MZDMQpgOKdM/KNMwPyUMcrqZFYvJfhhANFFe9tRPg2/fTkOS 3TkragWPDoMx6iitUfNO+ku4vq6JVcaFuAp7usKVLtv4Wm8BA/IdsEaUzQg3IserLgA3 NVjw== 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 k33si15535017pld.359.2019.06.12.02.20.17; Wed, 12 Jun 2019 02:20:32 -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 S1731658AbfFLI5i (ORCPT + 99 others); Wed, 12 Jun 2019 04:57:38 -0400 Received: from mx2.suse.de ([195.135.220.15]:51982 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726286AbfFLI5i (ORCPT ); Wed, 12 Jun 2019 04:57:38 -0400 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 0BB60AF49; Wed, 12 Jun 2019 08:57:37 +0000 (UTC) Subject: Re: [PATCH v2 1/3] fs/fuse, splice_write: Don't access pipe->buffers without pipe_lock() To: Andrey Ryabinin , Miklos Szeredi Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20180717160035.9422-1-aryabinin@virtuozzo.com> From: Vlastimil Babka Message-ID: Date: Wed, 12 Jun 2019 10:57:35 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: <20180717160035.9422-1-aryabinin@virtuozzo.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 7/17/18 6:00 PM, Andrey Ryabinin wrote: > 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: BTW, why don't we need to do the same in fuse_dev_splice_read()? Thanks, Vlastimil > --- > fs/fuse/dev.c | 7 +++++-- > 1 file changed, 5 insertions(+), 2 deletions(-) > > diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c > index c6b88fa85e2e..702592cce546 100644 > --- a/fs/fuse/dev.c > +++ b/fs/fuse/dev.c > @@ -1944,12 +1944,15 @@ static ssize_t fuse_dev_splice_write(struct pipe_inode_info *pipe, > 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++) >