From patchwork Mon Jun 12 10:14:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tetsuo Handa X-Patchwork-Id: 9780713 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 4CB7E60244 for ; Mon, 12 Jun 2017 10:16:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F5CD26E51 for ; Mon, 12 Jun 2017 10:16:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 31F25284BF; Mon, 12 Jun 2017 10:16:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C1ACD26E51 for ; Mon, 12 Jun 2017 10:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752441AbdFLKPx (ORCPT ); Mon, 12 Jun 2017 06:15:53 -0400 Received: from www262.sakura.ne.jp ([202.181.97.72]:34314 "EHLO www262.sakura.ne.jp" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752012AbdFLKPw (ORCPT ); Mon, 12 Jun 2017 06:15:52 -0400 Received: from fsav304.sakura.ne.jp (fsav304.sakura.ne.jp [153.120.85.135]) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id v5CAFhH4023068; Mon, 12 Jun 2017 19:15:43 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) Received: from www262.sakura.ne.jp (202.181.97.72) by fsav304.sakura.ne.jp (F-Secure/fsigk_smtp/530/fsav304.sakura.ne.jp); Mon, 12 Jun 2017 19:15:43 +0900 (JST) X-Virus-Status: clean(F-Secure/fsigk_smtp/530/fsav304.sakura.ne.jp) Received: from ccsecurity.localdomain (softbank126227147111.bbtec.net [126.227.147.111]) (authenticated bits=0) by www262.sakura.ne.jp (8.14.5/8.14.5) with ESMTP id v5CAFcFk023034 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Mon, 12 Jun 2017 19:15:43 +0900 (JST) (envelope-from penguin-kernel@I-love.SAKURA.ne.jp) From: Tetsuo Handa To: Alexander Viro , Andrew Morton Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Tetsuo Handa Subject: [PATCH] sendfile: Do not update file offset of non-lseek()able objects. Date: Mon, 12 Jun 2017 19:14:29 +0900 Message-Id: <1497262469-7536-1-git-send-email-penguin-kernel@I-love.SAKURA.ne.jp> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <201705181956.EFD60931.HFOMOVJFQFOtLS@I-love.SAKURA.ne.jp> References: <201705181956.EFD60931.HFOMOVJFQFOtLS@I-love.SAKURA.ne.jp> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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