From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 19056 invoked from network); 25 Oct 1999 01:24:19 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 25 Oct 1999 01:24:19 -0000 Received: from note.orchestra.cse.unsw.EDU.AU (note.orchestra.cse.unsw.EDU.AU [129.94.242.29]) by mail.redhat.com (8.8.7/8.8.7) with SMTP id VAA30326 for ; Sun, 24 Oct 1999 21:24:17 -0400 Received: From ganter With LocalMail ; Mon, 25 Oct 99 11:22:03 +1000 From: Luke Deller To: axp-list@redhat.com Date: Mon, 25 Oct 1999 11:22:03 +1000 (EST) X-Sender: luked@ganter.disy.cse.unsw.EDU.AU Reply-To: Luke Deller cc: Daniel Paul Potts Subject: Re: patch_v3: emulating missing instructions on Alpha In-Reply-To: <19991023135544.B15599@twiddle.net> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII 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