[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z09RshGMxW3q6JpA@ghost>
Date: Tue, 3 Dec 2024 10:45:06 -0800
From: Charlie Jenkins <charlie@...osinc.com>
To: "Dmitry V. Levin" <ldv@...ace.io>
Cc: Celeste Liu <uwu@...lacanthus.name>, Oleg Nesterov <oleg@...hat.com>,
Paul Walmsley <paul.walmsley@...ive.com>,
Palmer Dabbelt <palmer@...belt.com>,
Albert Ou <aou@...s.berkeley.edu>,
Eric Biederman <ebiederm@...ssion.com>, Kees Cook <kees@...nel.org>,
Alexandre Ghiti <alex@...ti.fr>,
Andrea Bolognani <abologna@...hat.com>,
Björn Töpel <bjorn@...nel.org>,
Thomas Gleixner <tglx@...utronix.de>, Ron Economos <re@...z.net>,
Felix Yan <felixonmars@...hlinux.org>,
Ruizhe Pan <c141028@...il.com>,
Shiqi Zhang <shiqi@...c.iscas.ac.cn>, Guo Ren <guoren@...nel.org>,
Yao Zi <ziyao@...root.org>, Han Gao <gaohan@...as.ac.cn>,
Quan Zhou <zhouquan@...as.ac.cn>, linux-riscv@...ts.infradead.org,
linux-kernel@...r.kernel.org, linux-mm@...ck.org
Subject: Re: [PATCH] riscv/ptrace: add new regset to get original a0 register
On Tue, Dec 03, 2024 at 02:19:48PM +0200, Dmitry V. Levin wrote:
> On Mon, Dec 02, 2024 at 09:37:04PM -0800, Charlie Jenkins wrote:
> [...]
> > +static void ptrace_test(int opt, int *result)
> > +{
> > + int status;
> > + pid_t pid;
> > + struct user_regs_struct regs;
> > + struct iovec iov = {
> > + .iov_base = ®s,
> > + .iov_len = sizeof(regs),
> > + };
> > +
> > + unsigned long orig_a0;
> > + struct iovec a0_iov = {
> > + .iov_base = &orig_a0,
> > + .iov_len = sizeof(orig_a0),
> > + };
> > +
> > + pid = fork();
> > + if (pid == 0) {
> > + /* Mark oneself being traced */
> > + long val = ptrace(PTRACE_TRACEME, 0, 0, 0);
> > + if (val)
> > + perr_and_exit("failed to request for tracer to trace me: %ld\n", val);
> > +
> > + kill(getpid(), SIGSTOP);
> > +
> > + /* Perform exit syscall that will be intercepted */
> > + exit(A0_OLD);
> > + }
> > +
> > + if (pid < 0)
> > + exit(1);
> > +
> > + if (waitpid(pid, &status, 0) != pid)
> > + perr_and_exit("failed to wait for the tracee %d\n", pid);
> > +
> > + /* Stop at the entry point of the syscall */
> > + resume_and_wait_tracee(pid, PTRACE_SYSCALL);
> > +
> > + /* Check tracee regs before the syscall */
> > + if (ptrace(PTRACE_GETREGSET, pid, NT_PRSTATUS, &iov))
> > + perr_and_exit("failed to get tracee registers\n");
> > + if (ptrace(PTRACE_GETREGSET, pid, NT_RISCV_ORIG_A0, &a0_iov))
> > + perr_and_exit("failed to get tracee registers\n");
> > + if (orig_a0 != A0_OLD)
> > + perr_and_exit("unexpected orig_a0: 0x%lx\n", orig_a0);
> > +
> > + /* Modify a0/orig_a0 for the syscall */
> > + switch (opt) {
> > + case A0_MODIFY:
> > + regs.a0 = A0_NEW;
> > + break;
>
> Did you mean applying the modified user_regs_struct using PTRACE_SETREGSET?
> If yes, then there should be an appropriate PTRACE_SETREGSET NT_PRSTATUS call.
> If no, then regs is ignored, so why would you change it in the first place?
>
Yes you are correct, there should be another PTRACE_SETREGSET. That was
a mistake in modifying the previous test case for this new patch.
- Charlie
> > + case ORIG_A0_MODIFY:
> > + orig_a0 = A0_NEW;
> > + break;
> > + }
> > +
> > + if (ptrace(PTRACE_SETREGSET, pid, NT_RISCV_ORIG_A0, &a0_iov))
> > + perr_and_exit("failed to set tracee registers\n");
> > +
> > + /* Resume the tracee */
> > + ptrace(PTRACE_CONT, pid, 0, 0);
> > + if (waitpid(pid, &status, 0) != pid)
> > + perr_and_exit("failed to wait for the tracee\n");
> > +
> > + *result = WEXITSTATUS(status);
> > +}
>
> --
> ldv
Powered by blists - more mailing lists