From: "Thomas Weißschuh" <thomas@t-8ch.de>
To: linux-fsdevel@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, linux-api@vger.kernel.org,
linux-nfs@vger.kernel.org, thomas.weissschuh@amadeus.com
Subject: O_LARGEFILE / EOVERFLOW on tmpfs / NFS
Date: Tue, 20 Sep 2022 12:33:31 +0200 [thread overview]
Message-ID: <76bedae6-22ea-4abc-8c06-b424ceb39217@t-8ch.de> (raw)
[-- Attachment #1: Type: text/plain, Size: 1082 bytes --]
Hi everybody,
it seems there is some inconsistency about how large files that are opened
*without* O_LARGEFILE on different filesystems.
On ext4/btrfs/xfs a large file openend without O_LARGEFILE results in an
EOVERFLOW error to be reported (as documented by open(2) and open(3p)).
On tmpfs/NFS the file is opened successfully but the values returned for
lseek() are bogus.
(See the reproducer attached to this mail.)
This has been reproduced on 5.19.8 but the sources look the same on current
torvalds/master.
Is this intentional? To me it seems this should fail with EOVERFLOW everywhere.
Looking at the sources, the O_LARGEFILE flag is checked in generic_file_open()
but not all filesystems call this function.
If this is a bug would it make sense to hoist this check into the VFS layer so
not all filesystems have to call this manually?
Another question would be about backwards-compatibility becaus fixing it would
prevent applications from opening files they could open before.
On the other hand they could have experienced silent data corruption before.
Thanks,
Thomas
[-- Attachment #2: test.c --]
[-- Type: text/plain, Size: 774 bytes --]
/*
* Compile:
* cc -m32 test.c -o test
*
* Prepare testfile:
* fallocate -l 4294967297 large-file
*
* Test:
* ./test large-file
*
* Result:
* Correct: open() fails, exit code 2
* Incorrect: Prints an incorrect file size
*
* Observation:
* Correct on ext4/btrfs
* Incorrect on NFS/tmpfs
*/
#include <assert.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdio.h>
static_assert(sizeof(void *) == 4, "This test only makes sense on 32bit");
static_assert(sizeof(off_t) == 4, "Large file support has to be disabled");
int main(int argc, char **argv)
{
if (argc != 2)
return 1;
int fd = open(argv[1], O_RDONLY);
if (fd == -1)
return 2;
off_t fsize = lseek(fd, 0, SEEK_END);
printf("file size=%lu\n", fsize);
}
reply other threads:[~2022-09-20 11:12 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=76bedae6-22ea-4abc-8c06-b424ceb39217@t-8ch.de \
--to=thomas@t-8ch.de \
--cc=linux-api@vger.kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nfs@vger.kernel.org \
--cc=thomas.weissschuh@amadeus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®