From: Tuomas Tynkkynen <tuomas@tuxera.com>
To: <linux-fsdevel@vger.kernel.org>
Subject: Weird writev() behaviour on EFAULT - also successfully modifying the file
Date: Thu, 11 Aug 2016 21:46:51 +0300 [thread overview]
Message-ID: <20160811214651.74515950@duuni> (raw)
Greetings,
I've noticed a corner case with writev() both modifying the file and
returning -EFAULT at the same time. This happens on filesystems using
generic_perform_write() (i.e. ext4, vfat) on 4.6.3 kernel and below,
down to 3.16. Here's the reproducer:
// 8<---- cut here ------------------------ >8
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/uio.h>
int main(int argc, char** argv) {
int fd;
ssize_t ret;
struct iovec iov[] = {
{ .iov_base = NULL, .iov_len = 0, },
{ .iov_base = NULL, .iov_len = 4096, },
};
system("dd if=/dev/zero bs=8k count=1 | tr '\\0' 'A' > foo");
fd = open("foo", O_RDWR);
if (fd < 0) {
perror("open()");
return 1;
}
ret = writev(fd, iov, 2);
if (ret < 0) {
perror("writev()");
return 1;
}
return 0;
}
// 8<---- cut here ------------------------ >8
Running that prints "writev(): Bad address" but also some NUL bytes have
appeared at the beginning file, in addition to the 'A's by the dd.
00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
*
00001000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 |AAAAAAAAAAAAAAAA|
*
00002000
Is that intented behaviour?
next reply other threads:[~2016-08-11 18:46 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-11 18:46 Tuomas Tynkkynen [this message]
2016-08-11 22:10 ` Weird writev() behaviour on EFAULT - also successfully modifying the file Al Viro
2016-08-11 22:39 ` Linus Torvalds
2016-08-11 23:03 ` Al Viro
2016-08-11 23:10 ` Linus Torvalds
2016-08-11 23:13 ` Linus Torvalds
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=20160811214651.74515950@duuni \
--to=tuomas@tuxera.com \
--cc=linux-fsdevel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).