From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11655 Path: news.gmane.org!.POSTED!not-for-mail From: Rich Felker Newsgroups: gmane.linux.lib.musl.general Subject: Re: [PATCH] fix undefined behavior in ptrace Date: Tue, 4 Jul 2017 17:53:56 -0400 Message-ID: <20170704215356.GT1627@brightrain.aerifal.cx> References: <20170628132513.15483-1-amonakov@ispras.ru> <20170628151328.GD1627@brightrain.aerifal.cx> <20170704211058.GO1627@brightrain.aerifal.cx> Reply-To: musl@lists.openwall.com NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: blaine.gmane.org 1499205253 13761 195.159.176.226 (4 Jul 2017 21:54:13 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Tue, 4 Jul 2017 21:54:13 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11668-gllmg-musl=m.gmane.org@lists.openwall.com Tue Jul 04 23:54:10 2017 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by blaine.gmane.org with smtp (Exim 4.84_2) (envelope-from ) id 1dSVlk-00039K-Vt for gllmg-musl@m.gmane.org; Tue, 04 Jul 2017 23:54:05 +0200 Original-Received: (qmail 3310 invoked by uid 550); 4 Jul 2017 21:54:08 -0000 Mailing-List: contact musl-help@lists.openwall.com; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-ID: Original-Received: (qmail 3292 invoked from network); 4 Jul 2017 21:54:08 -0000 Content-Disposition: inline In-Reply-To: Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11655 Archived-At: On Wed, Jul 05, 2017 at 12:51:05AM +0300, Alexander Monakov wrote: > --- > On Tue, 4 Jul 2017, Rich Felker wrote: > > Thoughts? > > I'm not convinced it's a good idea, given that it's a Linux specific interface, > and the manpage rather explicitly discourages passing fewer than four > arguments. > > Plus, handling SPARC-specific differences of argument counts for > PTRACE_{GET,SET}{FP,}REGS would be annoying. > > What makes sense is to retrieve the fifth argument only when needed: Ah, okay. I'm fine with that. Thanks for clarifying. > src/linux/ptrace.c | 8 ++++++-- > 1 file changed, 6 insertions(+), 2 deletions(-) > > diff --git a/src/linux/ptrace.c b/src/linux/ptrace.c > index 83b8022b..a3f393d9 100644 > --- a/src/linux/ptrace.c > +++ b/src/linux/ptrace.c > @@ -7,14 +7,18 @@ long ptrace(int req, ...) > { > va_list ap; > pid_t pid; > - void *addr, *data, *addr2; > + void *addr, *data, *addr2 = 0; > long ret, result; > > va_start(ap, req); > pid = va_arg(ap, pid_t); > addr = va_arg(ap, void *); > data = va_arg(ap, void *); > - addr2 = va_arg(ap, void *); > + /* PTRACE_{READ,WRITE}{DATA,TEXT} (16...19) are specific to SPARC. */ > +#ifdef PTRACE_READDATA > + if ((unsigned)req - PTRACE_READDATA < 4) > + addr2 = va_arg(ap, void *); > +#endif > va_end(ap); > > if (req-1U < 3) data = &result; > -- > 2.11.0 Applying. Rich