Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp7059566ybi; Thu, 13 Jun 2019 08:54:18 -0700 (PDT) X-Google-Smtp-Source: APXvYqzrs1JjPtZSczuIfg1AxWckXM1vjUuQAQEK54pgAqLqNfclFyUFzZw6oMslaVck3QMdOQ9B X-Received: by 2002:a65:638a:: with SMTP id h10mr579400pgv.64.1560441257985; Thu, 13 Jun 2019 08:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560441257; cv=none; d=google.com; s=arc-20160816; b=Q74MVWSMDIDgccRMpHK5TsB0a/4V4Qz9K9+1fYB0y0b8oRTn7iQ8mXP7p/j/5xiEFX AvyTkUY3YWWnyFw3f9bNLgIEgutBSoKJKtVjOQCw2Oi/Wj0A63mXPFDio+6Sgyl6NeOi iA4wd3x807PfZzZDcm81uaFqdU8LlFgipsLHmlRnVnr/AfGRX/ovmfytkCCiBMD8/DnO T24Ba1CPJwTvN//edFoE4RWjBUXnkzFNsVrKnp23AvcS8W967HoDu88DDNn9GqKviwRL C01YaRSjabphRhOQvyRLgwIXwVFJUWMHed6/v2XoPBIjhb87W2tMSsil0deYkGDFj24R etkw== 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=M4aDfA1w4ZF6nIskixPuSNaOwkaByvQre2/9Y4kB6LE=; b=aQYlswwd/6KVnlVU+ekeadMvCU27iz5Q2+nn9z+ux6SNJ0nedmhZ1JOyjrWWg62V3t yjL1ooAkK37ZHxD7IR11QdQ+CrO9QYi85JVA+l6x3IrNVR4TLr5TUl27avc+ckWDsdso 3ssdjtZY/HxEwwZgY2+RfdHIMZDeRsa1h9qvxxj85B1Mlm02Mvpqgb36LCRfscnL5Y+p TdB54fMyEap8vTuehninPMo7Nz6wFA+H+5x3rZ6QEYpBZG0FLiOJnUhTa0nz3u16g/9a Y7TuzXN8ea0buS/E37PSLTARGVfoNibC0IENCF2ZOuDWQ4tlgd8WRtHacZC5Kyh18xGn H/Ng== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c15si68760pgm.421.2019.06.13.08.54.03; Thu, 13 Jun 2019 08:54:17 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=virtuozzo.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389977AbfFMPw0 (ORCPT + 99 others); Thu, 13 Jun 2019 11:52:26 -0400 Received: from relay.sw.ru ([185.231.240.75]:35994 "EHLO relay.sw.ru" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731641AbfFMJKM (ORCPT ); Thu, 13 Jun 2019 05:10:12 -0400 Received: from [172.16.25.12] by relay.sw.ru with esmtp (Exim 4.92) (envelope-from ) id 1hbLkG-0008MK-5e; Thu, 13 Jun 2019 12:10:08 +0300 Subject: Re: [PATCH v2 1/3] fs/fuse, splice_write: Don't access pipe->buffers without pipe_lock() To: Vlastimil Babka , 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: Andrey Ryabinin Message-ID: <3fcf7f4f-a9c0-f9c8-f526-ab12e283cd43@virtuozzo.com> Date: Thu, 13 Jun 2019 12:10:19 +0300 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: 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 6/12/19 11:57 AM, Vlastimil Babka wrote: > 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()? > do_splice() already takes the pipe_lock() before calling ->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++) >> >