From owner-dev-commits-src-all@freebsd.org Tue Jan 19 13:09:01 2021 Return-Path: Delivered-To: dev-commits-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id ECBA04F3DC0; Tue, 19 Jan 2021 13:09:01 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4DKprY0ymXz3RGC; Tue, 19 Jan 2021 13:09:00 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kib@localhost [127.0.0.1]) by kib.kiev.ua (8.16.1/8.16.1) with ESMTPS id 10JD8qC2074478 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NO); Tue, 19 Jan 2021 15:08:56 +0200 (EET) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.10.3 kib.kiev.ua 10JD8qC2074478 Received: (from kostik@localhost) by tom.home (8.16.1/8.16.1/Submit) id 10JD8qGC074477; Tue, 19 Jan 2021 15:08:52 +0200 (EET) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Tue, 19 Jan 2021 15:08:52 +0200 From: Konstantin Belousov To: src-committers@freebsd.org, dev-commits-src-all@freebsd.org, dev-commits-src-main@freebsd.org Subject: Re: git: 47f7345baba0 - main - linux: fix PTRACE_POKEDATA and PTRACE_POKETEXT. Message-ID: References: <202101191053.10JArcDa041994@gitrepo.freebsd.org> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FORGED_GMAIL_RCVD,FREEMAIL_FROM, NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on tom.home X-Rspamd-Queue-Id: 4DKprY0ymXz3RGC X-Spamd-Bar: - Authentication-Results: mx1.freebsd.org; dkim=none; dmarc=fail reason="No valid SPF, No valid DKIM" header.from=gmail.com (policy=none); spf=softfail (mx1.freebsd.org: 2001:470:d5e7:1::1 is neither permitted nor denied by domain of kostikbel@gmail.com) smtp.mailfrom=kostikbel@gmail.com X-Spamd-Result: default: False [-1.00 / 15.00]; ARC_NA(0.00)[]; FREEMAIL_ENVFROM(0.00)[gmail.com]; RCVD_TLS_ALL(0.00)[]; FROM_HAS_DN(0.00)[]; RCPT_COUNT_THREE(0.00)[3]; FREEMAIL_FROM(0.00)[gmail.com]; TO_MATCH_ENVRCPT_ALL(0.00)[]; MIME_GOOD(-0.10)[text/plain]; HAS_XAW(0.00)[]; TO_DN_NONE(0.00)[]; R_SPF_SOFTFAIL(0.00)[~all:c]; NEURAL_SPAM_SHORT(1.00)[0.995]; SPAMHAUS_ZRD(0.00)[2001:470:d5e7:1::1:from:127.0.2.255]; NEURAL_HAM_MEDIUM(-1.00)[-1.000]; RBL_DBL_DONT_QUERY_IPS(0.00)[2001:470:d5e7:1::1:from]; NEURAL_HAM_LONG(-1.00)[-1.000]; FROM_EQ_ENVFROM(0.00)[]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:6939, ipnet:2001:470::/32, country:US]; RCVD_COUNT_TWO(0.00)[2]; MAILMAN_DEST(0.00)[dev-commits-src-all,dev-commits-src-main]; DMARC_POLICY_SOFTFAIL(0.10)[gmail.com : No valid SPF, No valid DKIM,none] X-BeenThere: dev-commits-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Commit messages for all branches of the src repository List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jan 2021 13:09:02 -0000 On Tue, Jan 19, 2021 at 12:25:36PM +0000, Edward Tomasz Napierala wrote: > On 0119T1314, Konstantin Belousov wrote: > > On Tue, Jan 19, 2021 at 10:53:38AM +0000, Edward Tomasz Napierala wrote: > > > The branch main has been updated by trasz: > > > > > > URL: https://cgit.FreeBSD.org/src/commit/?id=47f7345baba01121e29c22b43f68345399a32912 > > > > > > commit 47f7345baba01121e29c22b43f68345399a32912 > > > Author: Edward Tomasz Napierala > > > AuthorDate: 2021-01-15 16:57:24 +0000 > > > Commit: Edward Tomasz Napierala > > > CommitDate: 2021-01-19 10:30:55 +0000 > > > > > > linux: fix PTRACE_POKEDATA and PTRACE_POKETEXT. > > > > > > Sponsored by: The FreeBSD Foundation > > > --- > > > sys/amd64/linux/linux_ptrace.c | 9 +++++++-- > > > 1 file changed, 7 insertions(+), 2 deletions(-) > > > > > > diff --git a/sys/amd64/linux/linux_ptrace.c b/sys/amd64/linux/linux_ptrace.c > > > index a14155ed7e97..c1d05db5bc42 100644 > > > --- a/sys/amd64/linux/linux_ptrace.c > > > +++ b/sys/amd64/linux/linux_ptrace.c > > > @@ -594,10 +594,15 @@ linux_ptrace(struct thread *td, struct linux_ptrace_args *uap) > > > error = linux_ptrace_peekuser(td, pid, addr, (void *)uap->data); > > > break; > > > case LINUX_PTRACE_POKETEXT: > > > - error = kern_ptrace(td, PT_WRITE_I, pid, addr, uap->data); > > > - break; > > This is wrong. You should access text AS if linux request was for text. > > Do we actually want to maintain that distinction? Looking > at sys/kern/sys_process.c, they are synonyms. It started on PDP-11 were text and data address spaces could be separate. Right now I think this distinction might be useful for applying different policy in addition to the plain mapping permissions, at least. I would prefer to not break the feature until we decide to, instead of doing it silently and on case by case. > > > > case LINUX_PTRACE_POKEDATA: > > > error = kern_ptrace(td, PT_WRITE_D, pid, addr, uap->data); > > > + if (error != 0) > > > + return (error); > > > + /* > > > + * Linux expects this syscall to write 64 bits, not 32. > > > + */ > > > + error = kern_ptrace(td, PT_WRITE_D, pid, > > > + (void *)(uap->addr + 4), uap->data >> 32); > > > break; > > You should use PT_IO there instead of doing two accesses (to the wrong AS). > > Hm, you're right. The only problem I can see is that PT_IO fetches > struct ptrace_io_desc from userspace, which makes wrapping somewhat > hard. How about introducing PT_READ64 and PT_WRITE64 request types > and using them instead? Are you sure? I see that the structure is copied in and out in sys_ptrace(9). Doing it in kern_ptrace(9) would require one more SV_ILP32 check, but it seems to be done right.