Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Luke Deller <luked@cse.unsw.edu.au>
To: axp-list@redhat.com
Cc: Daniel Paul Potts <danielp@cse.unsw.edu.au>
Subject: Re: patch_v3: emulating missing instructions on Alpha
Date: Mon, 25 Oct 1999 11:22:03 +1000 (EST)	[thread overview]
Message-ID: <Pine.OSF.3.95.991025103821.27250H-100000@ganter.disy.cse.unsw.EDU.AU> (raw)
In-Reply-To: <19991023135544.B15599@twiddle.net>

On Sat, 23 Oct 1999, Richard Henderson wrote:

> On Fri, Oct 22, 1999 at 02:23:22AM +1000, Luke Deller wrote:
> > +	srl	$0,LOG2_TASKSIZE,$5 /* if addr is not in userland, */
> > +	cmovne	$5,$31,$0       /* then force a segfault by putting addr=0 */
> > +	ldq_u	$3,0($0)
> > +	ldq_u	$5,1($0)
> 
> This is not sufficient to be safe.  Examine the extended
> measures taken by the uaccess.h code.

Actually I wrote this code after reading include/asm-alpha/uaccess.h ..
I must be missing something.  Let me explain why I think this is safe, then
you can point out where I'm mistaken :)

First let me acknowledge that I need to put some entries in the __ex_table
section for a segfault here to be handled correctly as a user-level segfault
(resulting in a SIGSEGV being sent) rather than a kernel bug segfault
(resulting in the user process being killed).  However this is not a
security hole; merely error handling that's too heavy handed (that I can
fix soon).

Now, the macro for reading from user memory in uaccess.h is:
  #define get_user(x,ptr) \
    __get_user_check((x),(ptr),sizeof(*(ptr)),get_fs())

and the macro __get_user_check does its security check by calling:
  __access_ok((long)__gu_addr,size,segment)

which is defined as:
  #define __access_ok(addr,size,segment) \
          (((segment).seg & (addr | size | (addr+size))) == 0)

Now "segment" in this last line is obtained from the "get_fs()" macro
which according to comments at the top of uaccess.h should be equal
to USER_DS or KERNEL_DS:
  #define KERNEL_DS       ((mm_segment_t) { 0UL })
  #define USER_DS         ((mm_segment_t) { -0x40000000000UL })

By inspecting the code for __access_ok, I see that checking is only
performed if get_fs()==USER_DS.  So the check performed for reading from
user space is:

(0xfffffc0000000000UL & (addr | size | (addr+size))) == 0

[ Strictly speaking I think the check should use (addr+size-1) rather than
  (addr+size), but it's probably not worth the extra cycle ]

According to this check, userland addresses must have the most significant
22 bits equal to zero.  For size==1 and size==2, I'll simplify the check
to:

(0xfffffc0000000000UL & addr) == 0
or equivalently: (addr >> 42) == 0

This is no problem for size==1; but for size==2 it allows the user to access
the byte at address 0x400000000000.  However I believe that this is no
problem since the kernel seems to use only addresses from
0xfffffc0000000000 and above.  Would you agree?

So can you see a hole in my understanding?
Thanks for your help,
- Luke


  parent reply	other threads:[~1999-10-25  1:24 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-10-18 14:46 patch_v2: (on Alpha) emulating missing instructions Robert Harley
1999-10-18 15:31 ` Phil Carmody
1999-10-23 20:39   ` Richard Henderson
1999-10-21 16:23 ` patch_v3: emulating missing instructions on Alpha Luke Deller
1999-10-23 20:55   ` Richard Henderson
1999-10-24  0:28     ` Daniel Potts
1999-10-25  1:22     ` Luke Deller [this message]
1999-10-28 23:34       ` Richard Henderson
  -- strict thread matches above, loose matches on Subject: below --
1999-01-13 14:10 Alpha 21264 Andy Almond
1999-01-13 16:36 ` Jeff Sturm
1999-01-14  6:50   ` Richard Henderson
1999-01-12  3:55 rpcc Christoph Dworzak
1999-01-12  3:20 ` rpcc Peter Petrakis
1999-01-12  4:59 ` rpcc Richard Henderson
     [not found]   ` <rth@twiddle.net>
1999-01-12 16:59     ` rpcc Christoph Dworzak
1999-01-12 19:27       ` rpcc Richard Henderson
1999-01-12 21:06         ` rpcc Wes Bauske
1999-01-13  2:16           ` rpcc Richard Henderson
1999-01-14 16:17     ` Alpha 21264 Christoph Dworzak
1999-01-14 15:46       ` Greg Lindahl
1999-01-14 17:27       ` Richard Henderson
1999-10-24 15:04     ` patch_v2: (on Alpha) emulating missing instructions Christoph Dworzak
1999-10-25  9:47       ` Phil Carmody
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox