Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3806148imu; Mon, 10 Dec 2018 08:07:30 -0800 (PST) X-Google-Smtp-Source: AFSGD/UJBEpBkoFrXkQiDTQBYFANBAGJIfcERdo5tsA0A4kw+FGZ/LruDwnwuQjLlEso8SJG5EL2 X-Received: by 2002:a62:6f49:: with SMTP id k70mr12788952pfc.7.1544458050822; Mon, 10 Dec 2018 08:07:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544458050; cv=none; d=google.com; s=arc-20160816; b=DOtclZtufCsa15g85SPmBZUIL/VPxpItSoOQsvdftIxKwFqrqU6uUkkjReBQtUUH1g eotlWPIWwFz2RqqDpBpc7uB0MaU24L0uk5ckY/EPhFmznqH16T4v78Km2tulf4OrCo7+ te3EEG5xUhW2ato4WUZ1UlqpS1xcyqDV4iSlaROFbU3KL1bHJlnC5X9T6vSpBb8xG3Jq DfNKdRGvzz7YlI3C9lBhAvD8Kc1DFKZzK3aSkVTX4LeCYopEhr0xT8PVhg2NO+sB1meC TSpizXoVihuVXa45hkgRclARLxV5vsdVsyf68Mr2/q8epPdWh1o1YInESw9y6T0uyQKi Y5Rw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date; bh=sua97kuWW9cZp2YJxnH5J8WXJYyAocmDxdeDPrrbyLM=; b=dNDokFtaNG3yfg6I/2oICxxi9QaGWBNGJEDSJPM/WuehGXW3heI/YXWIPsA1u78AWl OKJ+kY2HvYj8li5JwGGCZJCsbAc/Xa+88eIyrwOLB/C4x4l4FAm0ik3WUJg9LSoPQbwB bH9aKJ4onEGeyEQ75B+8cw1N1G8nyFtKO+Wa7UPmBjpwDqcmTTk4NQ2dtFX2QQDjWHJz oybeCu0YaElThoiVwSxCzdJadrX/VONXTDdhcUuLJJ6pcSpibfaxWzXdI6uwD+Hv+q1v ltZMQVAr5oZClZN55NYKVKlTLuALjIryG+KmG16r6QWOR0CxKE0X3AGanq+t9ty05Y+N d3wA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 2si9839459pgy.35.2018.12.10.08.07.15; Mon, 10 Dec 2018 08:07:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727665AbeLJNhA (ORCPT + 99 others); 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--