lkml.org 
[lkml]   [2011]   [Feb]   [27]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
From
SubjectRe: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccess
Date
On Sunday 27 February 2011, Guan Xuetao wrote:
> > -----Original Message-----
> > From: Arnd Bergmann [mailto:arnd@arndb.de]
> > Sent: Friday, February 18, 2011 1:45 AM
> > To: Guan Xuetao
> > Cc: linux-kernel@vger.kernel.org; linux-arch@vger.kernel.org; 'Greg KH'
> > Subject: Re: [PATCH 05/12] unicore32 additional architecture files: low-level lib: uaccess
> >
> > On Wednesday 16 February 2011, Guan Xuetao wrote:
> > > +
> > > +#define __kernel_ok (segment_eq(get_fs(), KERNEL_DS))
> > > +#define __user_ok(addr, size) (((size) <= TASK_SIZE) \
> > > + && ((addr) <= TASK_SIZE - (size)))
> > > +#define __access_ok(addr, size) (__kernel_ok || __user_ok((addr), (size)))
> >
> > A nice trick to simplify this is to introduce a per-process variable for comparing
> > the pointer, set_fs() then sets this variable to either TASK_SIZE or
> > UINT_MAX.
>
> Perhaps like this:
> 1. add a member named kaddr in thread_info
> 2. add following assignment codes in set_fs:
> current_thread_info()->kaddr = segment_eq(fs, KERNEL_DS) ? UINT_MAX : TASK_SIZE;
> 3. then __access_ok will be:
> #define addr
> #define __access_ok(addr, size) (((size) <= TASK_SIZE) \
> && ((addr) <= current_thread_info()->kaddr) - (size)))

That would also work. What I meant was to have

#define set_fs(fs) \
do { current_thread_info()->kaddr = (fs); } while (0)

#define KERNEL_DS UINT_MAX
#define USER_DS TASK_SIZE

Either way is fine with me, just choose whichever works best for you in terms of code size.

Arnd



\
 
 \ /
  Last update: 2011-02-28 00:47    [W:0.047 / U:0.324 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site