From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/11619 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: Wed, 28 Jun 2017 11:13:28 -0400 Message-ID: <20170628151328.GD1627@brightrain.aerifal.cx> References: <20170628132513.15483-1-amonakov@ispras.ru> 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 1498662822 23470 195.159.176.226 (28 Jun 2017 15:13:42 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 28 Jun 2017 15:13:42 +0000 (UTC) User-Agent: Mutt/1.5.21 (2010-09-15) To: musl@lists.openwall.com Original-X-From: musl-return-11632-gllmg-musl=m.gmane.org@lists.openwall.com Wed Jun 28 17:13:39 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 1dQEew-0005tJ-Dc for gllmg-musl@m.gmane.org; Wed, 28 Jun 2017 17:13:38 +0200 Original-Received: (qmail 21732 invoked by uid 550); 28 Jun 2017 15:13:41 -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 21708 invoked from network); 28 Jun 2017 15:13:41 -0000 Content-Disposition: inline In-Reply-To: <20170628132513.15483-1-amonakov@ispras.ru> Original-Sender: Rich Felker Xref: news.gmane.org gmane.linux.lib.musl.general:11619 Archived-At: On Wed, Jun 28, 2017 at 04:25:13PM +0300, Alexander Monakov wrote: > --- > src/linux/ptrace.c | 5 ++++- > 1 file changed, 4 insertions(+), 1 deletion(-) > > diff --git a/src/linux/ptrace.c b/src/linux/ptrace.c > index 83b8022b..ab7fcda3 100644 > --- a/src/linux/ptrace.c > +++ b/src/linux/ptrace.c > @@ -7,14 +7,17 @@ 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 *); > + /* PTRACE_{READ,WRITE}{DATA,TEXT} are specific to SPARC. */ > +#ifdef PTRACE_READTEXT > addr2 = va_arg(ap, void *); > +#endif I think there's still UB here, reading more args than were passed. These calls to va_arg should probably be dependent on the particular req; I don't see any reason for it to be compile-time dependent on the presence of one particular req value. Otherwise yes it's an improvement. Rich