[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAJF2gTQwkPgafMxJ8YxH-kCsyT82bTr_a2hBJ1Pido7SvN+o2A@mail.gmail.com>
Date: Mon, 28 Nov 2022 10:42:44 +0800
From: Guo Ren <guoren@...nel.org>
To: Ben Hutchings <ben@...adent.org.uk>
Cc: arnd@...db.de, palmer@...osinc.com, tglx@...utronix.de,
peterz@...radead.org, luto@...nel.org, conor.dooley@...rochip.com,
heiko@...ech.de, jszhang@...nel.org, lazyparser@...il.com,
falcon@...ylab.org, chenhuacai@...nel.org, apatel@...tanamicro.com,
atishp@...shpatra.org, palmer@...belt.com,
paul.walmsley@...ive.com, mark.rutland@....com,
zouyipeng@...wei.com, bigeasy@...utronix.de,
David.Laight@...lab.com, chenzhongjin@...wei.com,
greentime.hu@...ive.com, andy.chiu@...ive.com,
linux-arch@...r.kernel.org, linux-kernel@...r.kernel.org,
linux-riscv@...ts.infradead.org, Guo Ren <guoren@...ux.alibaba.com>
Subject: Re: [PATCH -next V8 06/14] riscv: convert to generic entry
On Mon, Nov 28, 2022 at 12:26 AM Ben Hutchings <ben@...adent.org.uk> wrote:
>
> On Thu, 2022-11-03 at 03:50 -0400, guoren@...nel.org wrote:
> [...]
> > --- a/arch/riscv/kernel/sys_riscv.c
> > +++ b/arch/riscv/kernel/sys_riscv.c
> [...]
> > +asmlinkage void do_sys_ecall_u(struct pt_regs *regs)
> > +{
> > + syscall_t syscall;
> > + ulong nr = regs->a7;
> > +
> > + regs->epc += 4;
> > + regs->orig_a0 = regs->a0;
> > + regs->a0 = -ENOSYS;
> > +
> > + nr = syscall_enter_from_user_mode(regs, nr);
> > +#ifdef CONFIG_COMPAT
> > + if ((regs->status & SR_UXL) == SR_UXL_32)
> > + syscall = compat_sys_call_table[nr];
> > + else
> > +#endif
> > + syscall = sys_call_table[nr];
> > +
> > + if (nr < NR_syscalls)
>
> This bounds check needs to be done before indexing the system call
> table, not after.
Yes, you are right. That would cause a wrong pointer bug. Here is the
new version:
asmlinkage void do_sys_ecall_u(struct pt_regs *regs)
{
syscall_t syscall;
ulong nr = regs->a7;
regs->epc += 4;
regs->orig_a0 = regs->a0;
regs->a0 = -ENOSYS;
nr = syscall_enter_from_user_mode(regs, nr);
if (nr < NR_syscalls) {
#ifdef CONFIG_COMPAT
if ((regs->status & SR_UXL) == SR_UXL_32)
syscall = compat_sys_call_table[nr];
else
#endif
syscall = sys_call_table[nr];
regs->a0 = syscall(regs->orig_a0, regs->a1, regs->a2,
regs->a3, regs->a4, regs->a5, regs->a6);
}
syscall_exit_to_user_mode(regs);
}
>
> Ben.
>
> > + regs->a0 = syscall(regs->orig_a0, regs->a1, regs->a2,
> > + regs->a3, regs->a4, regs->a5, regs->a6);
> > + syscall_exit_to_user_mode(regs);
> > +}
> [...]
>
> --
> Ben Hutchings
> This sentence contradicts itself - no actually it doesn't.
--
Best Regards
Guo Ren
Powered by blists - more mailing lists