From: "Paweł Jasiak" <pawel@jasiak.xyz>
To: Matthew Wilcox <willy@infradead.org>
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
jack@suse.cz
Subject: Re: PROBLEM: fanotify_mark EFAULT on x86
Date: Sun, 1 Nov 2020 23:27:59 +0100 [thread overview]
Message-ID: <20201101222759.GA25654@gmail.com> (raw)
In-Reply-To: <20201101213845.GH27442@casper.infradead.org>
[-- Attachment #1: Type: text/plain, Size: 1986 bytes --]
On 01/11/20, Matthew Wilcox wrote:
> On Sun, Nov 01, 2020 at 10:27:38PM +0100, Paweł Jasiak wrote:
> > I am trying to run examples from man fanotify.7 but fanotify_mark always
> > fail with errno = EFAULT.
> >
> > fanotify_mark declaration is
> >
> > SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags,
> > __u64, mask, int, dfd,
> > const char __user *, pathname)
>
> Don't worry about that. You aren't calling the SYSCALL, you're calling
> glibc and glibc is turning it into a syscall.
>
> extern int fanotify_mark (int __fanotify_fd, unsigned int __flags,
> uint64_t __mask, int __dfd, const char *__pathname)
>
> > When
> >
> > fanotify_mark(4, FAN_MARK_ADD | FAN_MARK_ONLYDIR,
> > FAN_CREATE | FAN_ONDIR, AT_FDCWD, 0xdeadc0de)
>
> The last argument is supposed to be a pointer to a string. I'm guessing
> there's no string at 0xdeadc0de.
You are right but it's not a problem. 0xdeadc0de is just a _well
known_ address here only for debug purpose.
pathname inside kernel should be a pointer to string located in
user space at 0xdeadc0de but it is equal to 0xffffff9c which is
AT_FDCWD.
If you call
fanotify_mark(fd, FAN_MARK_ADD | FAN_MARK_ONLYDIR, FAN_CREATE |
FAN_ONDIR, AT_FDCWD, argv[1]);
from example with *valid* pointer at argv[1] you still get EFAULT
because pathname is equal to AT_FDCWD in kernel space -- last argument
is not used.
In my example in user space we have
fanotify_fd = 4
flags = 0x9
mask = 0x40000100
dfd = 0xffffff9c
pathname = 0xdeadc0de
and in kernel space we have
fanotify_fd = 4
flags = 0x9
mask = 0x40000100
dfd = 0
pathname = 0xffffff9c
So all arguments after __u64 mask are shifted by one.
It looks similar to https://lists.linux.it/pipermail/ltp/2020-June/017436.html
--
Paweł Jasiak
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2020-11-01 22:28 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-01 21:27 PROBLEM: fanotify_mark EFAULT on x86 Paweł Jasiak
2020-11-01 21:38 ` Matthew Wilcox
2020-11-01 22:27 ` Paweł Jasiak [this message]
2020-11-02 12:26 ` Jan Kara
2020-11-02 17:16 ` Paweł Jasiak
2020-11-03 21:17 ` Paweł Jasiak
2020-11-04 10:14 ` Jan Kara
2020-11-23 16:46 ` Jan Kara
2020-11-23 22:46 ` Paweł Jasiak
2020-11-24 8:45 ` Borislav Petkov
2020-11-24 10:20 ` Jan Kara
2020-11-24 10:28 ` Borislav Petkov
2020-11-26 10:48 ` Jan Kara
2020-11-26 10:52 ` Borislav Petkov
2020-11-25 19:31 ` Naresh Kamboju
2020-11-26 10:48 ` Jan Kara
2020-11-23 23:07 ` [PATCH] fanotify: Fix fanotify_mark() on 32-bit archs kernel test robot
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=20201101222759.GA25654@gmail.com \
--to=pawel@jasiak.xyz \
--cc=jack@suse.cz \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=willy@infradead.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).