From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_PASS autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 25997C04EB8 for ; Mon, 10 Dec 2018 13:37:02 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E251E21473 for ; Mon, 10 Dec 2018 13:37:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E251E21473 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=altlinux.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727671AbeLJNhA (ORCPT ); Mon, 10 Dec 2018 08:37:00 -0500 Received: from vmicros1.altlinux.org ([194.107.17.57]:48598 "EHLO vmicros1.altlinux.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726902AbeLJNhA (ORCPT ); Mon, 10 Dec 2018 08:37:00 -0500 Received: from mua.local.altlinux.org (mua.local.altlinux.org [192.168.1.14]) by vmicros1.altlinux.org (Postfix) with ESMTP id AABB472CC66; Mon, 10 Dec 2018 16:36:56 +0300 (MSK) Received: by mua.local.altlinux.org (Postfix, from userid 508) id D9F1F7CF1FC; Mon, 10 Dec 2018 16:36:55 +0300 (MSK) Date: Mon, 10 Dec 2018 16:36:55 +0300 From: "Dmitry V. Levin" To: Oleg Nesterov Cc: Michael Ellerman , Elvira Khabirova , Benjamin Herrenschmidt , Paul Mackerras , Breno Leitao , Andy Lutomirski , Eugene Syromyatnikov , linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v6] powerpc/ptrace: replace ptrace_report_syscall() with a tracehook call Message-ID: <20181210133655.GH11942@altlinux.org> References: <87ftw12nyn.fsf@concordia.ellerman.id.au> <20181119210139.GA8360@altlinux.org> <87efbe166y.fsf@concordia.ellerman.id.au> <20181203031823.GE11573@altlinux.org> <20181207011946.GA18558@altlinux.org> <87y391k2tq.fsf@concordia.ellerman.id.au> <20181207154255.GA28964@altlinux.org> <20181207155605.GB28964@altlinux.org> <20181207185226.GB31278@altlinux.org> <20181210132806.GA4177@redhat.com> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha256; protocol="application/pgp-signature"; boundary="gMR3gsNFwZpnI/Ts" Content-Disposition: inline In-Reply-To: <20181210132806.GA4177@redhat.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --gMR3gsNFwZpnI/Ts Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Dec 10, 2018 at 02:28:07PM +0100, Oleg Nesterov wrote: > On 12/07, Dmitry V. Levin wrote: > > > > Please make either v5 or v6 edition of this fix, or any similar fix, > > into v4.20. >=20 > IIUC, v5 above means >=20 > [PATCH v5 23/25] powerpc/ptrace: replace ptrace_report_syscall() with a = tracehook call >=20 > you sent in another series... They just happen to have the same v5 here and there. In that series I included the most trivial variant of the change. > > long do_syscall_trace_enter(struct pt_regs *regs) > > { > > + struct thread_info *ti; > > + u32 cached_flags; > > + > > user_exit(); > > =20 > > - if (test_thread_flag(TIF_SYSCALL_EMU)) { > > - ptrace_report_syscall(regs); > > - /* > > - * Returning -1 will skip the syscall execution. We want to > > - * avoid clobbering any register also, thus, not 'gotoing' > > - * skip label. > > - */ > > - return -1; > > - } > > + ti =3D current_thread_info(); > > + cached_flags =3D READ_ONCE(ti->flags) & > > + (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE | > > + _TIF_SYSCALL_TRACEPOINT); > > =20 > > - /* > > - * The tracer may decide to abort the syscall, if so tracehook > > - * will return !0. Note that the tracer may also just change > > - * regs->gpr[0] to an invalid syscall number, that is handled > > - * below on the exit path. > > - */ > > - if (test_thread_flag(TIF_SYSCALL_TRACE) && > > - tracehook_report_syscall_entry(regs)) > > - goto skip; > > + if (cached_flags & (_TIF_SYSCALL_EMU | _TIF_SYSCALL_TRACE)) { > > + int rc =3D tracehook_report_syscall_entry(regs); > > + > > + if (unlikely(cached_flags & _TIF_SYSCALL_EMU)) { > > + /* > > + * A nonzero return code from > > + * tracehook_report_syscall_entry() tells us > > + * to prevent the syscall execution, but > > + * we are not going to execute it anyway. > > + * > > + * Returning -1 will skip the syscall execution. > > + * We want to avoid clobbering any register also, > > + * thus, not 'gotoing' skip label. > > + */ > > + return -1; > > + } > > + > > + if (rc) { > > + /* > > + * The tracer decided to abort the syscall. > > + * Note that the tracer may also just change > > + * regs->gpr[0] to an invalid syscall number, > > + * that is handled below on the exit path. > > + */ > > + goto skip; > > + } > > + } > > =20 > > /* Run seccomp after ptrace; allow it to set gpr[3]. */ > > if (do_seccomp(regs)) > > @@ -3293,7 +3309,7 @@ long do_syscall_trace_enter(struct pt_regs *regs) > > if (regs->gpr[0] >=3D NR_syscalls) > > goto skip; > > =20 > > - if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT))) > > + if (unlikely(cached_flags & _TIF_SYSCALL_TRACEPOINT)) >=20 > I will leave this to maintainers, but to me this change looks good and im= o it > also cleanups the code. >=20 > However I am not sure cached_flags should include _TIF_SYSCALL_TRACEPOINT= =2E If > nothing else, the caller can sleep in ptrace_stop() unpredictably long and > TIF_SYSCALL_TRACEPOINT can be set/cleared meanwhile. I agree, we shouldn't cache _TIF_SYSCALL_TRACEPOINT. --=20 ldv --gMR3gsNFwZpnI/Ts Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIcBAEBCAAGBQJcDmv3AAoJEAVFT+BVnCUIlrIQAPHIWnElYZge8NS1F64p0iO0 lXFKC/o5wdwokgzUtyLf3ngHyBHrjhJr16swFMKVs5PZoXFQtueXLBwJccvJFwbD 6e2sNrh7g0Mt07dfzEFeKYpYl6z6QLrFUFNDtJXchwnRf8vN6Qt8Eu4H4UDnY5kZ ic8KgON/Gg0JJ/b7dLqZZcynmBV6+xhgQSCUh0et4eHeCzW9cKJa5p3N46/QC4Kz ybhuVCiAIei8Xiy51v+/nWbPW+asWWJFJY/HQimNVHbPQwnFrfC2jThpUq7Jcs+5 fkmQtsQHDhvew5+ZL57lt3Xqq+wsbRJWAOIWBVfSj3+iwyJx8LDdtxZr+R0GOF6K 8aV1APcWpDVdqowvYbfYlqCdNHyRWkYPmedIr/VZAJmperyBeCgXx2Ojqs5Wiz20 2hcjXExfQ0m4r79k9TZb82rp2Vq9HqgPs+buQA6tEsxh5iHAsPE+5g4qJWSoXoXY XkVl+FRNCWSlZCM+hNG17mjR9kf5n3PReFnpEQk+U/2VBo6O2n4j/E/Kfx2ct7T+ l1jm/EaHocoRy+gx0vaDNM+ozwVibqRu8FiAtpJw2hG4Cw9LKMTBGJtQTOVGDitE aE3L1TfAVHwiRBL1gZTqNMOX+V+Lj3sviL2QE1idOtCPqlyAu9fKU3nJXZc7z7Lw 5Vu3dgy6Nik8QSZRcwR8 =bgMo -----END PGP SIGNATURE----- --gMR3gsNFwZpnI/Ts--