From mboxrd@z Thu Jan 1 00:00:00 1970 X-Msuck: nntp://news.gmane.org/gmane.linux.lib.musl.general/10005 Path: news.gmane.org!not-for-mail From: Alexander Monakov Newsgroups: gmane.linux.lib.musl.general Subject: ptrace addr2 weirdness Date: Thu, 5 May 2016 01:54:12 +0300 (MSK) Message-ID: Reply-To: musl@lists.openwall.com NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Trace: ger.gmane.org 1462402473 14053 80.91.229.3 (4 May 2016 22:54:33 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Wed, 4 May 2016 22:54:33 +0000 (UTC) To: musl@lists.openwall.com Original-X-From: musl-return-10018-gllmg-musl=m.gmane.org@lists.openwall.com Thu May 05 00:54:33 2016 Return-path: Envelope-to: gllmg-musl@m.gmane.org Original-Received: from mother.openwall.net ([195.42.179.200]) by plane.gmane.org with smtp (Exim 4.69) (envelope-from ) id 1ay5gd-0000bK-J0 for gllmg-musl@m.gmane.org; Thu, 05 May 2016 00:54:31 +0200 Original-Received: (qmail 19825 invoked by uid 550); 4 May 2016 22:54:28 -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 19783 invoked from network); 4 May 2016 22:54:24 -0000 User-Agent: Alpine 2.20 (LNX 67 2015-01-07) Xref: news.gmane.org gmane.linux.lib.musl.general:10005 Archived-At: I was eyeballing musl's ptrace syscall wrapper and noticed it passes an extra argument to the kernel: long ptrace(int req, ...) { [snip] 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 *); va_end(ap); if (req-1U < 3) data = &result; ret = syscall(SYS_ptrace, req, pid, addr, data, addr2); [snip] } The last argument is completely undocumented in the Linux manpage and if you look at generic kernel source you'll find that the syscall indeed only looks at four arguments, req, pid, addr, data. Turns out the fifth 'addr2' argument is used on sparc with PTRACE_{READ,WRITE}{DATA,TEXT} requests, but given that musl neither supports sparc, nor (correctly) exposes those request kinds in sys/ptrace.h, this argument passing is unnecessary, puzzling, and can be either removed or at least a comment would be nice :) The reason I was eyeballing it is to see how the variadicness is handled. In principle the caller can supply fewer arguments for some request kinds, although the manpage discourages that practice. musl could accept such calls like this: pid = 0; addr = data = 0; if (req != PTRACE_TRACEME) { va_start(ap, req); pid = va_arg(ap, pid_t); if (req != PTRACE_KILL && /*other 2-arg reqs*/) { addr = va_arg(ap, void *); if (req != PTRACE_PEEKDATA && /*other 3-arg reqs*/) data = va_arg(ap, void *); } va_end(ap); } Thanks. Alexander