From: James Hogan Subject: Re: [heads-up] weirdness in arch/metag/lib/usercopy.c Date: Wed, 29 Mar 2017 15:28:46 +0100 Message-ID: <20170329142846.GX31606@jhogan-linux.le.imgtec.org> References: <20170328235502.GG29622@ZenIV.linux.org.uk> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="w1TwAseT95X423KH" Return-path: Content-Disposition: inline In-Reply-To: <20170328235502.GG29622-3bDd1+5oDREiFSDQTTA3OLVCufUGDwFn@public.gmane.org> Sender: linux-metag-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org List-ID: To: Al Viro Cc: linux-metag-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, Linus Torvalds --w1TwAseT95X423KH Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Hi Al, On Wed, Mar 29, 2017 at 12:55:02AM +0100, Al Viro wrote: > AFAICS, given the definitions in there, you have > __asm_copy_from_user_4(to, from, ret) > expand to > __asm_copy_from_user_4x_cont(to, from, ret, "", "", "") > which expands to > __asm_copy_user_cont(to, from, ret, > " GETD D1Ar1,[%1++]\n" > "2: SETD [%0++],D1Ar1\n" "", > "3: ADD %2,%2,#4\n" > " SETD [%0++],D1Ar1\n" "", > " .long 2b,3b\n" "") > and > asm volatile ( > " GETD D1Ar1,[%1++]\n" > "2: SETD [%0++],D1Ar1\n" "" > "1:\n" > " .section .fixup,\"ax\"\n" > " MOV D1Ar1,#0\n" > "3: ADD %2,%2,#4\n" > " SETD [%0++],D1Ar1\n" "" > " MOVT D1Ar1,#HI(1b)\n" > " JUMP D1Ar1,#LO(1b)\n" > " .previous\n" > " .section __ex_table,\"a\"\n" > " .long 2b,3b\n" "" > " .previous\n" > : "=3Dr" (to), "=3Dr" (from), "=3Dr" (ret) > : "0" (to), "1" (from), "2" (ret) > : "D1Ar1", "memory") >=20 > Could you explain how does it ever manage to reach that > MOV D1Ar1, #0 > in the beginning of fixup? And I don't believe that it's something odd > about exception fixup on metag, because > __asm_copy_from_user_8(to, from, ret) > expands to > __asm_copy_from_user_8x_cont(to, from, ret, "", "", "") > then to > __asm_copy_from_user_4x_cont(to, from, ret, > " GETD D1Ar1,[%1++]\n" > "4: SETD [%0++],D1Ar1\n" "", > "5: ADD %2,%2,#4\n" > " SETD [%0++],D1Ar1\n" "", > " .long 4b,5b\n" "") > then to > __asm_copy_user_cont(to, from, ret, > " GETD D1Ar1,[%1++]\n" > "2: SETD [%0++],D1Ar1\n" > " GETD D1Ar1,[%1++]\n" > "4: SETD [%0++],D1Ar1\n" "", > "3: ADD %2,%2,#4\n" > " SETD [%0++],D1Ar1\n" > "5: ADD %2,%2,#4\n" > " SETD [%0++],D1Ar1\n" "", > " .long 2b,3b\n" > " .long 4b,5b\n" "") > and finally > asm volatile ( > " GETD D1Ar1,[%1++]\n" > "2: SETD [%0++],D1Ar1\n" > " GETD D1Ar1,[%1++]\n" > "4: SETD [%0++],D1Ar1\n" "" > "1:\n"=20 > " .section .fixup,\"ax\"\n" > " MOV D1Ar1,#0\n" > "3: ADD %2,%2,#4\n" > " SETD [%0++],D1Ar1\n" > "5: ADD %2,%2,#4\n" > " SETD [%0++],D1Ar1\n" "" > " MOVT D1Ar1,#HI(1b)\n" > " JUMP D1Ar1,#LO(1b)\n" > " .previous\n" > " .section __ex_table,\"a\"\n" > " .long 2b,3b\n" > " .long 4b,5b\n" "" > " .previous\n" > : "=3Dr" (to), "=3Dr" (from), "=3Dr" (ret) > : "0" (to), "1" (from), "2" (ret) > : "D1Ar1", "memory") >=20 > I could believe in fixup for fault on the first word hitting one insn > before 3:, but fault on the _second_ one sure as hell should not reach > back that far, or they would've ended up identical and both storing 8 byt= es > of zeroes, overflowing the destination in case of the second fault. > Moreover, it can't be relying upon the compiler leaving D1Ar1 zeroed on > the entry somehow - failure on the second word would have it equal to > the value of the first word, even if it had been zeroed to start with. Thanks for the heads up. Yeh that is rather suspect, I'll look into it. The first faulting byte/word/doubleword on <8 byte aligned copies from user will appear to get either the low x bits of the kernel destination address (if first copy) or a copy of the previous copy. The MOV of 0 to D1Ar1 prior to the fixup label dates back a long way too, through various refactors to the initial addition of proper fixup code on July 12th 2006 (based on v2.4.32). >=20 > How can that possibly work? And could somebody post a patch removing > zeroing altogether, both from those macros and from __copy_user_zeroing()? > copy_from_user() should be doing that memset() (it's on the slow path > anyway). Agreed. > I would've done that myself, but faults on metag are rather > odd and I've no way to test the damn thing, so I'd rather leave it to > metag maintainers. FWIW, that has come up when doing uaccess unification; > right now metag is one of two architectures still not converted to > raw_copy_{to,from}_user() (the other one is itanic). See vfs.git#work.ua= ccess > for details... >=20 > Another question is with your __copy_to_user() - unless I'm misreading th= at > code, it does *not* stop on store fault. That in itself wouldn't have be= en > a bug, but... what happens if you ask it to copy 3 pages worth of data in= to > a 3-page userland buffer, with the middle page unmapped? Indeed, that needs fixing too. Thanks James --w1TwAseT95X423KH Content-Type: application/pgp-signature; name="signature.asc" Content-Description: Digital signature -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJY28SWAAoJEGwLaZPeOHZ61csP/0/qFaUOaCON91RCkzGA5hNC o6qE1/ra7hdQyg6j8YaMyfW5TicX1Qe5Ozq1QjBFy+X7nf+bvcdF2wG0PFSsyKC6 gfqrkK6YCYOAXw4u4VFEXUo/NaeJx93EycaMI66PcpkL2CrQNjqPeOQ7eZBxtO0Q 8tnZp/CTuPckcbHjhw2P2UmGCJkUeQZeSmRd7VbeRZrX3Or4EwLMYys0l7/LivKe /mGOtaGI2A5pYfWgL5P782CtWG5WOVjeDo90zEmosA18B6RsK9wUCOJs6kBB15Xn iQplsjXaChM5tyZEp40GN2jnKLY7i3ILoMeM+Ch3E5ugD1rCxOCRunW+vRFB4V1P 3v2aKv/QHWAc8xsm2kxfJGJCgploZbUGrq9gvqgkud/LQFRX+YJLlZybtw5BBNk2 8fDEizhi4axMixrp2Y70QK005E3sRGqkQqzPGpqIuMDFuY3qpNtBq5PA2n5Zn+6J tBKfo6BG0OmobZXspUKlxFAaMW92JXIaxA9TbMRlPqUNj0lfUQzdlj8N0mrZtHJy jPSvOTIuqQzpQ4+Yqgna5J/NZ79uNXiGajr66mDPqcRKURDootVIbswk/fr98x23 n1boPpbLcNpBRGOw7jTXE5XeZN5loPOo2X26+C7kQCCkY8isC5Uad4knOP7U4iL5 t+7vbk4/Nu0GEDEtVd9G =qawD -----END PGP SIGNATURE----- --w1TwAseT95X423KH--