From patchwork Wed Jul 18 11:04:26 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chengguang Xu X-Patchwork-Id: 10532163 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 77E536020A for ; Wed, 18 Jul 2018 11:05:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6B2C02909D for ; Wed, 18 Jul 2018 11:05:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5F8722909F; Wed, 18 Jul 2018 11:05:36 +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=-7.9 required=2.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham 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 0B67F290A3 for ; Wed, 18 Jul 2018 11:05:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730151AbeGRLm4 (ORCPT ); Wed, 18 Jul 2018 07:42:56 -0400 Received: from mout.gmx.net ([212.227.15.19]:53057 "EHLO mout.gmx.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729233AbeGRLm4 (ORCPT ); Wed, 18 Jul 2018 07:42:56 -0400 Received: from localhost.localdomain ([220.112.58.66]) by mail.gmx.com (mrgmx001 [212.227.17.184]) with ESMTPSA (Nemesis) id 0MPUZ7-1fjr0C0w4n-004oKr; Wed, 18 Jul 2018 13:05:30 +0200 From: Chengguang Xu To: ceph-devel@vger.kernel.org Cc: zyan@redhat.com, idryomov@gmail.com, Chengguang Xu Subject: [PATCH 4/5] ceph: add additional offset check in ceph_read_iter() Date: Wed, 18 Jul 2018 19:04:26 +0800 Message-Id: <20180718110427.7775-5-cgxu519@gmx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180718110427.7775-1-cgxu519@gmx.com> References: <20180718110427.7775-1-cgxu519@gmx.com> X-Provags-ID: V03:K1:z7D035imPvHxAYHaGl/v4IksKoLR0y2nv17T506Ie+FJTE1gVQY H9x3wHOsUMdhf60pERVryiFwMFpBrJ3DSveE0gwws3vtv61WQGUKwKnhYz1BVliwcgkemts 8qeDP5HymosbwBmTxeXJ8QwTpwfmotbW38qczy5SJtlRFlqRhHn/qUMgx2gS27RsjdnR4bD hZGQLYxEW41OrONPhF5fQ== X-UI-Out-Filterresults: notjunk:1; V01:K0:h4ohNLiO6Qw=:LfjXT83u1xlcQjV4haM8cv /b4decEjlAOKm7kf+wZpcozY0QtSNW7l9uSvnUwXp12wFpTYimxj9Fcs1ywtP+WAOA8RTdKrK q2azPs/pUBN0txsgkArXRfcubkUF7w0r+azxIT9F8VrobtDIHnHr6ChnVqo5o+jdtu5hZqRsz dYDWKvQwPoQR9bX8wXu0unMSb9S9OvGUWwD5pZlANfIteW/pgkBAIOxgJJw2x4PAdW+c31Zq/ SLx0HeHJz4dqgQWwqhknGaopu2d4q7qlFWawzXtngw02UbVu18Z/7gyb5UKoYWSSNUzg8uBQC 7nilI1OlfXTvqIUNOeuD+4iA0fGStIhF4CpZ1RBN1G5I6FN+2rYT/LMxPoecbFkbkhLlYwVZ0 A/zF5fHdf7VwKIoZI9NLS4psbRRw+9sbb053dwIJ97qDK9Dx3UpJogBs0CM7sOtzkLyclM1tE LEtn1fe/ckfGDeOcdVqavQjLn92cEGRPU8Ot3a/4jwec8D48auyb0y+dMn4L1S0NIBlqfvb1C TMD2lhNc4fneQYLhpVTUoA9IIx8N1oBhYEQoO7ga5xSOjWgaCORt47cIQycHgJ3R10pJOePBI ehu0E7lyzSDuAEGiEQqEvaTqZUKHbx/U7z//+qaZTx/ofsQtbzlNSQeE9YAJbttM6/l/Iofe0 l7vTVfJFIpIwyyASh1NMuvuo39VahYAcRe8zoRNv76GnnLLLMAUyMoB3mk1rxR7CwF3x10zto LSDUouhXUFNBaf7LG6FKl/KqGlNhWItbeuh86I75x8XjQKz4AK5VWiEzFg4= Sender: ceph-devel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: ceph-devel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP if the offset is larger or equal to both real file size and max file size, then do nothing. Signed-off-by: Chengguang Xu --- fs/ceph/file.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/fs/ceph/file.c b/fs/ceph/file.c index 7a01fe627bd7..23b30cf8caf4 100644 --- a/fs/ceph/file.c +++ b/fs/ceph/file.c @@ -1248,9 +1248,12 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) struct inode *inode = file_inode(filp); struct ceph_inode_info *ci = ceph_inode(inode); struct page *pinned_page = NULL; + struct ceph_fs_client *fsc = inode->i_sb->s_fs_info; ssize_t ret; int want, got = 0; int retry_op = 0, read = 0; + loff_t limit = max(i_size_read(inode), fsc->max_file_size); + loff_t pos = iocb->ki_pos; again: dout("aio_read %p %llx.%llx %llu~%u trying to get caps on %p\n", @@ -1285,13 +1288,18 @@ static ssize_t ceph_read_iter(struct kiocb *iocb, struct iov_iter *to) retry_op = READ_INLINE; } } else { - CEPH_DEFINE_RW_CONTEXT(rw_ctx, got); - dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", - inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, - ceph_cap_string(got)); - ceph_add_rw_context(fi, &rw_ctx); - ret = generic_file_read_iter(iocb, to); - ceph_del_rw_context(fi, &rw_ctx); + if (unlikely(pos >= limit)) { + ret = 0; + } else { + CEPH_DEFINE_RW_CONTEXT(rw_ctx, got); + iov_iter_truncate(to, limit - pos); + dout("aio_read %p %llx.%llx %llu~%u got cap refs on %s\n", + inode, ceph_vinop(inode), iocb->ki_pos, (unsigned)len, + ceph_cap_string(got)); + ceph_add_rw_context(fi, &rw_ctx); + ret = generic_file_read_iter(iocb, to); + ceph_del_rw_context(fi, &rw_ctx); + } } dout("aio_read %p %llx.%llx dropping cap refs on %s = %d\n", inode, ceph_vinop(inode), ceph_cap_string(got), (int)ret);