Received: by 2002:a05:6a10:9e8c:0:0:0:0 with SMTP id y12csp2898227pxx; Sun, 1 Nov 2020 14:32:05 -0800 (PST) X-Google-Smtp-Source: ABdhPJwyugiEB10wxHG1UW8w99rtFHwm7ZODMVwBzRIU2t/tkG/mUG9NyKwJteJ3K6h1TxWvfPBd X-Received: by 2002:a17:906:c0c9:: with SMTP id bn9mr12447903ejb.289.1604269925469; Sun, 01 Nov 2020 14:32:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604269925; cv=none; d=google.com; s=arc-20160816; b=Ha3YHYVq7kJjLTNb1A/ig3+yXYyiDUj66YVdiKSROeE7oWjgssea7rb8ePt4rG9wSw 3FGXJoJyfFNjC60iq7RgVSsNn/1Oqboc3xdD+KZiIKr+H8Jn7dUr5WQD5xWeBRTGeFWC hOmQLDwYDYczsipaKzpc+RknJeky8gdycIRPoXk17haGtgyOT3q+dmLPujqw7uSM4hso 32Pa18V7n1zuIcxOXutH9c3QdyTw+qgDt6krSONgM/GAseZ3HomZAgKUpPNqrxd/JEdh Xqixdt00PTcWVKXkNb8XmeMrp2cb6/h8rZ5bE+0M8Mx+KhjBO5Mi/rRybjf8KiGfXd+B 7+Zg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=DMTV4qSTXxTsyRh79hlPaHDlwv+MDWJQbcfZIs8RYf0=; b=VqO7n3UV5hH3JQamAPWm3AEMQTV5nRiJON6dpg9gJ43yPRNg5zVGXXQom/l0DPmVtE 6+iiqHK5PUAOP2K0oZLLwOXV1ak8XmzIVVb2wDUEjY5lRziEk5ewSKsasSb/JoxD1/lO 4PRAjlWfxQctUWK6+AxS4cY11pgWaZEnVtB9SfpImxzZInadUg5WGIRz5S0gw3X+Ah2h 0dR4NfSWKW0k5cIHn/czPVeN6Z7qM28o0DEWN031e4CU9eUm0PGqvKhgZJxnfNRy+zc6 vKOHP4E5PSlNAAHMckH5NMFOXQ81AyImXVWJQRu7KZVkkI2/T4Lh52+XfoFRuOn3lGo7 NIgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@jasiak-xyz.20150623.gappssmtp.com header.s=20150623 header.b=gBvoLkPk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k14si935173edq.576.2020.11.01.14.31.43; Sun, 01 Nov 2020 14:32:05 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@jasiak-xyz.20150623.gappssmtp.com header.s=20150623 header.b=gBvoLkPk; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727081AbgKAW2L (ORCPT + 99 others); Sun, 1 Nov 2020 17:28:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727197AbgKAW2K (ORCPT ); Sun, 1 Nov 2020 17:28:10 -0500 Received: from mail-lj1-x241.google.com (mail-lj1-x241.google.com [IPv6:2a00:1450:4864:20::241]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 97835C061A04 for ; Sun, 1 Nov 2020 14:28:03 -0800 (PST) Received: by mail-lj1-x241.google.com with SMTP id i2so12956163ljg.4 for ; Sun, 01 Nov 2020 14:28:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jasiak-xyz.20150623.gappssmtp.com; s=20150623; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DMTV4qSTXxTsyRh79hlPaHDlwv+MDWJQbcfZIs8RYf0=; b=gBvoLkPk3+d2TToeRJtqTKN5julOkqomoTGzRtGzRlNOENsQr7sU4EVV0o2ClIyz+w Z2l+6ag18lKZMXY1whrSCc/fFubFsgQQGYqS+/elAH8IyRqUzQPzbbiJtIAaX3K9i0bN GhugijmGKZ5HbgDpIh0UIaufZIdPIiN23WiI4Aop0KvS5g/JfreWUjHdkHf/cnevtQNK YSqjDmJT9uFqLN5VF+lLk99TYIN/pX8c7ZEEYLiCVYYnTbDwDeUEckHN7sdJ/Af647tx 8Nq0T5ISO9AtmlRuSStMc0PoUETxHlX+3ZwjyMPxU7Y3+8FH/gfJhYlwgLnyz/N2rA9Q UFJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DMTV4qSTXxTsyRh79hlPaHDlwv+MDWJQbcfZIs8RYf0=; b=fmSVRvjfYvxDcU3l9l6Nd93SKbf/sxYyjbzvc+siTRUO5UVUjRjUm0RcWbglvIdpnr DbgLyXhU8ki409i/mWzaDHXyQaxNo0+LrR87AZBg5zmpEK1ZC+TT5euAjNWWyzaoQnaU 390m6AJxt406jKyAxnxLlUENjj2vvwwhZQiP+GNbsbrmVbU8XqRm4PrtadVSG6Qv1hbs jgHS6Rd4PTBuXnIpedWHYXHhBE5Tl2qi1/4IMpgkYNGHvbexyWtNtoIP+rSa5euOy6Cz 0r8/ClWSFKY5hfM52di7L8K03ElVQe9YqI8EV3hpfW2gyXLRi5qT3yTB3lq3NZ7rFb8N rk1w== X-Gm-Message-State: AOAM530HYoH3fqTsq5WStXJ+qN0kUdASzVQdT+eVMhQRgKP4MLuXnRqI ou+1tOoQNCqL6NmM3uas+r8NEd2VP/mrfW4H X-Received: by 2002:a2e:9b58:: with SMTP id o24mr4878374ljj.94.1604269682141; Sun, 01 Nov 2020 14:28:02 -0800 (PST) Received: from gmail.com (wireless-nat-78.ip4.greenlan.pl. [185.56.211.78]) by smtp.gmail.com with ESMTPSA id z26sm1999353ljm.121.2020.11.01.14.28.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 01 Nov 2020 14:28:01 -0800 (PST) Date: Sun, 1 Nov 2020 23:27:59 +0100 From: =?utf-8?B?UGF3ZcWC?= Jasiak To: Matthew Wilcox Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, jack@suse.cz Subject: Re: PROBLEM: fanotify_mark EFAULT on x86 Message-ID: <20201101222759.GA25654@gmail.com> References: <20201101212738.GA16924@gmail.com> <20201101213845.GH27442@casper.infradead.org> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha512; protocol="application/pgp-signature"; boundary="BXVAT5kNtrzKuDFl" Content-Disposition: inline In-Reply-To: <20201101213845.GH27442@casper.infradead.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --BXVAT5kNtrzKuDFl Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 01/11/20, Matthew Wilcox wrote: > On Sun, Nov 01, 2020 at 10:27:38PM +0100, Pawe=C5=82 Jasiak wrote: > > I am trying to run examples from man fanotify.7 but fanotify_mark always > > fail with errno =3D EFAULT. > >=20 > > fanotify_mark declaration is > >=20 > > SYSCALL_DEFINE5(fanotify_mark, int, fanotify_fd, unsigned int, flags, > > __u64, mask, int, dfd, > > const char __user *, pathname) >=20 > Don't worry about that. You aren't calling the SYSCALL, you're calling > glibc and glibc is turning it into a syscall. >=20 > extern int fanotify_mark (int __fanotify_fd, unsigned int __flags, > uint64_t __mask, int __dfd, const char *__pathn= ame) >=20 > > When=20 > >=20 > > fanotify_mark(4, FAN_MARK_ADD | FAN_MARK_ONLYDIR, > > FAN_CREATE | FAN_ONDIR, AT_FDCWD, 0xdeadc0de) >=20 > 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]); =66rom 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 =3D 4 flags =3D 0x9 mask =3D 0x40000100 dfd =3D 0xffffff9c pathname =3D 0xdeadc0de and in kernel space we have fanotify_fd =3D 4 flags =3D 0x9 mask =3D 0x40000100 dfd =3D 0 pathname =3D 0xffffff9c So all arguments after __u64 mask are shifted by one. It looks similar to https://lists.linux.it/pipermail/ltp/2020-June/017436.h= tml --=20 Pawe=C5=82 Jasiak --BXVAT5kNtrzKuDFl Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAABCgAdFiEENIqkLxDcCMlLMdi0FzfmQudzVTgFAl+fNmwACgkQFzfmQudz VTjRZhAA4fB7nZEsrAZKgFmixIZd5ROhKQIcstuQhSmfyve0iAWRyOS7XzxtNG98 u2qsUkddRorMb2RCp/Tns6zGrUsFQCv+Yy74Td/w91r/GjCHCDdVCq4bU9q1tlsj DGKLCYLVxzFr5h41/xn3TJ9FSMwZI4y+b08FcUKNdclA/jzT1RTzoNPo1q4iSTlI baF4Hx/kalIM7F7qV2zGgXnhTd45uDMJv8UAUN1Ky7h6wHCjZ/DzcBbn1WWGWmyw zJYSybXbAUhBj8VJUHuuubB9zDUWAcohBQ2JmwjxawIgDHmgJ3FLqNx3hkoY8WC6 G7f4gTZbqR7vWbgSEHsM9lg6vVH4VOSaSxvtwJOlB80wc6fTBi/cC/PyUBIP/KDI 8wl7003QMJI4UcrbojE+0QhWxFPRdH364qdGDlcb7B2/q9ckYuy/r5Oe10jVt/k+ f6lvGbXmveehYSgD5KWmF0LjrqtGL0m1EbxaeeJcTimcGCdBHJwxPDQ5tFXk7SM2 hkm2Xl++Jhk7gOrO4dYxrebgOkwYpyoMAPtwHZ2P4GGMdJUOM2FB8Jy2bEvMeeF4 eGsblO2Zy6V5KHRRNq8jt03jc24XDS7OJoiA5vN3RHV58UgLFfeVz6QemuBsInwL 9RC/ebRA8GBZXL6L8mVftY0olWjItiwgDVHwlLceUY/pIjPa1is= =Dvh3 -----END PGP SIGNATURE----- --BXVAT5kNtrzKuDFl--