mailing list of musl libc
 help / color / mirror / code / Atom feed
From: Alexander Monakov <amonakov@ispras.ru>
To: musl@lists.openwall.com
Subject: ptrace addr2 weirdness
Date: Thu, 5 May 2016 01:54:12 +0300 (MSK)	[thread overview]
Message-ID: <alpine.LNX.2.20.1605050058590.14322@monopod.intra.ispras.ru> (raw)

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


                 reply	other threads:[~2016-05-04 22:54 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=alpine.LNX.2.20.1605050058590.14322@monopod.intra.ispras.ru \
    --to=amonakov@ispras.ru \
    --cc=musl@lists.openwall.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).