From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by kanga.kvack.org (Postfix) with ESMTP id 6DD4A6B2D02 for ; Thu, 22 Nov 2018 14:58:19 -0500 (EST) Received: by mail-pl1-f199.google.com with SMTP id 4so14575431plc.5 for ; Thu, 22 Nov 2018 11:58:19 -0800 (PST) Received: from mail.kernel.org (mail.kernel.org. [198.145.29.99]) by mx.google.com with ESMTPS id n67si17352056pfk.34.2018.11.22.11.58.18 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 22 Nov 2018 11:58:18 -0800 (PST) From: Sasha Levin Subject: [PATCH AUTOSEL 3.18 7/7] tmpfs: make lseek(SEEK_DATA/SEK_HOLE) return ENXIO with a negative offset Date: Thu, 22 Nov 2018 14:57:49 -0500 Message-Id: <20181122195749.14086-7-sashal@kernel.org> In-Reply-To: <20181122195749.14086-1-sashal@kernel.org> References: <20181122195749.14086-1-sashal@kernel.org> Sender: owner-linux-mm@kvack.org List-ID: To: stable@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Yufen Yu , Al Viro , Hugh Dickins , William Kucharski , Andrew Morton , Linus Torvalds , Sasha Levin , linux-mm@kvack.org From: Yufen Yu [ Upstream commit 1a413646931cb14442065cfc17561e50f5b5bb44 ] Other filesystems such as ext4, f2fs and ubifs all return ENXIO when lseek (SEEK_DATA or SEEK_HOLE) requests a negative offset. man 2 lseek says : EINVAL whence is not valid. Or: the resulting file offset would be : negative, or beyond the end of a seekable device. : : ENXIO whence is SEEK_DATA or SEEK_HOLE, and the file offset is beyond : the end of the file. Make tmpfs return ENXIO under these circumstances as well. After this, tmpfs also passes xfstests's generic/448. [akpm@linux-foundation.org: rewrite changelog] Link: http://lkml.kernel.org/r/1540434176-14349-1-git-send-email-yuyufen@huawei.com Signed-off-by: Yufen Yu Reviewed-by: Andrew Morton Cc: Al Viro Cc: Hugh Dickins Cc: William Kucharski Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Sasha Levin --- mm/shmem.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/mm/shmem.c b/mm/shmem.c index 371d5eca80ed..64c33e3dbe69 100644 --- a/mm/shmem.c +++ b/mm/shmem.c @@ -1805,9 +1805,7 @@ static loff_t shmem_file_llseek(struct file *file, loff_t offset, int whence) mutex_lock(&inode->i_mutex); /* We're holding i_mutex so we can access i_size directly */ - if (offset < 0) - offset = -EINVAL; - else if (offset >= inode->i_size) + if (offset < 0 || offset >= inode->i_size) offset = -ENXIO; else { start = offset >> PAGE_CACHE_SHIFT; -- 2.17.1