linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] alpha/kernel/traps: Use find_vma_intersection() in traps for setting si_code
@ 2021-04-01 19:51 Liam Howlett
  2021-04-01 20:25 ` Michel Lespinasse
  0 siblings, 1 reply; 3+ messages in thread
From: Liam Howlett @ 2021-04-01 19:51 UTC (permalink / raw)
  To: Richard Henderson, Ivan Kokshaysky, Matt Turner, Andrew Morton,
	Liam Howlett, linux-alpha, linux-kernel
  Cc: Dmitry Safonov, Michel Lespinasse, Gustavo A . R . Silva

find_vma() will continue to search upwards until the end of the virtual
memory space.  This means the si_code would almost never be set to
SEGV_MAPERR even when the address falls outside of any VMA.

Using find_vma_intersection() allows for what is intended by only
returning a VMA if it falls within the range provided, in this case a
window of 1.

Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
---
 arch/alpha/kernel/traps.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
index 921d4b6e4d95..7f51386c06d0 100644
--- a/arch/alpha/kernel/traps.c
+++ b/arch/alpha/kernel/traps.c
@@ -957,8 +957,10 @@ do_entUnaUser(void __user * va, unsigned long opcode,
 		si_code = SEGV_ACCERR;
 	else {
 		struct mm_struct *mm = current->mm;
+		unsigned long addr = (unsigned long)va;
+
 		mmap_read_lock(mm);
-		if (find_vma(mm, (unsigned long)va))
+		if (find_vma_intersection(mm, addr, addr + 1))
 			si_code = SEGV_ACCERR;
 		else
 			si_code = SEGV_MAPERR;
-- 
2.30.0

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] alpha/kernel/traps: Use find_vma_intersection() in traps for setting si_code
  2021-04-01 19:51 [PATCH] alpha/kernel/traps: Use find_vma_intersection() in traps for setting si_code Liam Howlett
@ 2021-04-01 20:25 ` Michel Lespinasse
  2021-04-02 13:05   ` Liam Howlett
  0 siblings, 1 reply; 3+ messages in thread
From: Michel Lespinasse @ 2021-04-01 20:25 UTC (permalink / raw)
  To: Liam Howlett
  Cc: Richard Henderson, Ivan Kokshaysky, Matt Turner, Andrew Morton,
	linux-alpha, linux-kernel, Dmitry Safonov, Gustavo A . R . Silva

You are correct that find_vma is insufficient for what's intended
here, and that find_vma_intersection fixes it.

I'll let the arch maintainers speak of what the consequences of the
changed si_code would be - the bug has been here so long, that I would
worry some userspace might have come to depend on it (the old "common
law feature" issue).
 Just a concern I have, with 0 evidence behind it, so I hope it turns
out not to be an actual issue.

Acked-by: Michel Lespinasse <walken@google.com>

On Thu, Apr 1, 2021 at 12:51 PM Liam Howlett <liam.howlett@oracle.com> wrote:
>
> find_vma() will continue to search upwards until the end of the virtual
> memory space.  This means the si_code would almost never be set to
> SEGV_MAPERR even when the address falls outside of any VMA.
>
> Using find_vma_intersection() allows for what is intended by only
> returning a VMA if it falls within the range provided, in this case a
> window of 1.
>
> Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> ---
>  arch/alpha/kernel/traps.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> index 921d4b6e4d95..7f51386c06d0 100644
> --- a/arch/alpha/kernel/traps.c
> +++ b/arch/alpha/kernel/traps.c
> @@ -957,8 +957,10 @@ do_entUnaUser(void __user * va, unsigned long opcode,
>                 si_code = SEGV_ACCERR;
>         else {
>                 struct mm_struct *mm = current->mm;
> +               unsigned long addr = (unsigned long)va;
> +
>                 mmap_read_lock(mm);
> -               if (find_vma(mm, (unsigned long)va))
> +               if (find_vma_intersection(mm, addr, addr + 1))
>                         si_code = SEGV_ACCERR;
>                 else
>                         si_code = SEGV_MAPERR;
> --
> 2.30.0



-- 
Michel "Walken" Lespinasse
A program is never fully debugged until the last user dies.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] alpha/kernel/traps: Use find_vma_intersection() in traps for setting si_code
  2021-04-01 20:25 ` Michel Lespinasse
@ 2021-04-02 13:05   ` Liam Howlett
  0 siblings, 0 replies; 3+ messages in thread
From: Liam Howlett @ 2021-04-02 13:05 UTC (permalink / raw)
  To: Michel Lespinasse
  Cc: Richard Henderson, Ivan Kokshaysky, Matt Turner, Andrew Morton,
	linux-alpha, linux-kernel, Dmitry Safonov, Gustavo A . R . Silva

* Michel Lespinasse <walken@google.com> [210401 16:25]:
> You are correct that find_vma is insufficient for what's intended
> here, and that find_vma_intersection fixes it.
> 
> I'll let the arch maintainers speak of what the consequences of the
> changed si_code would be - the bug has been here so long, that I would
> worry some userspace might have come to depend on it (the old "common
> law feature" issue).

Fair point.  Is this a valid concern given the result will vary,
although uncommon, based on the address passed in?  A user would see
different behaviour based on where the address lands in the virtual
address space.

>  Just a concern I have, with 0 evidence behind it, so I hope it turns
> out not to be an actual issue.
> 
> Acked-by: Michel Lespinasse <walken@google.com>
> 
> On Thu, Apr 1, 2021 at 12:51 PM Liam Howlett <liam.howlett@oracle.com> wrote:
> >
> > find_vma() will continue to search upwards until the end of the virtual
> > memory space.  This means the si_code would almost never be set to
> > SEGV_MAPERR even when the address falls outside of any VMA.
> >
> > Using find_vma_intersection() allows for what is intended by only
> > returning a VMA if it falls within the range provided, in this case a
> > window of 1.
> >
> > Signed-off-by: Liam R. Howlett <Liam.Howlett@Oracle.com>
> > ---
> >  arch/alpha/kernel/traps.c | 4 +++-
> >  1 file changed, 3 insertions(+), 1 deletion(-)
> >
> > diff --git a/arch/alpha/kernel/traps.c b/arch/alpha/kernel/traps.c
> > index 921d4b6e4d95..7f51386c06d0 100644
> > --- a/arch/alpha/kernel/traps.c
> > +++ b/arch/alpha/kernel/traps.c
> > @@ -957,8 +957,10 @@ do_entUnaUser(void __user * va, unsigned long opcode,
> >                 si_code = SEGV_ACCERR;
> >         else {
> >                 struct mm_struct *mm = current->mm;
> > +               unsigned long addr = (unsigned long)va;
> > +
> >                 mmap_read_lock(mm);
> > -               if (find_vma(mm, (unsigned long)va))
> > +               if (find_vma_intersection(mm, addr, addr + 1))
> >                         si_code = SEGV_ACCERR;
> >                 else
> >                         si_code = SEGV_MAPERR;
> > --
> > 2.30.0
> 
> 
> 
> -- 
> Michel "Walken" Lespinasse
> A program is never fully debugged until the last user dies.

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-04-02 13:05 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-01 19:51 [PATCH] alpha/kernel/traps: Use find_vma_intersection() in traps for setting si_code Liam Howlett
2021-04-01 20:25 ` Michel Lespinasse
2021-04-02 13:05   ` Liam Howlett

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).