Path: csiph.com!weretis.net!feeder4.news.weretis.net!news.unit0.net!news.panservice.it!diesel.cu.mi.it!bofh.it!news.nic.it!robomod From: Tetsuo Handa Newsgroups: linux.kernel Subject: [PATCH] sendfile: Do not update file offset of non-lseek()able objects. Date: Mon, 12 Jun 2017 12:20:02 +0200 Message-ID: References: X-Original-To: Alexander Viro , Andrew Morton X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav304.sakura.ne.jp) X-Mailer: git-send-email 1.8.3.1 Sender: robomod@news.nic.it List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Approved: robomod@news.nic.it Lines: 29 Organization: linux.* mail to news gateway X-Original-Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Tetsuo Handa X-Original-Date: Mon, 12 Jun 2017 19:14:29 +0900 X-Original-Message-ID: <1497262469-7536-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Original-References: <201705181956.EFD60931.HFOMOVJFQFOtLS@I-love.SAKURA.ne.jp> X-Original-Sender: linux-kernel-owner@vger.kernel.org Xref: csiph.com linux.kernel:1663399 I tried to sendfile() a file which is larger than 4GB to a pipe (which is the stdout of Apache's CGI program), and noticed that sendfile() fails with EFBIG after 2GB is copied to stdout pipe. This is because sendfile() is updating file offset of the file descriptor of the pipe. sendfile() should not update file offset if the file descriptor refers to an non-lseek()able object. Signed-off-by: Tetsuo Handa --- fs/read_write.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/fs/read_write.c b/fs/read_write.c index 47c1d44..17ea13c 100644 --- a/fs/read_write.c +++ b/fs/read_write.c @@ -1459,7 +1459,8 @@ static ssize_t do_sendfile(int out_fd, int in_fd, loff_t *ppos, add_wchar(current, retval); fsnotify_access(in.file); fsnotify_modify(out.file); - out.file->f_pos = out_pos; + if (out.file->f_op->llseek != no_llseek) + out.file->f_pos = out_pos; if (ppos) *ppos = pos; else -- 1.8.3.1